Skip to content
Snippets Groups Projects
Commit 421f0ee2 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

WIP: Add treatment for events

parent 57ef07b1
Branches
Tags
1 merge request!1F awi sams
......@@ -38,10 +38,7 @@ const ext_samplemanagement = function($, navbar, log, form_elements, form_panel,
];
const required_column_names = [
"LinkAhead ID",
"Date collected start",
"Main User",
"Gear",
"Gear configuration",
"Latitude start",
"Longitude start",
"Collection",
......
#
# Copyright (C) 2025 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2025 Florian Spreckelsen <f.spreckelsen@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
import linkahead as db
import pandas as pd
from caosadvancedtools.datainconsistency import DataInconsistencyError
from .utils import get_column_header_name, get_entity_name
from ..bis_utils import return_value_if_not_none
def add_event_to_sample(sample: db.Record, data: pd.Series) -> db.Record:
"""Take a given sample and attach an event Record from the
data. Then, return the sample.
"""
_perform_sanity_checks(sample, data)
return sample
def _create_position(mode: str, lat: float, lng: float, ele: float):
pos = db.Record()
if mode.lower() == "start":
pos.add_parent(get_entity_name("StartPosition"))
elif mode.lower() == "stop":
pos.add_parent(get_entity_name("StopPosition"))
else:
pos.add_parent(get_entity_name("Position"))
pos.add_property(name=get_entity_name("latitude"), value=lat)
pos.add_property(name=get_entity_name("longitude"), value=lng)
pos.add_property(name=get_entity_name("elevation"), value=ele)
return pos
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):
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')}."
)
for name in ["start", "stop"]:
bool_list = [get_column_header_name(f"{val}_{name}") in data for val in [
"latitude", "longitude", "elevation"]]
raise_error = False
if bool_list.any():
if not bool_list.all():
raise_error = True
elif [return_value_if_not_none(data[get_column_header_name(f"{val}_{name}")]) is None for val in ["latitude", "longitude", "elevation"]].any():
raise_error = True
if raise_error:
raise DataInconsistencyError(
f"Sample with {get_entity_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):
raise DataInconsistencyError(
f"Sample with {get_entity_name('entity_id')} {sample.id} has a "
f"{get_entity_name('StopPosition')} but no valid "
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