2021-06-28 16:16:14 -04:00
|
|
|
import click
|
|
|
|
|
2021-08-05 15:35:54 -04:00
|
|
|
from .config import settings
|
|
|
|
from .etl.runner import etl_runner, score_generate, score_geo
|
|
|
|
from .etl.sources.census.etl_utils import reset_data_directories as census_reset
|
|
|
|
from .tile.generate import generate_tiles
|
|
|
|
from .utils import (
|
2021-07-12 15:50:44 -04:00
|
|
|
data_folder_cleanup,
|
2021-08-05 15:35:54 -04:00
|
|
|
get_module_logger,
|
2021-07-12 15:50:44 -04:00
|
|
|
score_folder_cleanup,
|
|
|
|
temp_folder_cleanup,
|
|
|
|
)
|
2021-06-28 16:16:14 -04:00
|
|
|
|
|
|
|
logger = get_module_logger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
def cli():
|
2021-07-12 15:50:44 -04:00
|
|
|
"""Defines a click group for the commands below"""
|
|
|
|
|
2021-06-28 16:16:14 -04:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-08-05 15:35:54 -04:00
|
|
|
@cli.command(help="Clean up all census data folders")
|
|
|
|
def census_cleanup():
|
|
|
|
"""CLI command to clean up the census data folder"""
|
|
|
|
|
|
|
|
data_path = settings.APP_ROOT / "data"
|
|
|
|
|
|
|
|
# census directories
|
|
|
|
logger.info("Initializing all census data")
|
|
|
|
census_reset(data_path)
|
|
|
|
|
|
|
|
logger.info("Cleaned up all census data files")
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command(help="Clean up all data folders")
|
2021-07-12 15:50:44 -04:00
|
|
|
def data_cleanup():
|
|
|
|
"""CLI command to clean up the all the data folders"""
|
2021-06-28 16:16:14 -04:00
|
|
|
|
2021-07-12 15:50:44 -04:00
|
|
|
data_folder_cleanup()
|
|
|
|
score_folder_cleanup()
|
|
|
|
temp_folder_cleanup()
|
2021-06-28 16:16:14 -04:00
|
|
|
|
2021-07-12 15:50:44 -04:00
|
|
|
logger.info("Cleaned up all data folders")
|
2021-06-28 16:16:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command(
|
|
|
|
help="Census data download",
|
|
|
|
)
|
|
|
|
def census_data_download():
|
2021-07-12 15:50:44 -04:00
|
|
|
"""CLI command to download all census shape files from the Census FTP and extract the geojson
|
|
|
|
to generate national and by state Census Block Group CSVs"""
|
|
|
|
|
2021-06-28 16:16:14 -04:00
|
|
|
data_path = settings.APP_ROOT / "data"
|
2021-08-05 12:55:21 -04:00
|
|
|
|
|
|
|
logger.info("Initializing all census data")
|
|
|
|
census_reset(data_path)
|
|
|
|
|
|
|
|
logger.info("Downloading census data")
|
2021-08-06 11:01:51 -04:00
|
|
|
etl_runner("census")
|
2021-06-28 16:16:14 -04:00
|
|
|
|
|
|
|
logger.info("Completed downloading census data")
|
2021-07-12 15:50:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command(
|
|
|
|
help="Run all ETL processes or a specific one",
|
|
|
|
)
|
|
|
|
@click.option("-d", "--dataset", required=False, type=str)
|
|
|
|
def etl_run(dataset: str):
|
|
|
|
"""Run a specific or all ETL processes
|
|
|
|
|
|
|
|
Args:
|
|
|
|
dataset (str): Name of the ETL module to be run (optional)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
|
|
|
|
etl_runner(dataset)
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command(
|
|
|
|
help="Generate Score",
|
|
|
|
)
|
|
|
|
def score_run():
|
|
|
|
"""CLI command to generate the score"""
|
2021-08-03 18:23:57 -04:00
|
|
|
|
2021-07-12 15:50:44 -04:00
|
|
|
score_generate()
|
2021-06-28 16:16:14 -04:00
|
|
|
|
|
|
|
|
2021-08-05 12:55:21 -04:00
|
|
|
@cli.command(
|
|
|
|
help="Run ETL + Score Generation",
|
|
|
|
)
|
|
|
|
def score_full_run():
|
|
|
|
"""CLI command to run ETL and generate the score in one command"""
|
|
|
|
|
|
|
|
data_folder_cleanup()
|
|
|
|
score_folder_cleanup()
|
|
|
|
temp_folder_cleanup()
|
|
|
|
etl_runner()
|
|
|
|
score_generate()
|
|
|
|
|
|
|
|
|
2021-08-05 15:35:54 -04:00
|
|
|
@cli.command(help="Generate Geojson files with scores baked in")
|
2021-07-28 16:07:28 -04:00
|
|
|
def geo_score():
|
|
|
|
"""CLI command to generate the score"""
|
2021-08-03 18:23:57 -04:00
|
|
|
|
2021-07-28 16:07:28 -04:00
|
|
|
score_geo()
|
|
|
|
|
|
|
|
|
2021-08-03 18:23:57 -04:00
|
|
|
@cli.command(
|
|
|
|
help="Generate map tiles",
|
|
|
|
)
|
|
|
|
def generate_map_tiles():
|
|
|
|
"""CLI command to generate the map tiles"""
|
|
|
|
|
|
|
|
data_path = settings.APP_ROOT / "data"
|
|
|
|
generate_tiles(data_path)
|
|
|
|
|
|
|
|
|
2021-06-28 16:16:14 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
cli()
|