homecontrol-dash: first attempt at visualization

This commit is contained in:
Konstantin Koslowski 2019-11-03 16:38:01 +01:00
commit 9c29ab825b
3 changed files with 94 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.idea/*
Pipfile.lock
dash
dcc

14
Pipfile Normal file
View file

@ -0,0 +1,14 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
dash = "*"
dash-daq = "*"
requests = "*"
[requires]
python_version = "3.7"

76
homecontrol-dash.py Executable file
View file

@ -0,0 +1,76 @@
#!/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)