aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2016-04-12 02:12:00 -0400
committerMatt Kohls <mattkohls13@gmail.com>2016-04-12 02:12:00 -0400
commitd48715b967e7ba5bf87fe2df8ff31654cfb35b18 (patch)
tree123a482c4bfe9149fa22ad81347e263e158fa087
parent614562bf2cf048b049af5304fead92a46f080d3e (diff)
downloadSensor-Server-d48715b967e7ba5bf87fe2df8ff31654cfb35b18.tar.gz
Sensor-Server-d48715b967e7ba5bf87fe2df8ff31654cfb35b18.tar.bz2
Sensor-Server-d48715b967e7ba5bf87fe2df8ff31654cfb35b18.zip
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
-rw-r--r--sensor.py10
-rw-r--r--templates/layout.html5
-rw-r--r--templates/show_entries.html14
3 files changed, 10 insertions, 19 deletions
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'])
diff --git a/templates/layout.html b/templates/layout.html
index 0f32195..2a06690 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -4,11 +4,6 @@
<div class=page>
<h1>Weather</h1>
<div class=metanav>
- {% if not session.logged_in %}
- <a href="{{ url_for('login') }}">log in</a>
- {% else %}
- <a href="{{ url_for('logout') }}">log out</a>
- {% endif %}
</div>
{% for message in get_flashed_messages() %}
<div class=flash>{{ message }}</div>
diff --git a/templates/show_entries.html b/templates/show_entries.html
index 5d9ff1a..1f18d68 100644
--- a/templates/show_entries.html
+++ b/templates/show_entries.html
@@ -1,18 +1,6 @@
{% extends "layout.html" %}
{% block body %}
- {% if session.logged_in %}
- <form action="{{ url_for('add_entry') }}" method=post class=add-entry>
- <dl>
- <dt>Temperature:
- <dd><input type=number size=30 name=temperature>
- <dt>Humidity:
- <dd><input type=number size=30 name=humidity>
- <dt>Pressure:
- <dd><input type=number size=30 name=pressure>
- <dd><input type=submit value=Submit>
- </dl>
- </form>
- {% endif %}
+ {{ wgraph.render()|safe }}
<ul class=weather>
{% for entry in weather %}
<li><h2>{{ entry.date }}</h2>Temp: {{ entry.temperature }}, Humidity: {{ entry.humidity }}, Pressure: {{ entry.pressure }}