diff --git a/production_tests.sh b/production_tests.sh index fa097acbeab8a1321ffc5d40c999ad363cbe00f0..299c9328ee510c1e5d4b2b78b114a6a9197e876f 100755 --- a/production_tests.sh +++ b/production_tests.sh @@ -8,30 +8,32 @@ curl http://127.0.0.1:8000/variables/CO curl -X POST -H "Content-Type:application/json" -d '{"name": "sabinene", "longname": "sabinene", "displayname": "Sabinene", "cf_standardname": "mole_fraction_of_sabinene_in_air", "units": "nmol mol-1", "chemical_formula": "C10H16"}' http://127.0.0.1:8000/variables/ curl http://127.0.0.1:8000/contacts/organisations/ -curl http://127.0.0.1:8000/contacts/organisations/id/2 +curl http://127.0.0.1:8000/contacts/organisations/id/36 curl http://127.0.0.1:8000/contacts/organisations/id/99 -curl http://127.0.0.1:8000/contacts/organisations/FZJ -curl -X POST -H "Content-Type:application/json" -d '{"organisation": {"name": "FZJ2", "longname": "Forschungszentrum Test", "kind": "Research", "city": "Jülich", "postcode": "52425", "street_address": "Wilhelm-Johnen-Straße", "country": "Germany", "homepage": "https://www.fz-juelich.de"}}' http://127.0.0.1:8000/contacts/organisations/ +curl http://127.0.0.1:8000/contacts/organisations/UBA +curl -X POST -H "Content-Type:application/json" -d '{"organisation": {"name": "FZJ", "longname": "Forschungszentrum Test", "kind": "Research", "city": "Jülich", "postcode": "52425", "street_address": "Wilhelm-Johnen-Straße", "country": "Germany", "homepage": "https://www.fz-juelich.de"}}' http://127.0.0.1:8000/contacts/organisations/ curl http://127.0.0.1:8000/contacts/persons/ -curl http://127.0.0.1:8000/contacts/persons/id/3 +curl http://127.0.0.1:8000/contacts/persons/id/8 curl http://127.0.0.1:8000/contacts/persons/id/99 -curl "http://127.0.0.1:8000/contacts/persons/Ute%20Dauert" +curl "http://127.0.0.1:8000/contacts/persons/Martin%20Schultz" +curl -X POST -H "Content-Type:application/json" -d '{"person": {"name": "Sabine Schröder", "email": "s.schroeder@fz-juelich.de", "phone": "+49-2461-61-6397", "isprivate": true}}' http://127.0.0.1:8000/contacts/persons/ curl "http://127.0.0.1:8000/contacts/persons/Sabine%20Schr%C3%B6der" -curl -X POST -H "Content-Type:application/json" -d '{"person": {"name": "Martin Schultz", "email": "m.schultz@fz-juelich.de", "phone": "+49-2461-61-96870", "isprivate": true}}' http://127.0.0.1:8000/contacts/persons/ + +curl http://127.0.0.1:8000/contacts/ curl http://127.0.0.1:8000/stationmeta_core/ curl http://127.0.0.1:8000/stationmeta/ -curl http://127.0.0.1:8000/stationmeta_core/China11 -curl http://127.0.0.1:8000/stationmeta/China11 +curl http://127.0.0.1:8000/stationmeta_core/DEUB001 +curl http://127.0.0.1:8000/stationmeta/DEUB001 # station upload without nested fields -curl -X POST -H "Content-Type:application/json" -d '{"stationmeta": {"codes":["ttt3","ttt4"],"name":"Test_China","coordinates":{"lat":36.256,"lng":17.106,"alt":1534.0},"country":"China","state":"Shandong Sheng","coordinate_validation_status":0,"coordinate_validation_date":"2020-03-11T12:22:18.047974+01:00","type_of_environment":0,"type_of_area":0,"category":"","timezone":"", "coordinate_validator_id": 1, "additional_metadata":"{}"}}' "http://127.0.0.1:8000/stationmeta/" +curl -X POST -H "Content-Type:application/json" -d '{"stationmeta": {"codes":["China11"],"name":"Mount Tai","coordinates":{"lat":36.256,"lng":17.106,"alt":1534.0},"country":"China","state":"Shandong Sheng","coordinate_validation_status":"NotChecked","coordinate_validation_date":"2020-03-11T12:22:18.047974+01:00","type_of_environment":"Background","type_of_area":"Rural","category":"","timezone":"Asia/Shanghai", "coordinate_validator_id": 1, "additional_metadata":"{}"}}' "http://127.0.0.1:8000/stationmeta/" # (nested) upload including 'global' (not defining all metadata -- getting the rest from default values) with human readable fields -curl -X POST -H "Content-Type:application/json" -d '{"stationmeta": {"codes":["ttt71"],"name":"Ttt_China71","coordinates":{"lat":36.256,"lng":17.106,"alt":1534.0},"country":"China","state":"Shandong Sheng","coordinate_validation_status":0,"coordinate_validation_date":"2020-03-11T12:22:18.047974+01:00","type_of_environment":0,"type_of_area":0,"category":"","timezone":"", "coordinate_validator_id": 1, "additional_metadata":"{}", "roles": [{"role": 0, "person_id": 3, "status": 0},{"role": 1, "person_id": 3, "status": 0}], "globalmeta": {"climatic_zone": "WarmTemperateMoist"}}}' http://127.0.0.1:8000/stationmeta/ +curl -X POST -H "Content-Type:application/json" -d '{"stationmeta": {"codes":["CHHKG015"],"name":"Shatin","coordinates":{"lat":22.3765,"lng":114.1847,"alt":25},"country":"China","state":"New Territories","coordinate_validation_status":"NotChecked","coordinate_validation_date":"2020-03-11T12:22:18.047974+01:00","type_of_environment":"Unknown","type_of_area":"Suburban","category":"","timezone":"Asia/Hong_Kong", "coordinate_validator_id": 1, "additional_metadata":"{}", "roles": [{"role": "PointOfContact", "contact_id": 43, "status": "active"},{"role": "PrincipalInvestigator", "contact_id": 41, "status": "active"}], "globalmeta": {"climatic_zone": "WarmTemperateMoist"}}}' http://127.0.0.1:8000/stationmeta/ curl http://127.0.0.1:8000/timeseries/ -curl http://127.0.0.1:8000/timeseries/2 +curl http://127.0.0.1:8000/timeseries/97 # timeseries upload with (nested) human readable fields -curl -X POST -H "Content-Type:application/json" -d '{"timeseries": {"label": "CMA5", "order": 1, "access_rights": "ByAttribution", "sampling_frequency": "Hourly", "aggregation": "Mean", "source": "Measurement", "data_start_date": "2003-09-07T15:30:00+02:00", "data_end_date": "2016-12-31T14:30:00+01:00", "measurement_method": "UV absorption", "sampling_height": 7.0, "date_added": "2020-05-15T15:30:00+02:00", "date_modified": "2020-05-16T09:30:00+02:00", "station_id": 2, "variable_id": 7, "additional_metadata":"{}", "roles": [{"role": "PointOfContact", "person_id": 3, "status": "active"},{"role": "Originator", "person_id": 1, "status": "active"}]}}' http://127.0.0.1:8000/timeseries/ +curl -X POST -H "Content-Type:application/json" -d '{"timeseries": {"label": "CMA5", "order": 1, "access_rights": "ByAttribution", "sampling_frequency": "Hourly", "aggregation": "Mean", "source": "Measurement", "data_start_date": "2003-09-07T15:30:00+02:00", "data_end_date": "2016-12-31T14:30:00+01:00", "measurement_method": "UVAbsorption", "sampling_height": 7.0, "date_added": "2020-05-15T15:30:00+02:00", "date_modified": "2020-05-16T09:30:00+02:00", "station_id": 60, "variable_id": 7, "additional_metadata":"{}", "roles": [{"role": "PointOfContact", "contact_id": 43, "status": "active"},{"role": "Originator", "contact_id": 41, "status": "active"}]}}' http://127.0.0.1:8000/timeseries/ # TBD: use person_email (instead of person_id) to identify persons, f. ex. "person_email": "s.schroeder@fz-juelich.de" curl -X POST -H 'Content-Type: multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__' -F "file=@o3_CO002_2012_2017_v1-0.dat" "http://127.0.0.1:8000/data/" diff --git a/toardb/stationmeta/crud.py b/toardb/stationmeta/crud.py index 8b296bd2de42e3df67869b872b5ea47763842c6d..066e82d879e5cebb21e3ac9ca6aa05c2969bdaf5 100644 --- a/toardb/stationmeta/crud.py +++ b/toardb/stationmeta/crud.py @@ -159,7 +159,7 @@ def create_stationmeta(db: Session, stationmeta: StationmetaCreate): if globalmeta_data: db_global = models.StationmetaGlobal(**globalmeta_data) if db_global.climatic_zone: - db_global.climatic_zone = get_value_from_str(db,CZ_enum,db_global.climatic_zone) + db_global.climatic_zone = get_value_from_str(CZ_enum,db_global.climatic_zone) db_global.station_id = stationmeta_core_id db.add(db_global) db.commit() diff --git a/toardb/stationmeta/schemas.py b/toardb/stationmeta/schemas.py index 9710a963b2bc0787f016bcedb5897517a03f4ad2..f9c7828b15101bdbe8b8126cb8d013834be95561 100644 --- a/toardb/stationmeta/schemas.py +++ b/toardb/stationmeta/schemas.py @@ -377,7 +377,7 @@ class StationmetaBase(StationmetaCoreBase): class StationmetaCreate(StationmetaCoreCreate): - roles: List[StationmetaRoleBase] = None + roles: List[StationmetaRoleCreate] = None annotations: List[StationmetaAnnotation] = None aux_images: List[StationmetaAuxImage] = None aux_docs: List[StationmetaAuxDoc] = None diff --git a/toardb/timeseries/crud.py b/toardb/timeseries/crud.py index a38ba93ea9264d0b3a32b144fed2a302f308e649..b108b979bfa7acc372f0c27e7c2151274edf8a2e 100644 --- a/toardb/timeseries/crud.py +++ b/toardb/timeseries/crud.py @@ -10,7 +10,7 @@ from fastapi.responses import JSONResponse from . import models from .models import timeseries_timeseries_roles_table, \ timeseries_timeseries_annotations_table, \ - DA_enum, SF_enum, AT_enum, DS_enum + DA_enum, SF_enum, AT_enum, DS_enum, MM_enum from toardb.generic.models import RS_enum, RC_enum from .schemas import TimeseriesCreate from toardb.utils.utils import get_value_from_str, get_str_from_value @@ -85,6 +85,7 @@ def create_timeseries(db: Session, timeseries: TimeseriesCreate): db_timeseries.sampling_frequency = get_value_from_str(SF_enum,db_timeseries.sampling_frequency) db_timeseries.aggregation = get_value_from_str(AT_enum,db_timeseries.aggregation) db_timeseries.source = get_value_from_str(DS_enum,db_timeseries.source) + db_timeseries.measurement_method= get_value_from_str(MM_enum,db_timeseries.measurement_method) db.add(db_timeseries) result = db.commit() db.refresh(db_timeseries) diff --git a/toardb/timeseries/models_core.py b/toardb/timeseries/models_core.py index b9ab1c96ad0032c3d51c75e902d7269b300cab44..ecd51e4c593d170c35d79e2c4c0015216073cb54 100644 --- a/toardb/timeseries/models_core.py +++ b/toardb/timeseries/models_core.py @@ -53,7 +53,7 @@ class Timeseries(Base): +---------------------+--------------------------+-----------+----------+----------------------------------------+ | variable_id | integer | | | | +---------------------+--------------------------+-----------+----------+----------------------------------------+ - | programme_id | integer | | | | + | programme_id | integer | | not null | 0 | +---------------------+--------------------------+-----------+----------+----------------------------------------+ Indexes: "timeseries_pkey" PRIMARY KEY, btree (id) @@ -109,7 +109,7 @@ class Timeseries(Base): # see: https://groups.google.com/forum/#!topic/sqlalchemy/YjGhE4d6K4U station_id = Column(ForeignKey(StationmetaCore.id, deferrable=True, initially='DEFERRED'), index=True) variable_id = Column(ForeignKey(Variable.id, deferrable=True, initially='DEFERRED'), index=True) - programme_id = Column(ForeignKey(TimeseriesProgramme.id)) + programme_id = Column(ForeignKey(TimeseriesProgramme.id), nullable=False, server_default=text("0")) # for the nested view # problems with station and coordinates in nested views!!! diff --git a/toardb/timeseries/schemas.py b/toardb/timeseries/schemas.py index f8a7584a8ed33c6a4d36e1340c68ac738d1ddfb3..e2c41544dec99df24151f129ee400b319aae7ab8 100644 --- a/toardb/timeseries/schemas.py +++ b/toardb/timeseries/schemas.py @@ -66,7 +66,7 @@ class TimeseriesCoreBaseStub(BaseModel): class TimeseriesCoreBase(TimeseriesCoreBaseStub): station_id: int variable_id: int - programme_id: int + programme_id: int = None class TimeseriesCoreCreate(TimeseriesCoreBase): @@ -120,9 +120,9 @@ class TimeseriesRoleBase(BaseModel): id: int = None role: str status: str -# contact_id: int # works + contact_id: int # works # contact: Contact # does not work! - contact: Any +# contact: Any # also works (but contact_id has to be extracted!) @validator('role') def check_role(cls, v): diff --git a/toardb_v2_dump.sql b/toardb_v2_dump.sql index 8b01b9e4db08238f42a82253b854996dd5db483f..0b1d1d1f0793cf2fb9b4b638a899f95154e4fe97 100644 --- a/toardb_v2_dump.sql +++ b/toardb_v2_dump.sql @@ -1437,6 +1437,7 @@ COPY public.stationmeta_core (id, codes, name, coordinates, country, state, coor 64 {DENW008} Dortmund-Eving 01010000A0E61000002B85402E71D41D406CEEE87FB9C449400000000000C05240 Germany Nordrhein-Westfalen 0 2020-07-06 15:30:34.924539+02 1 1 Europe/Berlin {"station_alt_flag": "0", "google_resolution": "19", "station_google_alt": "68", "station_reported_alt": "75", "station_landcover_description": "Urbanandbuilt-up:41.1%,Mixedforest:23.7%,Croplands:20.8%,Cropland/Naturalvegetationmosaic:11.7%,EvergreenNeedleleafforest:1.9%", "station_max_population_density_5km": "27082"} 1 65 {DENW034} Duisburg-Walsum 01010000A0E6100000410B09185DFE1A403831242713C349400000000000003C40 Germany Nordrhein-Westfalen 0 2020-07-06 15:30:35.373971+02 3 1 Europe/Berlin {"station_alt_flag": "0", "google_resolution": "19", "station_google_alt": "18", "station_reported_alt": "28", "station_landcover_description": "Urbanandbuilt-up:34.7%,Croplands:20.5%,Cropland/Naturalvegetationmosaic:20.1%,Mixedforest:17.1%,EvergreenNeedleleafforest:6.0%", "station_max_population_density_5km": "26864"} 1 66 {DENW071} Düsseldorf-Lörick 01010000A0E6100000E19524CFF5ED1A40D8666325E69F49400000000000004040 Germany Nordrhein-Westfalen 0 2020-07-06 15:30:35.809923+02 1 1 Europe/Berlin {"station_alt_flag": "0", "google_resolution": "19", "station_google_alt": "35", "station_reported_alt": "32", "station_landcover_description": "Urbanandbuilt-up:48.2%,Croplands:27.5%,Mixedforest:11.9%,Cropland/Naturalvegetationmosaic:7.2%,EvergreenNeedleleafforest:3.6%", "station_max_population_density_5km": "34528"} 1 +2 {CO002} U. S.Buenaventura 01010000A0E61000004260E5D0221B314054E3A59BC42042400000000000F89740 Colombia ANTIOQUIA 0 2020-07-06 15:30:35.809923+02 1 1 America/Bogota {} 1 \. @@ -1504,6 +1505,7 @@ COPY public.timeseries (id, label, "order", access_rights, sampling_frequency, a 100 1 0 0 1 1990-04-01 00:00:00+02 2020-07-06 15:00:00+02 2 {"parameter_status": "0", "parameter_attribute": "", "parameter_sampling_type": "continuous", "parameter_original_units": "ug m-3", "parameter_instrument_model": "", "parameter_instrument_manufacturer": ""} 2015-03-04 15:54:28.457564+01 2020-07-06 18:04:58.232375+02 64 5 1 1 0 101 1 0 0 1 1990-01-01 00:00:00+01 2020-07-06 15:00:00+02 2 {"parameter_status": "0", "parameter_attribute": "", "parameter_sampling_type": "continuous", "parameter_original_units": "ug m-3", "parameter_instrument_model": "", "parameter_instrument_manufacturer": ""} 2015-03-04 15:54:28.457564+01 2020-07-06 18:04:58.239781+02 65 5 1 1 0 102 1 0 0 1 1990-01-18 14:00:00+01 2020-07-06 15:00:00+02 2 {"parameter_status": "0", "parameter_attribute": "", "parameter_sampling_type": "continuous", "parameter_original_units": "ug m-3", "parameter_instrument_model": "", "parameter_instrument_manufacturer": ""} 2015-03-04 15:54:28.457564+01 2020-07-06 18:04:58.263259+02 66 5 1 1 0 +2 'IDEAM' 1 0 0 1 1990-01-18 14:00:00+01 2020-07-06 15:00:00+02 2 {"parameter_status": "0", "parameter_attribute": "", "parameter_sampling_type": "continuous", "parameter_original_units": "ug m-3", "parameter_instrument_model": "", "parameter_instrument_manufacturer": ""} 2015-03-04 15:54:28.457564+01 2020-07-06 18:04:58.263259+02 2 5 1 1 0 \.