コード例 #1
0
    def test_produce_incarceration_metrics_calculation_month_count_include_one(
            self):
        person = StatePerson.new_with_defaults(
            state_code="US_XX",
            person_id=12345,
            birthdate=date(1984, 8, 31),
            gender=Gender.FEMALE,
        )

        race = StatePersonRace.new_with_defaults(state_code="US_XX",
                                                 race=Race.WHITE)

        person.races = [race]

        ethnicity = StatePersonEthnicity.new_with_defaults(
            state_code="US_XX", ethnicity=Ethnicity.NOT_HISPANIC)

        person.ethnicities = [ethnicity]

        incarceration_event_include = IncarcerationStandardAdmissionEvent(
            state_code="US_XX",
            event_date=date(2000, 3, 12),
            facility="FACILITY X",
            county_of_residence=_COUNTY_OF_RESIDENCE,
        )

        incarceration_event_exclude = IncarcerationStandardAdmissionEvent(
            state_code="US_XX",
            event_date=date(1994, 3, 12),
            facility="FACILITY X",
            county_of_residence=_COUNTY_OF_RESIDENCE,
        )

        incarceration_events = [
            incarceration_event_include,
            incarceration_event_exclude,
        ]

        metrics = self.metric_producer.produce_metrics(
            person=person,
            identifier_events=incarceration_events,
            metric_inclusions=ALL_METRICS_INCLUSIONS_DICT,
            calculation_end_month=None,
            calculation_month_count=36,
            person_metadata=_DEFAULT_PERSON_METADATA,
            pipeline_job_id=PIPELINE_JOB_ID,
            pipeline_type=self.pipeline_config.pipeline_type,
        )

        expected_count = self.expected_metrics_count(
            [incarceration_event_include])

        self.assertEqual(expected_count, len(metrics))

        for metric in metrics:
            assert metric.year == 2000
コード例 #2
0
    def _admission_event_for_period(
        self,
        incarceration_sentences: List[StateIncarcerationSentence],
        supervision_sentences: List[StateSupervisionSentence],
        incarceration_period: StateIncarcerationPeriod,
        incarceration_period_index: PreProcessedIncarcerationPeriodIndex,
        supervision_period_index: PreProcessedSupervisionPeriodIndex,
        assessments: List[StateAssessment],
        sorted_violation_responses: List[StateSupervisionViolationResponse],
        supervision_period_to_agent_associations: Dict[int, Dict[Any, Any]],
        county_of_residence: Optional[str],
    ) -> Optional[IncarcerationAdmissionEvent]:
        """Returns an IncarcerationAdmissionEvent if this incarceration period represents an
        admission to incarceration."""

        admission_date: Optional[date] = incarceration_period.admission_date
        admission_reason: Optional[
            StateIncarcerationPeriodAdmissionReason
        ] = incarceration_period.admission_reason

        if admission_date and admission_reason:
            state_code = incarceration_period.state_code
            commitment_from_supervision_delegate = (
                get_state_specific_commitment_from_supervision_delegate(state_code)
            )
            violation_delegate = get_state_specific_violation_delegate(state_code)

            if is_commitment_from_supervision(admission_reason):

                return self._commitment_from_supervision_event_for_period(
                    incarceration_sentences=incarceration_sentences,
                    supervision_sentences=supervision_sentences,
                    incarceration_period=incarceration_period,
                    incarceration_period_index=incarceration_period_index,
                    supervision_period_index=supervision_period_index,
                    assessments=assessments,
                    sorted_violation_responses=sorted_violation_responses,
                    supervision_period_to_agent_associations=supervision_period_to_agent_associations,
                    county_of_residence=county_of_residence,
                    commitment_from_supervision_delegate=commitment_from_supervision_delegate,
                    violation_delegate=violation_delegate,
                )

            return IncarcerationStandardAdmissionEvent(
                state_code=incarceration_period.state_code,
                event_date=admission_date,
                facility=incarceration_period.facility,
                admission_reason=admission_reason,
                admission_reason_raw_text=incarceration_period.admission_reason_raw_text,
                specialized_purpose_for_incarceration=incarceration_period.specialized_purpose_for_incarceration,
                county_of_residence=county_of_residence,
            )

        return None
コード例 #3
0
    def test_produce_incarceration_metrics_all_types(self):
        person = StatePerson.new_with_defaults(
            state_code="US_XX",
            person_id=12345,
            birthdate=date(1984, 8, 31),
            gender=Gender.FEMALE,
        )

        race = StatePersonRace.new_with_defaults(state_code="US_XX",
                                                 race=Race.WHITE)

        person.races = [race]

        ethnicity = StatePersonEthnicity.new_with_defaults(
            state_code="US_XX", ethnicity=Ethnicity.NOT_HISPANIC)

        person.ethnicities = [ethnicity]

        incarceration_events = [
            IncarcerationStayEvent(
                admission_reason=StateIncarcerationPeriodAdmissionReason.
                PAROLE_REVOCATION,
                admission_reason_raw_text="NEW_ADMISSION",
                state_code="US_XX",
                event_date=date(2000, 3, 31),
                facility="FACILITY X",
                county_of_residence=_COUNTY_OF_RESIDENCE,
                most_serious_offense_ncic_code=_NCIC_CODE,
                most_serious_offense_statute=_STATUTE,
                specialized_purpose_for_incarceration=
                StateSpecializedPurposeForIncarceration.TREATMENT_IN_PRISON,
            ),
            IncarcerationStandardAdmissionEvent(
                state_code="US_XX",
                event_date=date(2000, 3, 12),
                facility="FACILITY X",
                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,
            ),
            IncarcerationReleaseEvent(
                state_code="US_XX",
                event_date=date(2003, 4, 12),
                facility="FACILITY X",
                county_of_residence=_COUNTY_OF_RESIDENCE,
                supervision_type_at_release=
                StateSupervisionPeriodSupervisionType.PAROLE,
            ),
            IncarcerationCommitmentFromSupervisionAdmissionEvent(
                state_code="US_XX",
                event_date=date(2000, 3, 12),
                facility="FACILITY X",
                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,
                supervision_type=StateSupervisionPeriodSupervisionType.PAROLE,
            ),
        ]

        metrics = self.metric_producer.produce_metrics(
            person=person,
            identifier_events=incarceration_events,
            metric_inclusions=ALL_METRICS_INCLUSIONS_DICT,
            calculation_end_month=None,
            calculation_month_count=-1,
            person_metadata=_DEFAULT_PERSON_METADATA,
            pipeline_job_id=PIPELINE_JOB_ID,
            pipeline_type=self.pipeline_config.pipeline_type,
        )

        expected_count = self.expected_metrics_count(incarceration_events)

        self.assertEqual(expected_count, len(metrics))