Skip to content
Snippets Groups Projects
Commit d31941d2 authored by Sabine Schröder's avatar Sabine Schröder
Browse files

correct clean-up of 'get_timeseries_by_unique_constraints' from commit...

correct clean-up of 'get_timeseries_by_unique_constraints' from commit 110e2c00
parent a673367a
Branches
No related tags found
1 merge request!228correct clean-up of 'get_timeseries_by_unique_constraints' from commit...
Pipeline #256997 passed
......@@ -315,6 +315,7 @@ def search_all_aggreagtion(db, path_params, signs, query_params_list, lts=False)
return JSONResponse(status_code=status_code, content=str(e))
def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_id: int, resource_provider: str = None,
sampling_frequency: str = None, provider_version: str = None, data_origin_type: str = None,
data_origin: str = None, sampling_height: float = None, label: str = None):
......@@ -341,11 +342,11 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
.filter(models.Timeseries.variable_id == variable_id).all()
# if already not found: return None
# if only one single object is found, it has to be checked whether all criterions are fullfilled
if not ret_db_object:
if len(ret_db_object) == 0:
return None
# filter_for criterion 14.3
# filter for criterion 14.3
if resource_provider:
# issue with '/' in organisation longname ==> only possible with double encoding!
resource_provider = resource_provider.replace('%2F', '/')
......@@ -353,13 +354,15 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
iter_obj = ret_db_object.copy()
counter=0
for db_object in iter_obj:
found = False
for role in db_object.roles:
# resource provider is always an organisation!
organisation = get_contact(db, contact_id=role.contact_id)
if ((role_num == role.role) and (organisation.longname == resource_provider)):
found = True
if not found:
ret_db_object.pop(counter)
counter -= 1
break
else:
counter += 1
else:
# time series that do not have a resource_provider are not identical to those who do not!
......@@ -367,17 +370,19 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
iter_obj = ret_db_object.copy()
counter=0
for db_object in iter_obj:
found = False
for role in db_object.roles:
if (role_num == role.role):
counter -= 1
found = True
if found:
ret_db_object.pop(counter)
break
counter = counter + 1
else:
counter += 1
# if already only none object --> return
# if only one single object is found, it has to be checked whether all criterions are fullfilled
if not ret_db_object:
if len(ret_db_object) == 0:
return None
# filter for criterion 14.4
......@@ -392,7 +397,7 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
# if already only none object --> return
# if only one single object is found, it has to be checked whether all criterions are fullfilled
if not ret_db_object:
if len(ret_db_object) == 0:
return None
# filter for criterion 14.5
......@@ -407,7 +412,7 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
# if already only none object --> return
# if only one single object is found, it has to be checked whether all criterions are fullfilled
if not ret_db_object:
if len(ret_db_object) == 0:
return None
# filter for criterion 14.6
......@@ -423,7 +428,7 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
# if already only none object --> return
# if only one single object is found, it has to be checked whether all criterions are fullfilled
if not ret_db_object:
if len(ret_db_object) == 0:
return None
# filter for criterion 14.7
......@@ -439,7 +444,7 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
# if already only none object --> return
# if only one single object is found, it has to be checked whether all criterions are fullfilled
if not ret_db_object:
if len(ret_db_object) == 0:
return None
# filter for criterion 14.8
......@@ -454,7 +459,7 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
# if already only none object --> return
# if only one single object is found, it has to be checked whether all criterions are fullfilled
if not ret_db_object:
if len(ret_db_object) == 0:
return None
# filter for criterion 14.9
......@@ -469,9 +474,10 @@ def get_timeseries_by_unique_constraints(db: Session, station_id: int, variable_
# check that only one object is left!!!
# adapt mismatches for return value
if not ret_db_object:
if len(ret_db_object) == 0:
ret_db_object = None
elif len(ret_db_object) == 1:
else:
if len(ret_db_object) == 1:
ret_db_object = ret_db_object[0]
# there is a mismatch with additional_metadata
ret_db_object.additional_metadata = clean_additional_metadata(ret_db_object.additional_metadata)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment