mirror of
https://github.com/DOI-DO/j40-cejst-2.git
synced 2025-02-23 10:04:18 -08:00
* Add pytest to tox run in CI/CD * Try fixing tox dependencies for pytest * update poetry to get ci/cd passing * Run poetry export with --dev flag to include dev dependencies such as pytest * WIP updating test fixtures to include PDF * Remove dev dependencies from reqs and add pytest to envlist to make build faster * passing score_post tests * Add pytest tox (#729) * Fix failing pytest * Fixes failing tox tests and updates requirements.txt to include dev deps * pickle protocol 4 Co-authored-by: Shelby Switzer <shelby.switzer@cms.hhs.gov> Co-authored-by: Jorge Escobar <jorge.e.escobar@omb.eop.gov> Co-authored-by: Billy Daly <williamdaly422@gmail.com> Co-authored-by: Jorge Escobar <83969469+esfoobar-usds@users.noreply.github.com>
71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from data_pipeline.config import settings
|
|
from data_pipeline.utils import unzip_file_from_url, remove_all_from_dir
|
|
|
|
|
|
class ExtractTransformLoad:
|
|
"""
|
|
A class used to instantiate an ETL object to retrieve and process data from
|
|
datasets.
|
|
|
|
Attributes:
|
|
DATA_PATH (pathlib.Path): Local path where all data will be stored
|
|
TMP_PATH (pathlib.Path): Local path where temporary data will be stored
|
|
GEOID_FIELD_NAME (str): The common column name for a Census Block Group identifier
|
|
GEOID_TRACT_FIELD_NAME (str): The common column name for a Census Tract identifier
|
|
"""
|
|
|
|
DATA_PATH: Path = settings.APP_ROOT / "data"
|
|
TMP_PATH: Path = DATA_PATH / "tmp"
|
|
FILES_PATH: Path = settings.APP_ROOT / "files"
|
|
GEOID_FIELD_NAME: str = "GEOID10"
|
|
GEOID_TRACT_FIELD_NAME: str = "GEOID10_TRACT"
|
|
# TODO: investigate. Census says there are only 217,740 CBGs in the US.
|
|
EXPECTED_MAX_CENSUS_BLOCK_GROUPS: int = 220405
|
|
|
|
def get_yaml_config(self) -> None:
|
|
"""Reads the YAML configuration file for the dataset and stores
|
|
the properies in the instance (upcoming feature)"""
|
|
|
|
pass
|
|
|
|
def check_ttl(self) -> None:
|
|
"""Checks if the ETL process can be run based on a the TLL value on the
|
|
YAML config (upcoming feature)"""
|
|
|
|
pass
|
|
|
|
def extract(
|
|
self,
|
|
source_url: str = None,
|
|
extract_path: Path = None,
|
|
verify: Optional[bool] = True,
|
|
) -> None:
|
|
"""Extract the data from
|
|
a remote source. By default it provides code to get the file from a source url,
|
|
unzips it and stores it on an extract_path."""
|
|
|
|
# this can be accessed via super().extract()
|
|
if source_url and extract_path:
|
|
unzip_file_from_url(
|
|
source_url, self.TMP_PATH, extract_path, verify=verify
|
|
)
|
|
|
|
def transform(self) -> None:
|
|
"""Transform the data extracted into a format that can be consumed by the
|
|
score generator"""
|
|
|
|
raise NotImplementedError
|
|
|
|
def load(self) -> None:
|
|
"""Saves the transformed data in the specified local data folder or remote AWS S3
|
|
bucket"""
|
|
|
|
raise NotImplementedError
|
|
|
|
def cleanup(self) -> None:
|
|
"""Clears out any files stored in the TMP folder"""
|
|
|
|
remove_all_from_dir(self.TMP_PATH)
|