Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IoTSmartMeter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kristian.tan
IoTSmartMeter
Commits
fef1933d
Commit
fef1933d
authored
Nov 13, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved daily_usage to seperate file
parent
0ed5ba8f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
17 deletions
+24
-17
app.py
app.py
+15
-14
daily_usage.py
daily_usage.py
+9
-3
No files found.
app.py
View file @
fef1933d
...
@@ -4,7 +4,7 @@ from flask_sqlalchemy import SQLAlchemy
...
@@ -4,7 +4,7 @@ from flask_sqlalchemy import SQLAlchemy
import
os
import
os
from
datetime
import
datetime
,
date
,
timedelta
from
datetime
import
datetime
,
date
,
timedelta
#
from daily_usage import DailyUsage
from
daily_usage
import
DailyUsage
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
os
.
environ
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///energyUsage'
os
.
environ
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///energyUsage'
...
@@ -20,19 +20,19 @@ os.environ['cost_per_kWh'] = '0.1622'
...
@@ -20,19 +20,19 @@ os.environ['cost_per_kWh'] = '0.1622'
# TODO: Move this into daily_usage class file
# TODO: Move this into daily_usage class file
class
DailyUsage
(
db
.
Model
):
#
class DailyUsage(db.Model):
__tablename__
=
'daily_usage'
#
__tablename__ = 'daily_usage'
#
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
#
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
date
=
db
.
Column
(
db
.
DateTime
,
unique
=
True
,
nullable
=
False
)
#
date = db.Column(db.DateTime, unique=True, nullable=False)
kwhUsed
=
db
.
Column
(
db
.
Float
,
unique
=
False
)
#
kwhUsed = db.Column(db.Float, unique=False)
#
def
__init__
(
self
,
date
,
kwhUsed
):
#
def __init__(self, date, kwhUsed):
self
.
date
=
date
#
self.date = date
self
.
kwhUsed
=
kwhUsed
#
self.kwhUsed = kwhUsed
#
def
__repr__
(
self
):
#
def __repr__(self):
return
'<DailyUsage
%
r,
%
r,
%
r>'
%
(
self
.
id
,
self
.
date
,
self
.
kwhUsed
)
#
return '<DailyUsage %r, %r, %r>' % (self.id, self.date, self.kwhUsed)
def
get_todays_usage
():
def
get_todays_usage
():
...
@@ -72,6 +72,7 @@ def create_entry(change_pin):
...
@@ -72,6 +72,7 @@ def create_entry(change_pin):
pins
[
change_pin
][
'on_time'
]
=
None
pins
[
change_pin
][
'on_time'
]
=
None
pins
[
change_pin
][
'on_date'
]
=
None
pins
[
change_pin
][
'on_date'
]
=
None
db
.
create_all
()
db
.
create_all
()
daily_total
=
get_todays_usage
()
daily_total
=
get_todays_usage
()
...
...
daily_usage.py
View file @
fef1933d
...
@@ -2,9 +2,15 @@ from app import db
...
@@ -2,9 +2,15 @@ from app import db
class
DailyUsage
(
db
.
Model
):
class
DailyUsage
(
db
.
Model
):
__tablename__
=
'daily_usage'
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
date
=
db
.
Column
(
db
.
String
(
80
),
unique
=
True
,
nullable
=
False
)
date
=
db
.
Column
(
db
.
DateTime
,
unique
=
True
,
nullable
=
False
)
hours
=
db
.
Column
(
db
.
Integer
(
120
),
unique
=
False
)
kwhUsed
=
db
.
Column
(
db
.
Float
,
unique
=
False
)
def
__init__
(
self
,
date
,
kwhUsed
):
self
.
date
=
date
self
.
kwhUsed
=
kwhUsed
def
__repr__
(
self
):
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment