Commit f958e3f49006c2f891fe8da6569d31d9978075c1

Authored by Alexis Koralewski
1 parent 0a236660
Exists in dev

Add new version of weather config view

config/schemas/schema_observatory-2.0.yml
... ... @@ -323,6 +323,10 @@ schema;schema_UNIT:
323 323 - type: seq
324 324 sequence:
325 325 - type: number
  326 + MONITORING_DEVICES:
  327 + type: seq
  328 + sequence:
  329 + - type: str
326 330 DATABASE:
327 331 include: schema_DATABASE
328 332 AGENTS:
... ...
privatedev/config/tnc/observatory_tnc.yml
... ... @@ -199,7 +199,10 @@ OBSERVATORY:
199 199 install:
200 200 shell: /bin/sh
201 201 script: "guitastro/install/install.sh"
202   -
  202 +
  203 + MONITORING_DEVICES:
  204 + - TAROT_meteo
  205 +
203 206 AGENTS:
204 207  
205 208 # ============================================
... ... @@ -368,6 +371,14 @@ OBSERVATORY:
368 371 protocol: private/plugin/agent/AgentTriton.py
369 372 path: private/plugin/agent/triton
370 373  
  374 + - AGENT_DEVICE:
  375 + name: AgentDevicePLC_ako
  376 + computer: AKoralewskiPersoComputer
  377 + path: private/plugin/agent_devices
  378 + device: TAROT_meteo
  379 + protocol: private/plugin/agent_devices/AgentDevicePLC.py
  380 + is_real: false
  381 +#
371 382 - AGENT:
372 383 name: AgentTriton_akz
373 384 computer: AKlotzPersoComputer
... ... @@ -437,6 +448,28 @@ OBSERVATORY:
437 448 computer: IRAP_SERVER
438 449 protocol: private/plugin/agent/AgentBasic.py
439 450 is_active: True
  451 +
  452 + # Agents for astroguita
  453 +
  454 + - AGENT:
  455 + name: AgentTriton
  456 + computer: astroguitaComputer
  457 + protocol: private/plugin/agent/AgentTriton.py
  458 + path: private/plugin/agent/triton
  459 +
  460 + - AGENT:
  461 + name: AgentEnvMonitor
  462 + computer: astroguitaComputer
  463 + protocol: private/plugin/agent/AgentEnvMonitor.py
  464 +
  465 + - AGENT_DEVICE:
  466 + name: AgentDevicePLC
  467 + computer: astroguitaComputer
  468 + path: private/plugin/agent_devices
  469 + device: TAROT_meteo
  470 + protocol: private/plugin/agent_devices/AgentDevicePLC.py
  471 + is_real: false
  472 +
440 473  
441 474 TOPOLOGY:
442 475  
... ...
src/core/pyros_django/monitoring/views.py
1 1 from datetime import datetime
2 2 from django.http import HttpResponse
3 3 from django.shortcuts import render
4   -from common.models import AgentCmd, WeatherWatchHistory
  4 +from common.models import AgentCmd, WeatherWatchHistory, SiteWatch
5 5 from django.http import Http404
6 6 import json, csv
  7 +import os
7 8 from django.db.models import Q
8 9 from django.views.decorators.csrf import csrf_exempt
9 10 from django.core import serializers
10   -
  11 +from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig
11 12 # Create your views here.
12 13  
13 14  
... ... @@ -50,19 +51,24 @@ def weather_config(request):
50 51 http://127.0.0.1:8000/dashboard/weather/config
51 52 Moved to monitoring
52 53 """
53   - try:
54   - # Import PLC status sensor parser
55   - from monitoring.plc_checker import PlcChecker
56   - # Parse PLC status in colibri-new-fixed-2.json
57   - #colibri_json = open("../simulators/plc/colibri-new-fixed-2.json")
58   - #colibri_struct = json.load(colibri_json)
59   - #plc_status = colibri_struct["statuses"][1]["entities"][0]
60   - plc_checker = PlcChecker()
61   - _struct = {"origin":plc_checker.origin, "sensors_table":plc_checker.sensors_table, "monitoring_names":list(plc_checker.monitoring_names.keys())}
62   - # Return template with sensors list
63   - return render(request, 'dashboard/config_weather.html', {'weather_config' : _struct, 'base_template' : "base.html"})
64   - except Config.DoesNotExist:
65   - return render(request, 'dashboard/config_weather.html', {'weather_info' : None})
  54 + # Import PLC status sensor parser
  55 + from monitoring.plc_checker import PlcChecker
  56 + # Parse PLC status in colibri-new-fixed-2.json
  57 + #colibri_json = open("../simulators/plc/colibri-new-fixed-2.json")
  58 + #colibri_struct = json.load(colibri_json)
  59 + #plc_status = colibri_struct["statuses"][1]["entities"][0]
  60 + plc_checker = PlcChecker()
  61 + _struct = {"origin":plc_checker.origin, "sensors_table":plc_checker.sensors_table, "monitoring_names":list(plc_checker.monitoring_names.keys())}
  62 + config = OBSConfig(
  63 + os.environ["PATH_TO_OBSCONF_FILE"], os.environ["unit_name"])
  64 + monitoring_devices = config.get_monitoring_devices()
  65 + devices = config.get_devices()
  66 + devices_config = []
  67 + for device in monitoring_devices:
  68 + device_config = devices[device]
  69 + devices_config.append(device_config)
  70 + # Return template with sensors list
  71 + return render(request, 'dashboard/config_weather.html', {'weather_config' : _struct, 'base_template' : "base.html","devices_config":devices_config})
66 72  
67 73  
68 74 def weather_config_update(request):
... ... @@ -106,3 +112,18 @@ def export_weather_data(request):
106 112 return response
107 113 except WeatherWatchHistory.DoesNotExist:
108 114 raise Http404("No WeatherWatchHistory matches the given query.")
  115 +
  116 +
  117 +def internal_monitoring(request):
  118 +
  119 + current_internal_state, created = SiteWatch.objects.get_or_create(id=1)
  120 + if not created:
  121 + current_internal_state.setAttribute("InsideHumidity",0)
  122 + current_internal_state.setAttribute("Pressure",1)
  123 + current_internal_state.setAttribute("InsideTemp",19)
  124 + current_internal_state.setAttribute("Roof_state","closed")
  125 + current_internal_state.setAttribute("Power_input",1)
  126 + current_internal_state.save()
  127 + current_internal_state.setGlobalStatus()
  128 +
  129 + return render(request, "monitoring/internal_state.html", locals())
109 130 \ No newline at end of file
... ...
src/core/pyros_django/obsconfig/obsconfig_class.py
... ... @@ -318,7 +318,11 @@ class OBSConfig:
318 318 for data in capability['output_data']:
319 319 cap_data = data["data"]
320 320 name = cap_data.pop("key")
321   - output_data[name] = cap_data
  321 + model_name = attributes.get("model").get("value")
  322 + if output_data.get(model_name) is None:
  323 + output_data[model_name] = {}
  324 +
  325 + output_data[model_name][name] = cap_data
322 326 # for each attributes of generic component attributes
323 327 for attribute_name in attributes.keys():
324 328 # merge attributes of general component with specified component in device config file
... ... @@ -1292,10 +1296,8 @@ class OBSConfig:
1292 1296 for component in device:
1293 1297 if component.get("output_data"):
1294 1298 output_data = component.get("output_data")
1295   - for data in output_data:
1296   - data = data["data"]
1297   - key = data.pop("key")
1298   - result[key] = data
  1299 + for key in output_data:
  1300 + result[key] = output_data[key]
1299 1301 return result
1300 1302  
1301 1303 def get_output_data_device_sort_monitoring_name(self,device):
... ... @@ -1310,6 +1312,10 @@ class OBSConfig:
1310 1312 monitoring_names[monitoring_name] = data_dict
1311 1313 return monitoring_names
1312 1314  
  1315 + def get_monitoring_devices(self):
  1316 + unit = self.get_unit_by_name(self.unit_name)
  1317 + monitoring_devices = unit.get("MONITORING_DEVICES")
  1318 + return monitoring_devices
1313 1319 class MissingMandatoryAgentException(Exception):
1314 1320 """
1315 1321 Exception raised when an mandatory Pyros Agent is missing in the observatory configuration.
... ... @@ -1341,8 +1347,11 @@ def main():
1341 1347 # print(config.getEditableAttributesOfChannel(unit_name,"OpticalChannel_down2"))
1342 1348 #print(config.getEditableAttributesOfMount(unit_name))
1343 1349 config.get_devices()
1344   - #print(config.get_output_data_device("TAROT_meteo"))
1345   - print(config.get_output_data_device_sort_monitoring_name("TAROT_meteo").keys())
  1350 +
  1351 + #print(config.get_output_data_device("TAROT_meteo").get("CV7"))
  1352 + print(config.get_device_for_agent(config.unit_name, "AgentDevicePLC_ako").get("device_config").get("CAPABILITIES")[0].get("output_data"))
  1353 + print(config.get_monitoring_devices())
  1354 + #.get("/entities/devices/CV7/Error_code").keys())
1346 1355 #print(config.get_device_capabilities("TAROT_meteo"))
1347 1356 # print(config.get_devices()["FLI-Kepler4040"]["device_config"])
1348 1357 # print(config.get_devices()["FLI-Kepler4040"]["device_config"]["CAPABILITIES"][1]["attributes"]["manufacturer"])
... ...