From 37f2eae6fd14cca338015ddf7a50df0e3562c91f Mon Sep 17 00:00:00 2001 From: gregor herrmann Date: Sun, 22 Sep 2024 01:17:15 +0200 Subject: [PATCH] annotate-output now accepts a datetime format, so let's use it update plot_mhz19.py to expect useful datetime values and remove startdate arg --- Makefile | 5 ++--- plot_mhz19.py | 15 ++++----------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index ad71d10..cfcd0f3 100644 --- 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 diff --git a/plot_mhz19.py b/plot_mhz19.py index defb0da..7d53481 100755 --- a/plot_mhz19.py +++ b/plot_mhz19.py @@ -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])) -- 2.39.5