Commit c5077d14 authored by Kristian Tan's avatar Kristian Tan

Moved get_todays_usage to service class

parent fe735c6b
......@@ -100,6 +100,7 @@ db.create_all()
daily_total = get_todays_usage()
todays_cost = get_todays_cost()
print(get_todays_usage())
print(daily_usage.DailyUsage.get_todays_usage())
print(get_todays_cost())
# Create dictionary to store pin info
......
from datetime import datetime, date
from sqlalchemy import desc
class DailyUsage:
@staticmethod
def test_me(msg):
print(msg)
\ No newline at end of file
@staticmethod
def get_todays_usage():
latest_entry = DailyUsage.query.order_by(desc(DailyUsage.date)).first()
# latest_entry = db.session.query(DailyUsage).order_by(DailyUsage.date.asc()).first()
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():
return format(latest_entry.kwhUsed, '.7f')
return 0
\ No newline at end of file
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