]> ToastFreeware Gitweb - toast/airingbutler.git/commitdiff
annotate-output now accepts a datetime format, so let's use it
authorgregor herrmann <gregor@toastfreeware.priv.at>
Sat, 21 Sep 2024 23:17:15 +0000 (01:17 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Sat, 21 Sep 2024 23:17:15 +0000 (01:17 +0200)
update plot_mhz19.py to expect useful datetime values and remove startdate
arg

Makefile
plot_mhz19.py

index ad71d101f3661ef50b1c6655b86ce43ebd4ccd7c..cfcd0f38a9edcccde12841800d64596372978513 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,11 +20,10 @@ all: $(CURDIR)
 log.csv: log
        cp $< $@
        fromdos $@
-       sed -i -e '/Started/ d' -e '/Finished/ d' -e '/error: / d' -e '/-[0-9]/ d' -e '/^I: / d' -e 's/ O: /,/g' $@
+       sed -i -e '/Started/ d' -e '/Finished/ d' -e '/error: / d' -e '/,-[0-9]/ d' -e '/^I: / d' -e 's/ O: /,/g' $@
        perl -ni -e 'BEGIN{$$i=0}; print if ($$_ !~ /CO2/ || $$i == 0); $$i++;' $@
 
-STARTDATE=$(shell date "+%F" --date @$$(stat --format "%Y" $$(find -name "log-*.gz" | sort | tail -n 1)))
 plot: log.csv
-       ./plot_mhz19.py --startdate $(STARTDATE) $<
+       ./plot_mhz19.py $<
 
 .PHONY: log.csv plot
index defb0da640ee66956c9bfb5b3b0ec764703c5c11..7d53481d34b141b33198380d6b5d86ab249b89d0 100755 (executable)
@@ -6,24 +6,18 @@ from datetime import datetime, date, timedelta
 from matplotlib import pyplot as plt
 
 '''
+# annotate-output +"%F %T" ./log_mhz19.py -d /dev/arduino | tee -a log
 filename = 'log.csv'
 Time,TS,CO2,Temp
-21:02:02,0,661,24
-21:02:08,5021,657,24
-
+2024-09-22 01:08:15,279472,1578,24
+2024-09-22 01:08:20,284518,1577,24
 '''
 
-def parsedatetime(timevalue, currentdate):
-    dt = datetime.strptime(timevalue, '%H:%M:%S')
-    return datetime.combine(currentdate, dt.time())
-
 def main():
     parser = argparse.ArgumentParser('Plot log.csv.')
     parser.add_argument('filename', nargs='?', default='log.csv', help='Name of csv file')
-    parser.add_argument('-s', '--startdate', nargs='?', default='2020-10-22', help='First date in csv file')
     parser.add_argument('-t', '--temperature', action='store_true', help='Include temperature plot')
     args = parser.parse_args()
-    startdate = datetime.strptime(args.startdate, '%Y-%m-%d').date()
 
     with open(args.filename) as f:
         reader = csv.reader(f)
@@ -33,9 +27,8 @@ def main():
         co2 = []
         temp = []
         for row in reader:
-            dt = parsedatetime(row[0], startdate)
+            dt = datetime.strptime(row[0], '%Y-%m-%d %H:%M:%S')
             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]))