- 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 -*-
"""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):