python.observation.esconstante

Created on Sun Aug 1 13:35:28 2021

@author: philippe@loco-labs.io

The python.observation.esconstante module describes the constants and default values used in other modules.

  1# -*- coding: utf-8 -*-
  2"""
  3Created on Sun Aug  1 13:35:28 2021
  4
  5@author: philippe@loco-labs.io
  6
  7The `python.observation.esconstante` module describes the constants and default values used in other modules.
  8"""
  9import datetime
 10import math
 11from typing import Dict
 12
 13
 14def _classval():
 15    import datetime
 16    from observation import LocationValue, DatationValue, PropertyValue, \
 17        NamedValue, ExternValue, TimeSlot, Observation, Dataset, Field
 18    return {ES.obs_clsName: Observation,
 19            ES.dat_clsName: DatationValue,
 20            ES.loc_clsName: LocationValue,
 21            ES.prp_clsName: PropertyValue,
 22            ES.ext_clsName: ExternValue,
 23            ES.nam_clsName: NamedValue,
 24            ES.ili_clsName: Dataset,
 25            ES.iin_clsName: Field,
 26            # ES.coo_clsName: coordinate,
 27            ES.tim_clsName: datetime.datetime,
 28            ES.slo_clsName: TimeSlot,
 29            ES.dat_classES: DatationValue,
 30            ES.loc_classES: LocationValue,
 31            ES.prp_classES: PropertyValue,
 32            ES.res_classES: NamedValue,
 33            ES.ES_clsName: NamedValue}
 34
 35
 36def _classESval():
 37    from observation.esobservation import LocationValue, DatationValue, PropertyValue, \
 38        NamedValue, ExternValue
 39    return {ES.obs_clsName: ExternValue,
 40            ES.dat_clsName: DatationValue,
 41            ES.loc_clsName: LocationValue,
 42            ES.prp_clsName: PropertyValue,
 43            ES.ext_clsName: ExternValue,
 44            ES.nam_clsName: NamedValue,
 45            ES.ili_clsName: ExternValue,
 46            # ES.coo_clsName: coordinate,
 47            ES.tim_clsName: DatationValue,
 48            ES.slo_clsName: DatationValue,
 49            ES.dat_classES: DatationValue,
 50            ES.loc_classES: LocationValue,
 51            ES.prp_classES: PropertyValue,
 52            ES.res_classES: NamedValue}
 53
 54
 55class Es:
 56    ''' initialization of constant data. '''
 57
 58    def _identity(self, x): return x
 59    def _inv(self, mp): return {val: key for key, val in mp.items()}
 60    #def _inv(self, mp)     : return dict(zip(mp.values(), mp.keys()))
 61
 62    def _invnum(self, mp): return dict(
 63        zip([k[0] for k in list(mp.values())], mp.keys()))
 64
 65    def __init__(self, defnone=True):
 66        self._initName()
 67        self._initReferenceValue()
 68        self._initStruct()
 69        self._initByte()
 70        self.debug = False
 71        self._initDefaultValue(defnone)
 72
 73    def _initStruct(self):
 74        # %% option initialization (dict)
 75        self.mOption: Dict = {
 76            "untyped": True,  # pas de type dans le json
 77            "encoded": True,  # sortie bson/json ou dict
 78            "encode_format": 'json',  # sortie bson ou json
 79            "simpleval": False,  # only value in json
 80            "json_res_index": True,  # affiche index
 81            "json_prp_name": False,  # affiche name ou property
 82            "json_dat_name": False,  # affiche name ou instant/slot
 83            "json_loc_name": False,  # affiche name ou instant/slot
 84            "json_param": False,  # ok
 85            "geojson": False,  # ok
 86            #"json_info": False,  # si True, ok pour tous les info_
 87            #"json_info_detail": False,
 88            # "json_info_type"      : False,
 89            # "json_info_nval"      : False,
 90            # "json_info_box"       : False,
 91            # "json_info_other"     : False,
 92            "unic_index": True,  # dans add
 93            # "add_equal"           : "full",  # sinon "value ou "name" pour les comparaisons
 94            "bytes_res_format": self.nullDict,  # calculé à partir de propperty si "null"
 95            "prp_dict": False,  # si True, prp_type doit être dans ES.prop
 96            "sort_order": 'dlp',
 97            "codif": {}  # self.codeb sinon
 98        }
 99        ''' Default options for `observation.Observation`'''
100
101        # %% observation initialization (dict)
102        self.vName: Dict = {self.obs_classES:   self.obs,
103                            self.dat_classES:   self.dat,
104                            self.loc_classES:   self.loc,
105                            self.res_classES:   self.res,
106                            self.prp_classES:   self.prp}
107        '''name for json classES identification '''
108
109        self.json_type: list = [
110            self.json_type_dat, self.json_type_loc, self.json_type_prp, self.json_type_res]
111        '''ordered list for json_type '''
112
113        self.json_nval: list = [
114            self.json_nval_dat, self.json_nval_loc, self.json_nval_prp, self.json_nval_res]
115        '''ordered list for json_type '''
116
117        self.esObsClass: list = [
118            self.dat_classES, self.loc_classES, self.prp_classES, self.res_classES]
119        '''ordered list for classES '''
120
121        """self.esObsId: dict = { self.dat_classES : 0, self.loc_classES : 1, self.prp_classES : 2, self.res_classES : 3}
122        '''ordered dict value for classES '''  """
123
124        self.mTypeAtt: Dict = {self.type: self.obs_classES,
125                               self.information: self.nul_classES,
126                               self.obs_resultTime: self.obs_classES,
127                               self.obs_reference: self.obs_classES,
128                               self.obs_id: self.obs_classES,
129                               "ResultQuality": self.res_classES,
130                               self.prp_type: self.prp_classES,
131                               self.prp_unit: self.prp_classES,
132                               self.prp_sampling: self.prp_classES,
133                               self.prp_appli: self.prp_classES,
134                               self.prp_EMFId: self.prp_classES,
135                               self.prp_sensorType: self.prp_classES,
136                               self.prp_upperValue: self.prp_classES,
137                               self.prp_lowerValue: self.prp_classES,
138                               self.prp_period: self.prp_classES,
139                               self.prp_interval: self.prp_classES,
140                               self.prp_uncertain: self.prp_classES,
141                               "EMFType ": "ObservingEMF",
142                               "ResultNature ": "ObservingEMF"}
143        ''' Assignment of attributes to Observation objects '''
144
145        # %% Xarray initialization (dict)
146        self.nax: Dict = {'dat': 0, 'loc': 1, 'prp': 2,
147                          'd': 0, 'l': 1, 'p': 2}
148        '''Dictionnary for axis Number '''
149
150        self.axes: Dict = {
151            0:  'dat',   # axes : [0,1,2], [0,21], [2, 10], [1, 20]
152            1:	'loc',  # [0, 1],  [0, 2], [1, 2], [120]
153            2:	'prp',
154            10:	'datloc',
155            20:	'datprp',
156            21:	'locprp',
157            120:	'datlocprp'}
158        '''Dictionnary for Xarray axis name '''
159
160        self.xattrs: Dict = {
161            'lon': {"units": "degrees",   "standard_name": "longitude"},
162            'lat': {"units": "degrees",   "standard_name": "latitude"},
163            'loc': {"units": "lon, lat",  "standard_name": "longitude - latitude"},
164            'dat': {"standard_name": "horodatage"},
165            'prp': {"standard_name": "property"}}
166        '''Dictionnary for Xarray attrs informations '''
167
168        # %% typevalue initialization (dict)
169        self.typeName: Dict = {
170            self.obs_valName: self.obs_clsName,
171            self.dat_valName: self.dat_clsName,
172            self.loc_valName: self.loc_clsName,
173            self.prp_valName: self.prp_clsName,
174            self.ext_valName: self.ext_clsName,
175            self.nam_valName: self.nam_clsName,
176            self.ili_valName: self.ili_clsName,
177            self.iin_valName: self.iin_clsName,
178            self.slo_valName: self.slo_clsName,
179            # self.coo_valName : self.coo_clsName,
180            # self.tim_valName : self.tim_clsName,
181            self.res_classES: self.ES_clsName,
182            self.dat_classES: self.dat_clsName,
183            self.loc_classES: self.loc_clsName,
184            self.prp_classES: self.prp_clsName,
185        }
186        self.valname: Dict = dict(zip(list(self.typeName.values())[:10],
187                                      list(self.typeName.keys())[:10]))
188        self.className: list = list(self.typeName.values())
189
190        self.EStypeName: Dict = {
191            self.dat_valName: self.dat_clsName,
192            self.loc_valName: self.loc_clsName,
193            self.prp_valName: self.prp_clsName,
194            self.ext_valName: self.ext_clsName,
195            self.nam_valName: self.nam_clsName,
196        }
197        self.ESvalName: Dict = self._inv(self.EStypeName)
198        self.ESclassName: list = list(self.EStypeName.values())
199
200        # %% reserved
201        self.reserved: list = [
202            self.json_nval_loc,
203            self.json_nval_dat,
204            self.json_nval_res,
205            self.json_nval_prp,
206            self.json_type_loc,
207            self.json_type_obs,
208            self.json_type_dat,
209            self.json_type_res,
210            self.json_type_prp,
211
212            #self.parameter    ,
213            self.param,
214            self.information,
215            self.type,
216            self.multi,
217            self.obs,
218            self.dat,
219            self.loc,
220            self.prp,
221            self.res,
222            self.coordinates,
223            self.index,
224            self.order,
225
226            self.nul_classES,
227            self.obs_classES,
228            self.dat_classES,
229            self.loc_classES,
230            self.prp_classES,
231            self.res_classES,
232
233            self.obs_attributes,
234            self.obs_id,
235            self.obs_resultTime,
236            self.obs_complet,
237            self.obs_reference,
238            self.obs_score,
239            self.obs_order,
240
241            self.res_mRate,
242            self.res_nEch,
243            self.res_dim,
244            self.res_axes,
245            self.set_nValue,
246
247            self.dat_box,
248            self.loc_box,
249
250            self.prp_type,
251            self.prp_unit,
252            self.prp_sampling,
253            self.prp_appli,
254            self.prp_EMFId,
255            self.prp_sensorType,
256            self.prp_upperValue,
257            self.prp_lowerValue,
258            self.prp_period,
259            self.prp_interval,
260            self.prp_uncertain,
261            self.prp_name,
262
263            self.dat_valName,
264            self.loc_valName,
265            self.prp_valName,
266            self.res_valName]
267
268    def _initByte(self):
269        # %% init byte
270        ''' Byte initialization (code) '''
271
272        self.codeb: Dict = {self.dat_classES:   1,
273                            self.loc_classES:   2,
274                            self.res_classES:   4,
275                            self.prp_classES:   3,
276                            self.res_value:   5,
277                            self.index:   6,
278                            self.variable:   7}
279        self.invcodeb: Dict = self._inv(self.codeb)
280        ''' Code for bynary interface `observation.Observation.from_bytes` and
281        `observation.Observation.to_bytes` '''
282        self.codevalue: Dict = {'name': 1,
283                                'value': 2,
284                                'namemini': 3,
285                                'valuemini': 4}
286        self.invcodevalue: Dict = self._inv(self.codevalue)
287        ''' Code for bynary interface `observation.Observation.from_bytes` and
288        `observation.Observation.to_bytes` '''
289        self.minivalue: list = [3, 4]
290        self.namevalue: list = [1, 3]
291
292        #  format : (code_ES, python format, lenght, dexp, bexp, unit)
293        self.prop: Dict = {'utf-8': (2,  '', 0,  0, 0, self.nullDict),
294                           'sfloat': (15, 'e', 2,  0, 0, self.nullDict),
295                           'uint16': (3, 'H', 2,  0, 0, self.nullDict),
296                           'uint8': (7, 'B', 1,  0, 0, self.nullDict),
297                           'sint24': (13, 'l', 3,  0, 0, self.nullDict),
298                           'uint24': (14, 'L', 3,  0, 0, self.nullDict),
299                           'sint8': (6, 'b', 1,  0, 0, self.nullDict),
300                           'sint16': (8, 'h', 4,  0, 0, self.nullDict),
301                           'uint32': (4, 'L', 4,  0, 0, self.nullDict),
302                           'PM25': (21, 'e', 2,  1, 2, 'kg/m3'),
303                           'PM10': (22, 'e', 2,  0, 0, 'kg/m3'),
304                           'CO2': (23, 'H', 2,  0, 0, 'ppm'),
305                           'temp': (24, 'h', 2, -2, 0, '°C'),
306                           'Temp': (24, 'e', 2,  0, 0, '°C'),
307                           self.nullDict: (0, 'e', 2,  0, 0, self.nullDict)}
308        self.invProp: Dict = self._invnum(self.prop)
309        self.bytedict: Dict = {self.dat_classES: ['namemini', 'value'],
310                               self.loc_classES: ['namemini', 'value'],
311                               self.prp_classES: ['valuemini'],
312                               self.res_classES: ['namemini', 'sfloat'],
313                               self.variable: ['namemini', 'value']}
314
315        '''Dictionnary for property codification (BLE - Environmental Sensing Service) '''
316
317        self.sampling: Dict = {self.nullDict: 0,
318                               'instantaneous': 1,
319                               'arithmetic mean': 2,
320                               'RMS': 3,
321                               'maximum': 4,
322                               'minimum': 5,
323                               'accumulated': 6,
324                               'count': 7}
325        '''Dictionnary for property sampling mode (BLE - Environmental Sensing Service) '''
326
327        self.invSampling: Dict = self._inv(self.sampling)
328        '''Dictionnary for property sampling mode (BLE - Environmental Sensing Service) '''
329
330        self.application: Dict = {self.nullDict: 0,
331                                  'air': 1,
332                                  'water': 2,
333                                  'barometric': 3,
334                                  'soil': 4,
335                                  'infrared': 5,
336                                  'map database': 6,
337                                  'barometric elevation source': 7}
338        '''Dictionnary for property application (BLE - Environmental Sensing Service) '''
339
340        self.invApplication = self._inv(self.application)
341        '''Dictionnary for property application (BLE - Environmental Sensing Service) '''
342
343    def _initName(self):
344        # %% init name
345        ''' Name initialization (string) '''
346        self.json_nval_loc = "nvalloc"
347        self.json_nval_dat = "nvaldat"
348        self.json_nval_res = "nvalres"
349        self.json_nval_prp = "nvalprop"
350        self.json_type_loc = "typeloc"
351        self.json_type_obs = "typeobs"
352        self.json_type_dat = "typedat"
353        self.json_type_res = "typeres"
354        self.json_type_prp = "typeprop"
355
356        self.data = "data"
357        self.datetime = "datetime"
358        self.ilist = 'ilist'
359        self.timeslot = 'timeslot'
360        #self.parameter        = "parameter"
361        self.id = "id"
362        self.param = "param"
363        self.information = "information"
364        self.observation = "observation"
365        self.type = "type"
366        self.multi = "Multi"
367        self.obs = "obs"
368        self.dat = "dat"
369        self.loc = "loc"
370        self.prp = "prp"
371        self.res = "res"
372        self.coordinates = "coordinates"
373        self.index = "index"
374        self.variable = "variable"
375        self.order = "order"
376        self.name = "name"
377        self.length = "length"
378        self.lenindex = "lenindex"
379        self.complete = "complete"
380        self.dimension = "dimension"
381        self.num = "num"
382        self.typevalue = "typevalue"
383        self.lencodec = "lencodec"
384        self.box = "box"
385        self.cat = "cat"
386        #self.typecoupl = "typecoupl"
387        self.pname = "pname"
388        self.parent = "parent"
389        self.root = "root"
390        self.typecodec = "typecodec"
391        self.rateder = "rateder"
392        self.disttomin = "disttomin"
393        self.disttomax = "disttomax"
394
395        self.nul_classES = "nullClass"
396        self.obs_classES = "observation"
397        self.dat_classES = "datation"
398        self.loc_classES = "location"
399        self.prp_classES = "property"
400        self.res_classES = "result"
401
402        self.obs_attributes = "attributes"
403        self.obs_id = "id"
404        self.obs_name = "name"
405        self.obs_data = "data"
406        self.obs_param = "param"
407        self.obs_resultTime = "ResultTime"
408        self.obs_complet = "complet"
409        self.obs_reference = "reference"
410        self.obs_score = "score"
411        self.obs_order = "order"
412
413        self.res_mRate = "measureRate"
414        self.res_nEch = "nEch"
415        self.res_dim = "dim"
416        self.res_axes = "axes"
417        self.set_nValue = "nval"
418        self.res_value = "resvalue"
419
420        self.dat_box = "datationBox"
421        self.loc_box = "locationBox"
422        self.geo_box = "geobox"
423        self.prp_box = "propertyBox"
424
425        self.prp_type = "prp"
426        self.prp_unit = "unit"
427        self.prp_sampling = "samplingFunction"
428        self.prp_appli = "application"
429        self.prp_EMFId = "EMFId"
430        self.prp_sensorType = "sensorType"
431        self.prp_upperValue = "upperValue"
432        self.prp_lowerValue = "lowerValue"
433        self.prp_period = "period"
434        self.prp_interval = "updateInterval"
435        self.prp_uncertain = "uncertainty"
436        self.prp_name = "name"
437
438        self.obs_valName = "obs"
439        self.dat_valName = "datvalue"
440        self.loc_valName = "locvalue"
441        self.prp_valName = "prpvalue"
442        self.ext_valName = "extvalue"
443        self.nam_valName = "namvalue"
444        self.res_valName = "resvalue"
445        self.ili_valName = "ilist"
446        self.iin_valName = "iindex"
447        self.coo_valName = "coordinate"
448        self.tim_valName = "datetime"
449        self.slo_valName = "timeslot"
450
451        self.obs_clsName = 'Observation'
452        self.dat_clsName = 'DatationValue'
453        self.loc_clsName = 'LocationValue'
454        self.prp_clsName = 'PropertyValue'
455        self.ext_clsName = 'ExternValue'
456        self.nam_clsName = 'NamedValue'
457        self.ili_clsName = 'Dataset'
458        self.iin_clsName = 'Field'
459        self.coo_clsName = 'coordinate'
460        self.tim_clsName = 'datetime'
461        self.slo_clsName = 'TimeSlot'
462        self.ES_clsName = 'ESValue'
463
464        self.filter = '$filter'
465
466    def _initReferenceValue(self):
467        # %% init reference value
468        ''' Reference value initialization '''
469        self.defaultindex = '$default'
470        self.variable = -1
471        self.nullparent = -2
472        self.notcrossed = -3
473        self.miniStr = 10
474        self.distRef = [48.87, 2.35]  # coordonnées Paris lat/lon
475        #self.nullDate         = datetime(1970, 1, 1)
476        #self.nullDate         = datetime.datetime.min.replace(tzinfo=datetime.timezone.utc)
477        self.nullDate = None
478        self.nullCoor = [-1, -1]
479        self.nullInd = [-1, -1, -1]
480        self.nullAtt = "null"
481        #self.nullPrp          = {}
482        self.nullPrp = {'prp': '-'}
483        self.nullName = ""
484        self.nullDict = "-"
485        self.nullInt = 0
486        self.nullVal = math.nan
487        self.nullExternVal = None
488        self.nullValues = (self.nullDate, self.nullCoor, self.nullInd, self.nullName,
489                           self.nullAtt, self.nullDict, self.nullName, self.nullVal,
490                           self.nullPrp)
491
492    def _initDefaultValue(self, defnone=True):
493        # %% init default value
494        ''' Default value initialization '''
495        if defnone:
496            self.def_clsName = None
497        else:
498            self.def_clsName = self.nam_clsName
499        if self.def_clsName:
500            self.def_dtype = self.valname[self.def_clsName]
501        else:
502            self.def_dtype = None
503
504
505ES = Es(defnone=True)
class Es:
 56class Es:
 57    ''' initialization of constant data. '''
 58
 59    def _identity(self, x): return x
 60    def _inv(self, mp): return {val: key for key, val in mp.items()}
 61    #def _inv(self, mp)     : return dict(zip(mp.values(), mp.keys()))
 62
 63    def _invnum(self, mp): return dict(
 64        zip([k[0] for k in list(mp.values())], mp.keys()))
 65
 66    def __init__(self, defnone=True):
 67        self._initName()
 68        self._initReferenceValue()
 69        self._initStruct()
 70        self._initByte()
 71        self.debug = False
 72        self._initDefaultValue(defnone)
 73
 74    def _initStruct(self):
 75        # %% option initialization (dict)
 76        self.mOption: Dict = {
 77            "untyped": True,  # pas de type dans le json
 78            "encoded": True,  # sortie bson/json ou dict
 79            "encode_format": 'json',  # sortie bson ou json
 80            "simpleval": False,  # only value in json
 81            "json_res_index": True,  # affiche index
 82            "json_prp_name": False,  # affiche name ou property
 83            "json_dat_name": False,  # affiche name ou instant/slot
 84            "json_loc_name": False,  # affiche name ou instant/slot
 85            "json_param": False,  # ok
 86            "geojson": False,  # ok
 87            #"json_info": False,  # si True, ok pour tous les info_
 88            #"json_info_detail": False,
 89            # "json_info_type"      : False,
 90            # "json_info_nval"      : False,
 91            # "json_info_box"       : False,
 92            # "json_info_other"     : False,
 93            "unic_index": True,  # dans add
 94            # "add_equal"           : "full",  # sinon "value ou "name" pour les comparaisons
 95            "bytes_res_format": self.nullDict,  # calculé à partir de propperty si "null"
 96            "prp_dict": False,  # si True, prp_type doit être dans ES.prop
 97            "sort_order": 'dlp',
 98            "codif": {}  # self.codeb sinon
 99        }
100        ''' Default options for `observation.Observation`'''
101
102        # %% observation initialization (dict)
103        self.vName: Dict = {self.obs_classES:   self.obs,
104                            self.dat_classES:   self.dat,
105                            self.loc_classES:   self.loc,
106                            self.res_classES:   self.res,
107                            self.prp_classES:   self.prp}
108        '''name for json classES identification '''
109
110        self.json_type: list = [
111            self.json_type_dat, self.json_type_loc, self.json_type_prp, self.json_type_res]
112        '''ordered list for json_type '''
113
114        self.json_nval: list = [
115            self.json_nval_dat, self.json_nval_loc, self.json_nval_prp, self.json_nval_res]
116        '''ordered list for json_type '''
117
118        self.esObsClass: list = [
119            self.dat_classES, self.loc_classES, self.prp_classES, self.res_classES]
120        '''ordered list for classES '''
121
122        """self.esObsId: dict = { self.dat_classES : 0, self.loc_classES : 1, self.prp_classES : 2, self.res_classES : 3}
123        '''ordered dict value for classES '''  """
124
125        self.mTypeAtt: Dict = {self.type: self.obs_classES,
126                               self.information: self.nul_classES,
127                               self.obs_resultTime: self.obs_classES,
128                               self.obs_reference: self.obs_classES,
129                               self.obs_id: self.obs_classES,
130                               "ResultQuality": self.res_classES,
131                               self.prp_type: self.prp_classES,
132                               self.prp_unit: self.prp_classES,
133                               self.prp_sampling: self.prp_classES,
134                               self.prp_appli: self.prp_classES,
135                               self.prp_EMFId: self.prp_classES,
136                               self.prp_sensorType: self.prp_classES,
137                               self.prp_upperValue: self.prp_classES,
138                               self.prp_lowerValue: self.prp_classES,
139                               self.prp_period: self.prp_classES,
140                               self.prp_interval: self.prp_classES,
141                               self.prp_uncertain: self.prp_classES,
142                               "EMFType ": "ObservingEMF",
143                               "ResultNature ": "ObservingEMF"}
144        ''' Assignment of attributes to Observation objects '''
145
146        # %% Xarray initialization (dict)
147        self.nax: Dict = {'dat': 0, 'loc': 1, 'prp': 2,
148                          'd': 0, 'l': 1, 'p': 2}
149        '''Dictionnary for axis Number '''
150
151        self.axes: Dict = {
152            0:  'dat',   # axes : [0,1,2], [0,21], [2, 10], [1, 20]
153            1:	'loc',  # [0, 1],  [0, 2], [1, 2], [120]
154            2:	'prp',
155            10:	'datloc',
156            20:	'datprp',
157            21:	'locprp',
158            120:	'datlocprp'}
159        '''Dictionnary for Xarray axis name '''
160
161        self.xattrs: Dict = {
162            'lon': {"units": "degrees",   "standard_name": "longitude"},
163            'lat': {"units": "degrees",   "standard_name": "latitude"},
164            'loc': {"units": "lon, lat",  "standard_name": "longitude - latitude"},
165            'dat': {"standard_name": "horodatage"},
166            'prp': {"standard_name": "property"}}
167        '''Dictionnary for Xarray attrs informations '''
168
169        # %% typevalue initialization (dict)
170        self.typeName: Dict = {
171            self.obs_valName: self.obs_clsName,
172            self.dat_valName: self.dat_clsName,
173            self.loc_valName: self.loc_clsName,
174            self.prp_valName: self.prp_clsName,
175            self.ext_valName: self.ext_clsName,
176            self.nam_valName: self.nam_clsName,
177            self.ili_valName: self.ili_clsName,
178            self.iin_valName: self.iin_clsName,
179            self.slo_valName: self.slo_clsName,
180            # self.coo_valName : self.coo_clsName,
181            # self.tim_valName : self.tim_clsName,
182            self.res_classES: self.ES_clsName,
183            self.dat_classES: self.dat_clsName,
184            self.loc_classES: self.loc_clsName,
185            self.prp_classES: self.prp_clsName,
186        }
187        self.valname: Dict = dict(zip(list(self.typeName.values())[:10],
188                                      list(self.typeName.keys())[:10]))
189        self.className: list = list(self.typeName.values())
190
191        self.EStypeName: Dict = {
192            self.dat_valName: self.dat_clsName,
193            self.loc_valName: self.loc_clsName,
194            self.prp_valName: self.prp_clsName,
195            self.ext_valName: self.ext_clsName,
196            self.nam_valName: self.nam_clsName,
197        }
198        self.ESvalName: Dict = self._inv(self.EStypeName)
199        self.ESclassName: list = list(self.EStypeName.values())
200
201        # %% reserved
202        self.reserved: list = [
203            self.json_nval_loc,
204            self.json_nval_dat,
205            self.json_nval_res,
206            self.json_nval_prp,
207            self.json_type_loc,
208            self.json_type_obs,
209            self.json_type_dat,
210            self.json_type_res,
211            self.json_type_prp,
212
213            #self.parameter    ,
214            self.param,
215            self.information,
216            self.type,
217            self.multi,
218            self.obs,
219            self.dat,
220            self.loc,
221            self.prp,
222            self.res,
223            self.coordinates,
224            self.index,
225            self.order,
226
227            self.nul_classES,
228            self.obs_classES,
229            self.dat_classES,
230            self.loc_classES,
231            self.prp_classES,
232            self.res_classES,
233
234            self.obs_attributes,
235            self.obs_id,
236            self.obs_resultTime,
237            self.obs_complet,
238            self.obs_reference,
239            self.obs_score,
240            self.obs_order,
241
242            self.res_mRate,
243            self.res_nEch,
244            self.res_dim,
245            self.res_axes,
246            self.set_nValue,
247
248            self.dat_box,
249            self.loc_box,
250
251            self.prp_type,
252            self.prp_unit,
253            self.prp_sampling,
254            self.prp_appli,
255            self.prp_EMFId,
256            self.prp_sensorType,
257            self.prp_upperValue,
258            self.prp_lowerValue,
259            self.prp_period,
260            self.prp_interval,
261            self.prp_uncertain,
262            self.prp_name,
263
264            self.dat_valName,
265            self.loc_valName,
266            self.prp_valName,
267            self.res_valName]
268
269    def _initByte(self):
270        # %% init byte
271        ''' Byte initialization (code) '''
272
273        self.codeb: Dict = {self.dat_classES:   1,
274                            self.loc_classES:   2,
275                            self.res_classES:   4,
276                            self.prp_classES:   3,
277                            self.res_value:   5,
278                            self.index:   6,
279                            self.variable:   7}
280        self.invcodeb: Dict = self._inv(self.codeb)
281        ''' Code for bynary interface `observation.Observation.from_bytes` and
282        `observation.Observation.to_bytes` '''
283        self.codevalue: Dict = {'name': 1,
284                                'value': 2,
285                                'namemini': 3,
286                                'valuemini': 4}
287        self.invcodevalue: Dict = self._inv(self.codevalue)
288        ''' Code for bynary interface `observation.Observation.from_bytes` and
289        `observation.Observation.to_bytes` '''
290        self.minivalue: list = [3, 4]
291        self.namevalue: list = [1, 3]
292
293        #  format : (code_ES, python format, lenght, dexp, bexp, unit)
294        self.prop: Dict = {'utf-8': (2,  '', 0,  0, 0, self.nullDict),
295                           'sfloat': (15, 'e', 2,  0, 0, self.nullDict),
296                           'uint16': (3, 'H', 2,  0, 0, self.nullDict),
297                           'uint8': (7, 'B', 1,  0, 0, self.nullDict),
298                           'sint24': (13, 'l', 3,  0, 0, self.nullDict),
299                           'uint24': (14, 'L', 3,  0, 0, self.nullDict),
300                           'sint8': (6, 'b', 1,  0, 0, self.nullDict),
301                           'sint16': (8, 'h', 4,  0, 0, self.nullDict),
302                           'uint32': (4, 'L', 4,  0, 0, self.nullDict),
303                           'PM25': (21, 'e', 2,  1, 2, 'kg/m3'),
304                           'PM10': (22, 'e', 2,  0, 0, 'kg/m3'),
305                           'CO2': (23, 'H', 2,  0, 0, 'ppm'),
306                           'temp': (24, 'h', 2, -2, 0, '°C'),
307                           'Temp': (24, 'e', 2,  0, 0, '°C'),
308                           self.nullDict: (0, 'e', 2,  0, 0, self.nullDict)}
309        self.invProp: Dict = self._invnum(self.prop)
310        self.bytedict: Dict = {self.dat_classES: ['namemini', 'value'],
311                               self.loc_classES: ['namemini', 'value'],
312                               self.prp_classES: ['valuemini'],
313                               self.res_classES: ['namemini', 'sfloat'],
314                               self.variable: ['namemini', 'value']}
315
316        '''Dictionnary for property codification (BLE - Environmental Sensing Service) '''
317
318        self.sampling: Dict = {self.nullDict: 0,
319                               'instantaneous': 1,
320                               'arithmetic mean': 2,
321                               'RMS': 3,
322                               'maximum': 4,
323                               'minimum': 5,
324                               'accumulated': 6,
325                               'count': 7}
326        '''Dictionnary for property sampling mode (BLE - Environmental Sensing Service) '''
327
328        self.invSampling: Dict = self._inv(self.sampling)
329        '''Dictionnary for property sampling mode (BLE - Environmental Sensing Service) '''
330
331        self.application: Dict = {self.nullDict: 0,
332                                  'air': 1,
333                                  'water': 2,
334                                  'barometric': 3,
335                                  'soil': 4,
336                                  'infrared': 5,
337                                  'map database': 6,
338                                  'barometric elevation source': 7}
339        '''Dictionnary for property application (BLE - Environmental Sensing Service) '''
340
341        self.invApplication = self._inv(self.application)
342        '''Dictionnary for property application (BLE - Environmental Sensing Service) '''
343
344    def _initName(self):
345        # %% init name
346        ''' Name initialization (string) '''
347        self.json_nval_loc = "nvalloc"
348        self.json_nval_dat = "nvaldat"
349        self.json_nval_res = "nvalres"
350        self.json_nval_prp = "nvalprop"
351        self.json_type_loc = "typeloc"
352        self.json_type_obs = "typeobs"
353        self.json_type_dat = "typedat"
354        self.json_type_res = "typeres"
355        self.json_type_prp = "typeprop"
356
357        self.data = "data"
358        self.datetime = "datetime"
359        self.ilist = 'ilist'
360        self.timeslot = 'timeslot'
361        #self.parameter        = "parameter"
362        self.id = "id"
363        self.param = "param"
364        self.information = "information"
365        self.observation = "observation"
366        self.type = "type"
367        self.multi = "Multi"
368        self.obs = "obs"
369        self.dat = "dat"
370        self.loc = "loc"
371        self.prp = "prp"
372        self.res = "res"
373        self.coordinates = "coordinates"
374        self.index = "index"
375        self.variable = "variable"
376        self.order = "order"
377        self.name = "name"
378        self.length = "length"
379        self.lenindex = "lenindex"
380        self.complete = "complete"
381        self.dimension = "dimension"
382        self.num = "num"
383        self.typevalue = "typevalue"
384        self.lencodec = "lencodec"
385        self.box = "box"
386        self.cat = "cat"
387        #self.typecoupl = "typecoupl"
388        self.pname = "pname"
389        self.parent = "parent"
390        self.root = "root"
391        self.typecodec = "typecodec"
392        self.rateder = "rateder"
393        self.disttomin = "disttomin"
394        self.disttomax = "disttomax"
395
396        self.nul_classES = "nullClass"
397        self.obs_classES = "observation"
398        self.dat_classES = "datation"
399        self.loc_classES = "location"
400        self.prp_classES = "property"
401        self.res_classES = "result"
402
403        self.obs_attributes = "attributes"
404        self.obs_id = "id"
405        self.obs_name = "name"
406        self.obs_data = "data"
407        self.obs_param = "param"
408        self.obs_resultTime = "ResultTime"
409        self.obs_complet = "complet"
410        self.obs_reference = "reference"
411        self.obs_score = "score"
412        self.obs_order = "order"
413
414        self.res_mRate = "measureRate"
415        self.res_nEch = "nEch"
416        self.res_dim = "dim"
417        self.res_axes = "axes"
418        self.set_nValue = "nval"
419        self.res_value = "resvalue"
420
421        self.dat_box = "datationBox"
422        self.loc_box = "locationBox"
423        self.geo_box = "geobox"
424        self.prp_box = "propertyBox"
425
426        self.prp_type = "prp"
427        self.prp_unit = "unit"
428        self.prp_sampling = "samplingFunction"
429        self.prp_appli = "application"
430        self.prp_EMFId = "EMFId"
431        self.prp_sensorType = "sensorType"
432        self.prp_upperValue = "upperValue"
433        self.prp_lowerValue = "lowerValue"
434        self.prp_period = "period"
435        self.prp_interval = "updateInterval"
436        self.prp_uncertain = "uncertainty"
437        self.prp_name = "name"
438
439        self.obs_valName = "obs"
440        self.dat_valName = "datvalue"
441        self.loc_valName = "locvalue"
442        self.prp_valName = "prpvalue"
443        self.ext_valName = "extvalue"
444        self.nam_valName = "namvalue"
445        self.res_valName = "resvalue"
446        self.ili_valName = "ilist"
447        self.iin_valName = "iindex"
448        self.coo_valName = "coordinate"
449        self.tim_valName = "datetime"
450        self.slo_valName = "timeslot"
451
452        self.obs_clsName = 'Observation'
453        self.dat_clsName = 'DatationValue'
454        self.loc_clsName = 'LocationValue'
455        self.prp_clsName = 'PropertyValue'
456        self.ext_clsName = 'ExternValue'
457        self.nam_clsName = 'NamedValue'
458        self.ili_clsName = 'Dataset'
459        self.iin_clsName = 'Field'
460        self.coo_clsName = 'coordinate'
461        self.tim_clsName = 'datetime'
462        self.slo_clsName = 'TimeSlot'
463        self.ES_clsName = 'ESValue'
464
465        self.filter = '$filter'
466
467    def _initReferenceValue(self):
468        # %% init reference value
469        ''' Reference value initialization '''
470        self.defaultindex = '$default'
471        self.variable = -1
472        self.nullparent = -2
473        self.notcrossed = -3
474        self.miniStr = 10
475        self.distRef = [48.87, 2.35]  # coordonnées Paris lat/lon
476        #self.nullDate         = datetime(1970, 1, 1)
477        #self.nullDate         = datetime.datetime.min.replace(tzinfo=datetime.timezone.utc)
478        self.nullDate = None
479        self.nullCoor = [-1, -1]
480        self.nullInd = [-1, -1, -1]
481        self.nullAtt = "null"
482        #self.nullPrp          = {}
483        self.nullPrp = {'prp': '-'}
484        self.nullName = ""
485        self.nullDict = "-"
486        self.nullInt = 0
487        self.nullVal = math.nan
488        self.nullExternVal = None
489        self.nullValues = (self.nullDate, self.nullCoor, self.nullInd, self.nullName,
490                           self.nullAtt, self.nullDict, self.nullName, self.nullVal,
491                           self.nullPrp)
492
493    def _initDefaultValue(self, defnone=True):
494        # %% init default value
495        ''' Default value initialization '''
496        if defnone:
497            self.def_clsName = None
498        else:
499            self.def_clsName = self.nam_clsName
500        if self.def_clsName:
501            self.def_dtype = self.valname[self.def_clsName]
502        else:
503            self.def_dtype = None

initialization of constant data.

Es(defnone=True)
66    def __init__(self, defnone=True):
67        self._initName()
68        self._initReferenceValue()
69        self._initStruct()
70        self._initByte()
71        self.debug = False
72        self._initDefaultValue(defnone)
debug