Commit 601efee5 authored by Federico Sismondi's avatar Federico Sismondi

Merge branch 'flowerbed_updates_sug_by_carouge' into 'master'

Update() FlowerBed data model with last suggested changes from Carouge

See merge request !14
parents f3d97966 1b82e867
......@@ -51,7 +51,7 @@ def get_ngsiv2_typed_description(val):
# Data model templates, they describe those MUST-HAVE attributes, extra attributes can be added later on using the API
extra_args = {
attrs = {
'WeatherObserved': {
'dateObserved': datetime.utcnow(), # mandatory
'location': Point([0, 0]), # mandatory
......@@ -77,13 +77,18 @@ extra_args = {
'FlowerBed': {
'location': Point([0, 0]), # mandatory
'flowerType': None,
'taxon': None,
'category': [],
'width': 0,
'height': 0,
'depth': 0,
'sunExposure': None,
'dateLastWatering': datetime.fromtimestamp(0),
'nextWateringDeadline': datetime.fromtimestamp(0),
'nextWateringAmountRecommendation': datetime.fromtimestamp(0),
'soilMoisture': 0.0,
'refDevice': None,
}
},
}
entities = [
......@@ -123,7 +128,7 @@ entities = [
# http headers
headers = {
'Fiware-Service': None,
'Fiware-Service': None, # UPDATE this before sending request!
'Content-Type': 'application/json'
}
......@@ -138,20 +143,22 @@ for urn, pilots in entities:
data_type = str(urn).split(':')[2]
for pilot in pilots:
try:
entities_map[pilot].append({'id': urn,
'type': data_type,
**{attr_n: get_ngsiv2_typed_description(attr_v) for attr_n, attr_v in
extra_args[data_type].items()}
})
data = {attr_n: get_ngsiv2_typed_description(attr_v) for attr_n, attr_v in attrs[data_type].items()}
entities_map[pilot].append(
{'id': urn,
'type': data_type,
**data}
)
except KeyError:
raise KeyError('Unrecognized pilot {}'.format(pilot))
# for _, ents in entities_map.items():
# pprint(ents, indent=4)
#import sys
#sys.exit(0)
# import sys
# sys.exit(0)
# create entities in IoT platform
print('Updating/creating entities')
......
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