Skip to content

Commit

Permalink
no more demographic nofilter
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Jan 28, 2021
1 parent eb24e87 commit 8af4e1d
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ test("fills in missing data", async () => {
const metric = await getMetric();

DemographicViewList.forEach((demographicView) => {
if (demographicView === "nofilter") return;

runInAction(() => {
metric.demographicView = demographicView;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ export default class HistoricalPopulationBreakdownMetric extends Metric<

// isolate each data series and impute any missing records
DemographicViewList.forEach((demographicView) => {
if (demographicView === "nofilter") return;

const recordsForDemographicView = transformedData.filter(
recordIsTotalByDimension(demographicView)
);
Expand Down Expand Up @@ -181,7 +179,7 @@ export default class HistoricalPopulationBreakdownMetric extends Metric<

get dataSeries(): DataSeries<HistoricalPopulationBreakdownRecord>[] | null {
const { records, demographicView } = this;
if (!records || demographicView === "nofilter") return null;
if (!records) return null;

const categories = getDemographicCategories(demographicView);

Expand Down
11 changes: 6 additions & 5 deletions spotlight-client/src/contentModels/createMetricMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { assertNever } from "assert-never";
import { MetricTypeIdList, TenantContent, TenantId } from "../contentApi/types";
import {
NOFILTER_KEY,
parolePopulationCurrent,
parolePopulationHistorical,
paroleProgramParticipationCurrent,
Expand Down Expand Up @@ -50,7 +51,7 @@ import SentenceTypeByLocationMetric from "./SentenceTypeByLocationMetric";
import SupervisionSuccessRateDemographicsMetric from "./SupervisionSuccessRateDemographicsMetric";
import SupervisionSuccessRateMonthlyMetric from "./SupervisionSuccessRateMonthlyMetric";
import { ERROR_MESSAGES } from "../constants";
import { NOFILTER_KEY, TOTAL_KEY } from "../demographics";
import { TOTAL_KEY } from "../demographics";

type MetricMappingFactoryOptions = {
localityLabelMapping: TenantContent["localities"];
Expand Down Expand Up @@ -92,7 +93,7 @@ export default function createMetricMapping({
new PopulationBreakdownByLocationMetric({
...metadata,
tenantId,
defaultDemographicView: NOFILTER_KEY,
defaultDemographicView: "total",
defaultLocalityId: TOTAL_KEY,
localityLabels: localityLabelMapping.Sentencing,
dataTransformer: sentencePopulationCurrent,
Expand Down Expand Up @@ -126,7 +127,7 @@ export default function createMetricMapping({
new PopulationBreakdownByLocationMetric({
...metadata,
tenantId,
defaultDemographicView: NOFILTER_KEY,
defaultDemographicView: "total",
defaultLocalityId: TOTAL_KEY,
localityLabels: localityLabelMapping.Prison,
dataTransformer: prisonPopulationCurrent,
Expand All @@ -144,7 +145,7 @@ export default function createMetricMapping({
new PopulationBreakdownByLocationMetric({
...metadata,
tenantId,
defaultDemographicView: NOFILTER_KEY,
defaultDemographicView: "total",
defaultLocalityId: TOTAL_KEY,
localityLabels: localityLabelMapping.Probation,
dataTransformer: probationPopulationCurrent,
Expand All @@ -162,7 +163,7 @@ export default function createMetricMapping({
new PopulationBreakdownByLocationMetric({
...metadata,
tenantId,
defaultDemographicView: NOFILTER_KEY,
defaultDemographicView: "total",
defaultLocalityId: TOTAL_KEY,
localityLabels: localityLabelMapping.Parole,
dataTransformer: parolePopulationCurrent,
Expand Down
4 changes: 0 additions & 4 deletions spotlight-client/src/demographics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
export type TotalIdentifier = "ALL";
export const TOTAL_KEY: TotalIdentifier = "ALL";

type NoFilterIdentifier = "nofilter";
export const NOFILTER_KEY: NoFilterIdentifier = "nofilter";

export type RaceIdentifier =
| TotalIdentifier
| "AMERICAN_INDIAN_ALASKAN_NATIVE"
Expand All @@ -44,7 +41,6 @@ export const DemographicViewList = [
"raceOrEthnicity",
"gender",
"ageBucket",
"nofilter",
] as const;
export type DemographicView = typeof DemographicViewList[number];
export function isDemographicView(x: string): x is DemographicView {
Expand Down
4 changes: 0 additions & 4 deletions spotlight-client/src/demographics/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ describe("recordIsTotalByDimension", () => {
expect(testData.filter(recordIsTotalByDimension(view))).toEqual(expected);
};

test("returns all records", () => {
verifyFilter("nofilter", testData);
});

test("returns only totals", () => {
verifyFilter("total", testData.slice(0, 1));
});
Expand Down
6 changes: 1 addition & 5 deletions spotlight-client/src/demographics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@ import {
DemographicView,
DemographicViewList,
GenderIdentifier,
NOFILTER_KEY,
RaceIdentifier,
TOTAL_KEY,
} from "./types";

/**
* Returns a filter predicate for the specified demographic view
* that will exclude totals and breakdowns for all other views.
* Respects a special bypass value (see `NOFILTER_KEY`)
*/
export function recordIsTotalByDimension(
demographicView: DemographicView
): (record: DemographicFields) => boolean {
if (demographicView === NOFILTER_KEY) return () => true;

const keysToCheck = [...DemographicViewList].filter(isDemographicFieldKey);

if (demographicView !== "total") {
Expand Down Expand Up @@ -92,7 +88,7 @@ const ageBucketCategories: AgeCategory[] = [
];

export function getDemographicCategories(
view: Exclude<DemographicView, "nofilter">
view: DemographicView
): (TotalCategory | RaceOrEthnicityCategory | GenderCategory | AgeCategory)[] {
switch (view) {
case "total":
Expand Down
3 changes: 3 additions & 0 deletions spotlight-client/src/metricsApi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ export type RateFields = {
rateNumerator: number;
rate: number;
};

type NoFilterIdentifier = "nofilter";
export const NOFILTER_KEY: NoFilterIdentifier = "nofilter";
3 changes: 1 addition & 2 deletions spotlight-client/src/metricsApi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import { ValuesType } from "utility-types";
import {
AgeIdentifier,
GenderIdentifier,
NOFILTER_KEY,
RaceIdentifier,
} from "../demographics/types";
import { RawMetricData } from "./fetchMetrics";
import { DemographicFields, LocalityFields } from "./types";
import { DemographicFields, LocalityFields, NOFILTER_KEY } from "./types";

export function extractDemographicFields(
record: ValuesType<RawMetricData>
Expand Down

0 comments on commit 8af4e1d

Please sign in to comment.