Update backend for Puerto Rico (#1686)

* Update PR threshold count to 10

We now show 10 indicators for PR. See the discussion on the github issue for more info: https://github.com/usds/justice40-tool/issues/1621

* Do not use linguistic iso for Puerto Rico

Closes 1350.

Co-authored-by: Shelby Switzer <shelbyswitzer@gmail.com>
This commit is contained in:
Shelby Switzer 2022-06-23 12:00:48 -04:00 committed by Emma Nechamkin
parent 1782d022a9
commit 05748c9fa2
2 changed files with 50 additions and 8 deletions

View file

@ -123,7 +123,7 @@ TILES_ROUND_NUM_DECIMALS = 2
# Controlling Tile user experience columns # Controlling Tile user experience columns
THRESHOLD_COUNT_TO_SHOW_FIELD_NAME = "THRHLD" THRESHOLD_COUNT_TO_SHOW_FIELD_NAME = "THRHLD"
TILES_ISLAND_AREAS_THRESHOLD_COUNT = 3 TILES_ISLAND_AREAS_THRESHOLD_COUNT = 3
TILES_PUERTO_RICO_THRESHOLD_COUNT = 4 TILES_PUERTO_RICO_THRESHOLD_COUNT = 10
TILES_NATION_THRESHOLD_COUNT = 21 TILES_NATION_THRESHOLD_COUNT = 21
# Note that the FIPS code is a string # Note that the FIPS code is a string

View file

@ -551,7 +551,7 @@ class ScoreNarwhal(Score):
# Where the percent of households at or below 100% of the federal poverty level # Where the percent of households at or below 100% of the federal poverty level
# is above Xth percentile # is above Xth percentile
# or # or
# Where linguistic isolation is above Xth percentile # Where linguistic isolation is above Xth percentile (except PR)
# AND # AND
# Where the high school degree achievement rates for adults 25 years and older # Where the high school degree achievement rates for adults 25 years and older
# is less than Y% # is less than Y%
@ -566,6 +566,12 @@ class ScoreNarwhal(Score):
field_names.LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD, field_names.LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD,
] ]
pr_workforce_eligibility_columns = [
field_names.UNEMPLOYMENT_LOW_HS_EDUCATION_FIELD,
field_names.POVERTY_LOW_HS_EDUCATION_FIELD,
field_names.LOW_MEDIAN_INCOME_LOW_HS_EDUCATION_FIELD,
]
self.df[field_names.LOW_HS_EDUCATION_FIELD] = ( self.df[field_names.LOW_HS_EDUCATION_FIELD] = (
self.df[field_names.HIGH_SCHOOL_ED_FIELD] self.df[field_names.HIGH_SCHOOL_ED_FIELD]
>= self.LACK_OF_HIGH_SCHOOL_MINIMUM_THRESHOLD >= self.LACK_OF_HIGH_SCHOOL_MINIMUM_THRESHOLD
@ -622,9 +628,41 @@ class ScoreNarwhal(Score):
& self.df[field_names.LOW_HS_EDUCATION_FIELD] & self.df[field_names.LOW_HS_EDUCATION_FIELD]
) )
workforce_combined_criteria_for_states = self.df[ self.df[field_names.WORKFORCE_THRESHOLD_EXCEEDED] = (
## First we calculate for the non-island areas
(
(
self.df[field_names.POVERTY_PCTILE_THRESHOLD]
| self.df[field_names.UNEMPLOYMENT_PCTILE_THRESHOLD]
)
| self.df[field_names.LOW_MEDIAN_INCOME_PCTILE_THRESHOLD]
)
| (
self.df[field_names.LINGUISTIC_ISOLATION_PCTILE_THRESHOLD]
& (self.df[field_names.GEOID_TRACT_FIELD].str[:2] != constants.TILES_PUERTO_RICO_FIPS_CODE[0] )
)
)
# Use only PR combined criteria for rows with PR FIPS code;
# otherwise use all criteria.
workforce_combined_criteria_for_states = (
(
(
self.df[field_names.GEOID_TRACT_FIELD].str[:2] == constants.TILES_PUERTO_RICO_FIPS_CODE[0]
)
&
self.df[pr_workforce_eligibility_columns].any(axis="columns")
)
|
(
(
self.df[field_names.GEOID_TRACT_FIELD].str[:2] != constants.TILES_PUERTO_RICO_FIPS_CODE[0]
)
& self.df[
workforce_eligibility_columns workforce_eligibility_columns
].any(axis="columns") ].any(axis="columns")
)
)
self._increment_total_eligibility_exceeded( self._increment_total_eligibility_exceeded(
workforce_eligibility_columns workforce_eligibility_columns
@ -742,17 +780,21 @@ class ScoreNarwhal(Score):
# Because these criteria are calculated differently for the islands, we also calculate the # Because these criteria are calculated differently for the islands, we also calculate the
# thresholds to pass to the FE slightly differently # thresholds to pass to the FE slightly differently
# If it's PR, we don't use linguistic isolation.
self.df[field_names.WORKFORCE_THRESHOLD_EXCEEDED] = ( self.df[field_names.WORKFORCE_THRESHOLD_EXCEEDED] = (
## First we calculate for the non-island areas ## First we calculate for the non-island areas
( (
( (
self.df[field_names.POVERTY_PCTILE_THRESHOLD] self.df[field_names.POVERTY_PCTILE_THRESHOLD]
| self.df[field_names.LINGUISTIC_ISOLATION_PCTILE_THRESHOLD] | self.df[field_names.UNEMPLOYMENT_PCTILE_THRESHOLD]
) )
| self.df[field_names.LOW_MEDIAN_INCOME_PCTILE_THRESHOLD] | self.df[field_names.LOW_MEDIAN_INCOME_PCTILE_THRESHOLD]
) )
| self.df[field_names.UNEMPLOYMENT_PCTILE_THRESHOLD] | (
self.df[field_names.LINGUISTIC_ISOLATION_PCTILE_THRESHOLD]
& ( self.df[field_names.GEOID_TRACT_FIELD].str[:2] != constants.TILES_PUERTO_RICO_FIPS_CODE[0] )
)
) | ( ) | (
## then we calculate just for the island areas ## then we calculate just for the island areas
( (
@ -777,7 +819,7 @@ class ScoreNarwhal(Score):
) )
def add_columns(self) -> pd.DataFrame: def add_columns(self) -> pd.DataFrame:
logger.info("Adding Score M") logger.info("Adding Score Narhwal")
self.df[field_names.THRESHOLD_COUNT] = 0 self.df[field_names.THRESHOLD_COUNT] = 0