def test_map_incarceration_combinations_all_types(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationStayEvent( admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION, admission_reason_raw_text='NEW_ADMISSION', supervision_type_at_admission= StateSupervisionPeriodSupervisionType.PAROLE, state_code='CA', event_date=date(2000, 3, 31), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, most_serious_offense_statute=_STATUTE, ), IncarcerationAdmissionEvent( state_code='CA', event_date=date(2000, 3, 12), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, admission_reason=AdmissionReason.PAROLE_REVOCATION, supervision_type_at_admission= StateSupervisionPeriodSupervisionType.PAROLE, admission_reason_raw_text='PAROLE_REVOCATION', specialized_purpose_for_incarceration= StateSpecializedPurposeForIncarceration.TREATMENT_IN_PRISON), IncarcerationReleaseEvent( state_code='CA', event_date=date(2003, 4, 12), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, ) ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=-1) expected_combinations_count = expected_metric_combos_count( person, incarceration_events, ALL_INCLUSIONS_DICT) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations)
def test_map_incarceration_combinations_two_stays_same_month_facility( self): person = StatePerson.new_with_defaults( state_code="CA", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, ) race = StatePersonRace.new_with_defaults(state_code="CA", race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code="CA", ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationStayEvent( state_code="CA", event_date=date(2010, 3, 31), facility="FACILITY 33", county_of_residence=_COUNTY_OF_RESIDENCE, most_serious_offense_ncic_code=_NCIC_CODE, most_serious_offense_statute=_STATUTE, admission_reason=AdmissionReason.PAROLE_REVOCATION, admission_reason_raw_text="PAROLE_REVOCATION", specialized_purpose_for_incarceration= StateSpecializedPurposeForIncarceration.TREATMENT_IN_PRISON, ), IncarcerationStayEvent( state_code="CA", event_date=date(2010, 3, 31), facility="FACILITY 18", county_of_residence=_COUNTY_OF_RESIDENCE, admission_reason=AdmissionReason.PAROLE_REVOCATION, admission_reason_raw_text="PAROLE_REVOCATION", specialized_purpose_for_incarceration= StateSpecializedPurposeForIncarceration.TREATMENT_IN_PRISON, ), ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, metric_inclusions=ALL_METRICS_INCLUSIONS_DICT, calculation_end_month=None, calculation_month_count=-1, person_metadata=_DEFAULT_PERSON_METADATA, ) expected_combinations_count = expected_metric_combos_count( incarceration_events) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations)
def test_map_incarceration_combinations_calculation_month_limit_exclude( self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_event = IncarcerationAdmissionEvent( state_code='CA', event_date=date(1990, 3, 12), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, ) incarceration_events = [incarceration_event] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=1) self.assertEqual(0, len(incarceration_combinations))
def process(self, element, calculation_end_month, calculation_month_count, metric_inclusions): """Produces various incarceration metric combinations. Sends the calculator the StatePerson entity and their corresponding IncarcerationEvents for mapping all incarceration combinations. Args: element: Tuple containing a StatePerson and their IncarcerationEvents calculation_end_month: The year and month of the last month for which metrics should be calculated. calculation_month_count: The number of months to limit the monthly calculation output to. metric_inclusions: A dictionary where the keys are each IncarcerationMetricType, and the values are boolean flags for whether or not to include that metric type in the calculations Yields: Each incarceration metric combination. """ person, incarceration_events = element # Calculate incarceration metric combinations for this person and events metric_combinations = calculator.map_incarceration_combinations( person, incarceration_events, metric_inclusions, calculation_end_month, calculation_month_count) # Return each of the incarceration metric combinations for metric_combination in metric_combinations: yield metric_combination
def test_map_incarceration_combinations_calculation_month_count_include_one( self): person = StatePerson.new_with_defaults( state_code="CA", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, ) race = StatePersonRace.new_with_defaults(state_code="CA", race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code="CA", ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_event_include = IncarcerationAdmissionEvent( state_code="CA", event_date=date(2000, 3, 12), facility="SAN QUENTIN", county_of_residence=_COUNTY_OF_RESIDENCE, ) incarceration_event_exclude = IncarcerationAdmissionEvent( state_code="CA", event_date=date(1994, 3, 12), facility="SAN QUENTIN", county_of_residence=_COUNTY_OF_RESIDENCE, ) incarceration_events = [ incarceration_event_include, incarceration_event_exclude, ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, metric_inclusions=ALL_METRICS_INCLUSIONS_DICT, calculation_end_month=None, calculation_month_count=36, person_metadata=_DEFAULT_PERSON_METADATA, ) expected_combinations_count = expected_metric_combos_count( [incarceration_event_include]) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations) for combo, _ in incarceration_combinations: assert combo.get("year") == 2000
def test_map_incarceration_combinations_relevant_periods_revocations(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationAdmissionEvent( state_code='CA', event_date=date(2010, 10, 2), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, admission_reason=AdmissionReason.PAROLE_REVOCATION), IncarcerationAdmissionEvent( state_code='CA', event_date=date(2010, 10, 19), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, admission_reason=AdmissionReason.NEW_ADMISSION) ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=-1) expected_combinations_count = expected_metric_combos_count( person, incarceration_events, ALL_INCLUSIONS_DICT, len(calculator_utils.METRIC_PERIOD_MONTHS)) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations) for combo, _ in incarceration_combinations: assert combo.get('year') == 2010 for combo, _ in incarceration_combinations: if combo.get('admission_reason')\ and combo_has_enum_value_for_key( combo, 'metric_type', MetricMethodologyType.PERSON): # Ensure that all person-based metrics have the parole # revocation admission reason on them assert combo.get('admission_reason') == \ AdmissionReason.PAROLE_REVOCATION
def test_map_incarceration_combinations_includes_statute_output(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationStayEvent(state_code='CA', event_date=date(2010, 3, 31), facility='FACILITY 33', county_of_residence=_COUNTY_OF_RESIDENCE, most_serious_offense_ncic_code=_NCIC_CODE, most_serious_offense_statute=_STATUTE), IncarcerationStayEvent(state_code='CA', event_date=date(2010, 4, 30), facility='FACILITY 33', county_of_residence=_COUNTY_OF_RESIDENCE, most_serious_offense_ncic_code=_NCIC_CODE, most_serious_offense_statute=_STATUTE), IncarcerationStayEvent(state_code='CA', event_date=date(2010, 5, 31), facility='FACILITY 33', county_of_residence=_COUNTY_OF_RESIDENCE, most_serious_offense_ncic_code=_NCIC_CODE, most_serious_offense_statute=_STATUTE) ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=-1) expected_combinations_count = expected_metric_combos_count( person, incarceration_events, ALL_INCLUSIONS_DICT) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations) assert all( combo.get('most_serious_offense_statute') is not None for combo, value in incarceration_combinations if combo.get('person_id') is not None)
def test_map_incarceration_combinations_calculation_month_limit_include_one( self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_event_include = IncarcerationAdmissionEvent( state_code='CA', event_date=date(2000, 3, 12), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, ) incarceration_event_exclude = IncarcerationAdmissionEvent( state_code='CA', event_date=date(1994, 3, 12), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, ) incarceration_events = [ incarceration_event_include, incarceration_event_exclude ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=36) expected_combinations_count = expected_metric_combos_count( person, [incarceration_event_include], ALL_INCLUSIONS_DICT, num_relevant_periods_admissions=len( calculator_utils.METRIC_PERIOD_MONTHS)) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations) for combo, _ in incarceration_combinations: assert combo.get('year') == 2000
def test_map_incarceration_combinations(self): person = StatePerson.new_with_defaults( state_code="CA", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, ) race = StatePersonRace.new_with_defaults(state_code="CA", race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code="CA", ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_event = IncarcerationAdmissionEvent( state_code="CA", admission_reason=StateIncarcerationPeriodAdmissionReason. NEW_ADMISSION, admission_reason_raw_text="NEW_ADMISSION", supervision_type_at_admission=StateSupervisionPeriodSupervisionType .PROBATION, event_date=date(2000, 3, 12), facility="SAN QUENTIN", county_of_residence=_COUNTY_OF_RESIDENCE, ) incarceration_events = [incarceration_event] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, metric_inclusions=ALL_METRICS_INCLUSIONS_DICT, calculation_end_month="2000-03", calculation_month_count=1, person_metadata=_DEFAULT_PERSON_METADATA, ) expected_combinations_count = expected_metric_combos_count( incarceration_events) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations) for combo, _ in incarceration_combinations: assert combo.get("year") == 2000
def test_map_incarceration_combinations_two_stays_same_month(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationStayEvent( state_code='CA', event_date=date(2010, 3, 31), facility='FACILITY 33', county_of_residence=_COUNTY_OF_RESIDENCE, most_serious_offense_ncic_code=_NCIC_CODE, most_serious_offense_statute=_STATUTE, admission_reason=AdmissionReason.PAROLE_REVOCATION, admission_reason_raw_text='PAROLE_REVOCATION', ), IncarcerationStayEvent( state_code='CA', event_date=date(2010, 3, 31), facility='FACILITY 33', county_of_residence=_COUNTY_OF_RESIDENCE, most_serious_offense_ncic_code=_NCIC_CODE, most_serious_offense_statute=_STATUTE, admission_reason=AdmissionReason.PAROLE_REVOCATION, admission_reason_raw_text='PAROLE_REVOCATION', ) ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=-1) expected_combinations_count = expected_metric_combos_count( person, incarceration_events, ALL_INCLUSIONS_DICT) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations)
def test_map_incarceration_combinations_two_releases_same_month(self): person = StatePerson.new_with_defaults( state_code="CA", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, ) race = StatePersonRace.new_with_defaults(state_code="CA", race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code="CA", ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationReleaseEvent( state_code="CA", event_date=date(2010, 3, 12), facility="FACILITY 33", county_of_residence=_COUNTY_OF_RESIDENCE, ), IncarcerationReleaseEvent( state_code="CA", event_date=date(2010, 3, 24), facility="FACILITY 33", county_of_residence=_COUNTY_OF_RESIDENCE, ), ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, metric_inclusions=ALL_METRICS_INCLUSIONS_DICT, calculation_end_month=None, calculation_month_count=-1, person_metadata=_DEFAULT_PERSON_METADATA, ) expected_combinations_count = expected_metric_combos_count( incarceration_events) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations)
def test_map_incarceration_combinations(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_event = IncarcerationAdmissionEvent( state_code='CA', admission_reason=StateIncarcerationPeriodAdmissionReason. NEW_ADMISSION, admission_reason_raw_text='NEW_ADMISSION', supervision_type_at_admission=StateSupervisionPeriodSupervisionType .PROBATION, event_date=date(2000, 3, 12), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, ) incarceration_events = [incarceration_event] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=-1) expected_combinations_count = expected_metric_combos_count( person, incarceration_events, ALL_INCLUSIONS_DICT) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations) for combo, _ in incarceration_combinations: assert combo.get('year') == 2000
def test_map_incarceration_combinations_admission_relevant_periods(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_event = IncarcerationAdmissionEvent( state_code='CA', event_date=date(2000, 3, 12), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, admission_reason=AdmissionReason.NEW_ADMISSION, specialized_purpose_for_incarceration= StateSpecializedPurposeForIncarceration.SHOCK_INCARCERATION) incarceration_events = [incarceration_event] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=-1) expected_combinations_count = expected_metric_combos_count( person, incarceration_events, ALL_INCLUSIONS_DICT, len(calculator_utils.METRIC_PERIOD_MONTHS)) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations) for combo, _ in incarceration_combinations: assert combo.get('year') == 2000 if combo.get('person_id') is not None: assert combo.get('admission_date') is not None
def test_map_incarceration_combinations_multiple_overlapping_stays(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationStayEvent(state_code='US_ND', event_date=date(2019, 11, 30), facility='JRCC', county_of_residence=_COUNTY_OF_RESIDENCE), IncarcerationStayEvent(state_code='US_ND', event_date=date(2019, 11, 30), facility='JRCC', county_of_residence=_COUNTY_OF_RESIDENCE), IncarcerationStayEvent(state_code='US_ND', event_date=date(2019, 11, 30), facility='JRCC', county_of_residence=_COUNTY_OF_RESIDENCE) ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=-1) expected_combinations_count = expected_metric_combos_count( person, incarceration_events, ALL_INCLUSIONS_DICT) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations)
def test_map_incarceration_combinations_two_admissions_same_month(self): person = StatePerson.new_with_defaults(person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) race = StatePersonRace.new_with_defaults(state_code='CA', race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code='CA', ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationAdmissionEvent( state_code='CA', event_date=date(2000, 3, 12), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, admission_reason=AdmissionReason.NEW_ADMISSION), IncarcerationAdmissionEvent( state_code='CA', event_date=date(2000, 3, 17), facility='SAN QUENTIN', county_of_residence=_COUNTY_OF_RESIDENCE, admission_reason=AdmissionReason.NEW_ADMISSION) ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, inclusions=ALL_INCLUSIONS_DICT, calculation_month_limit=-1) expected_combinations_count = expected_metric_combos_count( person, incarceration_events, ALL_INCLUSIONS_DICT) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations)
def process(self, element, calculation_month_limit, inclusions): """Produces various incarceration metric combinations. Sends the calculator the StatePerson entity and their corresponding IncarcerationEvents for mapping all incarceration combinations. Args: element: Tuple containing a StatePerson and their IncarcerationEvents calculation_month_limit: The number of months to limit the monthly calculation output to. inclusions: This should be a dictionary with values for the following keys: - age_bucket - gender - race - ethnicity Yields: Each incarceration metric combination, tagged by metric type. """ person, incarceration_events = element # Calculate incarceration metric combinations for this person and events metric_combinations = calculator.map_incarceration_combinations(person, incarceration_events, inclusions, calculation_month_limit) # Return each of the incarceration metric combinations for metric_combination in metric_combinations: metric_key, value = metric_combination metric_type = metric_key.get('metric_type') # Converting the metric key to a JSON string so it is hashable serializable_dict = json_serializable_metric_key(metric_key) json_key = json.dumps(serializable_dict, sort_keys=True) if metric_type == MetricType.ADMISSION.value: yield beam.pvalue.TaggedOutput('admissions', (json_key, value)) elif metric_type == MetricType.POPULATION.value: yield beam.pvalue.TaggedOutput('populations', (json_key, value)) elif metric_type == MetricType.RELEASE.value: yield beam.pvalue.TaggedOutput('releases', (json_key, value))
def test_map_incarceration_combinations_multiple_overlapping_stays(self): person = StatePerson.new_with_defaults( state_code="US_ND", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, ) race = StatePersonRace.new_with_defaults(state_code="US_ND", race=Race.WHITE) person.races = [race] ethnicity = StatePersonEthnicity.new_with_defaults( state_code="US_ND", ethnicity=Ethnicity.NOT_HISPANIC) person.ethnicities = [ethnicity] incarceration_events = [ IncarcerationStayEvent( state_code="US_ND", event_date=date(2019, 11, 30), facility="JRCC", county_of_residence=_COUNTY_OF_RESIDENCE, specialized_purpose_for_incarceration= StateSpecializedPurposeForIncarceration.TREATMENT_IN_PRISON, ), IncarcerationStayEvent( state_code="US_ND", event_date=date(2019, 11, 30), facility="JRCC", county_of_residence=_COUNTY_OF_RESIDENCE, specialized_purpose_for_incarceration= StateSpecializedPurposeForIncarceration.TREATMENT_IN_PRISON, ), IncarcerationStayEvent( state_code="US_ND", event_date=date(2019, 11, 30), facility="JRCC", county_of_residence=_COUNTY_OF_RESIDENCE, specialized_purpose_for_incarceration= StateSpecializedPurposeForIncarceration.TREATMENT_IN_PRISON, ), ] incarceration_combinations = calculator.map_incarceration_combinations( person=person, incarceration_events=incarceration_events, metric_inclusions=ALL_METRICS_INCLUSIONS_DICT, calculation_end_month=None, calculation_month_count=-1, person_metadata=_DEFAULT_PERSON_METADATA, ) expected_combinations_count = expected_metric_combos_count( incarceration_events) self.assertEqual(expected_combinations_count, len(incarceration_combinations)) assert all(value == 1 for _combination, value in incarceration_combinations)