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

Frontend: Updates providers to "all" fallback and new dataset methods #3831

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
92 changes: 19 additions & 73 deletions frontend/src/data/providers/AcsConditionProvider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { getDataManager } from '../../utils/globals'
import type { TimeView, Breakdowns } from '../query/Breakdowns'
import { type MetricQuery, MetricQueryResponse } from '../query/MetricQuery'
import VariableProvider from './VariableProvider'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import type { DataTypeId, MetricId } from '../config/MetricConfigTypes'
import type { DatasetId } from '../config/DatasetMetadata'
import type { Breakdowns } from '../query/Breakdowns'
import {
type MetricQuery,
MetricQueryResponse,
resolveDatasetId,
} from '../query/MetricQuery'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import VariableProvider from './VariableProvider'

export const ACS_CONDITION_DATATYPES: DataTypeId[] = [
'health_insurance',
Expand All @@ -31,87 +34,30 @@ class AcsConditionProvider extends VariableProvider {
super('acs_condition_provider', ACS_CONDITION_METRICS)
}

getDatasetId(
breakdowns: Breakdowns,
_dataTypeId?: DataTypeId,
timeView?: TimeView,
): DatasetId | undefined {
if (timeView === 'historical') {
if (breakdowns.geography === 'national') {
if (breakdowns.hasOnlyRace())
return 'acs_condition-by_race_national_historical'
if (breakdowns.hasOnlyAge())
return 'acs_condition-by_age_national_historical'
if (breakdowns.hasOnlySex())
return 'acs_condition-by_sex_national_historical'
}
if (breakdowns.geography === 'state') {
if (breakdowns.hasOnlyRace())
return 'acs_condition-by_race_state_historical'
if (breakdowns.hasOnlyAge())
return 'acs_condition-by_age_state_historical'
if (breakdowns.hasOnlySex())
return 'acs_condition-by_sex_state_historical'
}

if (breakdowns.geography === 'county') {
if (breakdowns.hasOnlyRace())
return 'acs_condition-by_race_county_historical'
if (breakdowns.hasOnlyAge())
return 'acs_condition-by_age_county_historical'
if (breakdowns.hasOnlySex())
return 'acs_condition-by_sex_county_historical'
}
}

if (timeView === 'current') {
if (breakdowns.geography === 'national') {
if (breakdowns.hasOnlyRace())
return 'acs_condition-by_race_national_current'
if (breakdowns.hasOnlyAge())
return 'acs_condition-by_age_national_current'
if (breakdowns.hasOnlySex())
return 'acs_condition-by_sex_national_current'
}
if (breakdowns.geography === 'state') {
if (breakdowns.hasOnlyRace())
return 'acs_condition-by_race_state_current'
if (breakdowns.hasOnlyAge()) return 'acs_condition-by_age_state_current'
if (breakdowns.hasOnlySex()) return 'acs_condition-by_sex_state_current'
}

if (breakdowns.geography === 'county') {
if (breakdowns.hasOnlyRace())
return 'acs_condition-by_race_county_current'
if (breakdowns.hasOnlyAge())
return 'acs_condition-by_age_county_current'
if (breakdowns.hasOnlySex())
return 'acs_condition-by_sex_county_current'
}
}
}

async getDataInternal(
metricQuery: MetricQuery,
): Promise<MetricQueryResponse> {
const breakdowns = metricQuery.breakdowns
const timeView = metricQuery.timeView
const datasetId = this.getDatasetId(breakdowns, undefined, timeView)
const { breakdowns, datasetId, isFallbackId } = resolveDatasetId(
'acs_condition',
'by_',
metricQuery,
)
if (!datasetId) {
return new MetricQueryResponse([], [])
}
const specificDatasetId = appendFipsIfNeeded(datasetId, breakdowns)
const acsDataset = await getDataManager().loadDataset(specificDatasetId)

let df = acsDataset.toDataFrame()

// If requested, filter geography by state or county level
// We apply the geo filter right away to reduce subsequent calculation times
df = this.filterByGeo(df, breakdowns)
df = this.renameGeoColumns(df, breakdowns)

df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)
if (isFallbackId) {
df = this.castAllsAsRequestedDemographicBreakdown(df, breakdowns)
} else {
df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)
}

return new MetricQueryResponse(df.toArray(), [datasetId])
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/data/providers/AcsPopulationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { IDataFrame } from 'data-forge'
import { getDataManager } from '../../utils/globals'
import type { DatasetId } from '../config/DatasetMetadata'
import type { Breakdowns } from '../query/Breakdowns'
import { type MetricQuery, MetricQueryResponse } from '../query/MetricQuery'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import VariableProvider from './VariableProvider'
import type { DatasetId } from '../config/DatasetMetadata'

export function GetAcsDatasetId(breakdowns: Breakdowns): DatasetId | undefined {
if (breakdowns.geography === 'national') {
Expand Down Expand Up @@ -44,7 +44,6 @@ class AcsPopulationProvider extends VariableProvider {

df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)

const datasetId = this.getDatasetId(breakdowns)
let consumedDatasetIds
if (datasetId) consumedDatasetIds = [datasetId]
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/data/providers/AhrProvider.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { getDataManager } from '../../utils/globals'
import { getParentDropdownFromDataTypeId } from '../../utils/MadLibs'
import type { DatasetId } from '../config/DatasetMetadata'
import type { DataTypeId, MetricId } from '../config/MetricConfigTypes'
import type { DropdownVarId } from '../config/DropDownIds'
import { BEHAVIORAL_HEALTH_CATEGORY_DROPDOWNIDS } from '../config/MetricConfigBehavioralHealth'
import type { DataTypeId, MetricId } from '../config/MetricConfigTypes'
import type {
DemographicBreakdownKey,
Breakdowns,
DemographicBreakdownKey,
TimeView,
} from '../query/Breakdowns'
import { type MetricQuery, MetricQueryResponse } from '../query/MetricQuery'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import VariableProvider from './VariableProvider'
import type { DropdownVarId } from '../config/DropDownIds'

const CHR_DATATYPE_IDS_ONLY_ALLS: DataTypeId[] = [
'diabetes',
Expand Down Expand Up @@ -257,8 +257,12 @@
})
}

df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)
if (isFallbackId) {

Check failure on line 260 in frontend/src/data/providers/AhrProvider.ts

View workflow job for this annotation

GitHub Actions / Runs frontend unit tests

src/data/providers/AhrProvider.test.ts > AhrProvider > State and Race Breakdown

ReferenceError: isFallbackId is not defined ❯ AhrProvider.getDataInternal src/data/providers/AhrProvider.ts:260:5 ❯ AhrProvider.getData src/data/providers/VariableProvider.ts:33:18 ❯ ensureCorrectDatasetsDownloaded src/data/providers/AhrProvider.test.ts:31:32 ❯ src/data/providers/AhrProvider.test.ts:61:5

Check failure on line 260 in frontend/src/data/providers/AhrProvider.ts

View workflow job for this annotation

GitHub Actions / Runs frontend unit tests

src/data/providers/AhrProvider.test.ts > AhrProvider > National and Race Breakdown

ReferenceError: isFallbackId is not defined ❯ AhrProvider.getDataInternal src/data/providers/AhrProvider.ts:260:5 ❯ AhrProvider.getData src/data/providers/VariableProvider.ts:33:18 ❯ ensureCorrectDatasetsDownloaded src/data/providers/AhrProvider.test.ts:31:32 ❯ src/data/providers/AhrProvider.test.ts:69:5

Check failure on line 260 in frontend/src/data/providers/AhrProvider.ts

View workflow job for this annotation

GitHub Actions / Runs frontend unit tests

src/data/providers/AhrProvider.test.ts > AhrProvider > State and Age Breakdown

ReferenceError: isFallbackId is not defined ❯ AhrProvider.getDataInternal src/data/providers/AhrProvider.ts:260:5 ❯ AhrProvider.getData src/data/providers/VariableProvider.ts:33:18 ❯ ensureCorrectDatasetsDownloaded src/data/providers/AhrProvider.test.ts:31:32 ❯ src/data/providers/AhrProvider.test.ts:77:5

Check failure on line 260 in frontend/src/data/providers/AhrProvider.ts

View workflow job for this annotation

GitHub Actions / Runs frontend unit tests

src/data/providers/AhrProvider.test.ts > AhrProvider > National and Age Breakdown

ReferenceError: isFallbackId is not defined ❯ AhrProvider.getDataInternal src/data/providers/AhrProvider.ts:260:5 ❯ AhrProvider.getData src/data/providers/VariableProvider.ts:33:18 ❯ ensureCorrectDatasetsDownloaded src/data/providers/AhrProvider.test.ts:31:32 ❯ src/data/providers/AhrProvider.test.ts:85:5

Check failure on line 260 in frontend/src/data/providers/AhrProvider.ts

View workflow job for this annotation

GitHub Actions / Runs frontend unit tests

src/data/providers/AhrProvider.test.ts > AhrProvider > State and Sex Breakdown

ReferenceError: isFallbackId is not defined ❯ AhrProvider.getDataInternal src/data/providers/AhrProvider.ts:260:5 ❯ AhrProvider.getData src/data/providers/VariableProvider.ts:33:18 ❯ ensureCorrectDatasetsDownloaded src/data/providers/AhrProvider.test.ts:31:32 ❯ src/data/providers/AhrProvider.test.ts:93:5

Check failure on line 260 in frontend/src/data/providers/AhrProvider.ts

View workflow job for this annotation

GitHub Actions / Runs frontend unit tests

src/data/providers/AhrProvider.test.ts > AhrProvider > National and Sex Breakdown

ReferenceError: isFallbackId is not defined ❯ AhrProvider.getDataInternal src/data/providers/AhrProvider.ts:260:5 ❯ AhrProvider.getData src/data/providers/VariableProvider.ts:33:18 ❯ ensureCorrectDatasetsDownloaded src/data/providers/AhrProvider.test.ts:31:32 ❯ src/data/providers/AhrProvider.test.ts:101:5

Check failure on line 260 in frontend/src/data/providers/AhrProvider.ts

View workflow job for this annotation

GitHub Actions / Runs frontend unit tests

src/data/providers/AhrProvider.test.ts > AhrProvider > County and Race Breakdown

ReferenceError: isFallbackId is not defined ❯ AhrProvider.getDataInternal src/data/providers/AhrProvider.ts:260:5 ❯ AhrProvider.getData src/data/providers/VariableProvider.ts:33:18 ❯ ensureCorrectDatasetsDownloaded src/data/providers/AhrProvider.test.ts:31:32 ❯ src/data/providers/AhrProvider.test.ts:109:5

Check failure on line 260 in frontend/src/data/providers/AhrProvider.ts

View workflow job for this annotation

GitHub Actions / Runs frontend unit tests

src/data/providers/AhrProvider.test.ts > AhrProvider > County and Sex Breakdown (should just get the ALLs)

ReferenceError: isFallbackId is not defined ❯ AhrProvider.getDataInternal src/data/providers/AhrProvider.ts:260:5 ❯ AhrProvider.getData src/data/providers/VariableProvider.ts:33:18 ❯ ensureCorrectDatasetsDownloaded src/data/providers/AhrProvider.test.ts:31:32 ❯ src/data/providers/AhrProvider.test.ts:117:5
df = this.castAllsAsRequestedDemographicBreakdown(df, breakdowns)
} else {
df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)
}

return new MetricQueryResponse(df.toArray(), consumedDatasetIds)
}
Expand Down
66 changes: 28 additions & 38 deletions frontend/src/data/providers/CawpProvider.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { getDataManager } from '../../utils/globals'
import type { MetricId, DataTypeId } from '../config/MetricConfigTypes'
import type { DataTypeId, MetricId } from '../config/MetricConfigTypes'

import type { TimeView, Breakdowns } from '../query/Breakdowns'
import { type MetricQuery, MetricQueryResponse } from '../query/MetricQuery'
import { GetAcsDatasetId } from './AcsPopulationProvider'
import VariableProvider from './VariableProvider'
import type { Breakdowns } from '../query/Breakdowns'
import {
UNKNOWN_RACE,
type MetricQuery,
MetricQueryResponse,
resolveDatasetId,
} from '../query/MetricQuery'
import {
type RaceAndEthnicityGroup,
HISP_W,
HISPANIC,
MULTI,
UNREPRESENTED,
type RaceAndEthnicityGroup,
OTHER_W,
MULTI_W,
OTHER_STANDARD,
OTHER_W,
UNKNOWN_RACE,
UNKNOWN_W,
HISP_W,
UNREPRESENTED,
} from '../utils/Constants'
import type { DatasetId } from '../config/DatasetMetadata'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import { GetAcsDatasetId } from './AcsPopulationProvider'
import VariableProvider from './VariableProvider'

export const CAWP_CONGRESS_COUNTS: MetricId[] = [
'women_this_race_us_congress_count',
Expand Down Expand Up @@ -76,41 +79,21 @@ class CawpProvider extends VariableProvider {
super('cawp_provider', CAWP_METRICS)
}

getDatasetId(
breakdowns: Breakdowns,
dataTypeId?: DataTypeId,
timeView?: TimeView,
): DatasetId | undefined {
if (timeView === 'current') {
if (breakdowns.geography === 'national' && breakdowns.hasOnlyRace())
return 'cawp_time_data-race_and_ethnicity_national_current'
if (breakdowns.geography === 'state' && breakdowns.hasOnlyRace())
return 'cawp_time_data-race_and_ethnicity_state_current'
}
if (timeView === 'historical') {
if (breakdowns.geography === 'national' && breakdowns.hasOnlyRace())
return 'cawp_time_data-race_and_ethnicity_national_historical'
if (breakdowns.geography === 'state' && breakdowns.hasOnlyRace())
return 'cawp_time_data-race_and_ethnicity_state_historical'
}
}

async getDataInternal(
metricQuery: MetricQuery,
): Promise<MetricQueryResponse> {
const breakdowns = metricQuery.breakdowns
const timeView = metricQuery.timeView
const datasetId = this.getDatasetId(breakdowns, undefined, timeView)
const { breakdowns, datasetId, isFallbackId, timeView } = resolveDatasetId(
'cawp_time_data',
'',
metricQuery,
)
if (!datasetId) {
return new MetricQueryResponse([], [])
}
const specificDatasetId = appendFipsIfNeeded(datasetId, breakdowns)
const cawp = await getDataManager().loadDataset(specificDatasetId)
let df = cawp.toDataFrame()

df = this.filterByGeo(df, breakdowns)
df = this.renameGeoColumns(df, breakdowns)

const consumedDatasetIds = [datasetId]

// no population numbers used for rates, only comparison pop. and pct_rel_inequity
Expand Down Expand Up @@ -143,8 +126,15 @@ class CawpProvider extends VariableProvider {
consumedDatasetIds.push('the_unitedstates_project')
}

df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)
df = this.filterByGeo(df, breakdowns)
df = this.renameGeoColumns(df, breakdowns)

if (isFallbackId) {
df = this.castAllsAsRequestedDemographicBreakdown(df, breakdowns)
} else {
df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)
}

return new MetricQueryResponse(df.toArray(), consumedDatasetIds)
}
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/data/providers/CdcCovidProvider.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { IDataFrame } from 'data-forge'
import { getDataManager } from '../../utils/globals'
import type { Breakdowns, TimeView } from '../query/Breakdowns'
import { type MetricQuery, MetricQueryResponse } from '../query/MetricQuery'
import { GetAcsDatasetId } from './AcsPopulationProvider'
import VariableProvider from './VariableProvider'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import type { DatasetId } from '../config/DatasetMetadata'
import type { DataTypeId } from '../config/MetricConfigTypes'
import {
AGE_ADJUST_COVID_DEATHS_US_SETTING,
AGE_ADJUST_COVID_HOSP_US_SETTING,
} from '../../utils/internalRoutes'
import type { IDataFrame } from 'data-forge'
import type { DatasetId } from '../config/DatasetMetadata'
import type { DataTypeId } from '../config/MetricConfigTypes'
import type { Breakdowns, TimeView } from '../query/Breakdowns'
import { type MetricQuery, MetricQueryResponse } from '../query/MetricQuery'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import { GetAcsDatasetId } from './AcsPopulationProvider'
import VariableProvider from './VariableProvider'

// when alternate data types are available, provide a link to the national level, by race report for that data type
export const dataTypeLinkMap: Partial<Record<DataTypeId, string>> = {
Expand Down
38 changes: 28 additions & 10 deletions frontend/src/data/providers/IncarcerationProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { getDataManager } from '../../utils/globals'
import type { DataTypeId, MetricId } from '../config/MetricConfigTypes'
import type { Breakdowns, TimeView } from '../query/Breakdowns'
import { type MetricQuery, MetricQueryResponse } from '../query/MetricQuery'
import type { MetricId, DataTypeId } from '../config/MetricConfigTypes'
import {
type MetricQuery,
MetricQueryResponse,
resolveDatasetId,
} from '../query/MetricQuery'

import VariableProvider from './VariableProvider'
import { GetAcsDatasetId } from './AcsPopulationProvider'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import type { DatasetId } from '../config/DatasetMetadata'
import { appendFipsIfNeeded } from '../utils/datasetutils'
import { GetAcsDatasetId } from './AcsPopulationProvider'
import VariableProvider from './VariableProvider'

// states with combined prison and jail systems
export const COMBINED_INCARCERATION_STATES_LIST = [
Expand Down Expand Up @@ -88,9 +92,19 @@ class IncarcerationProvider extends VariableProvider {
async getDataInternal(
metricQuery: MetricQuery,
): Promise<MetricQueryResponse> {
const breakdowns = metricQuery.breakdowns
const timeView = metricQuery.timeView
const datasetId = this.getDatasetId(breakdowns, undefined, timeView)
const isVera = metricQuery.breakdowns.geography === 'county'

const datasetName = isVera
? 'vera_incarceration_county'
: 'bjs_incarceration_data'
const prefix = isVera ? 'by_' : ''

const { breakdowns, datasetId, isFallbackId, timeView } = resolveDatasetId(
datasetName,
prefix,
metricQuery,
)

if (!datasetId) {
return new MetricQueryResponse([], [])
}
Expand Down Expand Up @@ -132,8 +146,12 @@ class IncarcerationProvider extends VariableProvider {
}
}

df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)
if (isFallbackId) {
df = this.castAllsAsRequestedDemographicBreakdown(df, breakdowns)
} else {
df = this.applyDemographicBreakdownFilters(df, breakdowns)
df = this.removeUnrequestedColumns(df, metricQuery)
}

return new MetricQueryResponse(df.toArray(), consumedDatasetIds)
}
Expand Down
Loading
Loading