diff logplot.py @ 8:cb03cea09bda

Logfile plotter
author darius
date Sat, 29 Sep 2007 14:40:33 +0000
parents
children 87d9d862ecc4
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logplot.py	Sat Sep 29 14:40:33 2007 +0000
@@ -0,0 +1,74 @@
+#!/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()