Commit fef1933d authored by Kristian Tan's avatar Kristian Tan

Moved daily_usage to seperate file

parent 0ed5ba8f
......@@ -4,7 +4,7 @@ from flask_sqlalchemy import SQLAlchemy
import os
from datetime import datetime, date, timedelta
# from daily_usage import DailyUsage
from daily_usage import DailyUsage
app = Flask(__name__)
os.environ['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///energyUsage'
......@@ -20,19 +20,19 @@ os.environ['cost_per_kWh'] = '0.1622'
# TODO: Move this into daily_usage class file
class DailyUsage(db.Model):
__tablename__ = 'daily_usage'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
date = db.Column(db.DateTime, unique=True, nullable=False)
kwhUsed = db.Column(db.Float, unique=False)
def __init__(self, date, kwhUsed):
self.date = date
self.kwhUsed = kwhUsed
def __repr__(self):
return '<DailyUsage %r, %r, %r>' % (self.id, self.date, self.kwhUsed)
# class DailyUsage(db.Model):
# __tablename__ = 'daily_usage'
#
# id = db.Column(db.Integer, primary_key=True, autoincrement=True)
# date = db.Column(db.DateTime, unique=True, nullable=False)
# kwhUsed = db.Column(db.Float, unique=False)
#
# def __init__(self, date, kwhUsed):
# self.date = date
# self.kwhUsed = kwhUsed
#
# def __repr__(self):
# return '<DailyUsage %r, %r, %r>' % (self.id, self.date, self.kwhUsed)
def get_todays_usage():
......@@ -72,6 +72,7 @@ def create_entry(change_pin):
pins[change_pin]['on_time'] = None
pins[change_pin]['on_date'] = None
db.create_all()
daily_total = get_todays_usage()
......
......@@ -2,9 +2,15 @@ from app import db
class DailyUsage(db.Model):
__tablename__ = 'daily_usage'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
date = db.Column(db.String(80), unique=True, nullable=False)
hours = db.Column(db.Integer(120), unique=False)
date = db.Column(db.DateTime, unique=True, nullable=False)
kwhUsed = db.Column(db.Float, unique=False)
def __init__(self, date, kwhUsed):
self.date = date
self.kwhUsed = kwhUsed
def __repr__(self):
return '<DailyUsage %r>' % self.id
return '<DailyUsage %r, %r, %r>' % (self.id, self.date, self.kwhUsed)
\ 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