Commit 0253196e authored by Kristian Tan's avatar Kristian Tan

environment variable for unit cost

parent f65be37a
...@@ -16,7 +16,7 @@ GPIO.setmode(GPIO.BCM) ...@@ -16,7 +16,7 @@ GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False) GPIO.setwarnings(False)
db = SQLAlchemy(app) db = SQLAlchemy(app)
os.environ['cost_per_kWh'] = 0.1622
# TODO: Move this into daily_usage class file # TODO: Move this into daily_usage class file
class DailyUsage(db.Model): class DailyUsage(db.Model):
...@@ -44,7 +44,7 @@ if latest_entry: ...@@ -44,7 +44,7 @@ if latest_entry:
if latest_entry_date == datetime.today().date(): if latest_entry_date == datetime.today().date():
daily_total = format(latest_entry.kwhUsed, '.7f') 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 # Create dictionary to store pin info
pins = { pins = {
...@@ -100,7 +100,7 @@ def toggle_pin(change_pin): ...@@ -100,7 +100,7 @@ def toggle_pin(change_pin):
else: else:
daily_total = 0 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 = { template_data = {
'pins': pins, 'pins': pins,
...@@ -135,10 +135,11 @@ def create_entry(change_pin): ...@@ -135,10 +135,11 @@ def create_entry(change_pin):
pins[change_pin]['on_time'] = None pins[change_pin]['on_time'] = None
pins[change_pin]['on_date'] = None pins[change_pin]['on_date'] = None
@app.route('/handle_data', methods=['POST']) @app.route('/handle_data', methods=['POST'])
def handle_data(): def handle_data():
projectpath = request.form['kWhprice'] new_price = request.form['kWhprice']
print(projectpath) os.environ['cost_per_kWh'] = new_price
template_data = { template_data = {
'pins': pins, 'pins': pins,
'daily_total': daily_total, 'daily_total': daily_total,
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
</div> </div>
<div class="inputs"> <div class="inputs">
<form action="{{ url_for('handle_data') }}" method="post"> <form action="{{ url_for('handle_data') }}" method="post">
Cost per kWh: <input type="text" name="kWhprice"> Change cost per kWh: <input type="text" name="kWhprice">
<input type="submit"> <input type="submit">
</form> </form>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment