Commit d2c6495a5836724ca4782135d083d918fd64f9eb

Authored by Alain Klotz
1 parent 5e183657
Exists in dev

Mise à jour version 1.3 du rapport Json.

src/utils/report/doc/user_guide_module_report.odt
No preview for this file type
src/utils/report/status_json.py
... ... @@ -28,7 +28,7 @@ class Status_json:
28 28  
29 29 Example a a very wimple Json file report contents:
30 30 {
31   - "frame_model": "1.2",
  31 + "frame_model": "1.3",
32 32 "producer_name": "PLC",
33 33 "producer_version": "20180909",
34 34 "entities": [
... ... @@ -37,7 +37,7 @@ Example a a very wimple Json file report contents:
37 37 "origin": "Raspberry",
38 38 "version_firmware": "20180924A",
39 39 "site": "MyObservatory",
40   - "date": "2018-11-29T15:07:20.999",
  40 + "date": "2019-01-10T20:20:20.738",
41 41 "devices": [
42 42 {
43 43 "device_name": "DHT22",
... ... @@ -51,14 +51,15 @@ Example a a very wimple Json file report contents:
51 51 "value": "22",
52 52 "unit": "degC",
53 53 "monitoring_name": "Temperature_outside",
54   - "comment": "Temperature"
  54 + "comment": "Temperature",
  55 + "date_data": "2019-01-10T20:20:20.738"
55 56 }
56 57 ]
57 58 }
58 59 ]
59 60 }
60 61 ]
61   -}
  62 +}
62 63  
63 64 A value is stored in a UFKI (Unique Four Key Identifier):
64 65 UFKI = entity_name device_name serial_number name
... ... @@ -242,7 +243,7 @@ https://github.com/hjson/hjson-py
242 243 ####################################################################
243 244  
244 245 def _status_new(self, producer_name, producer_version):
245   - status_header = {'frame_model':'1.2', 'producer_name':producer_name, 'producer_version':producer_version, 'entities':[]}
  246 + status_header = {'frame_model':'1.3', 'producer_name':producer_name, 'producer_version':producer_version, 'entities':[]}
246 247 #self._status = { 'statuses':[] }
247 248 #self._status['statuses'].append(status_header)
248 249 self._status = status_header
... ... @@ -263,7 +264,7 @@ https://github.com/hjson/hjson-py
263 264 #self._status['statuses'][0]['entities'][indicee]['devices'].append(device)
264 265 self._status['entities'][indicee]['devices'].append(device)
265 266  
266   - def _status_entity_device_new_value(self, entity_name, device_name, serial_number, name, data_type, value, unit="", monitoring_name="", comment=""):
  267 + def _status_entity_device_new_value(self, entity_name, device_name, serial_number, name, data_type, value, unit="", monitoring_name="", comment="", date_data=""):
267 268 entities = self._get_entity_names()
268 269 indicee = self._get_indice_from_entities(entities,entity_name)
269 270 if indicee == -1:
... ... @@ -273,7 +274,11 @@ https://github.com/hjson/hjson-py
273 274 indiced = self._get_indice_from_devices(devices, device_name, serial_number)
274 275 if indiced == -1:
275 276 return ""
276   - dico = {'name':name, 'data_type':data_type, 'value':value, 'unit':unit, 'monitoring_name':monitoring_name, 'comment':comment}
  277 + if date_data=="":
  278 + date_data = (celme.Date("now")).iso()
  279 + else:
  280 + date_data = (celme.Date(date_data)).iso()
  281 + dico = {'name':name, 'data_type':data_type, 'value':value, 'unit':unit, 'monitoring_name':monitoring_name, 'comment':comment, 'date_data':date_data}
277 282 #self._status['statuses'][0]['entities'][indicee]['devices'][indiced]['device_values'].append(dico)
278 283 self._status['entities'][indicee]['devices'][indiced]['device_values'].append(dico)
279 284  
... ... @@ -343,7 +348,7 @@ https://github.com/hjson/hjson-py
343 348 self._device_name = device_name
344 349 self._serial_number = serial_number
345 350  
346   - def append_value(self, name, data_type, value, unit="", monitoring_name="", comment=""):
  351 + def append_value(self, name, data_type, value, unit="", monitoring_name="", comment="", date_data=""):
347 352 """ Append a new value to a device
348 353  
349 354 Inputs:
... ... @@ -356,7 +361,7 @@ https://github.com/hjson/hjson-py
356 361 >>> report.new_status("PLC","20180909")
357 362 >>> rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory")
358 363 >>> rep.append_device("DHT22", "meteo", "1", "0")
359   - >>> rep.append_value( "OutsideTemperature", "float","22","degC","temperature","Temperature")
  364 + >>> rep.append_value( "OutsideTemperature", "float","22","degC","temperature","Temperature","")
360 365  
361 366 Related topics:
362 367 ---------------
... ... @@ -365,7 +370,7 @@ https://github.com/hjson/hjson-py
365 370 entity_name = self._entity_name
366 371 device_name = self._device_name
367 372 serial_number = self._serial_number
368   - self._status_entity_device_new_value(entity_name, device_name, serial_number, name, data_type, value, unit, monitoring_name, comment)
  373 + self._status_entity_device_new_value(entity_name, device_name, serial_number, name, data_type, value, unit, monitoring_name, comment, date_data)
369 374  
370 375 def load_json(self, full_filename):
371 376 """ Load a Json file as an object
... ... @@ -721,7 +726,7 @@ if __name__ == "__main__":
721 726 rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory")
722 727 # --- one device with one value
723 728 rep.append_device("DHT22", "meteo", "1", "0")
724   - rep.append_value( "OutsideTemperature", "float","22","degC","Temperature_outside","Temperature")
  729 + rep.append_value( "OutsideTemperature", "float","22","degC","Temperature_outside","Temperature","now")
725 730 # --- List the UFKIs
726 731 ufkis = rep.get_ufkis("","",False)
727 732 print(" List of all UFKIs:")
... ... @@ -739,31 +744,31 @@ if __name__ == "__main__":
739 744 rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "Guitalens Observatory")
740 745 # --- device Came
741 746 rep.append_device("Came", "roof_controler", "124", "0")
742   - rep.append_value( "Error_code", "int","0","","","0=OK 1=PowerPB 2=SwitchPB")
743   - rep.append_value( "Power_input", "int","0","","","0=0Volt 1=24Volts")
744   - rep.append_value( "Mode_came", "int","0","","","0=Manual 1=Auto")
745   - rep.append_value( "Roof_state", "int","0","","","0=Closed 1=Opened 2=Intermediate")
  747 + rep.append_value( "Error_code", "int","0","","","0=OK 1=PowerPB 2=SwitchPB","now")
  748 + rep.append_value( "Power_input", "int","0","","","0=0Volt 1=24Volts","now")
  749 + rep.append_value( "Mode_came", "int","0","","","0=Manual 1=Auto","now")
  750 + rep.append_value( "Roof_state", "int","0","","","0=Closed 1=Opened 2=Intermediate","now")
746 751 # --- device CV7
747 752 rep.append_device("CV7", "weather_station", "RET6789", "0")
748   - rep.append_value( "Error_code", "int","0","","","0=OK 1=SerialPB 2=FramePB")
749   - rep.append_value( "Power_input", "int","0","","","0=0Volt 1=12Volts (Power from MiFe board)")
750   - rep.append_value( "Wind_dir", "float","0","degrees","Wind_direction","0=North 90=East")
751   - rep.append_value( "Wind_speed", "float","0","m/s","Wind_spped","Wind speed from ultrasonic sensors")
752   - rep.append_value( "OutsideTemperature", "float","0","degC","Temperature_outside","Temperature of the anemometer")
  753 + rep.append_value( "Error_code", "int","0","","","0=OK 1=SerialPB 2=FramePB","now")
  754 + rep.append_value( "Power_input", "int","0","","","0=0Volt 1=12Volts (Power from MiFe board)","now")
  755 + rep.append_value( "Wind_dir", "float","0","degrees","Wind_direction","0=North 90=East","now")
  756 + rep.append_value( "Wind_speed", "float","0","m/s","Wind_spped","Wind speed from ultrasonic sensors","now")
  757 + rep.append_value( "OutsideTemperature", "float","0","degC","Temperature_outside","Temperature of the anemometer","now")
753 758 # --- device DHT22
754 759 rep.append_device("DHT22", "weather_station", "123", "0")
755   - rep.append_value( "Error_code", "int","0","","","0=OK 1=CheksumPB 2=LengthPB 3=NodataPB")
756   - rep.append_value( "Temperature", "float","21","degC","temperature","Temperature inside PLX box")
757   - rep.append_value( "Humidity", "float","77","percent","humidity","Humidity inside PLX box")
  760 + rep.append_value( "Error_code", "int","0","","","0=OK 1=CheksumPB 2=LengthPB 3=NodataPB","now")
  761 + rep.append_value( "Temperature", "float","21","degC","temperature","Temperature inside PLX box","now")
  762 + rep.append_value( "Humidity", "float","77","percent","humidity","Humidity inside PLX box","now")
758 763 # --- device RG11
759 764 rep.append_device("RG11", "weather_station", "TY67", "0")
760   - rep.append_value( "Error_code", "int","0","","","0=OK +1=PowerPB +2=NopowerPB +4=AllonePB")
761   - rep.append_value( "RainSate", "int","0","","rain","0=Dry 1=Rain 2=Unknown")
  765 + rep.append_value( "Error_code", "int","0","","","0=OK +1=PowerPB +2=NopowerPB +4=AllonePB","now")
  766 + rep.append_value( "RainSate", "int","0","","rain","0=Dry 1=Rain 2=Unknown","now")
762 767 # --- device MLX90614
763 768 rep.append_device("MLX90614", "weather_station", "1", "0")
764   - rep.append_value( "Error_code", "int","0","","","0=OK 1=DataPB")
765   - rep.append_value( "SkyTemperature", "float","-15.67","degC","Temperature_sky","Temperature of the sky")
766   - rep.append_value( "CanTemperature", "float","22.47","degC","","Temperature of the TO can")
  769 + rep.append_value( "Error_code", "int","0","","","0=OK 1=DataPB","now")
  770 + rep.append_value( "SkyTemperature", "float","-15.67","degC","Temperature_sky","Temperature of the sky","now")
  771 + rep.append_value( "CanTemperature", "float","22.47","degC","","Temperature of the TO can","now")
767 772 # --- List the UFKIs
768 773 ufkis = rep.get_ufkis("","",False)
769 774 print(" List of all UFKIs:")
... ...