Skip to content

Commit

Permalink
Merge 3f8dccb into 7e9b979
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Jul 13, 2021
2 parents 7e9b979 + 3f8dccb commit 922b115
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 5 deletions.
2 changes: 2 additions & 0 deletions spotlight-api/core/metricsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const ALL_METRIC_FILES = [
"supervision_revocations_by_period_by_type_by_demographics.json",
"supervision_success_by_month.json",
"supervision_success_by_period_by_demographics.json",
"supervision_terminations_by_month.json",
"supervision_terminations_by_period_by_demographics.json",
];

/**
Expand Down
6 changes: 3 additions & 3 deletions spotlight-client/src/contentApi/sources/us_pa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const content: TenantContent = {
addressing critical needs of justice-involved individuals, including employment,
housing, and need-based care.
</p>`,
metricTypeId: "ParoleSuccessHistorical",
metricTypeId: "ParoleTerminationsHistorical",
},
{
title: "Why do revocations happen?",
Expand Down Expand Up @@ -281,8 +281,8 @@ const content: TenantContent = {
prison may occasionally serve their parole in a different state.
</p>`,
},
ParoleSuccessHistorical: {
name: "Historical Parole Completion Rates",
ParoleTerminationsHistorical: {
name: "Historical Parole Successful Termination Rates",
methodology: `<p>
This data reports the percentage of people projected to complete parole in a
given month who have successfully completed parole by the end of that month.
Expand Down
1 change: 1 addition & 0 deletions spotlight-client/src/contentApi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const MetricTypeIdList = [
"ParolePopulationCurrent",
"ParolePopulationHistorical",
"ParoleSuccessHistorical",
"ParoleTerminationsHistorical",
"ParoleRevocationsAggregate",
"ParoleProgrammingCurrent",
] as const;
Expand Down
12 changes: 10 additions & 2 deletions spotlight-client/src/contentModels/Metric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ describe("data fetching", () => {
MetricTypeIdList.filter(
(id) =>
// the `records` property is not supported for these metric types
!["ProbationSuccessHistorical", "ParoleSuccessHistorical"].includes(id)
![
"ProbationSuccessHistorical",
"ParoleSuccessHistorical",
"ParoleTerminationsHistorical",
].includes(id)
)
)("for metric %s", (metricId, done) => {
expect.hasAssertions();
Expand Down Expand Up @@ -198,7 +202,11 @@ describe("data download", () => {
(id) =>
// these metric types have multiple data sources, so the files they download will be different;
// see SupervisionSuccessRateMetric tests for coverage
!["ProbationSuccessHistorical", "ParoleSuccessHistorical"].includes(id)
![
"ProbationSuccessHistorical",
"ParoleSuccessHistorical",
"ParoleTerminationsHistorical",
].includes(id)
)
)("for metric %s", async (metricId, done) => {
const metric = getTestMetric(metricId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ const content: ExhaustiveTenantContent = {
name: "test ParoleSuccessHistorical name",
methodology: "test ParoleSuccessHistorical methodology",
},
ParoleTerminationsHistorical: {
name: "test ParoleTerminationsHistorical name",
methodology: "test ParoleTerminationsHistorical methodology",
},
ParoleRevocationsAggregate: {
name: "test ParoleRevocationsAggregate name",
methodology: "test ParoleRevocationsAggregate methodology",
Expand Down
24 changes: 24 additions & 0 deletions spotlight-client/src/contentModels/createMetricMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
paroleRevocationReasons,
paroleSuccessRateDemographics,
paroleSuccessRateMonthly,
paroleTerminationRateDemographics,
paroleTerminationRateMonthly,
prisonAdmissionReasons,
prisonPopulationCurrent,
prisonPopulationHistorical,
Expand Down Expand Up @@ -359,6 +361,28 @@ export default function createMetricMapping({
})
);
break;
case "ParoleTerminationsHistorical":
if (!localityLabelMapping?.Parole)
throw new Error(localityContentError);

metricMapping.set(
metricType,
new SupervisionSuccessRateMetric({
...metadata,
demographicFilter,
id: metricType,
tenantId,
defaultDemographicView: "total",
defaultLocalityId: TOTAL_KEY,
localityLabels: localityLabelMapping.Parole,
dataTransformer: paroleTerminationRateMonthly,
sourceFileName: "supervision_terminations_by_month",
demographicDataTransformer: paroleTerminationRateDemographics,
demographicSourceFileName:
"supervision_terminations_by_period_by_demographics",
})
);
break;
case "ProbationRevocationsAggregate":
metricMapping.set(
metricType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ function createSupervisionSuccessRateDemographicRecord(
};
}

function createSupervisionTerminationRateDemographicRecord(
record: ValuesType<RawMetricData>
) {
return {
rate: Number(record.success_rate),
rateDenominator: Number(record.termination_count),
rateNumerator: Number(record.successful_termination_count),
locality: record.district,
...extractDemographicFields(record),
};
}

export function probationSuccessRateDemographics(
rawRecords: RawMetricData
): SupervisionSuccessRateDemographicsRecord[] {
Expand All @@ -55,3 +67,11 @@ export function paroleSuccessRateDemographics(
.filter(recordIsParole)
.map(createSupervisionSuccessRateDemographicRecord);
}

export function paroleTerminationRateDemographics(
rawRecords: RawMetricData
): SupervisionSuccessRateDemographicsRecord[] {
return rawRecords
.filter(recordIsParole)
.map(createSupervisionTerminationRateDemographicRecord);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ function createSupervisionSuccessRateMonthlyRecord(
};
}

function createSupervisionTerminationRateMonthlyRecord(
record: ValuesType<RawMetricData>
) {
const year = Number(record.year);
const month = Number(record.month);

return {
locality: record.district,
year,
month,
label: getCohortLabel({ year, month }),
rateNumerator: Number(record.successful_termination_count),
rateDenominator: Number(record.termination_count),
rate: Number(record.success_rate),
};
}

export function probationSuccessRateMonthly(
rawRecords: RawMetricData
): SupervisionSuccessRateMonthlyRecord[] {
Expand All @@ -68,3 +85,11 @@ export function paroleSuccessRateMonthly(
.filter(recordIsParole)
.map(createSupervisionSuccessRateMonthlyRecord);
}

export function paroleTerminationRateMonthly(
rawRecords: RawMetricData
): SupervisionSuccessRateMonthlyRecord[] {
return rawRecords
.filter(recordIsParole)
.map(createSupervisionTerminationRateMonthlyRecord);
}

0 comments on commit 922b115

Please sign in to comment.