Commit 8879f53ddcb30bd50f6fdfab36b09719b37440c5

Authored by Patrick Maeght
1 parent 9bb6a2a9
Exists in dev

colibri-new-fixed json

simulators/plc/colibri-new-fixed-2.json
@@ -247,7 +247,7 @@ @@ -247,7 +247,7 @@
247 "device_name": "VantagePro", 247 "device_name": "VantagePro",
248 "device_type": "meteo", 248 "device_type": "meteo",
249 "serial_number": "ERTRY2344324", 249 "serial_number": "ERTRY2344324",
250 - "valid": "no", 250 + "valid": "yes",
251 "device_values": [ 251 "device_values": [
252 { 252 {
253 "name": "OutsideTemp", 253 "name": "OutsideTemp",
src/dashboard/templates/dashboard/config_weather.html 0 → 100644
@@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
  1 +<style>
  2 +
  3 +#none {
  4 + font-family: 'Montserra', sans-serif;
  5 +}
  6 +
  7 +</style>
  8 + <div class="row">
  9 +
  10 + <h1 id="none">Weather config</h1>
  11 +
  12 + <div class="well">
  13 + Captors list:
  14 + </div>
  15 + <div class="row">
  16 + <h3>Valid meteo devices</h3>
  17 + <div class="table-responsive">
  18 + <table
  19 + class="table table-bordered table-hover table-striped tablesorter" style="font-family: 'Montserra', sans-serif;">
  20 + <thead>
  21 + <tr>
  22 + <th>Device type<i class="fa fa-sort"></i></th>
  23 + <th>Deice id <i class="fa fa-sort"></i></th>
  24 + <th>value <i class="fa fa-sort"></i></th>
  25 + <th>Select <i class="fa fa-sort"></i></th>
  26 + </tr>
  27 + </thead>
  28 + <tbody>
  29 + {% for key1, value1 in weather_config.items %}
  30 + <tr>
  31 + <td>{{key1}}</td>
  32 + <td></td>
  33 + <td></td>
  34 + <td></td
  35 + </tr>
  36 + {% for key2, value2 in value1.items %}
  37 + <tr>
  38 + <td></td>
  39 + <td>{{key2}}</td>
  40 + <td>{{value2}}</td>
  41 + <td><input class="form-check-input" name="{{key1}}" id="oR{{key1}}/{{key2}}" value="option1" checked="" type="radio"></td>
  42 + {% endfor %}
  43 + {% endfor %}
  44 + </tbody>
  45 + </table>
  46 + </div>
  47 + </div>
src/dashboard/urls.py
@@ -11,6 +11,7 @@ urlpatterns = [ @@ -11,6 +11,7 @@ urlpatterns = [
11 path('routines', views.routines, name="routines"), 11 path('routines', views.routines, name="routines"),
12 path('weather', views.weather, name="weather"), 12 path('weather', views.weather, name="weather"),
13 path('weather/current', views.weather_current, name="weather_current"), 13 path('weather/current', views.weather_current, name="weather_current"),
  14 + path('weather/config', views.weather_config, name="weather_config"),
14 path('site', views.site, name="site"), 15 path('site', views.site, name="site"),
15 path('site/current', views.site_current, name="site_current"), 16 path('site/current', views.site_current, name="site_current"),
16 path('proposal', views.proposal, name='proposal'), 17 path('proposal', views.proposal, name='proposal'),
src/dashboard/views.py
@@ -143,28 +143,44 @@ def weather(request): @@ -143,28 +143,44 @@ def weather(request):
143 143
144 def weather_current(request): 144 def weather_current(request):
145 # PM 20180718 145 # PM 20180718
146 - if request.is_ajax():  
147 - try:  
148 - weather_status = WeatherWatch.objects.latest('updated')  
149 - plc_device_status = PlcDeviceStatus.objects.exclude(plc_mode=None).latest('created')  
150 - plc_mode = plc_device_status.plc_mode  
151 - is_safe = plc_device_status.is_safe  
152 - weather = serializers.serialize('json', [weather_status])  
153 - weather = json.loads(weather)  
154 - ack = Config.objects.get(id=1).ack  
155 - plc_timeout = Config.objects.get(pk=1).plc_timeout_seconds  
156 - timeout = (datetime.datetime.now() - plc_device_status.created).total_seconds()  
157 - weather[0]['max_sunelev'] = SUN_ELEV_DAY_THRESHOLD  
158 - weather[0]['sunelev'] = get_sunelev()  
159 - weather[0]["plc_mode"] = plc_mode  
160 - weather[0]["is_safe"] = is_safe  
161 - weather[0]["ACK"] = ack  
162 - weather[0]["plc_timeout"] = timeout  
163 - weather[0]["max_plc_timeout"] = plc_timeout  
164 - weather[0]["pyros_mode"] = Config.objects.get(id=1).pyros_state  
165 - return HttpResponse(json.dumps(weather), content_type="application/json")  
166 - except WeatherWatch.DoesNotExist:  
167 - raise Http404("No WeatherWatch matches the given query.") 146 + #if request.is_ajax():
  147 + try:
  148 + weather_status = WeatherWatch.objects.latest('updated')
  149 + plc_device_status = PlcDeviceStatus.objects.exclude(plc_mode=None).latest('created')
  150 + plc_mode = plc_device_status.plc_mode
  151 + is_safe = plc_device_status.is_safe
  152 + weather = serializers.serialize('json', [weather_status])
  153 + weather = json.loads(weather)
  154 + ack = Config.objects.get(id=1).ack
  155 + plc_timeout = Config.objects.get(pk=1).plc_timeout_seconds
  156 + timeout = (datetime.datetime.now() - plc_device_status.created).total_seconds()
  157 + weather[0]['max_sunelev'] = SUN_ELEV_DAY_THRESHOLD
  158 + weather[0]['sunelev'] = get_sunelev()
  159 + weather[0]["plc_mode"] = plc_mode
  160 + weather[0]["is_safe"] = is_safe
  161 + weather[0]["ACK"] = ack
  162 + weather[0]["plc_timeout"] = timeout
  163 + weather[0]["max_plc_timeout"] = plc_timeout
  164 + weather[0]["pyros_mode"] = Config.objects.get(id=1).pyros_state
  165 + return HttpResponse(json.dumps(weather), content_type="application/json")
  166 + except WeatherWatch.DoesNotExist:
  167 + raise Http404("No WeatherWatch matches the given query.")
  168 +
  169 +def weather_config(request):
  170 + # PM 20180926 prototype whithout database
  171 + try:
  172 + #import os
  173 + from src.monitoring.plc_checker import PlcChecker
  174 + #cur_dir = os.path.abspath(".")
  175 + colibri_json = open("../simulators/plc/colibri-new-fixed-2.json")
  176 + colibri_struct = json.load(colibri_json)
  177 + plc_status = colibri_struct["statuses"][1]["entities"][0]
  178 + plc_checker = PlcChecker(plc_status)
  179 + plc_checker.scan_captors()
  180 +
  181 + return render(request, 'dashboard/config_weather.html', {'weather_config' : plc_checker.captors_conf})
  182 + except Config.DoesNotExist:
  183 + return render(request, 'dashboard/config_weather.html', {'weather_info' : None})
168 184
169 def weather_current_old(request): 185 def weather_current_old(request):
170 try: 186 try:
src/monitoring/plc_checker.py
@@ -25,11 +25,17 @@ class PlcChecker(object): @@ -25,11 +25,17 @@ class PlcChecker(object):
25 self.captors_conf = {} 25 self.captors_conf = {}
26 26
27 def scan_captors(self): 27 def scan_captors(self):
28 - logger.debug(self.struct["date"]) 28 + try:
  29 + logger.debug(self.struct["date"])
  30 + except Exception as e:
  31 + logger.debug("No date")
29 for captor_type in self.captors: 32 for captor_type in self.captors:
30 self.captors_conf[captor_type] = {} 33 self.captors_conf[captor_type] = {}
31 logger.debug(captor_type + ":") 34 logger.debug(captor_type + ":")
32 - self.cross_devices_list(captor_type) 35 + try:
  36 + self.cross_devices_list(captor_type)
  37 + except Exception as e:
  38 + logger.debug(captor_type + " error")
33 39
34 def cross_devices_list(self, captor_type): 40 def cross_devices_list(self, captor_type):
35 """""" 41 """"""