Commit 7ab004d8 authored by Kristian Tan's avatar Kristian Tan

refactor

parent 896cbea8
...@@ -74,6 +74,19 @@ def create_entry(change_pin): ...@@ -74,6 +74,19 @@ def create_entry(change_pin):
pins[change_pin]['on_date'] = None pins[change_pin]['on_date'] = None
def generate_graph_data():
# Create data for chart
count = 0
records = DailyUsage.query.order_by(asc(DailyUsage.date)).all()
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 >= 7:
break
db.create_all() db.create_all()
daily_total = get_todays_usage() daily_total = get_todays_usage()
...@@ -96,19 +109,20 @@ for pin in pins: ...@@ -96,19 +109,20 @@ for pin in pins:
labels = [] labels = []
values = [] values = []
generate_graph_data()
max = 0 max = 0
# Create data for chart # Create data for chart
count = 0 # count = 0
records = DailyUsage.query.order_by(asc(DailyUsage.date)).all() # records = DailyUsage.query.order_by(asc(DailyUsage.date)).all()
for record in records: # for record in records:
labels.append(date(record.date.year, record.date.month, record.date.day)) # labels.append(date(record.date.year, record.date.month, record.date.day))
values.append(record.kwhUsed) # values.append(record.kwhUsed)
if record.kwhUsed > max: # if record.kwhUsed > max:
max = record.kwhUsed # max = record.kwhUsed
count += 1 # count += 1
if count >= 7: # if count >= 7:
break # break
@app.route("/") @app.route("/")
def main(): def main():
......
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