Skip to content

Commit

Permalink
Fix some bugs when changing the host
Browse files Browse the repository at this point in the history
  • Loading branch information
twzjwang committed Jun 19, 2018
1 parent 040fd7a commit 78b54d3
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 36 deletions.
16 changes: 10 additions & 6 deletions api/all_sensor_latest_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ def get_all_sensor_latest_data():
epoch = []
device_id = ''
for tx in claim_list:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[4]
sensor_data.extend(decode(msg)[0])
epoch.extend(decode(msg)[1])
device_id = split(response.text)[4].split('|')[4]
try:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[5]
msg = msg[11:len(msg)-1]
sensor_data.extend(decode(msg)[0])
epoch.extend(decode(msg)[1])
device_id = msg.split('|')[4]
except (IndexError):
pass
latest_data_epoch = 0
latest_data_string = ''
for i in range(0, len(epoch)):
Expand Down
2 changes: 1 addition & 1 deletion api/config.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
HOST_URL = 'http://node0.puyuma.org/tangleid_backend/api/'
HOST_URL = 'http://node3.puyuma.org:8000'
14 changes: 9 additions & 5 deletions api/specific_sensor_all_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ def get_specific_sensor_all_data(uuid):
sensor_data = []
device_id = ''
for tx in claim_list:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[4]
sensor_data.extend(decode(msg)[0])
device_id = split(response.text)[4].split('|')[4]
try:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[5]
msg = msg[11:len(msg)-1]
sensor_data.extend(decode(msg)[0])
device_id = msg.split('|')[4]
except (IndexError):
pass
sensor_data_string = ''
for string in sensor_data:
sensor_data_string += string
Expand Down
16 changes: 10 additions & 6 deletions api/specific_sensor_date_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ def get_specific_sensor_date_data(uuid, date):
epoch = []
device_id = ''
for tx in claim_list:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[4]
sensor_data.extend(decode(msg)[0])
epoch.extend(decode(msg)[1])
device_id = split(response.text)[4].split('|')[4]
try:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[5]
msg = msg[11:len(msg)-1]
sensor_data.extend(decode(msg)[0])
epoch.extend(decode(msg)[1])
device_id = msg.split('|')[4]
except (IndexError):
pass
epoch_a = time.mktime(datetime.datetime.strptime(date, "%Y-%m-%d").timetuple())
epoch_b = epoch_a + 86400
history_data = []
Expand Down
16 changes: 10 additions & 6 deletions api/specific_sensor_history_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ def get_specific_sensor_history_data(uuid):
epoch = []
device_id = ''
for tx in claim_list:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[4]
sensor_data.extend(decode(msg)[0])
epoch.extend(decode(msg)[1])
device_id = split(response.text)[4].split('|')[4]
try:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[5]
msg = msg[11:len(msg)-1]
sensor_data.extend(decode(msg)[0])
epoch.extend(decode(msg)[1])
device_id = msg.split('|')[4]
except (IndexError):
pass
week_epoch = calendar.timegm(time.gmtime()) - 604800
history_data = []
for i in range(0, len(epoch)):
Expand Down
16 changes: 10 additions & 6 deletions api/specific_sensor_latest_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ def get_specific_sensor_latest_data(uuid):
epoch = []
device_id = ''
for tx in claim_list:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[4]
sensor_data.extend(decode(msg)[0])
epoch.extend(decode(msg)[1])
device_id = split(response.text)[4].split('|')[4]
try:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
msg = split(response.text)[5]
msg = msg[11:len(msg)-1]
sensor_data.extend(decode(msg)[0])
epoch.extend(decode(msg)[1])
device_id = msg.split('|')[4]
except (IndexError):
pass
latest_data_epoch = 0
latest_data_string = ''
for i in range(0, len(epoch)):
Expand Down
2 changes: 1 addition & 1 deletion api/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
print('Input (type):\tuuid (string), date y-m-d (string)')
print('Output (type):\tsensor data (json)\n')
uuid = 'LASSPBUAUAXABBMBOBAB'
date = '2018-05-21'
date = '2018-06-18'
print(get_specific_sensor_date_data(uuid, date))

print('\n\n\n***** Test : get_all_sensor_latest_data() *****\n')
Expand Down
14 changes: 9 additions & 5 deletions api/uuid_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ def get_uuid_list():
claim_list = response.json()
uuid_list = []
for tx in claim_list:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
uuid = split(response.text)[4]
if uuid not in uuid_list:
uuid_list.append(uuid)
try:
payload = {'command':'get_claim_info', 'hash_txn':tx}
response = requests.post(HOST_URL, json=payload)
uuid = split(response.text)[5]
uuid = uuid[11:len(uuid)-1]
if uuid not in uuid_list:
uuid_list.append(uuid)
except (IndexError):
pass
return uuid_list

0 comments on commit 78b54d3

Please sign in to comment.