numeric value conversions

This commit is contained in:
tony 2025-01-11 14:42:38 -07:00
parent 30c55e7bc0
commit ad4dd790db

54
data.py
View File

@ -3,6 +3,14 @@ import ast
from datetime import datetime
from time import sleep
import pickle
import numpy as np
def convert_lghtng_dist(value):
try:
return float(value)
except:
return np.nan
data_url = "http://192.168.1.221/get_livedata_info"
@ -31,30 +39,30 @@ except:
data_dict = {}
datum_dict = {}
datum_dict['den_temp'] = den_dict['intemp']
datum_dict['den_humi'] = den_dict['inhumi']
datum_dict['den_pabs'] = den_dict['abs']
datum_dict['den_prel'] = den_dict['rel']
datum_dict['lroom_temp'] = lroom_dict['temp']
datum_dict['lroom_humi'] = lroom_dict['humidity']
datum_dict['lroom_batt'] = lroom_dict['battery']
datum_dict['roffice_temp'] = roffice_dict['temp']
datum_dict['roffice_humi'] = roffice_dict['humidity']
datum_dict['roffice_batt'] = roffice_dict['battery']
datum_dict['toffice_temp'] = toffice_dict['temp']
datum_dict['toffice_humi'] = toffice_dict['humidity']
datum_dict['toffice_batt'] = toffice_dict['battery']
datum_dict['broom_temp'] = broom_dict['temp']
datum_dict['broom_humi'] = broom_dict['humidity']
datum_dict['broom_batt'] = broom_dict['battery']
datum_dict['outdoor_temp'] = outdoor_dict['temp']
datum_dict['outdoor_humi'] = outdoor_dict['humidity']
datum_dict['outdoor_batt'] = outdoor_dict['battery']
datum_dict['lghtng_dist'] = lightning_dict['distance']
datum_dict['den_temp'] = float(den_dict['intemp'])
datum_dict['den_humi'] = float(den_dict['inhumi'].strip("%"))/100
datum_dict['den_pabs'] = float(den_dict['abs'].strip(" inHg"))
datum_dict['den_prel'] = float(den_dict['rel'].strip(" inHg"))
datum_dict['lroom_temp'] = float(lroom_dict['temp'])
datum_dict['lroom_humi'] = float(lroom_dict['humidity'].strip("%"))/100
datum_dict['lroom_batt'] = int(lroom_dict['battery'])
datum_dict['roffice_temp'] = float(roffice_dict['temp'])
datum_dict['roffice_humi'] = float(roffice_dict['humidity'].strip("%"))/100
datum_dict['roffice_batt'] = int(roffice_dict['battery'])
datum_dict['toffice_temp'] = float(toffice_dict['temp'])
datum_dict['toffice_humi'] = float(toffice_dict['humidity'].strip("%"))/100
datum_dict['toffice_batt'] = int(toffice_dict['battery'])
datum_dict['broom_temp'] = float(broom_dict['temp'])
datum_dict['broom_humi'] = float(broom_dict['humidity'].strip("%"))/100
datum_dict['broom_batt'] = int(broom_dict['battery'])
datum_dict['outdoor_temp'] = float(outdoor_dict['temp'])
datum_dict['outdoor_humi'] = float(outdoor_dict['humidity'].strip("%"))/100
datum_dict['outdoor_batt'] = int(outdoor_dict['battery'])
datum_dict['lghtng_dist'] = convert_lghtng_dist(lightning_dict['distance'])
datum_dict['lghtng_date'] = lightning_dict['date']
datum_dict['lghtng_time'] = lightning_dict['timestamp']
datum_dict['lghtng_scnt'] = lightning_dict['count']
datum_dict['lghtng_batt'] = lightning_dict['battery']
data_dict[datetime.now().strftime('%s')] = datum_dict
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)