comparison web/log.py @ 68:a26da94f3164

merge
author Matt Johnston <matt@ucc.asn.au>
date Tue, 26 Jun 2012 23:49:31 +0800
parents 46c43e13a759
children a8ff20f15734
comparison
equal deleted inserted replaced
66:c5ad12670cae 68:a26da94f3164
8 import tempfile 8 import tempfile
9 import time 9 import time
10 import syslog 10 import syslog
11 import sqlite3 11 import sqlite3
12 import traceback 12 import traceback
13 import datetime
13 from colorsys import hls_to_rgb 14 from colorsys import hls_to_rgb
14 15
15 import config 16 import config
16 17
17 def sensor_rrd_path(s): 18 def sensor_rrd_path(s):
69 width = config.LINE_WIDTH 70 width = config.LINE_WIDTH
70 legend = config.SENSOR_NAMES.get(sensor, sensor) 71 legend = config.SENSOR_NAMES.get(sensor, sensor)
71 colour = config.SENSOR_COLOURS.get(legend, colour_from_string(sensor)) 72 colour = config.SENSOR_COLOURS.get(legend, colour_from_string(sensor))
72 graph_args.append('LINE%(width)f:%(vname)s#%(colour)s:%(legend)s' % locals()) 73 graph_args.append('LINE%(width)f:%(vname)s#%(colour)s:%(legend)s' % locals())
73 74
75 end = int(start+length)
76 start = int(start)
77
74 tempf = tempfile.NamedTemporaryFile() 78 tempf = tempfile.NamedTemporaryFile()
75 args = [tempf.name, '-s', str(int(start)), 79 dateformat = '%H:%M:%S %Y-%m-%d'
76 '-e', str(int(start+length)), 80 watermark = ("Now %s\t"
81 "Start %s\t"
82 "End %s" % (
83 datetime.datetime.now().strftime(dateformat),
84 datetime.datetime.fromtimestamp(start).strftime(dateformat),
85 datetime.datetime.fromtimestamp(end).strftime(dateformat) ))
86
87 args = [tempf.name, '-s', str(start),
88 '-e', str(end),
77 '-w', str(config.GRAPH_WIDTH), 89 '-w', str(config.GRAPH_WIDTH),
78 '-h', str(config.GRAPH_HEIGHT), 90 '-h', str(config.GRAPH_HEIGHT),
79 '--slope-mode', 91 '--slope-mode',
80 '--border', '0', 92 '--border', '0',
81 '--vertical-label', 'Temperature', 93 '--vertical-label', 'Temperature',
82 '--y-grid', '1:1', 94 '--y-grid', '1:1',
83 '--grid-dash', '1:0', 95 '--grid-dash', '1:0',
84 '--color', 'GRID#00000000', 96 '--color', 'GRID#00000000',
85 '--color', 'MGRID#aaaaaa', 97 '--color', 'MGRID#aaaaaa',
86 '--color', 'BACK#ffffff', 98 '--color', 'BACK#ffffff',
99 '--disable-rrdtool-tag',
87 'VRULE:%d#ee0000' % time.time(), 100 'VRULE:%d#ee0000' % time.time(),
101 '--watermark', watermark,
88 '--imgformat', 'PNG'] \ 102 '--imgformat', 'PNG'] \
89 + graph_args 103 + graph_args
90 args += ['--font', 'DEFAULT:11:%s' % config.GRAPH_FONT] 104 args += ['--font', 'DEFAULT:12:%s' % config.GRAPH_FONT]
91 args += ['--font', 'WATERMARK:6:%s' % config.GRAPH_FONT] 105 args += ['--font', 'WATERMARK:10:%s' % config.GRAPH_FONT]
92 if have_volts: 106 if have_volts:
93 args += ['--right-axis', '0.1:2', # matches the scalevolts CDEF above 107 args += ['--right-axis', '0.1:2', # matches the scalevolts CDEF above
94 '--right-axis-format', '%.2lf', 108 '--right-axis-format', '%.2lf',
95 '--right-axis-label', 'Voltage'] 109 '--right-axis-label', 'Voltage']
96 110