Skip to content
Snippets Groups Projects
Commit f2f6997d authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-event-name' into 'main'

FEAT(sample_upload): Allow event names in registration, upload, and export

See merge request !3
parents 9635a06a 1bcc0dba
No related branches found
No related tags found
1 merge request!3FEAT(sample_upload): Allow event names in registration, upload, and export
...@@ -54,6 +54,7 @@ const ext_samplemanagement = function($, navbar, log, form_elements, form_panel, ...@@ -54,6 +54,7 @@ const ext_samplemanagement = function($, navbar, log, form_elements, form_panel,
"Elevation start", "Elevation start",
"Elevation stop", "Elevation stop",
"End date", "End date",
"Event name",
"Event responsible", "Event responsible",
"IGSN DOI", "IGSN DOI",
"Latitude stop", "Latitude stop",
......
...@@ -335,6 +335,17 @@ def extract_event_url(record, key): ...@@ -335,6 +335,17 @@ def extract_event_url(record, key):
return None return None
def extract_event_name(record, key):
events = retrieve_event(record)
if not events:
return None
if len(events) == 1:
return events[0].name
logger.debug(f"Sample {record.id} has multiple events.")
return None
def extract_sample_name(record, key): def extract_sample_name(record, key):
return record.name return record.name
...@@ -353,6 +364,7 @@ EXTRACTORS = use_custom_names({ ...@@ -353,6 +364,7 @@ EXTRACTORS = use_custom_names({
"Elevation stop": extract_ele_stop, "Elevation stop": extract_ele_stop,
"Embargo": default_find, "Embargo": default_find,
"End date": extract_end_date, "End date": extract_end_date,
"event_name": extract_event_name,
"Latitude start": extract_lat_start, "Latitude start": extract_lat_start,
"Latitude stop": extract_lat_stop, "Latitude stop": extract_lat_stop,
"Level": extract_level, "Level": extract_level,
...@@ -397,7 +409,8 @@ ADDITIONAL_EXPORTS = use_custom_names([ ...@@ -397,7 +409,8 @@ ADDITIONAL_EXPORTS = use_custom_names([
"LinkAhead URL", "LinkAhead URL",
"parent_sample_prop", "parent_sample_prop",
"Storage chain", "Storage chain",
"sample_name" "sample_name",
"event_name"
]) ])
......
...@@ -26,6 +26,7 @@ csv_column_names: ...@@ -26,6 +26,7 @@ csv_column_names:
responsible_person_event: "Event responsible" responsible_person_event: "Event responsible"
parent_sample_prop: "Parent LinkAhead ID" parent_sample_prop: "Parent LinkAhead ID"
sample_name: "Sample name" sample_name: "Sample name"
event_name: "Event name"
csv_column_descriptions: csv_column_descriptions:
LinkAhead ID: "An ID generated by LinkAhead (either integer or URL to this entity). Do not change this column!" LinkAhead ID: "An ID generated by LinkAhead (either integer or URL to this entity). Do not change this column!"
......
...@@ -63,6 +63,7 @@ DATATYPE_DEFINITIONS = use_custom_names({ ...@@ -63,6 +63,7 @@ DATATYPE_DEFINITIONS = use_custom_names({
"Elevation start": float, "Elevation start": float,
"Elevation stop": float, "Elevation stop": float,
"End date": str, "End date": str,
"event_name": str,
"Latitude start": float, "Latitude start": float,
"Latitude stop": float, "Latitude stop": float,
"Longitude start": float, "Longitude start": float,
...@@ -105,6 +106,7 @@ SPECIAL_TREATMENT_SAMPLE = use_custom_names([ ...@@ -105,6 +106,7 @@ SPECIAL_TREATMENT_SAMPLE = use_custom_names([
"Elevation stop", "Elevation stop",
"Embargo", "Embargo",
"End date", "End date",
"event_name",
"responsible_person_event", "responsible_person_event",
"igsn_doi_prop", "igsn_doi_prop",
"Latitude start", "Latitude start",
......
...@@ -35,6 +35,10 @@ def add_event_to_sample(sample: db.Record, data: pd.Series) -> db.Record: ...@@ -35,6 +35,10 @@ def add_event_to_sample(sample: db.Record, data: pd.Series) -> db.Record:
event_rt = db.get_entity_by_name(get_entity_name("event_rt"), role="RECORDTYPE") event_rt = db.get_entity_by_name(get_entity_name("event_rt"), role="RECORDTYPE")
event = db.Record().add_parent(event_rt) event = db.Record().add_parent(event_rt)
# Event name. Replace with empty if cell is empty.
if get_column_header_name("event_name") in data:
event.name = return_value_if_not_none(data[get_column_header_name("event_name")])
# We performed the sanity checks so we can assume that if the # We performed the sanity checks so we can assume that if the
# Start/Stop Latitude exists, all start/stop data exist. # Start/Stop Latitude exists, all start/stop data exist.
positions = [] positions = []
...@@ -134,8 +138,11 @@ def _perform_sanity_checks(sample, data): ...@@ -134,8 +138,11 @@ def _perform_sanity_checks(sample, data):
) )
for name in ["start", "stop"]: for name in ["start", "stop"]:
bool_list = [get_column_header_name(f"{val} {name}") in data for val in [ bool_list = [
"Latitude", "Longitude", "Elevation"]] ((get_column_header_name(f"{val} {name}") in data) and
(return_value_if_not_none(data[get_column_header_name(f"{val} {name}")]) is not None))
for val in ["Latitude", "Longitude", "Elevation"]
]
raise_error = False raise_error = False
if any(bool_list): if any(bool_list):
if not all(bool_list): if not all(bool_list):
...@@ -155,9 +162,9 @@ def _perform_sanity_checks(sample, data): ...@@ -155,9 +162,9 @@ def _perform_sanity_checks(sample, data):
if (get_column_header_name("Latitude stop") in data and 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): 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 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): return_value_if_not_none(data[get_column_header_name("Latitude start")]) is None):
raise DataInconsistencyError( raise DataInconsistencyError(
f"Sample with {get_entity_name('entity_id')} {sample.id} has a " f"Sample with {get_column_header_name('entity_id')} {sample.id} has a "
f"{get_entity_name('StopPosition')} but no valid " f"{get_entity_name('StopPosition')} but no valid "
f"{get_entity_name('StartPosition')}." f"{get_entity_name('StartPosition')}."
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment