From 9402cf8ffe972496408ae7542a296fe7266f563e Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Wed, 13 Apr 2016 16:53:51 -0400 Subject: Added graphs sensor.py added routes to draw additional graphs fixed problem reading datetime from database show_entries.html added additional figures for graphs --- sensor.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'sensor.py') diff --git a/sensor.py b/sensor.py index 1a6614d..b21d51f 100644 --- a/sensor.py +++ b/sensor.py @@ -46,15 +46,40 @@ def show_entries(): return render_template('show_entries.html', weather=entries) -@app.route('/wgraph.svg') -def weather_route(): +# drawing graphs +@app.route('/tgraph.svg') +def draw_t_graph(): cur = g.db.execute('SELECT date, temperature, humidity, pressure FROM weather ORDER BY id desc') datetimeline = pygal.DateTimeLine( x_label_rotation=30, truncate_label=-1, x_value_formatter=lambda dt: dt.strftime('%d, %b %Y %I:%M %p') ) - datetimeline.add("Temp F", [(datetime.strptime(row[0], '%Y-%m-%d %I:%M:%S.%f'), float(row[1])) for row in cur.fetchall()]) + datetimeline.add("Temp", [(datetime.strptime(row[0], '%Y-%m-%d %H:%M:%S.%f'), float(row[1])) for row in cur.fetchall()]) + + return datetimeline.render_response() + +@app.route('/hgraph.svg') +def draw_h_graph(): + cur = g.db.execute('SELECT date, temperature, humidity, pressure FROM weather ORDER BY id desc') + + datetimeline = pygal.DateTimeLine( + x_label_rotation=30, truncate_label=-1, + x_value_formatter=lambda dt: dt.strftime('%d, %b %Y %I:%M %p') + ) + datetimeline.add("Humidity", [(datetime.strptime(row[0], '%Y-%m-%d %H:%M:%S.%f'), float(row[2])) for row in cur.fetchall()]) + + return datetimeline.render_response() + +@app.route('/pgraph.svg') +def draw_p_graph(): + cur = g.db.execute('SELECT date, temperature, humidity, pressure FROM weather ORDER BY id desc') + + datetimeline = pygal.DateTimeLine( + x_label_rotation=30, truncate_label=-1, + x_value_formatter=lambda dt: dt.strftime('%d, %b %Y %I:%M %p') + ) + datetimeline.add("Pressure", [(datetime.strptime(row[0], '%Y-%m-%d %H:%M:%S.%f'), float(row[3])) for row in cur.fetchall()]) return datetimeline.render_response() -- cgit v1.2.3