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

Iss 228 add std clean dbt stages to census taskflow #231

Merged
merged 2 commits into from
Dec 29, 2024
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
17 changes: 11 additions & 6 deletions airflow/dags/cc_utils/census/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ def api_call_geographies(self):


class CensusAPIDataset(Protocol):
def api_call(self) -> str:
...
def api_call(self) -> str: ...

def make_api_call(self) -> pd.DataFrame:
...
def make_api_call(self) -> pd.DataFrame: ...


class CensusVariableGroupAPICall(CensusAPIDataset):
Expand Down Expand Up @@ -127,7 +125,10 @@ def make_api_call(self) -> pd.DataFrame:
resp_json = resp.json()
return pd.DataFrame(resp_json[1:], columns=resp_json[0])
else:
raise Exception(f"The API call produced an invalid response ({resp.status_code})")
raise Exception(
f"The API call produced an invalid response ({resp.status_code}), "
f"message: {resp.text}"
)


class CensusDatasetVariablesAPICaller(CensusAPIDataset):
Expand Down Expand Up @@ -160,14 +161,18 @@ def make_api_call(self) -> pd.DataFrame:
resp_json = resp.json()
return pd.DataFrame(resp_json[1:], columns=resp_json[0])
else:
raise Exception(f"The API call produced an invalid response ({resp.status_code})")
raise Exception(
f"The API call produced an invalid response ({resp.status_code}), "
f"message: {resp.text}."
)


@dataclass
class CensusVariableGroupDataset:
dataset_name: str
api_call_obj: CensusVariableGroupAPICall
schedule: Optional[str] = None
vintage: Optional[str] = None


class CensusAPIDatasetSource:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import datetime as dt
import logging

from airflow.decorators import dag

from tasks.census_tasks import update_census_table

from sources.census_api_datasets import CC_HOUSING_OCCUPANCY_BY_TRACT_ACS5 as CENSUS_DATASET

task_logger = logging.getLogger("airflow.task")


@dag(
schedule=CENSUS_DATASET.schedule,
start_date=dt.datetime(2022, 11, 1),
catchup=False,
tags=["cook_county", "census", "acs5"],
)
def update_cc_housing_occupancy_by_tract_acs5():
update_census_table(
census_dataset=CENSUS_DATASET,
datasource_name="fluent_dwh_source",
conn_id="dwh_db_conn",
task_logger=task_logger,
)


update_cc_housing_occupancy_by_tract_acs5()
52 changes: 52 additions & 0 deletions airflow/dags/sources/census_api_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,58 @@
schedule="40 5 20 3,9 *",
)

CC_HOUSING_OCCUPANCY_BY_TRACT_ACS5 = CensusVariableGroupDataset(
dataset_name="cc_housing_occupancy_by_tract_acs5",
api_call_obj=CensusDatasetVariablesAPICaller(
dataset_base_url="http://api.census.gov/data/2023/acs/acs5",
geographies=COOK_COUNTY_CENSUS_TRACTS,
variable_names=[
"GEO_ID",
"NAME",
"B25001_001E", "B25001_001EA", "B25001_001M", "B25001_001MA",
"B25002_001E", "B25002_001EA", "B25002_001M", "B25002_001MA",
"B25002_002E", "B25002_002EA", "B25002_002M", "B25002_002MA",
"B25002_003E", "B25002_003EA", "B25002_003M", "B25002_003MA",
"B25004_001E", "B25004_001EA", "B25004_001M", "B25004_001MA",
"B25004_002E", "B25004_002EA", "B25004_002M", "B25004_002MA",
"B25004_003E", "B25004_003EA", "B25004_003M", "B25004_003MA",
"B25004_004E", "B25004_004EA", "B25004_004M", "B25004_004MA",
"B25004_005E", "B25004_005EA", "B25004_005M", "B25004_005MA",
"B25004_006E", "B25004_006EA", "B25004_006M", "B25004_006MA",
"B25004_007E", "B25004_007EA", "B25004_007M", "B25004_007MA",
"B25004_008E", "B25004_008EA", "B25004_008M", "B25004_008MA",
],
),
schedule="20 5 15 2,6,10 *",
vintage="2023",
)

CC_HOUSING_TENURE_SINGLE_RACE_BY_TRACT_ACS5 = CensusVariableGroupDataset(
dataset_name="cc_housing_tenure_single_race_by_tract_acs5",
api_call_obj=CensusDatasetVariablesAPICaller(
dataset_base_url="http://api.census.gov/data/2023/acs/acs5",
geographies=COOK_COUNTY_CENSUS_TRACTS,
variable_names=[
"GEO_ID",
"NAME",
"B25003_001E", "B25003_001EA", "B25003_001M", "B25003_001MA",
"B25003_002E", "B25003_002EA", "B25003_002M", "B25003_002MA",
"B25003_003E", "B25003_003EA", "B25003_003M", "B25003_003MA",
"B25003A_001E", "B25003A_001EA", "B25003A_001M", "B25003A_001MA",
"B25003A_002E", "B25003A_002EA", "B25003A_002M", "B25003A_002MA",
"B25003A_003E", "B25003A_003EA", "B25003A_003M", "B25003A_003MA",
"B25003B_001E", "B25003B_001EA", "B25003B_001M", "B25003B_001MA",
"B25003B_002E", "B25003B_002EA", "B25003B_002M", "B25003B_002MA",
"B25003B_003E", "B25003B_003EA", "B25003B_003M", "B25003B_003MA",
"B25003D_001E", "B25003D_001EA", "B25003D_001M", "B25003D_001MA",
"B25003D_002E", "B25003D_002EA", "B25003D_002M", "B25003D_002MA",
"B25003D_003E", "B25003D_003EA", "B25003D_003M", "B25003D_003MA",
],
),
schedule="25 5 15 2,6,10 *",
vintage="2023",
)

CC_HH_INCOME_IN_LAST_12MO_BY_TRACT = CensusVariableGroupDataset(
dataset_name="cc_hh_income_in_last_12mo_by_tract",
api_call_obj=CensusVariableGroupAPICall(
Expand Down
Loading
Loading