Commit a8c3ab7403acfa4c7d0d31403f341815f076b09e

Authored by Patrick Maeght
1 parent 0ca00ebd
Exists in dev

weather query

Showing 1 changed file with 25 additions and 0 deletions   Show diff stats
src/dashboard/views.py
... ... @@ -129,6 +129,31 @@ def weather(request):
129 129 return render(request, 'dashboard/reload_weather.html', {'base_template' : "base_unlogged.html"})
130 130  
131 131 def weather_current(request):
  132 + # PM 20180718
  133 + if request.is_ajax():
  134 + try:
  135 + weather_status = WeatherWatch.objects.latest('updated')
  136 + plc_device_status = PlcDeviceStatus.objects.exclude(plc_mode=None).latest('created')
  137 + plc_mode = plc_device_status.plc_mode
  138 + is_safe = plc_device_status.is_safe
  139 + weather = serializers.serialize('json', [weather_status])
  140 + weather = json.loads(weather)
  141 + ack = Config.objects.get(id=1).ack
  142 + plc_timeout = Config.objects.get(pk=1).plc_timeout_seconds
  143 + timeout = (datetime.datetime.now() - plc_device_status.created).total_seconds()
  144 + weather[0]['max_sunelev'] = SUN_ELEV_DAY_THRESHOLD
  145 + weather[0]['sunelev'] = get_sunelev()
  146 + weather[0]["plc_mode"] = plc_mode
  147 + weather[0]["is_safe"] = is_safe
  148 + weather[0]["ACK"] = ack
  149 + weather[0]["plc_timeout"] = timeout
  150 + weather[0]["max_plc_timeout"] = plc_timeout
  151 + weather[0]["pyros_mode"] = Config.objects.get(id=1).pyros_state
  152 + return HttpResponse(json.dumps(weather), content_type="application/json")
  153 + except WeatherWatch.DoesNotExist:
  154 + raise Http404("No WeatherWatch matches the given query.")
  155 +
  156 +def weather_current_old(request):
132 157 try:
133 158 if (len(Config.objects.all()) == 1):
134 159 monitoring = int(int(Config.objects.get(id=1).row_data_save_frequency) / 5)
... ...