rename data to sensors, clean up code a little
This commit is contained in:
parent
ad4dd790db
commit
d053fb28ce
42
data.py
42
data.py
@ -12,31 +12,25 @@ def convert_lghtng_dist(value):
|
||||
except:
|
||||
return np.nan
|
||||
|
||||
data_url = "http://192.168.1.221/get_livedata_info"
|
||||
sensors_url = "http://192.168.1.221/get_livedata_info"
|
||||
|
||||
data_response = requests.get(data_url)
|
||||
sensors_response = requests.get(sensors_url)
|
||||
|
||||
data_dict = ast.literal_eval(data_response.content.decode('utf-8'))
|
||||
sensors_dict = ast.literal_eval(sensors_response.content.decode('utf-8'))
|
||||
|
||||
den_dict = sensors_dict['wh25'][0]
|
||||
outdoor_dict = sensors_dict['ch_aisle'][0]
|
||||
lroom_dict = sensors_dict['ch_aisle'][1]
|
||||
roffice_dict = sensors_dict['ch_aisle'][2]
|
||||
toffice_dict = sensors_dict['ch_aisle'][3]
|
||||
broom_dict = sensors_dict['ch_aisle'][4]
|
||||
lightning_dict = sensors_dict['lightning'][0]
|
||||
|
||||
den_dict = data_dict['wh25'][0]
|
||||
outdoor_dict = data_dict['ch_aisle'][0]
|
||||
lroom_dict = data_dict['ch_aisle'][1]
|
||||
roffice_dict = data_dict['ch_aisle'][2]
|
||||
toffice_dict = data_dict['ch_aisle'][3]
|
||||
broom_dict = data_dict['ch_aisle'][4]
|
||||
lightning_dict = data_dict['lightning'][0]
|
||||
# print(den_dict.keys())
|
||||
# print(outdoor_dict.keys())
|
||||
# print(lroom_dict.keys())
|
||||
# print(roffice_dict.keys())
|
||||
# print(toffice_dict.keys())
|
||||
# print(broom_dict.keys())
|
||||
# print(lightning_dict.keys())
|
||||
try:
|
||||
with open('saved_data_dict.pkl', 'rb') as f:
|
||||
data_dict = pickle.load(f)
|
||||
with open('saved_sensors_dict.pkl', 'rb') as f:
|
||||
sensors_dict = pickle.load(f)
|
||||
except:
|
||||
data_dict = {}
|
||||
sensors_dict = {}
|
||||
|
||||
datum_dict = {}
|
||||
datum_dict['den_temp'] = float(den_dict['intemp'])
|
||||
@ -63,6 +57,8 @@ datum_dict['lghtng_date'] = lightning_dict['date']
|
||||
datum_dict['lghtng_time'] = lightning_dict['timestamp']
|
||||
datum_dict['lghtng_scnt'] = float(lightning_dict['count'])
|
||||
datum_dict['lghtng_batt'] = int(lightning_dict['battery'])
|
||||
data_dict[int(datetime.now().strftime('%s'))] = datum_dict
|
||||
with open('saved_data_dict.pkl', 'wb') as f:
|
||||
pickle.dump(data_dict, f)
|
||||
|
||||
sensors_dict[int(datetime.now().strftime('%s'))] = datum_dict
|
||||
|
||||
with open('saved_sensors_dict.pkl', 'wb') as f:
|
||||
pickle.dump(sensors_dict, f)
|
||||
|
Loading…
Reference in New Issue
Block a user