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

Add constants/enums for field values #172

Open
Mr0grog opened this issue Jan 15, 2021 · 0 comments
Open

Add constants/enums for field values #172

Mr0grog opened this issue Jan 15, 2021 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Mr0grog
Copy link
Collaborator

Mr0grog commented Jan 15, 2021

We have a (semi) standard set of values that are available for each of:

  • Race/Ethnicity
  • Gender
  • Comorbidities/Underlying Conditions
  • Transmission Categories

(See the data model docs for more on this. Note that age does not have standardized values like this because the categories are so different across counties that we can’t meaningfully bucket them.)

Rather than having strings that could contain typos for these all over the codebase, we should really have a set of constants or (better yet) enums for them, e.g:

# This part should be in a centralized module somewhere.
from enum import Enum
class RaceEthnicity(Enum):
    african_american = "African_Amer"
    asian = "Asian"
    latinx = "Latinx_or_Hispanic"
    native_american = "Native_Amer"
    pacific_islander = "Pacific_Islander"
    white = "White"
    multiple = "Multiple_Race"
    other = "Other"
    unknown = "Unknown"

# Elsewhere in some scraper code...
# This example from Marin (https://github.com/sfbrigade/data-covid19-sfbayarea/blob/5fb99a51fa89ddc3ffacf65c3ae1c1fda19e75e9/covid19_sfbayarea/data/marin.py#L190-L206)

# Map the county's naming scheme to ours:
mapping = {
    'american indian/alaska native': RaceEthnicity.native_american,
    'asian': RaceEthnicity.asian,
    'black/african american': RaceEthnicity.african_american,
    'hispanic/latinx': RaceEthnicity.latinx,
    'multiracial': RaceEthnicity.multiple,
    'native hawaiian/pacific islander': RaceEthnicity.pacific_islander,
    'unknown': RaceEthnicity.unknown,
    'other': RaceEthnicity.other,
    'white': RaceEthnicity.white,
}
data = get_demographic_totals(api, 'Race')
return {mapping[row['grouping'].lower()]: int(row['cumulative'])
        for row in data}

This way, mypy can check that we haven’t made any typos and our values are consistent across the codebase.

@Mr0grog Mr0grog added good first issue Good for newcomers help wanted Extra attention is needed labels Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant