created a feature flag, which disables the PORT_ADMINISTRATION validation rules. Currently, the flag is 'hardcoded' once in the library. Adapting the test to properly facilitate the feature flag

cherry picking the feature flag of 'port administration' rules
This commit is contained in:
scopesorting 2023-12-12 13:20:31 +01:00 committed by puls200
parent ba424b18b0
commit d004e77650
3 changed files with 22 additions and 13 deletions

2
.gitignore vendored
View File

@ -288,3 +288,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear # 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. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
src/notebooks_metz/
src/server/editable_requirements.txt

View File

@ -54,6 +54,7 @@ class ValidationRuleBaseFunctions():
self.sql_handler = sql_handler self.sql_handler = sql_handler
self.time_logic = TimeLogic() self.time_logic = TimeLogic()
self.error_message_dict = error_message_dict 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: def describe_error_message(self, key)->str:
""" """
@ -127,7 +128,10 @@ class ValidationRuleBaseFunctions():
return violation_state return violation_state
# filter by participant types of interest (agency, mooring, portauthority/administration, pilot, tug) # 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),:] 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) # 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. - Checks, if times_port_administration.eta_berth is filled in.
- Measures the difference between 'now' and 'times_agency.eta_berth'. - 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]: if not shipcall.type in [ShipcallType.INCOMING.value]:
return self.get_no_violation_default_output() return self.get_no_violation_default_output()
@ -376,12 +383,8 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions):
- Checks, if times_port_administration.etd_berth is filled in. - Checks, if times_port_administration.etd_berth is filled in.
- Measures the difference between 'now' and 'times_agency.etd_berth'. - Measures the difference between 'now' and 'times_agency.etd_berth'.
""" """
if not shipcall.type in [ShipcallType.OUTGOING.value, ShipcallType.SHIFTING.value]: # check, if the header is filled in (agency & PORT_ADMINISTRATION)
return self.get_no_violation_default_output() 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):
# 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:
return self.get_no_violation_default_output() return self.get_no_violation_default_output()
# preparation: obtain the correct times of the participant, define the query time and the key time # preparation: obtain the correct times of the participant, define the query time and the key time

View File

@ -343,8 +343,10 @@ def test_validation_rule_fct_missing_time_portadministration_berth_eta__shipcall
# apply the validation rule # apply the validation rule
(state, msg) = vr.validation_rule_fct_missing_time_portadministration_berth_eta(shipcall=shipcall, df_times=df_times) (state, msg) = vr.validation_rule_fct_missing_time_portadministration_berth_eta(shipcall=shipcall, df_times=df_times)
# expectation: green state, no msg 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)" 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 return
@ -381,8 +383,10 @@ def test_validation_rule_fct_missing_time_portadministration_berth_etd__shipcall
# apply the validation rule # apply the validation rule
(state, msg) = vr.validation_rule_fct_missing_time_portadministration_berth_etd(shipcall=shipcall, df_times=df_times) (state, msg) = vr.validation_rule_fct_missing_time_portadministration_berth_etd(shipcall=shipcall, df_times=df_times)
# expectation: green state, no msg 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)" 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 return
def test_validation_rule_fct_missing_time_pilot_berth_eta__shipcall_soon_but_participant_estimated_time_undefined(build_sql_proxy_connection): 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 # apply the validation rule
(state, msg) = vr.validation_rule_fct_missing_time_pilot_berth_eta(shipcall=shipcall, df_times=df_times) (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)" 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 return