aboutsummaryrefslogtreecommitdiffstats
path: root/sensor.py
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2016-04-13 16:53:51 -0400
committerMatt Kohls <mattkohls13@gmail.com>2016-04-13 16:53:51 -0400
commit9402cf8ffe972496408ae7542a296fe7266f563e (patch)
tree4bda2b6ac9203a4c7490d98b3eadfc09f7b05b5e /sensor.py
parent83da2a713548629fed8268d53793178ea84a81f2 (diff)
downloadSensor-Server-9402cf8ffe972496408ae7542a296fe7266f563e.tar.gz
Sensor-Server-9402cf8ffe972496408ae7542a296fe7266f563e.tar.bz2
Sensor-Server-9402cf8ffe972496408ae7542a296fe7266f563e.zip
Added graphs
sensor.py added routes to draw additional graphs fixed problem reading datetime from database show_entries.html added additional figures for graphs
Diffstat (limited to 'sensor.py')
-rw-r--r--sensor.py31
1 files changed, 28 insertions, 3 deletions
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()