def test_add_person_characteristics_IncludeExternalId(self): person = StatePerson.new_with_defaults( state_code='US_MO', person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, races=[StatePersonRace.new_with_defaults()], ethnicities=[StatePersonEthnicity.new_with_defaults()], external_ids=[ StatePersonExternalId.new_with_defaults(external_id='SID1341', id_type='US_MO_DOC', state_code='US_MO') ]) event_date = date(2010, 9, 1) person_metadata = PersonMetadata() updated_characteristics = person_characteristics( person, event_date, person_metadata, 'supervision') expected_output = { 'age_bucket': '25-29', 'gender': Gender.FEMALE, 'person_id': person.person_id, 'person_external_id': 'SID1341' } self.assertEqual(updated_characteristics, expected_output)
def test_add_person_characteristics_IncludeExternalId(self): person = StatePerson.new_with_defaults( state_code="US_XX", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, races=[StatePersonRace.new_with_defaults(state_code="US_XX", )], ethnicities=[ StatePersonEthnicity.new_with_defaults(state_code="US_XX", ) ], external_ids=[ StatePersonExternalId.new_with_defaults(external_id="DOC1341", id_type="US_XX_DOC", state_code="US_XX"), StatePersonExternalId.new_with_defaults(external_id="SID9889", id_type="US_XX_SID", state_code="US_XX"), ], ) event_date = date(2010, 9, 1) person_metadata = PersonMetadata() updated_characteristics = person_characteristics( person, event_date, person_metadata, "test_pipeline") expected_output = { "age_bucket": "25-29", "gender": Gender.FEMALE, "person_id": person.person_id, "person_external_id": "DOC1341", } self.assertEqual(updated_characteristics, expected_output)
def setUp(self) -> None: self.fake_person_id = 12345 self.fake_supervision_violation_id = 23456 self.person_metadata = PersonMetadata( prioritized_race_or_ethnicity="ASIAN") self.pipeline_config = ViolationPipeline().pipeline_config
def test_add_person_characteristics_RaceEthnicity(self): person = StatePerson.new_with_defaults( state_code='US_XX', person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, races=[StatePersonRace.new_with_defaults(race=Race.ASIAN)], ethnicities=[ StatePersonEthnicity.new_with_defaults( ethnicity=Ethnicity.HISPANIC) ]) event_date = date(2010, 9, 1) person_metadata = PersonMetadata( prioritized_race_or_ethnicity='HISPANIC') updated_characteristics = person_characteristics( person, event_date, person_metadata, 'pipeline') expected_output = { 'age_bucket': '25-29', 'race': [Race.ASIAN], 'gender': Gender.FEMALE, 'ethnicity': [Ethnicity.HISPANIC], 'person_id': person.person_id, 'prioritized_race_or_ethnicity': 'HISPANIC' } self.assertEqual(updated_characteristics, expected_output)
def test_add_person_characteristics_MultipleRaces(self): person = StatePerson.new_with_defaults( person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, races=[ StatePersonRace.new_with_defaults(race=Race.ASIAN), StatePersonRace.new_with_defaults(race=Race.BLACK) ]) event_date = date(2010, 9, 1) person_metadata = PersonMetadata(prioritized_race_or_ethnicity='BLACK') updated_characteristics = person_characteristics( person, event_date, person_metadata, 'pipeline') expected_output = { 'age_bucket': '25-29', 'race': [Race.ASIAN, Race.BLACK], 'gender': Gender.FEMALE, 'person_id': person.person_id, 'prioritized_race_or_ethnicity': 'BLACK' } self.assertEqual(updated_characteristics, expected_output)
def test_build_person_metadata(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] person_metadata = build_person_metadata( person, self.state_race_ethnicity_population_counts) expected_person_metadata = PersonMetadata( prioritized_race_or_ethnicity=Race.WHITE.value) self.assertEqual(expected_person_metadata, person_metadata)
def test_build_person_metadata_no_race_ethnicity(self): person = StatePerson.new_with_defaults(state_code='US_XX', person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE) person_metadata = build_person_metadata( person, self.state_race_ethnicity_population_counts) expected_person_metadata = PersonMetadata() self.assertEqual(expected_person_metadata, person_metadata)
def test_add_person_characteristics_NoAttributes(self): person = StatePerson.new_with_defaults(person_id=12345) event_date = date(2010, 9, 1) person_metadata = PersonMetadata() updated_characteristics = person_characteristics( person, event_date, person_metadata, 'pipeline') expected_output = {'person_id': person.person_id} self.assertEqual(updated_characteristics, expected_output)
def test_add_person_characteristics_EmptyRaceEthnicity(self): person = StatePerson.new_with_defaults( state_code="US_XX", person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, ) event_date = date(2010, 9, 1) person_metadata = PersonMetadata() updated_characteristics = person_characteristics( person, event_date, person_metadata, "pipeline") expected_output = { "age_bucket": "25-29", "gender": Gender.FEMALE, "person_id": person.person_id, } self.assertEqual(updated_characteristics, expected_output)
def test_add_person_characteristics_EmptyRaceEthnicity(self): person = StatePerson.new_with_defaults( person_id=12345, birthdate=date(1984, 8, 31), gender=Gender.FEMALE, races=[StatePersonRace.new_with_defaults()], ethnicities=[StatePersonEthnicity.new_with_defaults()]) event_date = date(2010, 9, 1) person_metadata = PersonMetadata() updated_characteristics = person_characteristics( person, event_date, person_metadata, 'pipeline') expected_output = { 'age_bucket': '25-29', 'gender': Gender.FEMALE, 'person_id': person.person_id } self.assertEqual(updated_characteristics, expected_output)
) from recidiviz.calculator.pipeline.program.metrics import ProgramMetricType from recidiviz.calculator.pipeline.utils.metric_utils import RecidivizMetric from recidiviz.calculator.pipeline.utils.person_utils import PersonMetadata from recidiviz.common.constants.person_characteristics import Ethnicity, Gender, Race from recidiviz.common.constants.state.state_assessment import StateAssessmentType from recidiviz.common.constants.state.state_supervision import StateSupervisionType from recidiviz.persistence.entity.state.entities import ( StatePerson, StatePersonEthnicity, StatePersonRace, ) ALL_METRICS_INCLUSIONS_DICT = {metric_type: True for metric_type in ProgramMetricType} _DEFAULT_PERSON_METADATA = PersonMetadata(prioritized_race_or_ethnicity="BLACK") PIPELINE_JOB_ID = "TEST_JOB_ID" class TestProduceProgramMetrics(unittest.TestCase): """Tests the produce_program_metrics function.""" def setUp(self) -> None: self.metric_producer = metric_producer.ProgramMetricProducer() self.pipeline_config = pipeline.ProgramPipeline().pipeline_config @freeze_time("2030-11-02") def test_produce_program_metrics(self) -> None: person = StatePerson.new_with_defaults( state_code="US_ND",
def setUp(self) -> None: self.fake_person_id = 12345 self.person_metadata = PersonMetadata(prioritized_race_or_ethnicity='BLACK')