Skip to content

Commit

Permalink
register new metric for CCs
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Jun 2, 2021
1 parent db14bf5 commit 86ea451
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 3 deletions.
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 86ea451

Please sign in to comment.