From 0596e4cb387c44753c3dbf8d1da8de7f529c12b4 Mon Sep 17 00:00:00 2001 From: Ian MacFarland Date: Fri, 29 Oct 2021 16:14:48 -0700 Subject: [PATCH] remove support for legacy age categories --- .../src/contentModels/Metric.test.ts | 23 --- spotlight-client/src/contentModels/Metric.ts | 21 +- .../contentModels/__fixtures__/metricData.ts | 188 ------------------ spotlight-client/src/demographics/types.ts | 12 +- .../src/demographics/utils.test.ts | 16 +- spotlight-client/src/demographics/utils.ts | 10 +- 6 files changed, 5 insertions(+), 265 deletions(-) delete mode 100644 spotlight-client/src/contentModels/__fixtures__/metricData.ts diff --git a/spotlight-client/src/contentModels/Metric.test.ts b/spotlight-client/src/contentModels/Metric.test.ts index 92466568..e6b6d965 100644 --- a/spotlight-client/src/contentModels/Metric.test.ts +++ b/spotlight-client/src/contentModels/Metric.test.ts @@ -28,7 +28,6 @@ import allTestContent from "./__fixtures__/tenant_content_exhaustive"; import { MetricTypeId, MetricTypeIdList } from "../contentApi/types"; import { reactImmediately } from "../testUtils"; import createMetricMapping from "./createMetricMapping"; -import { incarcerationReleasesLegacyAgeBuckets } from "./__fixtures__/metricData"; jest.mock("downloadjs"); const downloadjsMock = downloadjs as jest.MockedFunction; @@ -304,25 +303,3 @@ describe("data download", () => { }); }); }); - -test("switch to legacy age categories after hydration", async () => { - // expect any metric that supports demographics to behave the same - const metric = getTestMetric("PrisonReleaseTypeAggregate"); - - fetchMock.doMock(); - fetchMock.mockResponse( - JSON.stringify({ - incarceration_releases_by_type_by_period: incarcerationReleasesLegacyAgeBuckets, - }) - ); - - await metric.hydrate(); - - expect(metric.getDemographicCategories("ageBucket")).toEqual([ - { identifier: "<25", label: "<25" }, - { identifier: "25-29", label: "25-29" }, - { identifier: "30-34", label: "30-34" }, - { identifier: "35-39", label: "35-39" }, - { identifier: "40<", label: "40+" }, - ]); -}); diff --git a/spotlight-client/src/contentModels/Metric.ts b/spotlight-client/src/contentModels/Metric.ts index 8fcebd2a..b7687d29 100644 --- a/spotlight-client/src/contentModels/Metric.ts +++ b/spotlight-client/src/contentModels/Metric.ts @@ -34,7 +34,6 @@ import { DemographicCategories, DemographicView, getDemographicCategoriesForView, - LegacyAgeValueList, } from "../demographics"; import { RawMetricData, @@ -42,7 +41,6 @@ import { LocalityFields, SupervisionSuccessRateMonthlyRecord, fetchAndTransformMetric, - isDemographicFields, } from "../metricsApi"; import downloadData from "./downloadData"; import { MetricRecord, Hydratable } from "./types"; @@ -102,11 +100,7 @@ export default abstract class Metric error?: Error; // filter properties - // TODO(#479): don't need to store a copy of the filter once legacy age categories are removed - private readonly demographicFilter?: DemographicCategoryFilter; - - // TODO(#479): this can become readonly again once legacy age categories are removed - private demographicCategories: DemographicCategories; + private readonly demographicCategories: DemographicCategories; localityId: RecordFormat extends LocalityFields ? string : undefined; @@ -154,7 +148,6 @@ export default abstract class Metric this.dataTransformer = dataTransformer; // initialize filters - this.demographicFilter = demographicFilter; this.demographicCategories = createDemographicCategories(demographicFilter); this.getDemographicCategories = this.getDemographicCategories.bind(this); this.localityId = defaultLocalityId; @@ -171,18 +164,6 @@ export default abstract class Metric tenantId: this.tenantId, transformFn: this.dataTransformer, }); - // if data has legacy values, use the old categories - // TODO (#479): no longer needed once views are updated - if ( - records.some( - (record) => isDemographicFields(record) && record.ageBucket === "40<" - ) - ) { - this.demographicCategories = createDemographicCategories({ - ...this.demographicFilter, - ageBucket: [...LegacyAgeValueList], - }); - } return records; } diff --git a/spotlight-client/src/contentModels/__fixtures__/metricData.ts b/spotlight-client/src/contentModels/__fixtures__/metricData.ts deleted file mode 100644 index 7b366ede..00000000 --- a/spotlight-client/src/contentModels/__fixtures__/metricData.ts +++ /dev/null @@ -1,188 +0,0 @@ -// Recidiviz - a data platform for criminal justice reform -// Copyright (C) 2021 Recidiviz, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// ============================================================================= - -export const incarcerationReleasesLegacyAgeBuckets = [ - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "ALL", - race_or_ethnicity: "ALL", - total_release_count: "3492", - external_transfer_count: "346", - sentence_completion_count: "203", - parole_count: "680", - probation_count: "1088", - death_count: "1174", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "<25", - race_or_ethnicity: "ALL", - total_release_count: "504", - external_transfer_count: "170", - sentence_completion_count: "50", - parole_count: "98", - probation_count: "29", - death_count: "157", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "25-29", - race_or_ethnicity: "ALL", - total_release_count: "477", - external_transfer_count: "160", - sentence_completion_count: "93", - parole_count: "47", - probation_count: "28", - death_count: "149", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "30-34", - race_or_ethnicity: "ALL", - total_release_count: "836", - external_transfer_count: "49", - sentence_completion_count: "163", - parole_count: "260", - probation_count: "83", - death_count: "281", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "35-39", - race_or_ethnicity: "ALL", - total_release_count: "1046", - external_transfer_count: "104", - sentence_completion_count: "326", - parole_count: "352", - probation_count: "204", - death_count: "61", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "40<", - race_or_ethnicity: "ALL", - total_release_count: "629", - external_transfer_count: "123", - sentence_completion_count: "62", - parole_count: "212", - probation_count: "196", - death_count: "37", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "ALL", - race_or_ethnicity: "AMERICAN_INDIAN_ALASKAN_NATIVE", - total_release_count: "1046", - external_transfer_count: "104", - sentence_completion_count: "352", - parole_count: "326", - probation_count: "61", - death_count: "204", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "ALL", - race_or_ethnicity: "BLACK", - total_release_count: "1025", - external_transfer_count: "344", - sentence_completion_count: "200", - parole_count: "319", - probation_count: "60", - death_count: "102", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "ALL", - race_or_ethnicity: "HISPANIC", - total_release_count: "372", - external_transfer_count: "22", - sentence_completion_count: "37", - parole_count: "125", - probation_count: "116", - death_count: "72", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "ALL", - race_or_ethnicity: "WHITE", - total_release_count: "605", - external_transfer_count: "203", - sentence_completion_count: "188", - parole_count: "35", - probation_count: "118", - death_count: "60", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "ALL", - age_bucket: "ALL", - race_or_ethnicity: "OTHER", - total_release_count: "445", - external_transfer_count: "44", - sentence_completion_count: "139", - parole_count: "87", - probation_count: "150", - death_count: "26", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "MALE", - age_bucket: "ALL", - race_or_ethnicity: "ALL", - total_release_count: "1906", - external_transfer_count: "594", - sentence_completion_count: "189", - parole_count: "641", - probation_count: "371", - death_count: "111", - metric_period_months: "36", - }, - { - state_code: "US_ND", - gender: "FEMALE", - age_bucket: "ALL", - race_or_ethnicity: "ALL", - total_release_count: "1586", - external_transfer_count: "92", - sentence_completion_count: "494", - parole_count: "533", - probation_count: "309", - death_count: "157", - metric_period_months: "36", - }, -]; diff --git a/spotlight-client/src/demographics/types.ts b/spotlight-client/src/demographics/types.ts index 5ae310ac..26bd4585 100644 --- a/spotlight-client/src/demographics/types.ts +++ b/spotlight-client/src/demographics/types.ts @@ -55,17 +55,7 @@ export const AgeValueList = [ "60-69", "70<", ] as const; -// TODO(#479): delete these once views are updated -export const LegacyAgeValueList = [ - "<25", - "25-29", - "30-34", - "35-39", - "40<", -] as const; -export type AgeValue = - | typeof AgeValueList[number] - | typeof LegacyAgeValueList[number]; +export type AgeValue = typeof AgeValueList[number]; export type AgeIdentifier = TotalIdentifier | UnknownIdentifier | AgeValue; export const DemographicViewList = [ diff --git a/spotlight-client/src/demographics/utils.test.ts b/spotlight-client/src/demographics/utils.test.ts index 19dcbd05..657c0bb6 100644 --- a/spotlight-client/src/demographics/utils.test.ts +++ b/spotlight-client/src/demographics/utils.test.ts @@ -16,7 +16,7 @@ // ============================================================================= import { DemographicFields } from "../metricsApi"; -import { DemographicView, LegacyAgeValueList } from "./types"; +import { DemographicView } from "./types"; import { createDemographicCategories, dataIncludesBreakdowns, @@ -122,20 +122,6 @@ describe("createDemographicCategories", () => { { identifier: "OTHER", label: "Other" }, ]); }); - - test("customized age", () => { - const legacyCategories = createDemographicCategories({ - ageBucket: [...LegacyAgeValueList], - }); - - expect(legacyCategories.ageBucket).toEqual([ - { identifier: "<25", label: "<25" }, - { identifier: "25-29", label: "25-29" }, - { identifier: "30-34", label: "30-34" }, - { identifier: "35-39", label: "35-39" }, - { identifier: "40<", label: "40+" }, - ]); - }); }); test("dataIncludesBreakdowns", () => { diff --git a/spotlight-client/src/demographics/utils.ts b/spotlight-client/src/demographics/utils.ts index e61281a6..e23fc97f 100644 --- a/spotlight-client/src/demographics/utils.ts +++ b/spotlight-client/src/demographics/utils.ts @@ -20,7 +20,6 @@ import { DemographicCategoryFilter } from "../contentApi/types"; import { DemographicFields, isDemographicFieldKey } from "../metricsApi"; import { AgeValue, - AgeValueList, DemographicView, DemographicViewList, GenderValue, @@ -94,10 +93,6 @@ const ageBucketCategories: AgeCategory[] = [ { identifier: "50-59", label: "50-59" }, { identifier: "60-69", label: "60-69" }, { identifier: "70<", label: "70+" }, - // TODO(#479): eliminate legacy categories below this line - { identifier: "30-34", label: "30-34" }, - { identifier: "35-39", label: "35-39" }, - { identifier: "40<", label: "40+" }, ]; export type DemographicCategories = { @@ -109,8 +104,6 @@ export type DemographicCategories = { export function createDemographicCategories( demographicFilter?: DemographicCategoryFilter ): DemographicCategories { - // TODO(#479): eliminate override once legacy categories are deleted - const ageFilter = demographicFilter?.ageBucket || [...AgeValueList]; return { total: totalCategories, // only applying filters if the keys are actually present @@ -123,7 +116,8 @@ export function createDemographicCategories( demographicFilter?.gender?.includes(identifier) ?? true ), ageBucket: ageBucketCategories.filter( - ({ identifier }) => ageFilter.includes(identifier) ?? true + ({ identifier }) => + demographicFilter?.ageBucket?.includes(identifier) ?? true ), }; }