From: gregor herrmann Date: Sun, 25 Oct 2020 18:38:46 +0000 (+0100) Subject: fix datetime in plot X-Git-Url: https://git.toastfreeware.priv.at/toast/airingbutler.git/commitdiff_plain/cf26fcd56b445bf8e4cb1121408a1706fcd1009c?ds=sidebyside;hp=965b869664a58ba0ee86250d06115311f1b712b5 fix datetime in plot --- diff --git a/plot_mhz19.py b/plot_mhz19.py index fc3976a..0e68605 100755 --- a/plot_mhz19.py +++ b/plot_mhz19.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import csv +from datetime import datetime, date, timedelta from matplotlib import pyplot as plt filename = 'log.csv' @@ -10,20 +11,29 @@ Time,TS,CO2,Temp 21:02:08,5021,657,24 ''' + +def parsedatetime(timevalue, currentdate): + dt = datetime.strptime(timevalue, '%H:%M:%S') + return datetime.combine(currentdate, dt.time()) + with open(filename) as f: reader = csv.reader(f) headers = next(reader) time = [] co2 = [] + startdate = date(2020, 10, 22) for row in reader: - time.append(row[0]) + dt = parsedatetime(row[0], startdate) + if len(time) > 0 and dt - time[-1] < timedelta(hours=-2): # DST switch! + startdate += timedelta(days=1) + dt += timedelta(days=1) + time.append(dt) co2.append(int(row[2])) - fig = plt.figure(dpi = 128, figsize = (10,6)) - plt.plot(co2, c = 'red') - plt.title('CO₂', fontsize = 24) - plt.xlabel('',fontsize = 16) - plt.ylabel('ppm', fontsize = 16) - plt.tick_params(axis = 'both', which = 'major', labelsize = 16) + plt.plot(time, co2, c = 'red') + plt.title('CO₂') + plt.xlabel('time') + plt.ylabel('ppm') + plt.tick_params(axis = 'both', which = 'major') plt.show()