def execute_get(self): state = State('config.json') server = yield from Server.create(state) body = { "entity": "specimen", "action": "retrieve", "params": { "specimen": self.specimen_link } } # Preparing the Request object request = HttpRequest("POST", '/rest', body=body) response = yield from server.execute_http_request( request, stats=True ) assert response['response']['success'] specimen = response['response']['data'][0] assert body[ 'params']['specimen'].split('/')[-1] == specimen['identifier']
def execute_get(self): # Installation of the istSOS server print("\n") server = yield from Server.create() # Preparing the Request object request = HttpRequest( "GET", "sos", parameters={ "service": "SOS", "version": "2.0.0", "request": "GetObservation", "procedure": "LUGANO", "temporalFilter": ( "om:phenomenonTime," "2017-01-01T00:00:00+0100/" "2018-01-01T00:00:00+0100" ) } ) response = yield from server.execute_http_request( request, stats=True )
def execute_getobservation_01(self): server = yield from Server.create() request = HttpRequest("GET", "sos", parameters={ "service": "SOS", "version": "2.0.0", "request": "GetObservation", "offering": "T_LUGANO" }) self.response = yield from server.execute_http_request(request) print(self.response)
def execute_get(self): # Installation of the istSOS server server = yield from Server.create() # Preparing the Request object request = HttpRequest("GET", "sos", parameters={ "service": "SOS", "version": "2.0.0", "request": "GetCapabilities", "AcceptVersions": "2.0.0" }) response = yield from server.execute_http_request(request, stats=True)
def execute_post(self): state = State('config.json') server = yield from Server.create(state) self.body = { "entity": "offering", "action": "create", "data": { "observable_property": [{ "type": ("http://www.opengis.net/def/observationType/" "OGC-OM/2.0/OM_Measurement"), "name": "air-temperature", "definition": ("urn:ogc:def:parameter:x-istsos:1.0:" "meteo:air:temperature"), "uom": "°C" }], "observation_type": [{ "definition": ("http://www.opengis.net/def/observationType/" "OGC-OM/2.0/OM_Measurement"), "description": "" }], "procedure": ("urn:ogc:def:procedure:x-istsos:1.0:{}").format(uuid.uuid4()), "procedure_description_format": ["http://www.opengis.net/sensorML/1.0.1"], "foi_type": ("http://www.opengis.net/def/samplingFeatureType/OGC-OM/" "2.0/SF_SamplingPoint"), "foi_name": "https://istsos.org/istsos3/fois/ceresio", "systemType": "undefined" } } # Preparing the Request object request = HttpRequest("POST", '/rest', body=self.body) response = yield from server.execute_http_request(request, stats=True) assert response['response']['success']
def execute_post(self): state = State('config.json') server = yield from Server.create(state) self.body = { "entity": "material", "action": "create", "data": { "name": "{}".format(uuid.uuid4()), "description": "test method API" } } # Preparing the Request object request = HttpRequest("POST", '/rest', body=self.body) response = yield from server.execute_http_request(request, stats=True) assert response['response']['success']
def execute_insert_observation(self, path): with open(path) as xml_file: # Installation of the istSOS server server = yield from Server.create() # Preparing the Request object request = HttpRequest( "POST", "sos", body=xml_file.read(), content_type="application/xml" ) print() response = yield from server.execute_http_request( request, stats=True )
def execute_get(self): # Installation of the istSOS server state = State('config.json') server = yield from Server.create(state) body = {"entity": "uoms", "action": "retrieve"} # Preparing the Request object request = HttpRequest("POST", 'rest', body=body) response = yield from server.execute_http_request(request, stats=True) uom_lists = response['response']['data'] for key in uom_lists.keys(): if uom_lists[key]['name'] == self.body['data']['name']: assert True return assert False
def execute_get(self): # Installation of the istSOS server state = State('config.json') server = yield from Server.create(state) body = {"entity": "observedProperties", "action": "retrieve"} # Preparing the Request object request = HttpRequest("POST", '/rest', body=body) response = yield from server.execute_http_request(request, stats=True) op_list = response['response']['data'] for op in op_list: if op['def'] == self.body['data']['def']: assert True return assert False
def execute_get(self): # Installation of the istSOS server state = State('config.json') server = yield from Server.create(state) body = {"entity": "material", "action": "retrieve"} # Preparing the Request object request = HttpRequest("GET", '/rest', body=body) response = yield from server.execute_http_request(request, stats=True) mat_lists = response['response']['data'] for mat in mat_lists: if mat['name'] == self.body['data']['name']: assert True return assert False
def execute_getobservation_02(self): server = yield from Server.create() request = HttpRequest("GET", "sos", parameters={ "service": "SOS", "version": "2.0.0", "request": "GetObservation", "offering": "T_LUGANO", "temporalFilter": ("om:phenomenonTime," "2009-05-19T00:00:00+0100/" "2009-06-19T00:00:00+0100") }) self.response = yield from server.execute_http_request(request) print(self.response)
def execute_get(self): # Installation of the istSOS server server = yield from Server.create() # Preparing the Request object request = HttpRequest("GET", "sos", parameters={ "service": "SOS", "version": "2.0.0", "request": "DescribeSensor", "procedure": "LUGANO", "procedureDescriptionFormat": ("http://www.opengis.net/sensorML/1.0.1") }) response = yield from server.execute_http_request(request, stats=True)
def execute_get(self): # Installation of the istSOS server state = State('config.json') server = yield from Server.create(state) body = {"entity": "systemType", "action": "retrieve"} # Preparing the Request object request = HttpRequest("GET", '/rest', body=body) response = yield from server.execute_http_request(request, stats=True) assert response['response']['success'] sys_lists = response['response']['data'] for system in sys_lists: if system['name'] == 'insitu-fixed-point': assert True return assert False
def execute_insert_sensor(self, path): with open(path) as xml_file: # Installation of the istSOS server server = yield from Server.create() if server.state.is_cache_active(): print("\nObservation in cache at startup %s\n" % len(server.state.get_cached_offerings().keys())) # Preparing the Request object request = HttpRequest("POST", "sos", body=xml_file.read(), content_type="application/xml") response = yield from server.execute_http_request(request, stats=True) if server.state.is_cache_active(): print("\nObservation in cache after InsertSensor %s\n" % len(server.state.get_cached_offerings().keys()))
def execute_get(self): # Installation of the istSOS server state = State('config.json') server = yield from Server.create(state) body = { "entity": "offering", "action": "retrieve", "params": { "procedures": [self.body['data']['procedure']] } } # Preparing the Request object request = HttpRequest("POST", '/rest', body=body) response = yield from server.execute_http_request(request, stats=True) assert response['response']['success'] procedure = response['response']['data'][0]['procedure'] assert procedure == self.body['data']['procedure']
def execute_post(self): state = State('config.json') server = yield from Server.create(state) self.body = { "entity": "observedProperties", "action": "create", "data": { "description": ("Air temperature at 2 meters above terrain"), "def": ("urn:ogc:def:parameter:x-istsos:1.0:" "meteo:air:temperature:{}").format(uuid.uuid4()), "name": "air-temperature-test", "type": ("http://www.opengis.net/def/observationType/" "OGC-OM/2.0/OM_Measurement") } } # Preparing the Request object request = HttpRequest("POST", '/rest', body=self.body) response = yield from server.execute_http_request(request, stats=True) assert response['response']['success']
def execute(args, logger=None): # Activate and print verbose information d = args['v'] if 'v' in args else False p = args['p'] # istSOS2 user and password su = args['su'] if 'su' in args else None sp = args['sp'] if 'sp' in args else None # Initializing Requests Session s = requests.Session() # Setting basic authentication if given if su is not None and sp is not None: s.auth = (su, sp) # istSOS2 address and service name url = args['url'] srv = args['srv'] if p == '*': # Using istSOS2 Rest API to get procedures names r = s.get("%s/wa/istsos/services/%s/procedures/operations/getlist" % (url, srv)) p = [] for procedure in r.json()['data']: p.append(procedure['name']) if d: print("Migration started for %s procedure:\n - %s" % (len(p), "\n - ".join(p))) print("\n1. Loading sensor descriptions") print("==============================") # Loading sensor descriptions sd = [] for name in p: # Using istSOS2 Rest API to get full procedures list r = s.get("%s/wa/istsos/services/%s/procedures/%s" % (url, srv, name)) sd.append(r.json()['data']) if r.json()['success'] is False: print(" > Error while loading description fro %s" % name) print(" %s" % r.json()['message']) if d: print(" > Loaded sensor description for %s" % name) # istSOS3 server initialization server = yield from Server.create() # Registering sensor in istSOS3 foiIdents = [] # used to avoid exeption of foi duplicate ** for sensor in sd: # Check sensor type: # > up to now only insitu fixed sensor are supported for classification in sensor['classification']: if classification['definition'] == ( 'urn:ogc:def:classifier:x-istsos:1.0:systemType'): if classification['value'] != "insitu-fixed-point": print("Skipping %s, %s procedure" % (sensor['name'], classification['value'])) continue # Finding unique identifier identification = sensor['system_id'] for sid in sensor['identification']: if sid['definition'] == 'urn:ogc:def:identifier:OGC:uniqueID': identification = sid['value'] # Preparing Observation types observation_types = [] observable_properties = [] if len(sensor['outputs']) > 2: # Find the complex name opDefs = [] # List of observed property definitions for outs in sensor['outputs']: if 'iso8601' not in outs['definition']: opDefs.append(outs['definition']) complexDef = os.path.commonprefix(opDefs) if complexDef[-1] == ':': complexDef = complexDef[:-1] observable_properties.append({ "definition": complexDef, "type": setting._COMPLEX_OBSERVATION }) observation_types.append(setting._COMPLEX_OBSERVATION) # Preparing Observable Properties for outs in sensor['outputs']: if 'iso8601' not in outs['definition']: observable_properties.append({ "definition": outs['definition'], "name": outs['name'], "description": outs['description'], "uom": outs['uom'], "type": setting._MESAUREMENT_OBSERVATION }) observation_types.append(setting._MESAUREMENT_OBSERVATION) # Preparing sampled feature of interest ** sampled_foi = None sampled_foi_identifier = sensor['location']['properties'][ 'name'].replace('loc_', '') shape = sensor['location']['geometry'] shape['coordinates'] = list(map(float, shape['coordinates'])) shape['epsg'] = int( sensor['location']['crs']['properties']['name'].split(":")[1]) if sampled_foi_identifier in foiIdents: sampled_foi = sampled_foi_identifier else: foiIdents.append(sampled_foi_identifier) sampled_foi = { "identifier": sampled_foi_identifier, "name": sampled_foi_identifier, "shape": shape, "type": setting._SAMPLING_POINT } request = HttpRequest("POST", "rest", json={ "action": "CREATE_SENSOR", "data": Offering.get_template({ "fixed": True, "name": sensor['system_id'], "procedure": identification, "procedure_description": { "general_info": { "alias": sensor['system_id'], "keywords": sensor['keywords'].split(","), "description": sensor['description'] } }, "observable_properties": observable_properties, "observation_types": observation_types, "foi_type": setting._SAMPLING_POINT, "sampled_foi": sampled_foi }) }) r = yield from server.execute_http_request(request)
def execute(args, logger=None): # Activate and print verbose information d = args['v'] if 'v' in args else False # Procedure name p = args['p'] # Begin date b = args['b'] if 'b' in args else "*" # End date e = args['e'] if 'e' in args else "*" # istSOS2 user and password su = args['su'] if 'su' in args else None sp = args['sp'] if 'sp' in args else None # Initializing Requests Session s = requests.Session() # Setting basic authentication if given if su is not None and sp is not None: s.auth = (su, sp) # istSOS2 address and service name url = args['url'] srv = args['srv'] # Loading sensor descriptions # Using istSOS2 Rest API to get full procedures list r = s.get("%s/wa/istsos/services/%s/procedures/%s" % (url, srv, p)) if r.json()['success'] is False: raise Exception("Description of procedure %s can not be loaded from " "istSOS2 service: %s" % (p, r.json()['message'])) # Storing istSOS2 sensor description s2 = r.json()['data'] # Get istSOS2 begin position try: start = istsos.str2date(s2['outputs'][0]['constraint']['interval'][0]) except Exception: raise Exception("The date in the source procedure constraint " "interval (%s) is not valid." % s2['outputs'][0]['constraint']['interval'][0]) # Get istSOS2 end position try: stop = istsos.str2date(s2['outputs'][0]['constraint']['interval'][1]) except Exception: raise Exception("The date in the source procedure constraint " "interval (%s) is not valid." % s2['outputs'][0]['constraint']['interval'][1]) # istSOS3 server initialization server = yield from Server.create() # Loadind sensor description from istSOS3 request = HttpRequest("POST", "rest", json={ "action": "FETCH_OFFERINGS", "data": { "offerings": [s2['system_id']] } }) yield from server.execute_http_request(request) if request['response']['success'] is False: raise Exception("Description of procedure %s can not be loaded from " "istSOS3 service: %s" % (p, request['response']['message'])) # Storing istSOS3 sensor description s3 = request['response']['data'][0] # normalizing observable_properties s3op = {} for field in s3['observable_properties']: s3op[field['definition']] = { "def": field['definition'], "name": field['name'], "type": field['type'], "uom": field['uom'] } # Start migrating observations interval = timedelta(days=15) if start < stop and (start + interval) > stop: interval = stop - start while start + interval <= stop: nextStart = start + interval if d: print("- Inserting period: %s / %s" % (start.isoformat(), nextStart.isoformat())) # Getting interval of istSOS2 observations start_time = time.time() r = s.get("%s/%s" % (url, srv), params={ "request": "GetObservation", "service": "SOS", "version": "1.0.0", "observedProperty": ':', "procedure": p, "qualityIndex": False, "responseFormat": "application/json", "offering": 'temporary', "eventTime": "%s/%s" % (start.isoformat(), nextStart.isoformat()) }) if d: print("- GetObservation in %s seconds" % (time.time() - start_time)) # Check if an Exception occured if 'ExceptionReport' in r.text: raise Exception(r.text) fields = r.json( )['ObservationCollection']['member'][0]['result']['DataArray']['field'] rows = r.json()['ObservationCollection']['member'][0]['result'][ 'DataArray']['values'] ot = None if setting._COMPLEX_OBSERVATION in s3['observation_types']: # Identifing definition name of complex observed property cpxDef = None for op in s3['observable_properties']: if op['type'] == setting._COMPLEX_OBSERVATION: cpxDef = (op['definition'] if 'definition' in op else None) # Building complex observation fields cpxFields = [] for field in fields: if 'iso8601' not in field['definition']: cpxFields.append(s3op[field['definition']]) ot = Observation.get_template({ "offering": s3['name'], "procedure": s3['procedure'], "type": setting._COMPLEX_OBSERVATION, "featureOfInterest": s3['sampled_foi']['identifier'], "observedProperty": { "def": cpxDef, "type": setting._COMPLEX_OBSERVATION, "fields": cpxFields }, "result": None }) observations = [] for row in rows: # Preparing Observation template ot['phenomenonTime'] = {"timeInstant": {"instant": row[0]}} ot['resultTime'] = {"timeInstant": {"instant": row[0]}} if 'None' in row[1:] or 'NaN' in row[1:]: rowFloat = [] if d: print("!!!!!!!!! NULL VALUE AT: %s" % row) for cell in row[1:]: if cell == 'None' or cell == 'NaN': rowFloat.append(None) else: rowFloat.append(float(cell)) ot['result'] = rowFloat else: ot['result'] = list(map(float, row[1:])) observations.append(ot.copy()) request = HttpRequest("POST", "rest", json={ "action": "INSERT_OBSERVATIONS", "data": observations }) start_time = time.time() yield from server.execute_http_request(request) if d: print("- Inserting observation in %s seconds" % (time.time() - start_time)) start = nextStart if start < stop and (start + interval) > stop: interval = stop - start
def execute_post(self): state = State('config.json') server = yield from Server.create(state) body = { "entity": "specimen", "action": "create", "data": { "description": ( "A sample for the Lugano Lake water quality monitoring"), "identifier": str(uuid.uuid4()), "name": "LUG_20170808", "type": { "href": ( "http://www.opengis.net/def/samplingFeatureType/" "OGC-OM/2.0/SF_Specimen") }, "sampledFeature": { "href": "http://www.istsos.org/demo/feature/LuganoLake" }, "materialClass": { "href": "http://www.istsos.org/material/water" }, "samplingTime": { "timeInstant": { "instant": "2017-06-30T15:27:00+01:00" } }, "samplingMethod": { "href": "http://www.istsos.org/samplingMethod/still-water" }, "samplingLocation": { "type": "point", "coordinates": [100.0, 0.0] }, "processingDetails": [ { "processOperator": { "href": "http://www.supsi.ch/ist?person=MarioBianchi" }, "processingDetails": { "href": "http://www.istsos.org/processes/storage" }, "time": "2017-07-01T15:27:00+01:00" }, { "processOperator": { "href": "https://www.supsi.ch/ist?person=LucaRossi" }, "processingDetails": { "href": "http://www.istsos.org/processes/Reaction" }, "time": "2017-07-06T15:27:00+01:00" } ], "size": { "value": 1, "uom": "liter" }, "currentLocation": { "href": "http://www.ti.ch/umam", "rel": "http://www.onu.org/offices", "title": "Ufficio Monitoraggio Ambientale - Canton Ticino" }, "specimenType": None } } request = HttpRequest("POST", '/rest', body=body) response = yield from server.execute_http_request(request, stats=False) assert response['response']['success'] self.specimen_link = response[ 'response']['message'].split(': ')[-1].strip()