From d2c6495a5836724ca4782135d083d918fd64f9eb Mon Sep 17 00:00:00 2001 From: Alain Klotz Date: Thu, 10 Jan 2019 21:33:24 +0100 Subject: [PATCH] Mise à jour version 1.3 du rapport Json. --- src/utils/report/doc/user_guide_module_report.odt | Bin 24632 -> 0 bytes src/utils/report/status_json.py | 61 +++++++++++++++++++++++++++++++++---------------------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/utils/report/doc/user_guide_module_report.odt b/src/utils/report/doc/user_guide_module_report.odt index d4c4165..01f91f9 100644 Binary files a/src/utils/report/doc/user_guide_module_report.odt and b/src/utils/report/doc/user_guide_module_report.odt differ diff --git a/src/utils/report/status_json.py b/src/utils/report/status_json.py index 81875ab..b086a69 100644 --- a/src/utils/report/status_json.py +++ b/src/utils/report/status_json.py @@ -28,7 +28,7 @@ class Status_json: Example a a very wimple Json file report contents: { - "frame_model": "1.2", + "frame_model": "1.3", "producer_name": "PLC", "producer_version": "20180909", "entities": [ @@ -37,7 +37,7 @@ Example a a very wimple Json file report contents: "origin": "Raspberry", "version_firmware": "20180924A", "site": "MyObservatory", - "date": "2018-11-29T15:07:20.999", + "date": "2019-01-10T20:20:20.738", "devices": [ { "device_name": "DHT22", @@ -51,14 +51,15 @@ Example a a very wimple Json file report contents: "value": "22", "unit": "degC", "monitoring_name": "Temperature_outside", - "comment": "Temperature" + "comment": "Temperature", + "date_data": "2019-01-10T20:20:20.738" } ] } ] } ] -} +} A value is stored in a UFKI (Unique Four Key Identifier): UFKI = entity_name device_name serial_number name @@ -242,7 +243,7 @@ https://github.com/hjson/hjson-py #################################################################### def _status_new(self, producer_name, producer_version): - status_header = {'frame_model':'1.2', 'producer_name':producer_name, 'producer_version':producer_version, 'entities':[]} + status_header = {'frame_model':'1.3', 'producer_name':producer_name, 'producer_version':producer_version, 'entities':[]} #self._status = { 'statuses':[] } #self._status['statuses'].append(status_header) self._status = status_header @@ -263,7 +264,7 @@ https://github.com/hjson/hjson-py #self._status['statuses'][0]['entities'][indicee]['devices'].append(device) self._status['entities'][indicee]['devices'].append(device) - def _status_entity_device_new_value(self, entity_name, device_name, serial_number, name, data_type, value, unit="", monitoring_name="", comment=""): + def _status_entity_device_new_value(self, entity_name, device_name, serial_number, name, data_type, value, unit="", monitoring_name="", comment="", date_data=""): entities = self._get_entity_names() indicee = self._get_indice_from_entities(entities,entity_name) if indicee == -1: @@ -273,7 +274,11 @@ https://github.com/hjson/hjson-py indiced = self._get_indice_from_devices(devices, device_name, serial_number) if indiced == -1: return "" - dico = {'name':name, 'data_type':data_type, 'value':value, 'unit':unit, 'monitoring_name':monitoring_name, 'comment':comment} + if date_data=="": + date_data = (celme.Date("now")).iso() + else: + date_data = (celme.Date(date_data)).iso() + dico = {'name':name, 'data_type':data_type, 'value':value, 'unit':unit, 'monitoring_name':monitoring_name, 'comment':comment, 'date_data':date_data} #self._status['statuses'][0]['entities'][indicee]['devices'][indiced]['device_values'].append(dico) self._status['entities'][indicee]['devices'][indiced]['device_values'].append(dico) @@ -343,7 +348,7 @@ https://github.com/hjson/hjson-py self._device_name = device_name self._serial_number = serial_number - def append_value(self, name, data_type, value, unit="", monitoring_name="", comment=""): + def append_value(self, name, data_type, value, unit="", monitoring_name="", comment="", date_data=""): """ Append a new value to a device Inputs: @@ -356,7 +361,7 @@ https://github.com/hjson/hjson-py >>> report.new_status("PLC","20180909") >>> rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory") >>> rep.append_device("DHT22", "meteo", "1", "0") - >>> rep.append_value( "OutsideTemperature", "float","22","degC","temperature","Temperature") + >>> rep.append_value( "OutsideTemperature", "float","22","degC","temperature","Temperature","") Related topics: --------------- @@ -365,7 +370,7 @@ https://github.com/hjson/hjson-py entity_name = self._entity_name device_name = self._device_name serial_number = self._serial_number - self._status_entity_device_new_value(entity_name, device_name, serial_number, name, data_type, value, unit, monitoring_name, comment) + self._status_entity_device_new_value(entity_name, device_name, serial_number, name, data_type, value, unit, monitoring_name, comment, date_data) def load_json(self, full_filename): """ Load a Json file as an object @@ -721,7 +726,7 @@ if __name__ == "__main__": rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory") # --- one device with one value rep.append_device("DHT22", "meteo", "1", "0") - rep.append_value( "OutsideTemperature", "float","22","degC","Temperature_outside","Temperature") + rep.append_value( "OutsideTemperature", "float","22","degC","Temperature_outside","Temperature","now") # --- List the UFKIs ufkis = rep.get_ufkis("","",False) print(" List of all UFKIs:") @@ -739,31 +744,31 @@ if __name__ == "__main__": rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "Guitalens Observatory") # --- device Came rep.append_device("Came", "roof_controler", "124", "0") - rep.append_value( "Error_code", "int","0","","","0=OK 1=PowerPB 2=SwitchPB") - rep.append_value( "Power_input", "int","0","","","0=0Volt 1=24Volts") - rep.append_value( "Mode_came", "int","0","","","0=Manual 1=Auto") - rep.append_value( "Roof_state", "int","0","","","0=Closed 1=Opened 2=Intermediate") + rep.append_value( "Error_code", "int","0","","","0=OK 1=PowerPB 2=SwitchPB","now") + rep.append_value( "Power_input", "int","0","","","0=0Volt 1=24Volts","now") + rep.append_value( "Mode_came", "int","0","","","0=Manual 1=Auto","now") + rep.append_value( "Roof_state", "int","0","","","0=Closed 1=Opened 2=Intermediate","now") # --- device CV7 rep.append_device("CV7", "weather_station", "RET6789", "0") - rep.append_value( "Error_code", "int","0","","","0=OK 1=SerialPB 2=FramePB") - rep.append_value( "Power_input", "int","0","","","0=0Volt 1=12Volts (Power from MiFe board)") - rep.append_value( "Wind_dir", "float","0","degrees","Wind_direction","0=North 90=East") - rep.append_value( "Wind_speed", "float","0","m/s","Wind_spped","Wind speed from ultrasonic sensors") - rep.append_value( "OutsideTemperature", "float","0","degC","Temperature_outside","Temperature of the anemometer") + rep.append_value( "Error_code", "int","0","","","0=OK 1=SerialPB 2=FramePB","now") + rep.append_value( "Power_input", "int","0","","","0=0Volt 1=12Volts (Power from MiFe board)","now") + rep.append_value( "Wind_dir", "float","0","degrees","Wind_direction","0=North 90=East","now") + rep.append_value( "Wind_speed", "float","0","m/s","Wind_spped","Wind speed from ultrasonic sensors","now") + rep.append_value( "OutsideTemperature", "float","0","degC","Temperature_outside","Temperature of the anemometer","now") # --- device DHT22 rep.append_device("DHT22", "weather_station", "123", "0") - rep.append_value( "Error_code", "int","0","","","0=OK 1=CheksumPB 2=LengthPB 3=NodataPB") - rep.append_value( "Temperature", "float","21","degC","temperature","Temperature inside PLX box") - rep.append_value( "Humidity", "float","77","percent","humidity","Humidity inside PLX box") + rep.append_value( "Error_code", "int","0","","","0=OK 1=CheksumPB 2=LengthPB 3=NodataPB","now") + rep.append_value( "Temperature", "float","21","degC","temperature","Temperature inside PLX box","now") + rep.append_value( "Humidity", "float","77","percent","humidity","Humidity inside PLX box","now") # --- device RG11 rep.append_device("RG11", "weather_station", "TY67", "0") - rep.append_value( "Error_code", "int","0","","","0=OK +1=PowerPB +2=NopowerPB +4=AllonePB") - rep.append_value( "RainSate", "int","0","","rain","0=Dry 1=Rain 2=Unknown") + rep.append_value( "Error_code", "int","0","","","0=OK +1=PowerPB +2=NopowerPB +4=AllonePB","now") + rep.append_value( "RainSate", "int","0","","rain","0=Dry 1=Rain 2=Unknown","now") # --- device MLX90614 rep.append_device("MLX90614", "weather_station", "1", "0") - rep.append_value( "Error_code", "int","0","","","0=OK 1=DataPB") - rep.append_value( "SkyTemperature", "float","-15.67","degC","Temperature_sky","Temperature of the sky") - rep.append_value( "CanTemperature", "float","22.47","degC","","Temperature of the TO can") + rep.append_value( "Error_code", "int","0","","","0=OK 1=DataPB","now") + rep.append_value( "SkyTemperature", "float","-15.67","degC","Temperature_sky","Temperature of the sky","now") + rep.append_value( "CanTemperature", "float","22.47","degC","","Temperature of the TO can","now") # --- List the UFKIs ufkis = rep.get_ufkis("","",False) print(" List of all UFKIs:") -- libgit2 0.21.2