From d48715b967e7ba5bf87fe2df8ff31654cfb35b18 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Tue, 12 Apr 2016 02:12:00 -0400 Subject: Adding code to draw graphs sensor.py starting pygal graph draws not working templates/ removed references to login.html added place for graph to go --- sensor.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'sensor.py') diff --git a/sensor.py b/sensor.py index a0123d0..8d1e000 100644 --- a/sensor.py +++ b/sensor.py @@ -3,6 +3,7 @@ import sqlite3 from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash from contextlib import closing from datetime import datetime +import pygal # configuration DATABASE = '/tmp/sensors.db' @@ -42,7 +43,14 @@ def teardown_request(exception): def show_entries(): cur = g.db.execute('SELECT date, temperature, humidity, pressure FROM weather ORDER BY id desc') entries = [dict(date=row[0], temperature=row[1], humidity=row[2], pressure=row[3]) for row in cur.fetchall()] - return render_template('show_entries.html', weather=entries) + + 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", [(row[0], row[1]) for row in cur.fetchall()]) + + return render_template('show_entries.html', wgraph=datetimeline, weather=entries) # adding entries to database @app.route('/data', methods=['POST']) -- cgit v1.2.3