diff options
author | Florian Pritz <bluewind@xinu.at> | 2013-07-28 14:25:44 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2013-07-28 14:25:44 +0200 |
commit | 281972260d0302dddd23c0012bb025e5bfb04d63 (patch) | |
tree | 1cd391f7637207bf3258733d9b0e99597e4493fa | |
parent | 47288ef2d494922f6b48a147afc80165b7444fa4 (diff) | |
download | temp-logger-master.tar.gz temp-logger-master.tar.xz |
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-x | plot.py | 79 |
1 files changed, 79 insertions, 0 deletions
@@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +# based on https://github.com/cnvogelg/ardu/blob/master/datalog/tools/plot_log.py + +import sys +import subprocess +import os + +if len(sys.argv) != 3: + print("Usage: plot.py <log> <png>", file=sys.stderr) + sys.exit(1) + +log_file = sys.argv[1] +png_file = sys.argv[2] +rrd_file = "tmp.rrd" + +create = [ + 'rrdtool','create',rrd_file,'--step','30','--start',0, + 'DS:temp:GAUGE:50:U:U', + 'RRA:AVERAGE:0.5:1:10000', + 'RRA:MIN:0.5:1:10000', + 'RRA:MAX:0.5:1:10000' +] + +graph = [ + 'rrdtool','graph',png_file, + '-s',None,'-e',None, + '--height=300','--width=750', + '--color=BACK#FFFFFF', + '--vertical-label', '°C', + '--title','Temperature', + '-l','25','-u','30', + 'DEF:temp='+rrd_file+':temp:AVERAGE', + 'LINE1:temp#3366CC' +] + +samples = [] +f = open(log_file,"r") +for line in f: + elem = line.split(' ') + temp = float(elem[1].split("=")[1]) + ts = int(elem[0]) + samples.append((ts,temp)) +f.close() + +# create rrd +start_ts = samples[0][0] +end_ts = samples[-1][0] +create[6] = str(start_ts - 1) +print("creating rrdb:",create) +ret = subprocess.call(create) +if ret != 0: + print("ERROR calling: {}".format(" ".join(create))) + sys.exit(1) + +# update rrd +n = len(samples) +for i in range(n): + print(i,n,end="\r") + sys.stdout.flush() + s = samples[i] + entry = "{}:{}".format(s[0],s[1]) + cmd = ['rrdupdate',rrd_file,'--',entry] + ret = subprocess.call(cmd) + if ret != 0: + print("ERROR calling: {}".format(" ".join(cmd))) + sys.exit(1) + +# graph +print("plotting rrdb:",graph) +graph[4] = str(start_ts) +graph[6] = str(end_ts) +ret = subprocess.call(graph) +if ret != 0: + print("ERROR calling: {}".format(" ".join(cmd))) + sys.exit(1) + +os.unlink(rrd_file) +print("done") |