- small changes on script for "Pechgraben images" and "Gschliefgraben piezometer"

This commit is contained in:
Arno Kaimbacher 2022-03-21 12:11:11 +01:00
parent b704e55a3e
commit 8621510230
5 changed files with 102 additions and 46 deletions

View File

@ -1,34 +1,35 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""This module does blah blah.""" """This module does blah blah."""
from ast import List
import requests import requests
# from insert_sensor.transactional import insert_sensor # from insert_sensor.transactional import insert_sensor
from insert_sensor.wrapper import (Offering, FoI, Procedure, SensorType) from insert_sensor.wrapper import (Offering, FoI, Procedure, SensorType)
# import json # import json
class Sos(): class Sensor:
""" """
A class to represent a sos service. A class to represent an input sensor.
... ...
Attributes Attributes
---------- ----------
sosurl : str name : str
first name of the person first name of the person
token : str x : float
token to access soso service
y : float
token to access soso service token to access soso service
""" """
def __init__(self, url, token=''): def __init__(self, name: str, x_coord: float, y_coord: float,
self.sosurl = str(url) # url to access the SOS feature_id: str, feature_name: str):
self.token = str(token) # security token, optional self.name = name
# Test if URL exists self.x_coord = x_coord
try: self.y_coord = y_coord
test = requests.get(self.sosurl) self.feature_id = feature_id
test.raise_for_status() self.feature_name = feature_name
except requests.HTTPError:
print("The URL is not valid")
def main(): def main():
@ -41,7 +42,7 @@ def main():
# offering = Offering( # offering = Offering(
# "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/", # "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/",
# "bohrloch", # "bohrloch1",
# "Bohrlöcher, Gschliefgraben Piezometer" # "Bohrlöcher, Gschliefgraben Piezometer"
# ) # )
# procedure = Procedure("bohrloch1", "bohrloch1") # procedure = Procedure("bohrloch1", "bohrloch1")
@ -89,30 +90,64 @@ def main():
# "bohrloch5-glasfaser-gschliefgraben", # "bohrloch5-glasfaser-gschliefgraben",
# "Piezometer5 am Gschliefgraben") # "Piezometer5 am Gschliefgraben")
offering = Offering( # offering = Offering(
"https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/", # "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/",
"bohrloch6", # "bohrloch6",
"Bohrloch, Gschliefgraben Piezometer" # "Bohrloch, Gschliefgraben Piezometer"
) # )
procedure = Procedure("bohrloch6", "bohrloch6") # procedure = Procedure("bohrloch6", "bohrloch6")
foi = FoI("degree", "m", (13.811537883268, 47.885082327907, 0.0), # foi = FoI("degree", "m", (13.811537883268, 47.885082327907, 0.0),
"bohrloch6-glasfaser-gschliefgraben", # "bohrloch6-glasfaser-gschliefgraben",
"Piezometer6 am Gschliefgraben") # "Piezometer6 am Gschliefgraben")
sensor_type = SensorType("piezometer") # creating list
post_data = insert_sensor(offering, procedure, foi, sensor_type) sensor_list: List[Sensor] = []
print(post_data)
headers = {'Accept': 'application/json'}
request = requests.post(sos_url, headers=headers, json=post_data)
print(request.text)
# { # appending instances to list
# "request" : "InsertSensor", sensor_list.append(
# "version" : "2.0.0", Sensor('gschliefgraben_bohrloch_1', 13.774966, 47.910849,
# "service" : "SOS", "bohrloch1-glasfaser-gschliefgraben", "Piezometer1 am Gschliefgraben"))
# "assignedProcedure" : "bohrloch1", sensor_list.append(
# "assignedOffering" : "bohrloch" 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): def insert_sensor(offering, procedure, foi, sensor_type):

View File

@ -36,7 +36,9 @@ def main():
resp = requests.get(url=url, params=params, headers=headers) resp = requests.get(url=url, params=params, headers=headers)
data: json = resp.json() # Check the JSON Response Content documentation below 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) \ pg_query = pg_session.query(Dataset) \
.join(Procedure) \ .join(Procedure) \
.join(Phenomenon) \ .join(Phenomenon) \
@ -85,8 +87,8 @@ def main():
"http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement") \ "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement") \
.first() .first()
elevation_dataset.fk_format_id = sensor_format.id elevation_dataset.fk_format_id = sensor_format.id
if sensor in data: if sensor_id in data:
create_observation(elevation_dataset, sensor, data, pg_session) create_observation(elevation_dataset, sensor_id, data, pg_session)
pg_session.commit() pg_session.commit()
first_elevation_observation = pg_session.query(Observation) \ first_elevation_observation = pg_session.query(Observation) \

View File

@ -58,4 +58,9 @@ https://stackoverflow.com/questions/51737548/how-to-set-primary-key-auto-increme
</swe:DataRecord> </swe:DataRecord>
</sml:output> </sml:output>
<swe:field name="wmo_weather_code"><swe:Category definition="https://www.nodc.noaa.gov/archive/arc0021/0002199/1.1/data/0-data/HTML/WMO-CODE/WMO4677.HTM"><swe:codeSpace xlink:href="NOT_DEFINED"/></swe:Category></swe:field> --> <swe:field name="wmo_weather_code"><swe:Category definition="https://www.nodc.noaa.gov/archive/arc0021/0002199/1.1/data/0-data/HTML/WMO-CODE/WMO4677.HTM"><swe:codeSpace xlink:href="NOT_DEFINED"/></swe:Category></swe:field> -->
1. Pechgraben images
2. Gschliefgraben Piezometer

View File

@ -55,13 +55,13 @@ def main():
offering = Offering( offering = Offering(
"https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/", "https://geomon.geologie.ac.at/52n-sos-webapp/api/offerings/",
"camera2", "camera1",
"camera2, Pechgraben" "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), foi = FoI("degree", "m", (14.54621, 47.92861, 0.0),
"pechgraben2", "Katastropheneinsatz in Pechgraben2") "pechgraben", "Katastropheneinsatz in Pechgraben")
sensor_type = SensorType("camera") sensor_type = SensorType("camera")
post_data = insert_sensor(offering, procedure, foi, sensor_type) post_data = insert_sensor(offering, procedure, foi, sensor_type)

View File

@ -17,7 +17,7 @@ def main():
''' main method ''' ''' main method '''
pg_session: session = create_pg_session() pg_session: session = create_pg_session()
platform_sta_identifier = "pechgraben_images" platform_sta_identifier = "pechgraben_images"
sensor = "camera2" sensor = "camera1"
pg_query = pg_session.query(Dataset) \ pg_query = pg_session.query(Dataset) \
.join(Procedure) \ .join(Procedure) \
@ -38,7 +38,21 @@ def main():
platform_exists: bool = pg_session.query(Platform.id).filter_by( platform_exists: bool = pg_session.query(Platform.id).filter_by(
sta_identifier=platform_sta_identifier).scalar() is not None 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) \ sensor_platform = pg_session.query(Platform.id) \
.filter(Platform.sta_identifier == platform_sta_identifier) \ .filter(Platform.sta_identifier == platform_sta_identifier) \
.first() .first()