-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
84 lines (71 loc) · 2.3 KB
/
main.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
"""aa"""
from dash import Dash, dcc, html, dash_table
import plotly.express as px
from plotly.subplots import make_subplots
from roomalyzer import Roomalyzer
ra = Roomalyzer()
app = Dash("Grzib")
def calculate_data():
"""Entry point"""
ra.read_thingspeak(
"https://api.thingspeak.com/channels/2394445/feeds.json?results=8000"
)
ra.read_dehumidifier_log("dehumidifier_log.csv")
ra.check_humidity_levels()
def prepare_app():
"""Sets visual stuff, like plots and tables"""
avg_day = ra.calc_average_vals("24H", offset="15H")
print(avg_day)
fig = make_subplots(rows=2, cols=1, shared_xaxes=True)
fig = ra.add_subplot_chart(fig, ra.data[ra.temp], 1, 1, name="Temperature")
fig = ra.add_subplot_chart(
fig,
avg_day[ra.temp],
1,
1,
x_data=avg_day[ra.date],
name="Średnia temperatura",
errorbars=avg_day["temperature_std"],
)
fig.update_yaxes(title_text=r"$^\circ \text{C}$", row=1, col=1)
fig = ra.add_subplot_chart(fig, ra.data[ra.hum], 2, 1, name="Humidity")
fig = ra.add_subplot_chart(
fig,
avg_day[ra.hum],
2,
1,
x_data=avg_day[ra.date],
name="Średnia wilgotność",
errorbars=avg_day["humidity_std"],
)
fig.update_yaxes(title_text=r"%RH", row=2, col=1)
fig.update_layout(
title="Temperatura i wilgotność",
height=600,
xaxis={"dtick": 86400000.0},
xaxis2={"dtick": 86400000.0},
)
timeline = px.timeline(
x_start=ra.dehum_log["on"],
x_end=ra.dehum_log["off"],
y=[1 for x in range(len(ra.dehum_log))],
)
timeline.update_layout(
title="Praca osuszacza", yaxis_title="on/off", xaxis={"dtick": 86400000.0}
)
timeline.layout.yaxis.update(showticklabels=False) # type: ignore
timeline.layout.height = 250 # type: ignore
app.layout = html.Div(
[
html.Div(children="Wrocław, Sienkiewicza"),
dcc.Graph(id="figure", figure=fig, mathjax=True),
dcc.Graph(id="timeline", figure=timeline),
dash_table.DataTable(
ra.summary.to_dict("records", index=True), fill_width=False
),
]
)
if __name__ == "__main__":
calculate_data()
prepare_app()
app.run(debug=False)