Mercurial > ~darius > hgwebdir.cgi > beermon.old
comparison logplot.py @ 10:a1e7bb27f6d5
Logfile plotter
author | darius |
---|---|
date | Sat, 29 Sep 2007 14:40:33 +0000 |
parents | |
children | de698afbe6fc |
comparison
equal
deleted
inserted
replaced
9:f15019afef84 | 10:a1e7bb27f6d5 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import re, datetime, time, pylab, matplotlib | |
4 daterestr = '([0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}): ' | |
5 targtre = re.compile(daterestr + 'target temperature - (-?[0-9]+\.[0-9]+)') | |
6 linere = re.compile(daterestr + '(-?[0-9]+\.[0-9]+)\s+(-?[0-9]+\.[0-9]+)\s+(-?[0-9]+\.[0-9]+)\s+([a-z-]+)\s+([a-z-]+)') | |
7 datefmt = '%Y/%m/%d %H:%M:%S' | |
8 tz = matplotlib.pytz.timezone('Australia/Adelaide') | |
9 | |
10 targetTemp = 18.0 | |
11 logfile = '/tmp/beermon.log' | |
12 start = time.mktime(time.strptime("2007/09/24 00:00:00", datefmt)) | |
13 #end = time.mktime(time.strptime("2007/09/28 00:00:00", datefmt)) | |
14 end = None | |
15 | |
16 f = open(logfile) | |
17 | |
18 times = [] | |
19 fermTemps = [] | |
20 fridgeTemps = [] | |
21 ambTemps = [] | |
22 states = [] | |
23 targetTemps = [] | |
24 | |
25 for line in f: | |
26 m = linere.match(line) | |
27 if (m == None): | |
28 m = targtre.match(line) | |
29 if (m != None): | |
30 t = time.mktime(time.strptime(m.group(1), datefmt)) | |
31 if (t < start or t > end): | |
32 continue | |
33 | |
34 targetTemp = float(m.group(2)) | |
35 continue | |
36 else: | |
37 continue | |
38 | |
39 t = time.mktime(time.strptime(m.group(1), datefmt)) | |
40 if (start != None and t < start): | |
41 continue | |
42 | |
43 if (end != None and t > end): | |
44 continue | |
45 | |
46 fermTemp = float(m.group(2)) | |
47 fridgeTemp = float(m.group(3)) | |
48 ambTemp = float(m.group(4)) | |
49 state = m.group(5) | |
50 | |
51 times.append(t / (24 * 60 * 60)) # Is in float days | |
52 fermTemps.append(fermTemp) | |
53 fridgeTemps.append(fridgeTemp) | |
54 ambTemps.append(ambTemp) | |
55 states.append(state) | |
56 targetTemps.append(targetTemp) | |
57 | |
58 print "From %s to %s" % (time.asctime(time.localtime(times[0] * (24 * 60 * 60))), | |
59 time.asctime(time.localtime(times[-1] * (24 * 60 * 60)))) | |
60 fig = pylab.figure() | |
61 ax = fig.add_subplot(111) | |
62 p = ax.plot(times, fermTemps, times, fridgeTemps, times, ambTemps, times, targetTemps) | |
63 ax.set_autoscale_on(True) | |
64 hoursFmt = pylab.DateFormatter('%d %b %H:%M', tz = tz) | |
65 ax.xaxis.set_major_formatter(hoursFmt) | |
66 labels = ax.get_xticklabels() | |
67 pylab.setp(labels, 'rotation', 5.0) | |
68 ax.grid(True) | |
69 ax.set_xlabel('time(UTC)') | |
70 ax.set_ylabel('Temperature(C)') | |
71 pylab.legend((p[0], p[1], p[2], p[3]), ('Fermenter', 'Fridge', 'Ambient', 'Target'), 'best') | |
72 #pylab.legend((p[0], p[1], p[2]), ('Fermenter', 'Fridge', 'Ambient'), 'best') | |
73 #pylab.axhline(y = targetTemp) | |
74 pylab.show() |