From 3cc1591aba108e539988d184b55faaeee35bfc43 Mon Sep 17 00:00:00 2001 From: scopesorting Date: Tue, 21 Nov 2023 11:41:56 +0100 Subject: [PATCH] potentially correcting 0006A/0006B --- src/server/BreCal/database/sql_handler.py | 16 ++++++++++++---- .../validators/validation_rule_functions.py | 8 ++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/server/BreCal/database/sql_handler.py b/src/server/BreCal/database/sql_handler.py index 3ecd895..f715b4b 100644 --- a/src/server/BreCal/database/sql_handler.py +++ b/src/server/BreCal/database/sql_handler.py @@ -159,7 +159,10 @@ class SQLHandler(): return all_data def df_loc_to_data_model(self, df, id, model_str, loc_type:str="loc"): - assert len(df)>0, f"empty dataframe" + if not len(df)>0: + import warnings + warnings.warn(f"empty dataframe in SQLHandler.df_loc_to_data_model for model type: {model_str}\n") + return df # get a pandas series from the dataframe series = df.loc[id] if loc_type=="loc" else df.iloc[id] @@ -177,7 +180,12 @@ class SQLHandler(): def get_times_for_participant_type(self, df_times, participant_type:int): filtered_series = df_times.loc[df_times["participant_type"]==participant_type] - assert len(filtered_series)<=1, f"found multiple results in function SQLHandler.get_times_for_participant_type" + if not len(filtered_series)<=1: + # correcting the error: ERROR:root:found multiple results + # however, a warning will still be issued + import warnings + warnings.warn(f"found multiple results in function SQLHandler.get_times_for_participant_type\nConsidering only the first match!\nAffected Times Indexes: {filtered_series.index}") + times = self.df_loc_to_data_model(filtered_series, id=0, model_str='times', loc_type="iloc") # use iloc! to retrieve the first result return times @@ -240,8 +248,8 @@ class SQLHandler(): """given a dataframe of all agency times, get all unique ship counts, their values (datetime) and the string tags. returns a tuple (values,unique,counts)""" # optional: rounding if rounding is not None: - all_df_times.loc[:, query] = all_df_times.loc[:, query].dt.round(rounding) # e.g., 'min' - query_time_agency = times_agency[query].iloc[0].round(rounding)# e.g., 'min' + all_df_times.loc[:, query] = pd.to_datetime(all_df_times.loc[:, query]).dt.round(rounding) # e.g., 'min' --- # correcting the error: 'AttributeError: Can only use .dt accessor with datetimelike values' + query_time_agency = pd.to_datetime(times_agency[query]).iloc[0].round(rounding)# e.g., 'min' # after rounding, filter {all_df_times}, so only those, which match the current query are of interest # takes 'times_agency' to sample, which value should match diff --git a/src/server/BreCal/validators/validation_rule_functions.py b/src/server/BreCal/validators/validation_rule_functions.py index 9bb2e94..e1c59ff 100644 --- a/src/server/BreCal/validators/validation_rule_functions.py +++ b/src/server/BreCal/validators/validation_rule_functions.py @@ -811,10 +811,10 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): Description: This validation rule checks, whether agency and terminal agree with their designated berth place by checking berth_id. """ # check, if the header is filled in (agency & terminal) - if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1: + if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) == 0: return self.get_no_violation_default_output() # rule not applicable - if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) != 1: + if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) == 0: return self.get_no_violation_default_output() # rule not applicable times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -847,10 +847,10 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): Description: This validation rule checks, whether agency and terminal agree with their designated pier side by checking pier_side. """ # check, if the header is filled in (agency & terminal) - if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1: + if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) == 0: return self.get_no_violation_default_output() # rule not applicable - if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) != 1: + if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) == 0: return self.get_no_violation_default_output() # rule not applicable times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value)