diff options
-rw-r--r-- | sensor.py | 31 | ||||
-rw-r--r-- | templates/show_entries.html | 8 |
2 files changed, 35 insertions, 4 deletions
@@ -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() diff --git a/templates/show_entries.html b/templates/show_entries.html index 5a9d989..572f360 100644 --- a/templates/show_entries.html +++ b/templates/show_entries.html @@ -1,7 +1,13 @@ {% extends "layout.html" %} {% block body %} <figure> - <embed type="image/svg+xml" src="/wgraph.svg" /> + <embed type="image/svg+xml" src="/tgraph.svg" /> + </figure> + <figure> + <embed type="image/svg+xml" src="/hgraph.svg" /> + </figure> + <figure> + <embed type="image/svg+xml" src="/pgraph.svg" /> </figure> <ul class=weather> {% for entry in weather %} |