fix the plots
The date was validated when the application startet not everytime the view was called. This commit moves the date calculation to the view.
This commit is contained in:
parent
4e391cb92c
commit
c980c2ac76
|
@ -1,13 +1,9 @@
|
|||
from datetime import timedelta
|
||||
from datetime import datetime
|
||||
from plotly.offline import plot
|
||||
from plotly.graph_objs import Scatter
|
||||
from collector.models import Temperature, Humidity, Pressure
|
||||
|
||||
|
||||
start_time = datetime.now() - timedelta(hours=12)
|
||||
|
||||
def temperature():
|
||||
def temperature(start_time):
|
||||
data = Temperature.objects.filter(time__gt=start_time)
|
||||
x_axis = []
|
||||
y_axis = []
|
||||
|
@ -22,7 +18,7 @@ def temperature():
|
|||
return plot_div
|
||||
|
||||
|
||||
def humidity():
|
||||
def humidity(start_time):
|
||||
data = Humidity.objects.filter(time__gt=start_time)
|
||||
x_axis = []
|
||||
y_axis = []
|
||||
|
@ -37,7 +33,7 @@ def humidity():
|
|||
return plot_div
|
||||
|
||||
|
||||
def pressure():
|
||||
def pressure(start_time):
|
||||
data = Pressure.objects.filter(time__gt=start_time)
|
||||
x_axis = []
|
||||
y_axis = []
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
from datetime import datetime, timedelta
|
||||
from django.shortcuts import render
|
||||
from . import plot
|
||||
|
||||
def index_view(request):
|
||||
plot_temp = plot.temperature()
|
||||
plot_humidity = plot.humidity()
|
||||
plot_pressure = plot.pressure()
|
||||
start_time = datetime.now() - timedelta(hours=24)
|
||||
plot_temp = plot.temperature(start_time)
|
||||
plot_humidity = plot.humidity(start_time)
|
||||
plot_pressure = plot.pressure(start_time)
|
||||
return render(request, "collector/index.html",
|
||||
context={'plot_temp': plot_temp,
|
||||
'plot_humidity': plot_humidity,
|
||||
|
|
Loading…
Reference in New Issue