a- add all gschliefgraben-Glasfaser sensors
This commit is contained in:
parent
8621510230
commit
fb010174b7
5 changed files with 337 additions and 46 deletions
|
@ -22,7 +22,7 @@ from sqlalchemy import func, asc, desc
|
|||
# from db.pg_models import Platform
|
||||
from db.models import (
|
||||
ObservationSchema, Person, PersonSchema, Observation,
|
||||
create_pg_session, Dataset, Procedure, Phenomenon, Platform)
|
||||
create_pg_session, Dataset, Procedure, Phenomenon, Platform, Format)
|
||||
from gschliefgraben_glasfaser.my_api import MyApi
|
||||
|
||||
|
||||
|
@ -56,13 +56,36 @@ 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()
|
||||
# slope_dataset.fk_platform_id = sensor_platform.id
|
||||
# else:
|
||||
# exit()
|
||||
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()
|
||||
slope_dataset.platform = sensor_platform
|
||||
else:
|
||||
sensor_platform = pg_session.query(Platform.id) \
|
||||
.filter(Platform.sta_identifier == platform_sta_identifier) \
|
||||
.first()
|
||||
slope_dataset.fk_platform_id = sensor_platform.id
|
||||
else:
|
||||
exit()
|
||||
|
||||
format_exists: bool = pg_session.query(Format.id).filter_by(
|
||||
definition="http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement"
|
||||
).scalar() is not None
|
||||
if format_exists:
|
||||
sensor_format = pg_session.query(Format.id) \
|
||||
.filter(Format.definition ==
|
||||
"http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement") \
|
||||
.first()
|
||||
slope_dataset.fk_format_id = sensor_format.id
|
||||
|
||||
# create all the observation for the given sensor names
|
||||
create_observations(sensor, slope_dataset)
|
||||
|
@ -98,7 +121,7 @@ def create_observations(sensor: str, slope_dataset: Dataset):
|
|||
# consider the start date as 2021-february 1 st
|
||||
start_date = date(2022, 1, 1)
|
||||
# consider the end date as 2021-march 1 st
|
||||
end_date = date(2022, 3, 6)
|
||||
end_date = date(2022, 3, 20)
|
||||
|
||||
# delta time
|
||||
delta = timedelta(days=7)
|
||||
|
@ -269,6 +292,6 @@ def create(person_json: PersonSchema):
|
|||
|
||||
if __name__ == "__main__":
|
||||
load_dotenv(find_dotenv())
|
||||
sensor_list1 = os.environ.get('GLASFASER_GSCHLIEFGRABEN_SENSORS', [])
|
||||
sensor_list1 = os.environ.get('GLASFASER_GSCHLIEFGRABEN_SENSORS', []).replace(r'\n', '\n')
|
||||
print(f'sensors: {sensor_list1} .')
|
||||
main()
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue