76 lines
No EOL
1.9 KiB
Python
Executable file
76 lines
No EOL
1.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import dash
|
|
import dash_core_components as dcc
|
|
import dash_html_components as html
|
|
from dash.dependencies import Input, Output
|
|
import time
|
|
import requests
|
|
|
|
x = [1]
|
|
y = [2]
|
|
|
|
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
|
|
|
|
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
|
|
|
|
available_sensors = ["refresh first"]
|
|
|
|
app.layout = html.Div(children=[
|
|
html.H1(children='homecontrol-dash'),
|
|
|
|
html.Div(children='''
|
|
homecontrol-dash: visualize data
|
|
'''),
|
|
dcc.Graph(
|
|
id='example-graph',
|
|
figure={
|
|
'data': [
|
|
{'x': x, 'y': y, 'mode': 'markers', 'name': 'SF'}
|
|
],
|
|
'layout': {
|
|
'title': 'initial values'
|
|
}
|
|
}
|
|
),
|
|
dcc.Dropdown(
|
|
id='select-sensor',
|
|
options=[{'label': i, 'value': i} for i in available_sensors],
|
|
value='Available Sensors'
|
|
),
|
|
html.Button(id='refresh-button', n_clicks=0, children='refresh')
|
|
])
|
|
|
|
|
|
@app.callback(
|
|
Output('select-sensor', 'options'),
|
|
[Input('refresh-button', 'n_clicks')])
|
|
def update_list(n_clicks):
|
|
url = "http://localhost:5000/sensors/get"
|
|
res = requests.get(url)
|
|
content = res.json()
|
|
return [{'label': content[i]["type"], 'value': i} for i in content]
|
|
|
|
|
|
@app.callback(
|
|
Output('example-graph', 'figure'),
|
|
[Input('refresh-button', 'n_clicks'), Input('select-sensor', 'value')])
|
|
def update_graph(n_clicks, sensor):
|
|
url = "http://localhost:5000/sensors/get_values/%s" % sensor
|
|
res = requests.get(url)
|
|
content = res.json()
|
|
x = [time.strftime("%Y%m%d-%H%M%S", time.localtime(float(i))) for i in content]
|
|
y = [content[i] for i in content]
|
|
|
|
return {
|
|
'data': [
|
|
{'x': x, 'y': y, 'mode': 'markers', 'name': sensor}
|
|
],
|
|
'layout': {
|
|
'title': 'Data for sensor: %s' % sensor
|
|
}
|
|
|
|
}
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run_server(debug=True) |