Maximum threshold should still be allowed (e.g. 1 hour)
This commit is contained in:
parent
3b01dbb7aa
commit
76bf4f01bd
@ -119,8 +119,8 @@ class ValidationRuleBaseFunctions():
|
|||||||
- there are no matching times for the provided {query} (e.g., "eta_berth")
|
- there are no matching times for the provided {query} (e.g., "eta_berth")
|
||||||
|
|
||||||
This method computes the absolute time difference between all time entries. A threshold (in seconds) is used
|
This method computes the absolute time difference between all time entries. A threshold (in seconds) is used
|
||||||
to identify, when the time differences are so large, that participants essentially disagree on the times.
|
to identify, when the time differences are so large, that participants essentially disagree on the times.
|
||||||
This circumvents previous instabilities, which stem from rounding the pd.Timestamp elements.
|
This circumvents previous instabilities, which stem from rounding the pd.Timestamp elements.
|
||||||
|
|
||||||
options:
|
options:
|
||||||
threshold: integer. Determines the threshold in seconds, when two Timestamps differ 'too much'
|
threshold: integer. Determines the threshold in seconds, when two Timestamps differ 'too much'
|
||||||
@ -142,7 +142,7 @@ class ValidationRuleBaseFunctions():
|
|||||||
if len(agency_times)==0:
|
if len(agency_times)==0:
|
||||||
violation_state = False
|
violation_state = False
|
||||||
return violation_state
|
return violation_state
|
||||||
|
|
||||||
df_times = df_times.loc[df_times["participant_type"].isin(participant_types),:]
|
df_times = df_times.loc[df_times["participant_type"].isin(participant_types),:]
|
||||||
agency_time = [time_ for time_ in agency_times.loc[:,query].tolist() if isinstance(time_, pd.Timestamp)]
|
agency_time = [time_ for time_ in agency_times.loc[:,query].tolist() if isinstance(time_, pd.Timestamp)]
|
||||||
|
|
||||||
@ -154,16 +154,16 @@ class ValidationRuleBaseFunctions():
|
|||||||
if len(estimated_times)==0:
|
if len(estimated_times)==0:
|
||||||
violation_state = False
|
violation_state = False
|
||||||
return violation_state
|
return violation_state
|
||||||
|
|
||||||
# for the given query, e.g., 'eta_berth', sample all times from the pandas DataFrame
|
# for the given query, e.g., 'eta_berth', sample all times from the pandas DataFrame
|
||||||
estimated_times = [time_ for time_ in df_times.loc[:,query].tolist() if isinstance(time_, pd.Timestamp)] # consider only pandas Timestamp objects
|
estimated_times = [time_ for time_ in df_times.loc[:,query].tolist() if isinstance(time_, pd.Timestamp)] # consider only pandas Timestamp objects
|
||||||
|
|
||||||
# measure the time difference between all pairs.
|
# measure the time difference between all pairs.
|
||||||
# for each pair of times, the absolute timedifference in seconds (float) is measured
|
# for each pair of times, the absolute timedifference in seconds (float) is measured
|
||||||
time_absolute_differences = [[abs(time_.to_pydatetime()-time__.to_pydatetime()).total_seconds() for j_, time__ in enumerate(estimated_times) if j_ != i_] for i_, time_ in enumerate(estimated_times)]
|
time_absolute_differences = [[abs(time_.to_pydatetime()-time__.to_pydatetime()).total_seconds() for j_, time__ in enumerate(estimated_times) if j_ != i_] for i_, time_ in enumerate(estimated_times)]
|
||||||
|
|
||||||
# list of lists: for each element in the list, create a boolean that indicates, whether the threshold is exceeded
|
# list of lists: for each element in the list, create a boolean that indicates, whether the threshold is exceeded
|
||||||
time_difference_exceeds_threshold = [[time__ >= threshold for time__ in time_] for time_ in time_absolute_differences]
|
time_difference_exceeds_threshold = [[time__ > threshold for time__ in time_] for time_ in time_absolute_differences]
|
||||||
|
|
||||||
# list of booleans for each time entry separately
|
# list of booleans for each time entry separately
|
||||||
time_difference_exceeds_threshold = [any(time_) for time_ in time_difference_exceeds_threshold]
|
time_difference_exceeds_threshold = [any(time_) for time_ in time_difference_exceeds_threshold]
|
||||||
@ -180,7 +180,7 @@ class ValidationRuleBaseFunctions():
|
|||||||
# violation_state = difference > pd.Timedelta("15min")
|
# violation_state = difference > pd.Timedelta("15min")
|
||||||
|
|
||||||
# this solution clamps the times to 15 minute intervals and compares these values. When there is a single time difference, a violation occurs
|
# this solution clamps the times to 15 minute intervals and compares these values. When there is a single time difference, a violation occurs
|
||||||
# the drawback is that in some cases if there is a minimal difference say of 1 minute (:22 and :23 minutes after the hour) the violation is
|
# the drawback is that in some cases if there is a minimal difference say of 1 minute (:22 and :23 minutes after the hour) the violation is
|
||||||
# triggered even though the times are very close to each other
|
# triggered even though the times are very close to each other
|
||||||
|
|
||||||
# apply rounding. For example, the agreement of different participants may be required to match minute-wise
|
# apply rounding. For example, the agreement of different participants may be required to match minute-wise
|
||||||
@ -639,7 +639,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions):
|
|||||||
"""
|
"""
|
||||||
if self.ignore_terminal_flag: # this feature flag may disable the validation rule for Terminals
|
if self.ignore_terminal_flag: # this feature flag may disable the validation rule for Terminals
|
||||||
return self.get_no_violation_default_output()
|
return self.get_no_violation_default_output()
|
||||||
|
|
||||||
if not shipcall.type in [ShipcallType.OUTGOING.value, ShipcallType.SHIFTING.value]:
|
if not shipcall.type in [ShipcallType.OUTGOING.value, ShipcallType.SHIFTING.value]:
|
||||||
return self.get_no_violation_default_output()
|
return self.get_no_violation_default_output()
|
||||||
|
|
||||||
@ -757,7 +757,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions):
|
|||||||
"""
|
"""
|
||||||
if self.ignore_terminal_flag: # this feature flag may disable the validation rule for Terminals
|
if self.ignore_terminal_flag: # this feature flag may disable the validation rule for Terminals
|
||||||
return self.get_no_violation_default_output()
|
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()
|
||||||
|
|
||||||
@ -800,7 +800,7 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions):
|
|||||||
"""
|
"""
|
||||||
if self.ignore_terminal_flag: # this feature flag may disable the validation rule for Terminals
|
if self.ignore_terminal_flag: # this feature flag may disable the validation rule for Terminals
|
||||||
return self.get_no_violation_default_output()
|
return self.get_no_violation_default_output()
|
||||||
|
|
||||||
if not shipcall.type in [ShipcallType.OUTGOING.value, ShipcallType.SHIFTING.value]:
|
if not shipcall.type in [ShipcallType.OUTGOING.value, ShipcallType.SHIFTING.value]:
|
||||||
return self.get_no_violation_default_output()
|
return self.get_no_violation_default_output()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user