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
7ab004d8
Commit
7ab004d8
authored
Nov 13, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
896cbea8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
10 deletions
+24
-10
app.py
app.py
+24
-10
No files found.
app.py
View file @
7ab004d8
...
...
@@ -74,6 +74,19 @@ def create_entry(change_pin):
pins
[
change_pin
][
'on_date'
]
=
None
def
generate_graph_data
():
# Create data for chart
count
=
0
records
=
DailyUsage
.
query
.
order_by
(
asc
(
DailyUsage
.
date
))
.
all
()
for
record
in
records
:
labels
.
append
(
date
(
record
.
date
.
year
,
record
.
date
.
month
,
record
.
date
.
day
))
values
.
append
(
record
.
kwhUsed
)
if
record
.
kwhUsed
>
max
:
max
=
record
.
kwhUsed
count
+=
1
if
count
>=
7
:
break
db
.
create_all
()
daily_total
=
get_todays_usage
()
...
...
@@ -96,19 +109,20 @@ for pin in pins:
labels
=
[]
values
=
[]
generate_graph_data
()
max
=
0
# Create data for chart
count
=
0
records
=
DailyUsage
.
query
.
order_by
(
asc
(
DailyUsage
.
date
))
.
all
()
for
record
in
records
:
labels
.
append
(
date
(
record
.
date
.
year
,
record
.
date
.
month
,
record
.
date
.
day
))
values
.
append
(
record
.
kwhUsed
)
if
record
.
kwhUsed
>
max
:
max
=
record
.
kwhUsed
count
+=
1
if
count
>=
7
:
break
#
count = 0
#
records = DailyUsage.query.order_by(asc(DailyUsage.date)).all()
#
for record in records:
#
labels.append(date(record.date.year, record.date.month, record.date.day))
#
values.append(record.kwhUsed)
#
if record.kwhUsed > max:
#
max = record.kwhUsed
#
count += 1
#
if count >= 7:
#
break
@
app
.
route
(
"/"
)
def
main
():
...
...
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