Commit ec047040 authored by Kristian Tan's avatar Kristian Tan

Displaying daily total on html

parent 49e359c9
......@@ -83,7 +83,6 @@ def toggle_pin(change_pin):
message += " off."
if pins[change_pin]['on_time'] is not None:
latest_entry = db.session.query(DailyUsage).order_by(DailyUsage.id.desc()).first()
latest_entry_date = date(latest_entry.date.year, latest_entry.date.month, latest_entry.date.day)
print(latest_entry_date)
start_time = pins[change_pin]['on_time']
# Get the elapsed time and strip away milliseconds
......@@ -92,8 +91,10 @@ def toggle_pin(change_pin):
# If there is already an entry for today, update on time
# if latest_entry:
if latest_entry and latest_entry_date == start_date:
latest_entry.on_time_seconds += elapsed
if latest_entry:
latest_entry_date = date(latest_entry.date.year, latest_entry.date.month, latest_entry.date.day)
if latest_entry_date == start_date:
latest_entry.on_time_seconds += elapsed
else:
# If no entry for today, make one
entry = DailyUsage(date=start_date, on_time_seconds=elapsed)
......@@ -110,8 +111,10 @@ def toggle_pin(change_pin):
pins[pin]['state'] = GPIO.input(pin)
latest_entry = db.session.query(DailyUsage).order_by(DailyUsage.id.desc()).first()
if latest_entry and latest_entry.date == datetime.today().date():
daily_total = latest_entry.on_time_seconds
if latest_entry:
latest_entry_date = date(latest_entry.date.year, latest_entry.date.month, latest_entry.date.day)
if latest_entry_date == datetime.today().date():
daily_total = latest_entry.on_time_seconds
else:
daily_total = 0
......
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