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
fe4533e5
Commit
fe4533e5
authored
Nov 13, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass total daily usage to html
parent
56b3b704
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
14 deletions
+9
-14
app.py
app.py
+8
-11
main.html
templates/main.html
+1
-3
No files found.
app.py
View file @
fe4533e5
...
...
@@ -35,6 +35,12 @@ class DailyUsage(db.Model):
db
.
create_all
()
daily_total
=
0
latest_entry
=
db
.
session
.
query
(
DailyUsage
)
.
order_by
(
DailyUsage
.
id
.
desc
())
.
first
()
if
latest_entry
and
latest_entry
.
date
==
datetime
.
today
():
daily_total
=
latest_entry
.
on_time_seconds
# Create dictionary to store pin info
pins
=
{
25
:
{
'name'
:
'Light'
,
'state'
:
GPIO
.
LOW
,
'on_time'
:
None
}
...
...
@@ -83,24 +89,15 @@ def toggle_pin(change_pin):
# Create datetime object from formatted time
start_date
=
datetime
.
strptime
(
start_date_string
,
'
%
Y-
%
m-
%
d'
)
# If there is already an entry for today, update on time
if
latest_entry
and
latest_entry
.
date
==
start_date
:
print
(
"SECS BEFORE UPDATE"
)
print
(
latest_entry
.
on_time_seconds
)
latest_entry
.
on_time_seconds
+=
elapsed
print
(
"SECS AFTER UPDATE"
)
print
(
latest_entry
.
on_time_seconds
)
else
:
print
(
"NEW ENTRY"
)
# If no entry for today, make one
entry
=
DailyUsage
(
date
=
start_date
,
on_time_seconds
=
elapsed
)
print
(
entry
.
on_time_seconds
)
db
.
session
.
add
(
entry
)
db
.
session
.
commit
()
print
(
"========="
)
print
(
DailyUsage
.
query
.
all
())
print
(
"========="
)
pins
[
change_pin
][
'on_time'
]
=
None
else
:
message
+=
" on."
...
...
templates/main.html
View file @
fe4533e5
...
...
@@ -39,9 +39,7 @@
{% endfor %}
</p>
{# Implement some way to display "No devices" message if none are in use#}
<p>
Used today:
</p>
<p>
Used today: {{ daily_total }}
</p>
</div>
</div>
</div>
...
...
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