Commit 6bfe542c authored by Kristian Tan's avatar Kristian Tan

Improve the way records are queried in generate_graph

parent 31eaac57
......@@ -85,18 +85,23 @@ def generate_graph_data():
max = 0
# Create data for chart
count = 0
records = DailyUsage.query.order_by(desc(DailyUsage.date)).all()
# count = 0
records = DailyUsage.query.order_by(desc(DailyUsage.date)).limit(5).all()
print(records)
for record in records:
labels.append(date(record.date.year, record.date.month, record.date.day))
values.append(record.kwhUsed)
if record.kwhUsed > max:
max = record.kwhUsed
count += 1
if count >= 5:
break
# count += 1
# if count >= 5:
# break
labels.reverse()
values.reverse()
return labels, values, max
db.create_all()
daily_total = get_todays_usage()
......@@ -119,6 +124,7 @@ for pin in pins:
labels, values, max = generate_graph_data()
@app.route("/")
def main():
# For each pin, read the pin state and store it in the pins dictionary:
......@@ -246,6 +252,7 @@ def delete_pin(delete_pin):
}
return render_template('main.html', **template_data)
@app.route("/update_info/kWh")
def change_kWh():
template_data = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment