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
6bfe542c
Commit
6bfe542c
authored
Nov 14, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve the way records are queried in generate_graph
parent
31eaac57
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
app.py
app.py
+12
-5
No files found.
app.py
View file @
6bfe542c
...
@@ -85,18 +85,23 @@ def generate_graph_data():
...
@@ -85,18 +85,23 @@ def generate_graph_data():
max
=
0
max
=
0
# Create data for chart
# Create data for chart
count
=
0
# count = 0
records
=
DailyUsage
.
query
.
order_by
(
desc
(
DailyUsage
.
date
))
.
all
()
records
=
DailyUsage
.
query
.
order_by
(
desc
(
DailyUsage
.
date
))
.
limit
(
5
)
.
all
()
print
(
records
)
for
record
in
records
:
for
record
in
records
:
labels
.
append
(
date
(
record
.
date
.
year
,
record
.
date
.
month
,
record
.
date
.
day
))
labels
.
append
(
date
(
record
.
date
.
year
,
record
.
date
.
month
,
record
.
date
.
day
))
values
.
append
(
record
.
kwhUsed
)
values
.
append
(
record
.
kwhUsed
)
if
record
.
kwhUsed
>
max
:
if
record
.
kwhUsed
>
max
:
max
=
record
.
kwhUsed
max
=
record
.
kwhUsed
count
+=
1
# count += 1
if
count
>=
5
:
# if count >= 5:
break
# break
labels
.
reverse
()
values
.
reverse
()
return
labels
,
values
,
max
return
labels
,
values
,
max
db
.
create_all
()
db
.
create_all
()
daily_total
=
get_todays_usage
()
daily_total
=
get_todays_usage
()
...
@@ -119,6 +124,7 @@ for pin in pins:
...
@@ -119,6 +124,7 @@ for pin in pins:
labels
,
values
,
max
=
generate_graph_data
()
labels
,
values
,
max
=
generate_graph_data
()
@
app
.
route
(
"/"
)
@
app
.
route
(
"/"
)
def
main
():
def
main
():
# For each pin, read the pin state and store it in the pins dictionary:
# For each pin, read the pin state and store it in the pins dictionary:
...
@@ -246,6 +252,7 @@ def delete_pin(delete_pin):
...
@@ -246,6 +252,7 @@ def delete_pin(delete_pin):
}
}
return
render_template
(
'main.html'
,
**
template_data
)
return
render_template
(
'main.html'
,
**
template_data
)
@
app
.
route
(
"/update_info/kWh"
)
@
app
.
route
(
"/update_info/kWh"
)
def
change_kWh
():
def
change_kWh
():
template_data
=
{
template_data
=
{
...
...
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