def test_identify_most_severe_response_decision_test_all_types(self): for decision in StateSupervisionViolationResponseDecision: decisions = [decision] most_severe_decision = calculator_utils.identify_most_severe_response_decision( decisions) self.assertEqual(most_severe_decision, decision)
def test_identify_most_severe_response_decision(self): decisions = [ StateSupervisionViolationResponseDecision.CONTINUANCE, StateSupervisionViolationResponseDecision.REVOCATION ] most_severe_decision = calculator_utils.identify_most_severe_response_decision( decisions) self.assertEqual(most_severe_decision, StateSupervisionViolationResponseDecision.REVOCATION)
def get_violation_and_response_history( revocation_date: date, violation_responses: List[StateSupervisionViolationResponse] ) -> ViolationHistory: """Looks at the series of violation responses that preceded a revocation. Selects the violation responses that occurred within VIOLATION_HISTORY_WINDOW_MONTHS months of the revocation return date, and looks at those responses and the corresponding violations. Identifies and returns the most severe violation type that was recorded during the period, the most severe decision on the responses, and the total number of responses during the period. """ history_cutoff_date = revocation_date - relativedelta( months=VIOLATION_HISTORY_WINDOW_MONTHS) responses_in_window = [ response for response in violation_responses if response.response_date is not None and not response.is_draft and response.response_type in ( StateSupervisionViolationResponseType.VIOLATION_REPORT, StateSupervisionViolationResponseType.CITATION) and history_cutoff_date <= response.response_date <= revocation_date ] violations_in_window: List[StateSupervisionViolation] = [] response_decisions: List[StateSupervisionViolationResponseDecision] = [] for response in responses_in_window: if response.supervision_violation: violations_in_window.append(response.supervision_violation) if response.supervision_violation_response_decisions: decision_entries = response.supervision_violation_response_decisions for decision_entry in decision_entries: if decision_entry.decision: response_decisions.append(decision_entry.decision) # Find the most severe violation type info of all of the entries in the window most_severe_violation_type, most_severe_violation_type_subtype = \ identify_most_severe_violation_type_and_subtype(violations_in_window) # Find the most severe decision in all of the responses in the window most_severe_response_decision = identify_most_severe_response_decision( response_decisions) violation_type_entries = [] for violation in violations_in_window: violation_type_entries.extend(violation.supervision_violation_types) violation_history_description = _get_violation_history_description( violations_in_window) violation_type_frequency_counter = _get_violation_type_frequency_counter( violations_in_window) # Count the number of responses in the window response_count = len(responses_in_window) violation_history_result = ViolationHistory( most_severe_violation_type, most_severe_violation_type_subtype, most_severe_response_decision, response_count, violation_history_description, violation_type_frequency_counter) return violation_history_result