-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
109 lines (85 loc) · 2.78 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from flask import Flask, render_template
from datetime import datetime
import firebase
import json
import os
from firebase_admin import db
from firebase_admin import credentials
#define number of bmass sensors and ponds
bmass_num = 5
ponds = 70
fb_key = os.getenv('fb_key')
if fb_key:
print("running in deployment mode")
deployed = True
else:
print("running in debug mode")
deployed = False
with open('fb_key.json', 'r') as file:
fb_key = file.read()
#login to firebase
fb_app = firebase.login(fb_key)
def get_all_battv():
"""
Get the latest battery voltages for all biomass sensors
"""
last_battv=dict()
for i in range(1, bmass_num + 1):
bmx = firebase.bmass_sensor(i, 1)
last_battv[bmx.id] = bmx.battv[-1]
return last_battv
def get_all_do():
"""
Get latest dissolved oxygen values for all ponds
"""
last_do = dict()
p_overview = db.reference('/LH_Farm/overview')
data = p_overview.get()
for i in data:
idx = i.split('_')[-1]
last_do[idx] = data[i]['last_do']
return last_do
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/HAUCS')
def haucs():
last_do = get_all_do()
with open('static/json/farm_features.json', 'r') as file:
data = file.read()
return render_template('HAUCS.html', data=data, do_values=json.dumps(last_do))
@app.route('/biomass')
def bmass():
last_battv = get_all_battv()
with open('static/json/tanks_features.json', 'r') as file:
data = file.read()
return render_template('biomass.html', data=data,battv=json.dumps(last_battv))
@app.route('/sensor'+'<int:sensor_id>')
def show_sensor(sensor_id):
bmx = firebase.bmass_sensor(sensor_id, 600)
last_battv = bmx.battv[-1]
last_dt = bmx.d_dt[-1]
str_date = last_dt.strftime('%A, %B %d')
str_time = last_dt.strftime('%I:%M %p')
bmx.plot_timeseries(mv=10)
return render_template('tanks_analytics.html', sensor_id=sensor_id, last_date=str_date, last_time = str_time, last_battv=last_battv, last_dt=last_dt)
@app.route('/pond'+'<int:pond_id>')
def show_pond(pond_id):
pondx = firebase.pond(pond_id, 48)
last_do = pondx.do[-1]
last_temp = round(pondx.temp[-1],2)
last_dt = pondx.d_dt[-1]
str_date = last_dt.strftime('%A, %B %d')
str_time = last_dt.strftime('%I:%M %p')
pondx.plot_temp_do(mv=10)
return render_template('haucs_analytics.html', pond_id=pond_id, last_date=str_date, last_time = str_time,last_do=last_do, last_temp = last_temp)
@app.route('/feedback')
def feedback():
return render_template('feedback.html',ponds=ponds)
if __name__ == "__main__":
if not deployed:
app.run(debug=True)