Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove support for legacy age categories #498

Merged
merged 1 commit into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions spotlight-client/src/contentModels/Metric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof downloadjs>;
Expand Down Expand Up @@ -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+" },
]);
});
21 changes: 1 addition & 20 deletions spotlight-client/src/contentModels/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ import {
DemographicCategories,
DemographicView,
getDemographicCategoriesForView,
LegacyAgeValueList,
} from "../demographics";
import {
RawMetricData,
DemographicFields,
LocalityFields,
SupervisionSuccessRateMonthlyRecord,
fetchAndTransformMetric,
isDemographicFields,
} from "../metricsApi";
import downloadData from "./downloadData";
import { MetricRecord, Hydratable } from "./types";
Expand Down Expand Up @@ -102,11 +100,7 @@ export default abstract class Metric<RecordFormat extends MetricRecord>
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;

Expand Down Expand Up @@ -154,7 +148,6 @@ export default abstract class Metric<RecordFormat extends MetricRecord>
this.dataTransformer = dataTransformer;

// initialize filters
this.demographicFilter = demographicFilter;
this.demographicCategories = createDemographicCategories(demographicFilter);
this.getDemographicCategories = this.getDemographicCategories.bind(this);
this.localityId = defaultLocalityId;
Expand All @@ -171,18 +164,6 @@ export default abstract class Metric<RecordFormat extends MetricRecord>
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;
}

Expand Down
188 changes: 0 additions & 188 deletions spotlight-client/src/contentModels/__fixtures__/metricData.ts

This file was deleted.

12 changes: 1 addition & 11 deletions spotlight-client/src/demographics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 1 addition & 15 deletions spotlight-client/src/demographics/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// =============================================================================

import { DemographicFields } from "../metricsApi";
import { DemographicView, LegacyAgeValueList } from "./types";
import { DemographicView } from "./types";
import {
createDemographicCategories,
dataIncludesBreakdowns,
Expand Down Expand Up @@ -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", () => {
Expand Down
10 changes: 2 additions & 8 deletions spotlight-client/src/demographics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { DemographicCategoryFilter } from "../contentApi/types";
import { DemographicFields, isDemographicFieldKey } from "../metricsApi";
import {
AgeValue,
AgeValueList,
DemographicView,
DemographicViewList,
GenderValue,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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
Expand All @@ -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
),
};
}
Expand Down