Commit a217470b authored by Kristian Tan's avatar Kristian Tan

Create model for daily_usage table

parent 8dd4df0e
from flask import Flask, render_template from flask import Flask, render_template
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from .daily_usage import DailyUsage
app = Flask(__name__) app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///energyUsage' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///energyUsage'
db = SQLAlchemy(app) db = SQLAlchemy(app)
SQLAlchemy.create_all()
db.create_all() db.create_all()
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False) GPIO.setwarnings(False)
test = DailyUsage("12/11/2019", 5)
db.session.add(test)
db.session.commit()
# Create dictionary to store pin info # Create dictionary to store pin info
pins = { pins = {
25: {'name': 'Light', 'state': GPIO.LOW} 25: {'name': 'Light', 'state': GPIO.LOW}
} }
# Setup each pin # Setup each pin
for pin in pins: for pin in pins:
GPIO.setup(pin, GPIO.OUT) GPIO.setup(pin, GPIO.OUT)
......
from .app import db
class DailyUsage(db.Model):
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)
def __repr__(self):
return '<User %r>' % self.username
\ No newline at end of file
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</p> </p>
{# Implement some way to display "No devices" message if none are in use#}
<p> Used today: <p> Used today:
</p> </p>
......
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