Skip to content

Commit

Permalink
Merge 2084009 into 3062bf2
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Jun 4, 2021
2 parents 3062bf2 + 2084009 commit 7ca4d48
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 8 deletions.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions spotlight-api/core/metricsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ALL_METRIC_FILES = [
"incarceration_population_by_facility_by_demographics.json",
"incarceration_population_by_month_by_demographics.json",
"incarceration_releases_by_type_by_period.json",
"community_corrections_population_by_facility_by_demographics.json",
"racial_disparities.json",
"recidivism_rates_by_cohort_by_year.json",
"sentence_type_by_district_by_demographics.json",
Expand Down
2 changes: 1 addition & 1 deletion spotlight-client/src/DataStore/TenantStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,6 @@ test("section number is validated against current narrative", () => {
});

reactImmediately(() => {
expect(tenantStore.currentSectionNumber).toBe(6);
expect(tenantStore.currentSectionNumber).toBe(7);
});
});
35 changes: 31 additions & 4 deletions spotlight-client/src/contentApi/sources/us_pa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,24 @@ const content: TenantContent = {
{
title: "How has the incarcerated population changed over time?",
body: `<p>
Broadly speaking, increased activity in earlier parts of the criminal justice
system (such as arrests and sentencing) will result in increases in the prison
population. Changes in sentence lengths and revocations from community
supervision may also contribute to the rise and fall of this number.
Broadly speaking, increased activity in earlier parts of the criminal justice
system (such as arrests and sentencing) will result in increases in the prison
population. Changes in sentence lengths and revocations from community
supervision may also contribute to the rise and fall of this number.
</p>`,
metricTypeId: "PrisonPopulationHistorical",
},
{
title: "Who is in a transitional facility?",
body: `<p>
People who are nearing the end of their prison term may be admitted to a
community correction center in advance of their release from incarceration.
These residential facilities, operated by the DOC or private contractors,
offer supportive programming to help prepare people for a successful
return to the community.
</p>`,
metricTypeId: "CommunityCorrectionsPopulationCurrent",
},
{
title: "How did they get there?",
body: `<p>
Expand Down Expand Up @@ -199,6 +210,18 @@ const content: TenantContent = {
after the individual is released from the DOC.
</p>`,
},
CommunityCorrectionsPopulationCurrent: {
name: "Community Correction Centers",
methodology: `
<p>
In distributions by age, individuals are counted towards the age group they
fall into as of the reporting date. Gender distributions only include male and
female due to low numbers of other reported genders. Distributions by race
count individuals with more than one reported race or ethnicity towards the
racial or ethnic identity that is least represented in the general population.
</p>`,
totalLabel: "Total people in community correction centers",
},

ParolePopulationCurrent: {
name: "Current Parole Population",
Expand Down Expand Up @@ -534,6 +557,10 @@ const content: TenantContent = {
{ id: "05", label: "Williamsport" },
],
},
CommunityCorrections: {
label: "Facility",
entries: [{ id: "ALL", label: "All Facilities" }],
},
},
};

Expand Down
7 changes: 6 additions & 1 deletion spotlight-client/src/contentApi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type TenantContent = {
| "PrisonPopulationCurrent"
| "ProbationPopulationCurrent"
| "ParolePopulationCurrent"
| "CommunityCorrectionsPopulationCurrent"
>]?: MetricContent & { totalLabel: string };
} &
{ [key in MetricTypeId]?: MetricContent };
Expand All @@ -59,7 +60,10 @@ export type TenantContent = {
// this is optional because it is possible (though unlikely)
// to not have any metrics that actually need it
localities?: {
[key in SystemNarrativeTypeId | "ProgramRegions"]?: LocalityLabels;
[key in
| SystemNarrativeTypeId
| "ProgramRegions"
| "CommunityCorrections"]?: LocalityLabels;
};
topologies?: {
ProgramRegions: MapData;
Expand All @@ -83,6 +87,7 @@ export const MetricTypeIdList = [
"PrisonReleaseTypeAggregate",
"PrisonRecidivismRateHistorical",
"PrisonRecidivismRateSingleFollowupHistorical",
"CommunityCorrectionsPopulationCurrent",
"ProbationPopulationCurrent",
"ProbationPopulationHistorical",
"ProbationSuccessHistorical",
Expand Down
3 changes: 1 addition & 2 deletions spotlight-client/src/contentModels/Metric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import JsZip from "jszip";
import { when } from "mobx";
import { fromPromise } from "mobx-utils";
import { stripHtml } from "string-strip-html";
import retrieveContent from "../contentApi/retrieveContent";
import allTestContent from "./__fixtures__/tenant_content_exhaustive";
import { MetricTypeId, MetricTypeIdList } from "../contentApi/types";
import { reactImmediately } from "../testUtils";
import createMetricMapping from "./createMetricMapping";
Expand All @@ -33,7 +33,6 @@ jest.mock("downloadjs");
const downloadjsMock = downloadjs as jest.MockedFunction<typeof downloadjs>;

const testTenantId = "US_ND";
const allTestContent = retrieveContent({ tenantId: testTenantId });
const testMetadataMapping = allTestContent.metrics;

const getTestMapping = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ const content: ExhaustiveTenantContent = {
methodology:
"test PrisonRecidivismRateSingleFollowupHistorical methodology",
},
CommunityCorrectionsPopulationCurrent: {
name: "test CommunityCorrectionsPopulationCurrent name",
methodology: "test CommunityCorrectionsPopulationCurrent methodology",
totalLabel: "test community corrections label",
},
ProbationPopulationCurrent: {
name: "test ProbationPopulationCurrent name",
methodology: "test ProbationPopulationCurrent methodology",
Expand Down Expand Up @@ -264,6 +269,19 @@ const content: ExhaustiveTenantContent = {
},
],
},
CommunityCorrections: {
label: "community corrections locality",
entries: [
{
id: "101",
label: "Facility A",
},
{
id: "201",
label: "Facility B",
},
],
},
},
topologies: {
ProgramRegions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,102 @@ Array [
]
`;

exports[`data fetching for metric CommunityCorrectionsPopulationCurrent 1`] = `
Array [
Object {
"ageBucket": "ALL",
"gender": "ALL",
"locality": "ALL",
"population": 123,
"raceOrEthnicity": "HISPANIC",
},
Object {
"ageBucket": "ALL",
"gender": "FEMALE",
"locality": "ALL",
"population": 67,
"raceOrEthnicity": "ALL",
},
Object {
"ageBucket": "ALL",
"gender": "ALL",
"locality": "ALL",
"population": 96,
"raceOrEthnicity": "BLACK",
},
Object {
"ageBucket": "ALL",
"gender": "MALE",
"locality": "ALL",
"population": 661,
"raceOrEthnicity": "ALL",
},
Object {
"ageBucket": "ALL",
"gender": "ALL",
"locality": "ALL",
"population": 244,
"raceOrEthnicity": "AMERICAN_INDIAN_ALASKAN_NATIVE",
},
Object {
"ageBucket": "35-39",
"gender": "ALL",
"locality": "ALL",
"population": 242,
"raceOrEthnicity": "ALL",
},
Object {
"ageBucket": "40<",
"gender": "ALL",
"locality": "ALL",
"population": 266,
"raceOrEthnicity": "ALL",
},
Object {
"ageBucket": "ALL",
"gender": "ALL",
"locality": "ALL",
"population": 2041,
"raceOrEthnicity": "ALL",
},
Object {
"ageBucket": "ALL",
"gender": "ALL",
"locality": "ALL",
"population": 12,
"raceOrEthnicity": "OTHER",
},
Object {
"ageBucket": "25-29",
"gender": "ALL",
"locality": "ALL",
"population": 284,
"raceOrEthnicity": "ALL",
},
Object {
"ageBucket": "<25",
"gender": "ALL",
"locality": "ALL",
"population": 146,
"raceOrEthnicity": "ALL",
},
Object {
"ageBucket": "ALL",
"gender": "ALL",
"locality": "ALL",
"population": 671,
"raceOrEthnicity": "WHITE",
},
Object {
"ageBucket": "30-34",
"gender": "ALL",
"locality": "ALL",
"population": 134,
"raceOrEthnicity": "ALL",
},
]
`;

exports[`data fetching for metric ParolePopulationCurrent 1`] = `
Array [
Object {
Expand Down
23 changes: 23 additions & 0 deletions spotlight-client/src/contentModels/createMetricMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,28 @@ export default function createMetricMapping({
);
else throw new Error(totalLabelError);
break;
case "CommunityCorrectionsPopulationCurrent":
if (!localityLabelMapping?.CommunityCorrections)
throw new Error(localityContentError);

if ("totalLabel" in metadata)
metricMapping.set(
metricType,
new PopulationBreakdownByLocationMetric({
...metadata,
demographicFilter,
id: metricType,
tenantId,
defaultDemographicView: NOFILTER_KEY,
defaultLocalityId: TOTAL_KEY,
localityLabels: localityLabelMapping.CommunityCorrections,
dataTransformer: prisonPopulationCurrent,
sourceFileName:
"community_corrections_population_by_facility_by_demographics",
})
);
else throw new Error(totalLabelError);
break;
case "ProbationPopulationCurrent":
if (!localityLabelMapping?.Probation)
throw new Error(localityContentError);
Expand Down Expand Up @@ -452,6 +474,7 @@ export default function createMetricMapping({
})
);
break;

default:
assertNever(metricType);
}
Expand Down

0 comments on commit 7ca4d48

Please sign in to comment.