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
0253196e
Commit
0253196e
authored
Nov 13, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
environment variable for unit cost
parent
f65be37a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
6 deletions
+7
-6
app.py
app.py
+6
-5
main.html
templates/main.html
+1
-1
No files found.
app.py
View file @
0253196e
...
...
@@ -16,7 +16,7 @@ GPIO.setmode(GPIO.BCM)
GPIO
.
setwarnings
(
False
)
db
=
SQLAlchemy
(
app
)
os
.
environ
[
'cost_per_kWh'
]
=
0.1622
# TODO: Move this into daily_usage class file
class
DailyUsage
(
db
.
Model
):
...
...
@@ -44,7 +44,7 @@ if latest_entry:
if
latest_entry_date
==
datetime
.
today
()
.
date
():
daily_total
=
format
(
latest_entry
.
kwhUsed
,
'.7f'
)
todays_cost
=
format
(
float
(
daily_total
)
*
0.1622
,
'0.5f'
)
todays_cost
=
format
(
float
(
daily_total
)
*
os
.
environ
[
'cost_per_kWh'
]
,
'0.5f'
)
# Create dictionary to store pin info
pins
=
{
...
...
@@ -100,7 +100,7 @@ def toggle_pin(change_pin):
else
:
daily_total
=
0
todays_cost
=
format
(
float
(
daily_total
)
*
0.1622
,
'0.5f'
)
todays_cost
=
format
(
float
(
daily_total
)
*
os
.
environ
[
'cost_per_kWh'
]
,
'0.5f'
)
template_data
=
{
'pins'
:
pins
,
...
...
@@ -135,10 +135,11 @@ def create_entry(change_pin):
pins
[
change_pin
][
'on_time'
]
=
None
pins
[
change_pin
][
'on_date'
]
=
None
@
app
.
route
(
'/handle_data'
,
methods
=
[
'POST'
])
def
handle_data
():
projectpath
=
request
.
form
[
'kWhprice'
]
print
(
projectpath
)
new_price
=
request
.
form
[
'kWhprice'
]
os
.
environ
[
'cost_per_kWh'
]
=
new_price
template_data
=
{
'pins'
:
pins
,
'daily_total'
:
daily_total
,
...
...
templates/main.html
View file @
0253196e
...
...
@@ -43,7 +43,7 @@
</div>
<div
class=
"inputs"
>
<form
action=
"{{ url_for('handle_data') }}"
method=
"post"
>
Cost per kWh:
<input
type=
"text"
name=
"kWhprice"
>
C
hange c
ost per kWh:
<input
type=
"text"
name=
"kWhprice"
>
<input
type=
"submit"
>
</form>
</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