diff --git a/.gitignore b/.gitignore index 005dd7b..2eea059 100644 --- a/.gitignore +++ b/.gitignore @@ -287,4 +287,6 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ +src/notebooks_metz/ +src/server/editable_requirements.txt diff --git a/src/server/BreCal/validators/validation_rule_functions.py b/src/server/BreCal/validators/validation_rule_functions.py index 92bf24e..cbce37e 100644 --- a/src/server/BreCal/validators/validation_rule_functions.py +++ b/src/server/BreCal/validators/validation_rule_functions.py @@ -54,6 +54,7 @@ class ValidationRuleBaseFunctions(): self.sql_handler = sql_handler self.time_logic = TimeLogic() self.error_message_dict = error_message_dict + self.ignore_port_administration_flag = True # flag: turn off all port administration validation rules def describe_error_message(self, key)->str: """ @@ -127,7 +128,10 @@ class ValidationRuleBaseFunctions(): return violation_state # filter by participant types of interest (agency, mooring, portauthority/administration, pilot, tug) - participant_types = [ParticipantType.AGENCY.value, ParticipantType.MOORING.value, ParticipantType.PORT_ADMINISTRATION.value, ParticipantType.PILOT.value, ParticipantType.TUG.value] + if not self.ignore_port_administration_flag: + participant_types = [ParticipantType.AGENCY.value, ParticipantType.MOORING.value, ParticipantType.PORT_ADMINISTRATION.value, ParticipantType.PILOT.value, ParticipantType.TUG.value] + else: + participant_types = [ParticipantType.AGENCY.value, ParticipantType.MOORING.value, ParticipantType.PORT_ADMINISTRATION.value, ParticipantType.PILOT.value, ParticipantType.TUG.value] df_times = df_times.loc[df_times["participant_type"].isin(participant_types),:] # exclude missing entries and consider only pd.Timestamp entries (which ignores pd.NaT/null entries) @@ -342,6 +346,9 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): - Checks, if times_port_administration.eta_berth is filled in. - Measures the difference between 'now' and 'times_agency.eta_berth'. """ + if self.ignore_port_administration_flag: + return self.get_no_violation_default_output() + if not shipcall.type in [ShipcallType.INCOMING.value]: return self.get_no_violation_default_output() @@ -376,12 +383,8 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): - Checks, if times_port_administration.etd_berth is filled in. - Measures the difference between 'now' and 'times_agency.etd_berth'. """ - if not shipcall.type in [ShipcallType.OUTGOING.value, ShipcallType.SHIFTING.value]: - return self.get_no_violation_default_output() - - # check, if the header is filled in - unassigned = self.sql_handler.check_if_any_participant_of_type_is_unassigned(shipcall, *[ParticipantType.AGENCY, ParticipantType.PORT_ADMINISTRATION]) - if unassigned: + # check, if the header is filled in (agency & PORT_ADMINISTRATION) + if (len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1) or (len(df_times.loc[df_times["participant_type"]==ParticipantType.PORT_ADMINISTRATION.value]) != 1): return self.get_no_violation_default_output() # preparation: obtain the correct times of the participant, define the query time and the key time diff --git a/src/server/tests/validators/test_validation_rule_functions.py b/src/server/tests/validators/test_validation_rule_functions.py index 2593e85..9eac8a4 100644 --- a/src/server/tests/validators/test_validation_rule_functions.py +++ b/src/server/tests/validators/test_validation_rule_functions.py @@ -343,8 +343,10 @@ def test_validation_rule_fct_missing_time_portadministration_berth_eta__shipcall # apply the validation rule (state, msg) = vr.validation_rule_fct_missing_time_portadministration_berth_eta(shipcall=shipcall, df_times=df_times) - # expectation: green state, no msg - assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" + if not vr.ignore_port_administration_flag: + assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" + else: + assert state==StatusFlags.GREEN, f"function should return 'green', because the feature flag is set, which disables this validation rule" return @@ -381,8 +383,10 @@ def test_validation_rule_fct_missing_time_portadministration_berth_etd__shipcall # apply the validation rule (state, msg) = vr.validation_rule_fct_missing_time_portadministration_berth_etd(shipcall=shipcall, df_times=df_times) - # expectation: green state, no msg - assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" + if not vr.ignore_port_administration_flag: + assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" + else: + assert state==StatusFlags.GREEN, f"function should return 'green', because the ignore flag is set" return def test_validation_rule_fct_missing_time_pilot_berth_eta__shipcall_soon_but_participant_estimated_time_undefined(build_sql_proxy_connection): @@ -416,7 +420,7 @@ def test_validation_rule_fct_missing_time_pilot_berth_eta__shipcall_soon_but_par # apply the validation rule (state, msg) = vr.validation_rule_fct_missing_time_pilot_berth_eta(shipcall=shipcall, df_times=df_times) - # expectation: green state, no msg + # expectation: yellow state assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" return