From 29b2b317eef79c24dbffe4d6d2049225bf837f53 Mon Sep 17 00:00:00 2001 From: Florian Spreckelsen <f.spreckelsen@indiscale.com> Date: Fri, 21 Mar 2025 13:47:28 +0100 Subject: [PATCH] FIX(sample_upload): Use correct column names in event sanity checks --- .../sample_helpers/sample_upload_get_event.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_event.py b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_event.py index c15df79..1949541 100644 --- a/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_event.py +++ b/sample-management-custom/caosdb-server/scripting/bin/sample_helpers/sample_upload_get_event.py @@ -85,6 +85,7 @@ def add_event_to_sample(sample: db.Record, data: pd.Series) -> db.Record: # only add if there was any event data at all: if len(event.properties) > 0: + sample = update_property(sample, event_rt.id, event, property_name=event_rt.name) return sample @@ -108,39 +109,39 @@ def _create_position(mode: str, lat: float, lng: float, ele: float): def _perform_sanity_checks(sample, data): - if (get_column_header_name("end_date") in data and - return_value_if_not_none(data[get_column_header_name("end_date")]) is not None): - if (get_column_header_name("start_date") not in data or - return_value_if_not_none(data[get_column_header_name("start_date")]) is None): + if (get_column_header_name("end_date_prop") in data and + return_value_if_not_none(data[get_column_header_name("end_date_prop")]) is not None): + if (get_column_header_name("start_date_prop") not in data or + return_value_if_not_none(data[get_column_header_name("start_date_prop")]) is None): raise DataInconsistencyError( f"Sample with {get_entity_name('entity_id')} {sample.id} has a " - f"{get_column_header_name('end_date')} but no valid " - f"{get_column_header_name('start_date')}." + f"{get_column_header_name('end_date_prop')} but no valid " + f"{get_column_header_name('start_date_prop')}." ) for name in ["start", "stop"]: - bool_list = [get_column_header_name(f"{val}_{name}") in data for val in [ - "latitude", "longitude", "elevation"]] + bool_list = [get_column_header_name(f"{val} {name}") in data for val in [ + "Latitude", "Longitude", "Elevation"]] raise_error = False if any(bool_list): if not all(bool_list): raise_error = True - elif any([return_value_if_not_none(data[get_column_header_name(f"{val}_{name}")]) is None for val in ["latitude", "longitude", "elevation"]]): + elif any([return_value_if_not_none(data[get_column_header_name(f"{val} {name}")]) is None for val in ["Latitude", "Longitude", "Elevation"]]): raise_error = True if raise_error: raise DataInconsistencyError( - f"Sample with {get_entity_name('entity_id')} {sample.id} has an " + f"Sample with {get_column_header_name('entity_id')} {sample.id} has an " f"invalid {name} position. Please make sure that latitude, longitude, " "and elevation are provided." ) # only need to check lat since we already checked that if lat is # present, lng and ele are present, too - if (get_column_header_name("latitude_stop") in data and - return_value_if_not_none(data[get_column_header_name("latitude_stop")]) is not None): - if (get_column_header_name("latitude_start") not in data or - return_value_if_not_none(data[get_column_header_name("latitude_start")]) is not None): + if (get_column_header_name("Latitude stop") in data and + return_value_if_not_none(data[get_column_header_name("Latitude stop")]) is not None): + if (get_column_header_name("Latitude start") not in data or + return_value_if_not_none(data[get_column_header_name("Latitude start")]) is not None): raise DataInconsistencyError( f"Sample with {get_entity_name('entity_id')} {sample.id} has a " f"{get_entity_name('StopPosition')} but no valid " -- GitLab