From 32efa9dbd85e03881ac8ac2c9e2a3d61e48f26d1 Mon Sep 17 00:00:00 2001 From: tony Date: Sun, 12 Jan 2025 20:25:25 -0700 Subject: [PATCH] apply float nan fallback conversion to all float converstions --- data.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/data.py b/data.py index a1e5a29..ab252de 100644 --- a/data.py +++ b/data.py @@ -6,7 +6,7 @@ import pickle import numpy as np -def convert_lghtng_dist(value): +def convert_float(value): try: return float(value) except: @@ -33,29 +33,29 @@ except: sensors_dict = {} datum_dict = {} -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['den_temp'] = convert_float(den_dict['intemp']) +datum_dict['den_humi'] = convert_float(den_dict['inhumi'].strip("%"))/100 +datum_dict['den_pabs'] = convert_float(den_dict['abs'].strip(" inHg")) +datum_dict['den_prel'] = convert_float(den_dict['rel'].strip(" inHg")) +datum_dict['lroom_temp'] = convert_float(lroom_dict['temp']) +datum_dict['lroom_humi'] = convert_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_temp'] = convert_float(roffice_dict['temp']) +datum_dict['roffice_humi'] = convert_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_temp'] = convert_float(toffice_dict['temp']) +datum_dict['toffice_humi'] = convert_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_temp'] = convert_float(broom_dict['temp']) +datum_dict['broom_humi'] = convert_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_temp'] = convert_float(outdoor_dict['temp']) +datum_dict['outdoor_humi'] = convert_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_dist'] = convert_float(lightning_dict['distance']) 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_scnt'] = convert_float(lightning_dict['count']) datum_dict['lghtng_batt'] = int(lightning_dict['battery']) sensors_dict[int(datetime.now().strftime('%s'))] = datum_dict