Commit 7aa93557 authored by Federico Sismondi's avatar Federico Sismondi

Add WeatherOberved data model, and included it in the entity generation...

Add WeatherOberved data model, and included it in the entity generation component. Updated script so it accepts as param pilot to be updated
parent 43842549
......@@ -112,7 +112,7 @@ def _dump_raw_data_to_filesystem():
return 'ok'
def _get_reading(message_data):
def get_values_from_raw_reading(message_data):
"""
>>> base64.standard_b64decode("+AACoQEDAAAAAANY").hex()
'f8 00 02 a1 01 03 00 00 00 00 03 58'
......@@ -170,7 +170,7 @@ def _get_reading(message_data):
@app.route('/dca-carouge-fountain-sensed-data/rest/callback/payloads/ul', methods=['POST'])
def post_dca_carouge_fountain_sensed_data_payload():
# get values
# soil_humidity, sensor_eui = _get_reading(request.json['dataFrame']), request.json['deveui']
# soil_humidity, sensor_eui = get_values_from_raw_reading(request.json['dataFrame']), request.json['deveui']
# log reading
# _log_level_of_moisture(soil_humidity, sensor_eui)
......
......@@ -10,10 +10,12 @@ this pushed data model to platform, yet no specific data about entities should b
import re
import os
import sys
import json
import datetime
import logging
import requests
import datetime
import argparse
from pprint import pprint
from geojson import Point
from datetime import datetime
......@@ -92,27 +94,46 @@ attrs = {
'soilMoisture': 0.0,
'refDevice': None,
},
'WaterQualityObserved': {
'dateObserved': datetime.utcnow(), # mandatory
'location': Point([0, 0]), # mandatory
'temperature': 0.0,
'pH': 0.0,
'turbidity': 0.0,
'redox': 0.0,
'freeChlorine': 0.0,
'totalChlorine': 0.0,
'chlorateEstimation': 0.0,
'phThresholdHigh': 0.0,
'phThresholdLow': 0.0,
'chlorineThresholdHigh': 0.0,
'chlorineThresholdLow': 0.0,
'refDevice': None,
}
}
# entities ids per pilot tuples
entities = [
# prediction use case - weather observed (current)
('urn:ngsi-ld:WeatherObserved:WeatherObserved', ['carouge', 'braila']),
('urn:ngsi-ld:WeatherObserved:WeatherObserved-1', ['alicante']),
('urn:ngsi-ld:WeatherObserved:WeatherObserved-2', ['alicante']),
("urn:ngsi-ld:WaterQualityObserved:Fountain-1", ['carouge']),
# # prediction use case - forecast today
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day0-0', ['carouge', 'alicante', 'braila']),
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day0-1', ['carouge', 'alicante', 'braila']),
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day0-2', ['carouge', 'alicante', 'braila']),
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day0-3', ['carouge', 'alicante', 'braila']),
#
# # prediction use case - forecast tomorrow
# #
# # # prediction use case - forecast tomorrow
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day1-0', ['carouge', 'alicante', 'braila']),
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day1-1', ['carouge', 'alicante', 'braila']),
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day1-2', ['carouge', 'alicante', 'braila']),
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day1-3', ['carouge', 'alicante', 'braila']),
#
# # prediction use case - forecast tomorrow
# #
# # # prediction use case - forecast tomorrow
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day2-0', ['carouge', 'alicante', 'braila']),
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day2-1', ['carouge', 'alicante', 'braila']),
# ('urn:ngsi-ld:WeatherForecast:WeatherForecast-Day2-2', ['carouge', 'alicante', 'braila']),
......@@ -163,31 +184,43 @@ for urn, pilots in entities:
# import sys
# sys.exit(0)
# create entities in IoT platform
print('Updating/creating entities')
# log created entities
for k, v in entities_map.items():
print('Number of entities to be created for {}: {}'.format(k, len(v)))
headers['Fiware-Service'] = k
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Create entities for pilot in IoT Platform.',
)
parser.add_argument('pilot', help='Pilot name to update')
args = parser.parse_args(sys.argv[1:2])
if args.pilot not in entities_map.keys():
print('Unrecognized pilot, options:{} '.format( list(entities_map.keys())))
exit(1)
# create entities in IoT platform
print('Updating/creating entities for {}'.format(args.pilot))
# log created entities
entities = entities_map[args.pilot]
print('Number of entities to be created for {}: {}'.format(args.pilot, len(entities )))
headers['Fiware-Service'] = args.pilot
operation = {
'actionType': 'append',
'entities': v
'actionType': 'append',
'entities': entities
}
print('*' * 72)
print('Service {} entities:'.format(k))
pprint([i['id'] for i in v])
print('Service {} entities:'.format(args.pilot))
pprint([i['id'] for i in entities ])
print('*' * 72)
try:
r = requests.post(url=URL_BASE + '/v2/op/update', headers=headers, json=operation)
if not (200 <= r.status_code < 300):
print('HTTP status received is {}, something went wrong..'.format(r.status_code))
print(r.reason)
print(r.json())
else:
print('Entities updated (HTTP response is 2xx)')
except StopIteration:
pass
print('Finished updating/creating entities')
r = requests.post(url=URL_BASE + '/v2/op/update', headers=headers, json=operation)
if not (200 <= r.status_code < 300):
print('HTTP status received is {}, something went wrong..'.format(r.status_code))
print(r.reason)
print(r.json())
else:
print('Entities updated (HTTP response is 2xx)')
print('Finished 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