homecontrol-dash: small steps forward
This commit is contained in:
parent
9c29ab825b
commit
91b4debe09
1 changed files with 26 additions and 13 deletions
|
@ -6,6 +6,8 @@ from dash.dependencies import Input, Output
|
|||
import time
|
||||
import requests
|
||||
|
||||
URL_BASE="http://innocence:5000"
|
||||
|
||||
x = [1]
|
||||
y = [2]
|
||||
|
||||
|
@ -13,7 +15,7 @@ external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
|
|||
|
||||
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
|
||||
|
||||
available_sensors = ["refresh first"]
|
||||
available_sensors = ["undefined"]
|
||||
|
||||
app.layout = html.Div(children=[
|
||||
html.H1(children='homecontrol-dash'),
|
||||
|
@ -35,7 +37,7 @@ app.layout = html.Div(children=[
|
|||
dcc.Dropdown(
|
||||
id='select-sensor',
|
||||
options=[{'label': i, 'value': i} for i in available_sensors],
|
||||
value='Available Sensors'
|
||||
value="undefined"
|
||||
),
|
||||
html.Button(id='refresh-button', n_clicks=0, children='refresh')
|
||||
])
|
||||
|
@ -45,28 +47,39 @@ app.layout = html.Div(children=[
|
|||
Output('select-sensor', 'options'),
|
||||
[Input('refresh-button', 'n_clicks')])
|
||||
def update_list(n_clicks):
|
||||
url = "http://localhost:5000/sensors/get"
|
||||
url = "%s/sensor/get" % URL_BASE
|
||||
print(url)
|
||||
res = requests.get(url)
|
||||
content = res.json()
|
||||
return [{'label': content[i]["type"], 'value': i} for i in content]
|
||||
options = [{'label': content[i]["sensorType"], 'value': i} for i in content]
|
||||
return options
|
||||
|
||||
|
||||
@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]
|
||||
def update_graph(n_clicks, sensorId):
|
||||
if not sensorId == "undefined":
|
||||
# url = "%s/sensor/get_values/%s?limit=10" % (URL_BASE, sensorId)
|
||||
url = "%s/sensor/get_values/%s" % (URL_BASE, sensorId)
|
||||
res = requests.get(url)
|
||||
content = res.json()
|
||||
v = content[sensorId]["values"]
|
||||
sensorType = content[sensorId]["sensorType"]
|
||||
x = [time.strftime("%m%d-%H%M%S", time.localtime(float(v[i]["ts"]))) for i in range(len(v))]
|
||||
y = [v[i]["value"] for i in range(len(v))]
|
||||
else:
|
||||
sensorType = sensorId
|
||||
x = [1]
|
||||
y = [1]
|
||||
|
||||
return {
|
||||
'data': [
|
||||
{'x': x, 'y': y, 'mode': 'markers', 'name': sensor}
|
||||
{'x': x, 'y': y, 'mode': 'markers', 'name': "%s (%s)" % (sensorType,
|
||||
sensorId)}
|
||||
],
|
||||
'layout': {
|
||||
'title': 'Data for sensor: %s' % sensor
|
||||
'title': 'Data for sensor: %s (%s)' % (sensorType, sensorId)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue