Mercurial > ~darius > hgwebdir.cgi > beermon.old
view logplot.py @ 10:a1e7bb27f6d5
Logfile plotter
author | darius |
---|---|
date | Sat, 29 Sep 2007 14:40:33 +0000 |
parents | |
children | de698afbe6fc |
line wrap: on
line source
#!/usr/bin/env python import re, datetime, time, pylab, matplotlib daterestr = '([0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}): ' targtre = re.compile(daterestr + 'target temperature - (-?[0-9]+\.[0-9]+)') linere = re.compile(daterestr + '(-?[0-9]+\.[0-9]+)\s+(-?[0-9]+\.[0-9]+)\s+(-?[0-9]+\.[0-9]+)\s+([a-z-]+)\s+([a-z-]+)') datefmt = '%Y/%m/%d %H:%M:%S' tz = matplotlib.pytz.timezone('Australia/Adelaide') targetTemp = 18.0 logfile = '/tmp/beermon.log' start = time.mktime(time.strptime("2007/09/24 00:00:00", datefmt)) #end = time.mktime(time.strptime("2007/09/28 00:00:00", datefmt)) end = None f = open(logfile) times = [] fermTemps = [] fridgeTemps = [] ambTemps = [] states = [] targetTemps = [] for line in f: m = linere.match(line) if (m == None): m = targtre.match(line) if (m != None): t = time.mktime(time.strptime(m.group(1), datefmt)) if (t < start or t > end): continue targetTemp = float(m.group(2)) continue else: continue t = time.mktime(time.strptime(m.group(1), datefmt)) if (start != None and t < start): continue if (end != None and t > end): continue fermTemp = float(m.group(2)) fridgeTemp = float(m.group(3)) ambTemp = float(m.group(4)) state = m.group(5) times.append(t / (24 * 60 * 60)) # Is in float days fermTemps.append(fermTemp) fridgeTemps.append(fridgeTemp) ambTemps.append(ambTemp) states.append(state) targetTemps.append(targetTemp) print "From %s to %s" % (time.asctime(time.localtime(times[0] * (24 * 60 * 60))), time.asctime(time.localtime(times[-1] * (24 * 60 * 60)))) fig = pylab.figure() ax = fig.add_subplot(111) p = ax.plot(times, fermTemps, times, fridgeTemps, times, ambTemps, times, targetTemps) ax.set_autoscale_on(True) hoursFmt = pylab.DateFormatter('%d %b %H:%M', tz = tz) ax.xaxis.set_major_formatter(hoursFmt) labels = ax.get_xticklabels() pylab.setp(labels, 'rotation', 5.0) ax.grid(True) ax.set_xlabel('time(UTC)') ax.set_ylabel('Temperature(C)') pylab.legend((p[0], p[1], p[2], p[3]), ('Fermenter', 'Fridge', 'Ambient', 'Target'), 'best') #pylab.legend((p[0], p[1], p[2]), ('Fermenter', 'Fridge', 'Ambient'), 'best') #pylab.axhline(y = targetTemp) pylab.show()