Querying the SQL
This is taken from a previous website post but the problem still remains, my home monitoring system has 4 zone with a wireless temperature sensor in each. They all wake up individually on a periodic basis and each time one sensor outputs data the main program writes an entry into the SQL database for all zones so only the sensor currently transmitting has new data and the previous readings from the other sensors are stored with the new.
What this means is that for given time period i can have a different number of readings for each zone or put another way my data export is not uniform meaning comparison of time periods is not simple
For example the following SQL select statement
python code snippet start
for row in curs.execute("SELECT * FROM home_mon WHERE DATE>(?) and DATE<(?)", ('2018-12-01', '2018-12-25')):
python code snippet end
counts 6547 rows for December 2018 whilst the same for 2019 only counts 6516 this discrepancy is larger for some other months. So to compare periods i wrote the following to get one value per hour
python code snippet start
for row in curs.execute("SELECT * FROM home_mon WHERE DATE>(?)", (yr18,)):
dat = dt.datetime.fromtimestamp(int(float(row[1]))).strftime('%Y-%m-%d %H:%M:%S')
hr = dt.datetime.fromtimestamp(int(float(row[1]))).strftime('%H:')
if dat > "2018-12-01" and dat < "2018-12-25":
if hr != pasthr18:
pasthr18 = hr
data_18.append(row[4])
if dat > "2019-12-01" and dat < "2019-12-25":
if hr != pasthr19:
pasthr19 = hr
data_19.append(row[4])
cnt = cnt + 1
x.append(cnt)
python code snippet end
The result of this is for the periods 01-12 > 25-12 in both years I get 576 values for both meaning a real comparison can now be done.