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
51b0e898
Commit
51b0e898
authored
Nov 13, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add entry when light is turned off db
parent
159b1f97
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
app.py
app.py
+17
-6
No files found.
app.py
View file @
51b0e898
...
...
@@ -20,21 +20,20 @@ db = SQLAlchemy(app)
# TODO: Move this into daily_usage class file
class
DailyUsage
(
db
.
Model
):
__tablename__
=
'daily_usage'
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
date
=
db
.
Column
(
db
.
DateTime
,
unique
=
True
,
nullable
=
False
)
hours
=
db
.
Column
(
db
.
String
,
unique
=
False
)
on_time
=
db
.
Column
(
db
.
String
,
unique
=
False
)
def
__init__
(
self
,
id
,
date
,
hours
):
self
.
id
=
id
def
__init__
(
self
,
date
,
on_time
):
self
.
date
=
date
self
.
hours
=
hours
self
.
on_time
=
on_time
def
__repr__
(
self
):
return
'<DailyUsage
%
r>'
%
self
.
date
db
.
create_all
()
print
(
DailyUsage
.
query
.
all
())
# Create dictionary to store pin info
pins
=
{
...
...
@@ -72,7 +71,19 @@ def toggle_pin(change_pin):
message
=
"Turned "
+
device_name
if
GPIO
.
input
(
change_pin
)
==
0
:
message
+=
" off."
pins
[
change_pin
][
'on_time'
]
=
None
if
pins
[
change_pin
][
'on_time'
]
is
not
None
:
start_time
=
pins
[
change_pin
][
'on_time'
]
elapsed
=
str
(
datetime
.
now
()
-
start_time
)
date
=
start_time
.
date
()
entry
=
DailyUsage
(
date
=
date
,
on_time
=
elapsed
)
db
.
session
.
add
(
entry
)
db
.
session
.
commit
()
print
(
"========="
)
DailyUsage
.
query
.
all
()
print
(
"========="
)
pins
[
change_pin
][
'on_time'
]
=
None
else
:
message
+=
" on."
pins
[
change_pin
][
'on_time'
]
=
datetime
.
now
()
...
...
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