aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2016-04-13 01:59:10 -0400
committerMatt Kohls <mattkohls13@gmail.com>2016-04-13 01:59:10 -0400
commit83da2a713548629fed8268d53793178ea84a81f2 (patch)
treebca41eb28cacd3cb8ec8ee54e7fdebdc0585a577
parentb34f83f65e4d2f74844d19a4974f96143fdd8136 (diff)
downloadSensor-Server-83da2a713548629fed8268d53793178ea84a81f2.tar.gz
Sensor-Server-83da2a713548629fed8268d53793178ea84a81f2.tar.bz2
Sensor-Server-83da2a713548629fed8268d53793178ea84a81f2.zip
Graph plotting data
sensor.py plots temperature data to graph
-rw-r--r--sensor.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/sensor.py b/sensor.py
index 2e6c46c..1a6614d 100644
--- a/sensor.py
+++ b/sensor.py
@@ -8,7 +8,7 @@ import pygal
# configuration
DATABASE = '/tmp/sensors.db'
DEBUG = True
-SECRET_KEY = 'development key'
+SECRET_KEY = 'development_key'
# app creation
app = Flask(__name__)
@@ -44,14 +44,6 @@ 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()]
- # 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()])
- # datetimeline.render_response()
-
- # return render_template('show_entries.html', wgraph=datetimeline, weather=entries)
return render_template('show_entries.html', weather=entries)
@app.route('/wgraph.svg')
@@ -62,13 +54,13 @@ def weather_route():
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()])
+ datetimeline.add("Temp F", [(datetime.strptime(row[0], '%Y-%m-%d %I:%M:%S.%f'), float(row[1])) for row in cur.fetchall()])
return datetimeline.render_response()
# adding entries to database
-@app.route('/data', methods=['POST'])
+@app.route('/data', methods=['POST', 'GET'])
def add_data():
mkey = request.args.get('key')
if mkey != SECRET_KEY:
@@ -80,7 +72,7 @@ def add_data():
g.db.execute('INSERT INTO weather (date, temperature, humidity, pressure) VALUES (?, ?, ?, ?)', \
[now, temp, humidity, pressure])
g.db.commit()
- return 200
+ return render_template('show_entries.html'), 200
if __name__ == '__main__':