2019-10-20 21:33:44 +02:00
|
|
|
from plotly.offline import plot
|
|
|
|
from plotly.graph_objs import Scatter
|
2019-10-21 06:57:44 +02:00
|
|
|
from collector.models import Temperature, Humidity, Pressure
|
2019-10-20 21:33:44 +02:00
|
|
|
|
|
|
|
|
2019-10-23 10:28:03 +02:00
|
|
|
def temperature(start_time):
|
2019-10-21 19:27:33 +02:00
|
|
|
data = Temperature.objects.filter(time__gt=start_time)
|
2019-10-20 21:33:44 +02:00
|
|
|
x_axis = []
|
|
|
|
y_axis = []
|
|
|
|
for point in data:
|
2019-10-20 21:38:42 +02:00
|
|
|
y_axis.append(point.value)
|
2019-10-21 06:57:44 +02:00
|
|
|
x_axis.append(point.time)
|
2019-10-20 21:33:44 +02:00
|
|
|
|
|
|
|
plot_div = plot([Scatter(x=x_axis , y=y_axis,
|
2019-10-21 18:30:04 +02:00
|
|
|
mode='lines+markers', name='temperature',
|
2019-10-21 18:23:41 +02:00
|
|
|
opacity=0.8, marker_color='green')],
|
2019-10-20 21:33:44 +02:00
|
|
|
output_type='div')
|
|
|
|
return plot_div
|
|
|
|
|
|
|
|
|
2019-10-23 10:28:03 +02:00
|
|
|
def humidity(start_time):
|
2019-10-21 19:27:33 +02:00
|
|
|
data = Humidity.objects.filter(time__gt=start_time)
|
2019-10-20 21:33:44 +02:00
|
|
|
x_axis = []
|
|
|
|
y_axis = []
|
|
|
|
for point in data:
|
2019-10-20 21:38:42 +02:00
|
|
|
y_axis.append(point.value)
|
2019-10-21 06:57:44 +02:00
|
|
|
x_axis.append(point.time)
|
2019-10-20 21:33:44 +02:00
|
|
|
|
|
|
|
plot_div = plot([Scatter(x=x_axis , y=y_axis,
|
2019-10-21 18:30:04 +02:00
|
|
|
mode='lines+markers', name='humidity',
|
2019-10-21 18:23:41 +02:00
|
|
|
opacity=0.8, marker_color='green')],
|
2019-10-20 21:33:44 +02:00
|
|
|
output_type='div')
|
|
|
|
return plot_div
|
|
|
|
|
|
|
|
|
2019-10-23 10:28:03 +02:00
|
|
|
def pressure(start_time):
|
2019-10-21 19:27:33 +02:00
|
|
|
data = Pressure.objects.filter(time__gt=start_time)
|
2019-10-20 21:33:44 +02:00
|
|
|
x_axis = []
|
|
|
|
y_axis = []
|
|
|
|
for point in data:
|
2019-10-20 21:38:42 +02:00
|
|
|
y_axis.append(point.value)
|
2019-10-21 06:57:44 +02:00
|
|
|
x_axis.append(point.time)
|
2019-10-20 21:33:44 +02:00
|
|
|
|
|
|
|
plot_div = plot([Scatter(x=x_axis , y=y_axis,
|
2019-10-21 18:30:04 +02:00
|
|
|
mode='lines+markers', name='pressure',
|
2019-10-21 18:23:41 +02:00
|
|
|
opacity=0.8, marker_color='green')],
|
2019-10-20 21:33:44 +02:00
|
|
|
output_type='div')
|
|
|
|
return plot_div
|