From 86215102303d2d3d25192865e99f9bfeb0a431ca Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Mon, 21 Mar 2022 12:11:11 +0100 Subject: [PATCH] - small changes on script for "Pechgraben images" and "Gschliefgraben piezometer" --- .../import_feature_sensor.py | 107 ++++++++++++------ .../import_piezometer_observations_hourly.py | 8 +- notes.txt | 7 +- pechgraben_images/import_feature_sensor.py | 8 +- .../import_image_observations.py | 18 ++- 5 files changed, 102 insertions(+), 46 deletions(-) diff --git a/gschliefgraben_piezometer/import_feature_sensor.py b/gschliefgraben_piezometer/import_feature_sensor.py index d9573b4..598ed90 100644 --- a/gschliefgraben_piezometer/import_feature_sensor.py +++ b/gschliefgraben_piezometer/import_feature_sensor.py @@ -1,34 +1,35 @@ # -*- coding: utf-8 -*- """This module does blah blah.""" +from ast import List import requests # from insert_sensor.transactional import insert_sensor from insert_sensor.wrapper import (Offering, FoI, Procedure, SensorType) # import json -class Sos(): +class Sensor: """ - A class to represent a sos service. + A class to represent an input sensor. ... Attributes ---------- - sosurl : str + name : str first name of the person - token : str + x : float + token to access soso service + y : float token to access soso service """ - def __init__(self, url, token=''): - self.sosurl = str(url) # url to access the SOS - self.token = str(token) # security token, optional - # Test if URL exists - try: - test = requests.get(self.sosurl) - test.raise_for_status() - except requests.HTTPError: - print("The URL is not valid") + def __init__(self, name: str, x_coord: float, y_coord: float, + feature_id: str, feature_name: str): + self.name = name + self.x_coord = x_coord + self.y_coord = y_coord + self.feature_id = feature_id + self.feature_name = feature_name def main(): @@ -41,7 +42,7 @@ def main(): # offering = Offering( # "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/", - # "bohrloch", + # "bohrloch1", # "Bohrlöcher, Gschliefgraben Piezometer" # ) # procedure = Procedure("bohrloch1", "bohrloch1") @@ -89,30 +90,64 @@ def main(): # "bohrloch5-glasfaser-gschliefgraben", # "Piezometer5 am Gschliefgraben") - offering = Offering( - "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/", - "bohrloch6", - "Bohrloch, Gschliefgraben Piezometer" - ) - procedure = Procedure("bohrloch6", "bohrloch6") - foi = FoI("degree", "m", (13.811537883268, 47.885082327907, 0.0), - "bohrloch6-glasfaser-gschliefgraben", - "Piezometer6 am Gschliefgraben") + # offering = Offering( + # "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/", + # "bohrloch6", + # "Bohrloch, Gschliefgraben Piezometer" + # ) + # procedure = Procedure("bohrloch6", "bohrloch6") + # foi = FoI("degree", "m", (13.811537883268, 47.885082327907, 0.0), + # "bohrloch6-glasfaser-gschliefgraben", + # "Piezometer6 am Gschliefgraben") - sensor_type = SensorType("piezometer") - post_data = insert_sensor(offering, procedure, foi, sensor_type) - print(post_data) - headers = {'Accept': 'application/json'} - request = requests.post(sos_url, headers=headers, json=post_data) - print(request.text) + # creating list + sensor_list: List[Sensor] = [] -# { -# "request" : "InsertSensor", -# "version" : "2.0.0", -# "service" : "SOS", -# "assignedProcedure" : "bohrloch1", -# "assignedOffering" : "bohrloch" -# } + # appending instances to list + sensor_list.append( + Sensor('gschliefgraben_bohrloch_1', 13.774966, 47.910849, + "bohrloch1-glasfaser-gschliefgraben", "Piezometer1 am Gschliefgraben")) + sensor_list.append( + Sensor('gschliefgraben_bohrloch_2', 13.80957276439, 47.882524348741, + "bohrloch2-glasfaser-gschliefgraben", "Piezometer2 am Gschliefgraben")) + sensor_list.append( + Sensor('gschliefgraben_bohrloch_3', 13.809990909737, 47.882824994038, + "bohrloch3-glasfaser-gschliefgraben", "Piezometer3 am Gschliefgraben")) + sensor_list.append( + Sensor('gschliefgraben_bohrloch_4', 13.809379587392, 47.883098856837, + "bohrloch4-glasfaser-gschliefgraben", "Piezometer4 am Gschliefgraben")) + sensor_list.append( + Sensor('gschliefgraben_bohrloch_5', 13.81120655331, 47.884145740545, + "bohrloch5-glasfaser-gschliefgraben", "Piezometer5 am Gschliefgraben")) + sensor_list.append( + Sensor('gschliefgraben_bohrloch_6', 13.811537883268, 47.885082327907, + "bohrloch6-glasfaser-gschliefgraben", "Piezometer6 am Gschliefgraben")) + + sensor: Sensor + for sensor in sensor_list: + # platform wolfsegg + offering = Offering( + "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/", + sensor.name, + "Bohrloch, Gschliefgraben Piezometer" + ) + procedure = Procedure(sensor.name, sensor.name) + foi = FoI("degree", "m", (sensor.x_coord, sensor.y_coord, 0.0), + sensor.feature_id, sensor.feature_name) + # now insert sensor via rest service: + sensor_type = SensorType("piezometer") + post_data = insert_sensor(offering, procedure, foi, sensor_type) + # print(post_data) + headers = {'Accept': 'application/json'} + request = requests.post(sos_url, headers=headers, json=post_data) + print(request.text) + # { + # "request" : "InsertSensor", + # "version" : "2.0.0", + # "service" : "SOS", + # "assignedProcedure" : "bohrloch1", + # "assignedOffering" : "bohrloch" + # } def insert_sensor(offering, procedure, foi, sensor_type): diff --git a/gschliefgraben_piezometer/import_piezometer_observations_hourly.py b/gschliefgraben_piezometer/import_piezometer_observations_hourly.py index 86ec689..6dde3a3 100644 --- a/gschliefgraben_piezometer/import_piezometer_observations_hourly.py +++ b/gschliefgraben_piezometer/import_piezometer_observations_hourly.py @@ -36,7 +36,9 @@ def main(): resp = requests.get(url=url, params=params, headers=headers) data: json = resp.json() # Check the JSON Response Content documentation below - for sensor in sensor_list: + for sensor_id in sensor_list: + # sensor_id = sensor_tuple[0] + sensor = sensor_list[sensor_id] pg_query = pg_session.query(Dataset) \ .join(Procedure) \ .join(Phenomenon) \ @@ -85,8 +87,8 @@ def main(): "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement") \ .first() elevation_dataset.fk_format_id = sensor_format.id - if sensor in data: - create_observation(elevation_dataset, sensor, data, pg_session) + if sensor_id in data: + create_observation(elevation_dataset, sensor_id, data, pg_session) pg_session.commit() first_elevation_observation = pg_session.query(Observation) \ diff --git a/notes.txt b/notes.txt index 68f0214..ca31134 100644 --- a/notes.txt +++ b/notes.txt @@ -58,4 +58,9 @@ https://stackoverflow.com/questions/51737548/how-to-set-primary-key-auto-increme - --> \ No newline at end of file + --> + + + +1. Pechgraben images +2. Gschliefgraben Piezometer \ No newline at end of file diff --git a/pechgraben_images/import_feature_sensor.py b/pechgraben_images/import_feature_sensor.py index fbd6863..a1eca2c 100644 --- a/pechgraben_images/import_feature_sensor.py +++ b/pechgraben_images/import_feature_sensor.py @@ -55,13 +55,13 @@ def main(): offering = Offering( "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/", - "camera2", - "camera2, Pechgraben" + "camera1", + "camera, Pechgraben" ) - procedure = Procedure("camera2", "Procedure camera2 am Pechgraben") + procedure = Procedure("camera1", "Procedure camera1 am Pechgraben") foi = FoI("degree", "m", (14.54621, 47.92861, 0.0), - "pechgraben2", "Katastropheneinsatz in Pechgraben2") + "pechgraben", "Katastropheneinsatz in Pechgraben") sensor_type = SensorType("camera") post_data = insert_sensor(offering, procedure, foi, sensor_type) diff --git a/pechgraben_images/import_image_observations.py b/pechgraben_images/import_image_observations.py index d08059b..0bcc88c 100644 --- a/pechgraben_images/import_image_observations.py +++ b/pechgraben_images/import_image_observations.py @@ -17,7 +17,7 @@ def main(): ''' main method ''' pg_session: session = create_pg_session() platform_sta_identifier = "pechgraben_images" - sensor = "camera2" + sensor = "camera1" pg_query = pg_session.query(Dataset) \ .join(Procedure) \ @@ -38,7 +38,21 @@ def main(): platform_exists: bool = pg_session.query(Platform.id).filter_by( sta_identifier=platform_sta_identifier).scalar() is not None - if platform_exists: + # if platform_exists: + # sensor_platform = pg_session.query(Platform.id) \ + # .filter(Platform.sta_identifier == platform_sta_identifier) \ + # .first() + # visual_perception_dataset.fk_platform_id = sensor_platform.id + + if not platform_exists: + sensor_platform = Platform() + # max_id = pg_session.query(func.max(Platform.id)).scalar() + # sensor_platform.id = max_id + 1 + sensor_platform.sta_identifier = platform_sta_identifier.lower() + sensor_platform.identifier = platform_sta_identifier.lower() + sensor_platform.name = platform_sta_identifier.lower() + visual_perception_dataset.platform = sensor_platform + else: sensor_platform = pg_session.query(Platform.id) \ .filter(Platform.sta_identifier == platform_sta_identifier) \ .first()