Commit f3d97966 authored by Federico Sismondi's avatar Federico Sismondi

Homogenized usage of NGSI for watering usecase and scripts

parent 4ba792a9
......@@ -8,6 +8,7 @@ https://telecombretagneeu-my.sharepoint.com/:x:/g/personal/federico_sismondi_tel
this pushed data model to platform, yet no specific data about entities should be included here, that should be handled by components using REST API
"""
import re
import os
import json
import datetime
......@@ -29,11 +30,20 @@ def get_ngsiv2_typed_description(val):
elif isinstance(val, int) or isinstance(val, float):
return {'type': 'Number', 'value': val}
elif isinstance(val, str):
return {'type': 'Text', 'value': val}
elif isinstance(val, datetime):
return {'type': 'DateTime', 'value': val.isoformat()}
pat = r'[<>"\'=;()]' # see https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html
r = re.compile(pat)
if r.search(val) is None:
new_val = val
else:
new_val = re.sub(pat, '', val)
return {'type': 'Text', 'value': new_val}
elif isinstance(val, datetime.datetime):
# replace +00:00 is the same as Z but Orion doesnt like it :/
return {'type': 'DateTime', 'value': str(val.isoformat()).replace("+00:00", "Z")}
elif isinstance(val, dict):
return {'type': 'StructuredValue', 'value': val}
return {'value': val} # bypassed
elif isinstance(val, list):
return {'value': val} # bypassed
elif isinstance(val, type(None)):
return {'type': 'Text', 'value': None}
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment