diff --git a/src/server/BreCal/database/sql_handler.py b/src/server/BreCal/database/sql_handler.py index 6c1acd2..3ecd895 100644 --- a/src/server/BreCal/database/sql_handler.py +++ b/src/server/BreCal/database/sql_handler.py @@ -176,7 +176,8 @@ 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" + + assert len(filtered_series)<=1, f"found multiple results in function SQLHandler.get_times_for_participant_type" 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 @@ -201,7 +202,9 @@ class SQLHandler(): df = df.set_index('shipcall_id', inplace=False) # the 'if' call is needed to ensure, that no Exception is raised, when the shipcall_id is not present in the df - participant_id_list = df.loc[shipcall_id, "participant_id"].to_list() if shipcall_id in list(df.index) else [] + participant_id_list = df.loc[shipcall_id, "participant_id"].tolist() if shipcall_id in list(df.index) else [] + if not isinstance(participant_id_list,list): + participant_id_list = [participant_id_list] return participant_id_list def get_times_of_shipcall(self, shipcall)->pd.DataFrame: diff --git a/src/server/BreCal/validators/validation_rule_functions.py b/src/server/BreCal/validators/validation_rule_functions.py index 80bb15d..a8138ab 100644 --- a/src/server/BreCal/validators/validation_rule_functions.py +++ b/src/server/BreCal/validators/validation_rule_functions.py @@ -63,6 +63,10 @@ class ValidationRuleBaseFunctions(): returns: string """ return self.error_message_dict.get(key,key) + + def get_no_violation_default_output(self): + """return the default output of a validation function with no validation: a tuple of (GREEN state, None)""" + return (StatusFlags.GREEN, None) def check_time_delta_violation_query_time_to_now(self, query_time:pd.Timestamp, key_time:pd.Timestamp, threshold:float)->bool: """ @@ -209,7 +213,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value])]) != 1: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -222,7 +226,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_agency_berth_etd(self, shipcall, df_times, *args, **kwargs): """ @@ -237,7 +241,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value])]) != 1: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -250,7 +254,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_mooring_berth_eta(self, shipcall, df_times, *args, **kwargs): """ @@ -265,7 +269,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency & MOORING) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.MOORING.value])]) != 2: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -280,7 +284,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_mooring_berth_etd(self, shipcall, df_times, *args, **kwargs): """ @@ -295,7 +299,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency & MOORING) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.MOORING.value])]) != 2: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -310,7 +314,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_portadministration_berth_eta(self, shipcall, df_times, *args, **kwargs): """ @@ -325,7 +329,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency & PORT_ADMINISTRATION) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.PORT_ADMINISTRATION.value])]) != 2: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -340,7 +344,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_portadministration_berth_etd(self, shipcall, df_times, *args, **kwargs): """ @@ -355,7 +359,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency & PORT_ADMINISTRATION) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.PORT_ADMINISTRATION.value])]) != 2: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -370,7 +374,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_pilot_berth_eta(self, shipcall, df_times, *args, **kwargs): """ @@ -385,7 +389,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency & PILOT) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.PILOT.value])]) != 2: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -400,7 +404,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_pilot_berth_etd(self, shipcall, df_times, *args, **kwargs): """ @@ -415,7 +419,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency & PILOT) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.PILOT.value])]) != 2: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -430,7 +434,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_tug_berth_eta(self, shipcall, df_times, *args, **kwargs): """ @@ -445,7 +449,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency & TUG) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.TUG.value])]) != 2: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -460,7 +464,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_tug_berth_etd(self, shipcall, df_times, *args, **kwargs): """ @@ -475,7 +479,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency & TUG) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.TUG.value])]) != 2: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -490,7 +494,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_terminal_berth_eta(self, shipcall, df_times, *args, **kwargs): """ @@ -504,8 +508,11 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): - Measures the difference between 'now' and 'times_agency.eta_berth'. """ # check, if the header is filled in (agency & terminal) - if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.TERMINAL.value])]) != 2: - return (StatusFlags.GREEN, None) + if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable + + if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -520,7 +527,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_missing_time_terminal_berth_etd(self, shipcall, df_times, *args, **kwargs): """ @@ -534,8 +541,11 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): - Measures the difference between 'now' and 'times_agency.etd_berth'. """ # check, if the header is filled in (agency & terminal) - if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.TERMINAL.value])]) != 2: - return (StatusFlags.GREEN, None) + if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable + + if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable # preparation: obtain the correct times of the participant, define the query time and the key time times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) @@ -550,8 +560,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) - + return self.get_no_violation_default_output() def validation_rule_fct_shipcall_incoming_participants_disagree_on_eta(self, shipcall, df_times, *args, **kwargs): """ @@ -574,7 +583,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.RED, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_shipcall_outgoing_participants_disagree_on_etd(self, shipcall, df_times, *args, **kwargs): """ @@ -597,7 +606,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.RED, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_shipcall_shifting_participants_disagree_on_eta_or_etd(self, shipcall, df_times, *args, **kwargs): """ @@ -634,7 +643,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.RED, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_eta_time_not_in_operation_window(self, shipcall, df_times, *args, **kwargs): """ @@ -646,15 +655,18 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): start_time & end_time: operations_start & operations_end (times_terminal) """ # check, if the header is filled in (agency & terminal) - if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.TERMINAL.value])]) != 2: - return (StatusFlags.GREEN, None) + if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable + + if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable # get agency & terminal times times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) times_terminal = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.TERMINAL.value) if self.check_is_not_a_time_or_is_none(times_terminal.operations_start) or self.check_is_not_a_time_or_is_none(times_agency.eta_berth): - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # check, whether the start of operations is AFTER the estimated arrival time violation_state = times_terminal.operations_start < times_agency.eta_berth @@ -663,7 +675,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.RED, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_etd_time_not_in_operation_window(self, shipcall, df_times, *args, **kwargs): """ @@ -675,15 +687,18 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): start_time & end_time: operations_start & operations_end (times_terminal) """ # check, if the header is filled in (agency & terminal) - if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value, ParticipantType.TERMINAL.value])]) != 2: - return (StatusFlags.GREEN, None) + if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable + + if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable # get agency & terminal times times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) times_terminal = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.TERMINAL.value) if self.check_is_not_a_time_or_is_none(times_terminal.operations_end) or self.check_is_not_a_time_or_is_none(times_agency.etd_berth): - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # check, whether the end of operations is AFTER the estimated departure time violation_state = times_terminal.operations_end > times_agency.etd_berth @@ -692,7 +707,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.RED, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_eta_time_not_in_tidal_window(self, shipcall, df_times, *args, **kwargs): """ @@ -705,12 +720,12 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value])]) != 1: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) # requirements: tidal window (from & to) is filled in if self.check_is_not_a_time_or_is_none(shipcall.tidal_window_from) or self.check_is_not_a_time_or_is_none(shipcall.tidal_window_to) or self.check_is_not_a_time_or_is_none(times_agency.eta_berth): # 202310310: note: this should check times_agency, shouldn't it? - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # check, whether the query time is between start & end time # a violation is observed, when the time is NOT between start & end @@ -720,7 +735,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.RED, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_etd_time_not_in_tidal_window(self, shipcall, df_times, *args, **kwargs): """ @@ -733,12 +748,12 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): """ # check, if the header is filled in (agency) if len(df_times.loc[df_times["participant_type"].isin([ParticipantType.AGENCY.value])]) != 1: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() times_agency = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.AGENCY.value) # requirements: tidal window (from & to) is filled in if self.check_is_not_a_time_or_is_none(shipcall.tidal_window_from) or self.check_is_not_a_time_or_is_none(shipcall.tidal_window_to) or self.check_is_not_a_time_or_is_none(times_agency.etd_berth): # 202310310: note: this should check times_agency, shouldn't it? - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # check, whether the query time is between start & end time # a violation is observed, when the time is NOT between start & end @@ -748,7 +763,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.RED, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_too_many_identical_eta_times(self, shipcall, df_times, rounding = "min", maximum_threshold = 3, all_times_agency=None, *args, **kwargs): """ @@ -759,7 +774,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): times_agency = df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value] # check, if the header is filled in (agency) if len(times_agency) != 1: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # when ANY of the unique values exceeds the threshold, a violation is observed query = "eta_berth" @@ -769,7 +784,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_too_many_identical_etd_times(self, shipcall, df_times, rounding = "min", maximum_threshold = 3, all_times_agency=None, *args, **kwargs): """ @@ -780,7 +795,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): times_agency = df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value] # check, if the header is filled in (agency) if len(times_agency) != 1: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # when ANY of the unique values exceeds the threshold, a violation is observed query = "etd_berth" @@ -790,7 +805,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_agency_and_terminal_berth_id_disagreement(self, shipcall, df_times, *args, **kwargs): """ @@ -799,22 +814,25 @@ 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"].isin([ParticipantType.AGENCY.value, ParticipantType.TERMINAL.value])]) != 2: - return (StatusFlags.GREEN, None) + if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable + + if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) != 1: + 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) times_terminal = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.TERMINAL.value) # when one of the two values is null, the state is GREEN if (times_agency.berth_id is None) or (times_terminal.berth_id is None): - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # when one of the two values is null, the state is GREEN if (pd.isnull(times_agency.berth_id)) or (pd.isnull(times_terminal.berth_id)): - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() if shipcall.type in [ShipcallType.OUTGOING.value, ShipcallType.SHIFTING.value]: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # only incoming shipcalls matter. The other ones are not relevant for the berth selection violation_state = times_agency.berth_id!=times_terminal.berth_id @@ -823,7 +841,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() def validation_rule_fct_agency_and_terminal_pier_side_disagreement(self, shipcall, df_times, *args, **kwargs): """ @@ -832,23 +850,26 @@ 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"].isin([ParticipantType.AGENCY.value, ParticipantType.TERMINAL.value])]) != 2: - return (StatusFlags.GREEN, None) + if len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1: + return self.get_no_violation_default_output() # rule not applicable + + if len(df_times.loc[df_times["participant_type"]==ParticipantType.TERMINAL.value]) != 1: + 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) times_terminal = self.sql_handler.get_times_for_participant_type(df_times, participant_type=ParticipantType.TERMINAL.value) # when one of the two values is null, the state is GREEN if (times_agency.pier_side is None) or (times_terminal.pier_side is None): - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # when one of the two values is null, the state is GREEN if (pd.isnull(times_agency.pier_side)) or (pd.isnull(times_terminal.pier_side)): - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() # only incoming shipcalls matter. The other ones are not relevant for the pier_side selection if shipcall.type in [ShipcallType.OUTGOING.value, ShipcallType.SHIFTING.value]: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output() violation_state = bool(times_agency.pier_side)!=bool(times_terminal.pier_side) @@ -856,6 +877,6 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): validation_name = inspect.currentframe().f_code.co_name return (StatusFlags.YELLOW, validation_name) else: - return (StatusFlags.GREEN, None) + return self.get_no_violation_default_output()