526c975d8f75fe91ec9db698768ee60151c2917c
[toast/airingbutler.git] / plot_mhz19.py
1 #!/usr/bin/python3
2
3 import csv
4 from datetime import datetime, date, timedelta
5 from matplotlib import pyplot as plt
6
7 filename = 'log.csv'
8 '''
9 Time,TS,CO2,Temp
10 21:02:02,0,661,24
11 21:02:08,5021,657,24
12
13 '''
14
15 def parsedatetime(timevalue, currentdate):
16     dt = datetime.strptime(timevalue, '%H:%M:%S')
17     return datetime.combine(currentdate, dt.time())
18
19 with open(filename) as f:
20     reader = csv.reader(f)
21     headers = next(reader)
22
23     time = []
24     co2 = []
25     temp = []
26     startdate = date(2020, 10, 22)
27     for row in reader:
28         dt = parsedatetime(row[0], startdate)
29         if len(time) > 0 and dt - time[-1] < timedelta(hours=-2): # DST switch!
30             startdate += timedelta(days=1)
31             dt += timedelta(days=1)
32         time.append(dt)
33         co2.append(int(row[2]))
34         temp.append(int(row[3]))
35
36     plt.plot(time, co2, c = 'red')
37     plt.title('CO₂')
38     plt.xlabel('time')
39     plt.ylabel('ppm')
40     plt.tick_params(axis = 'both', which = 'major')
41     plt.gca().twinx()
42     plt.plot(time, temp, c = 'blue')
43     plt.show()