aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--sensor.py31
-rw-r--r--templates/show_entries.html8
2 files changed, 35 insertions, 4 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()
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 %}