from build.chart_data_functions import get_confirmed_cases_by_county
from build.chart_data_functions import get_county_by_day
from build.constants import CONFIRMED_CASES_BY_COUNTIES_PATH
from build.constants import COUNTY_MAPPING
from build.constants import COUNTY_POPULATION
from build.constants import DATE_SETTINGS
from build.constants import TEST_RESULTS_PATH
from build.constants import TODAY_DMYHM
from build.constants import YESTERDAY_YMD
from build.utils import analyze_memory
from build.utils import analyze_time
from build.utils import logger
from build.utils import read_json_from_file
from build.utils import save_as_json
import pandas as pd


@analyze_time
@analyze_memory
def main():
    # Log status
    logger.info("Loading local data files")
    test_results = read_json_from_file(TEST_RESULTS_PATH)

    # Log status
    logger.info("Calculating main statistics")

    # Create date ranges for charts
    case_dates = pd.date_range(start=DATE_SETTINGS["firstCaseDate"], end=YESTERDAY_YMD)

    # Get data for each chart
    logger.info("Calculating data for charts")
    county_by_day = get_county_by_day(
        test_results, case_dates, COUNTY_MAPPING, COUNTY_POPULATION
    )
    confirmed_cases_by_county = get_confirmed_cases_by_county(
        test_results, COUNTY_MAPPING
    )

    del county_by_day["mapPlayback"]
    del county_by_day["mapPlayback10k"]

    # Create dictionary for final JSON
    logger.info("Compiling final JSON")
    final_json = {
        "updatedOn": TODAY_DMYHM,
        "dataConfirmedCasesByCounties": confirmed_cases_by_county,
        "countyByDay": county_by_day,
    }

    # Dump JSON output
    save_as_json(CONFIRMED_CASES_BY_COUNTIES_PATH, final_json)

    # Log finish time
    logger.info("Finished update process")


if __name__ == "__main__":
    main()

[((719, 758), 'build.utils.logger.info', 'logger.info', (['"""Loading local data files"""'], {}), "('Loading local data files')\n", (730, 758), False, 'from build.utils import logger\n'), ((778, 816), 'build.utils.read_json_from_file', 'read_json_from_file', (['TEST_RESULTS_PATH'], {}), '(TEST_RESULTS_PATH)\n', (797, 816), False, 'from build.utils import read_json_from_file\n'), ((839, 881), 'build.utils.logger.info', 'logger.info', (['"""Calculating main statistics"""'], {}), "('Calculating main statistics')\n", (850, 881), False, 'from build.utils import logger\n'), ((936, 1006), 'pandas.date_range', 'pd.date_range', ([], {'start': "DATE_SETTINGS['firstCaseDate']", 'end': 'YESTERDAY_YMD'}), "(start=DATE_SETTINGS['firstCaseDate'], end=YESTERDAY_YMD)\n", (949, 1006), True, 'import pandas as pd\n'), ((1042, 1084), 'build.utils.logger.info', 'logger.info', (['"""Calculating data for charts"""'], {}), "('Calculating data for charts')\n", (1053, 1084), False, 'from build.utils import logger\n'), ((1105, 1183), 'build.chart_data_functions.get_county_by_day', 'get_county_by_day', (['test_results', 'case_dates', 'COUNTY_MAPPING', 'COUNTY_POPULATION'], {}), '(test_results, case_dates, COUNTY_MAPPING, COUNTY_POPULATION)\n', (1122, 1183), False, 'from build.chart_data_functions import get_county_by_day\n'), ((1230, 1289), 'build.chart_data_functions.get_confirmed_cases_by_county', 'get_confirmed_cases_by_county', (['test_results', 'COUNTY_MAPPING'], {}), '(test_results, COUNTY_MAPPING)\n', (1259, 1289), False, 'from build.chart_data_functions import get_confirmed_cases_by_county\n'), ((1426, 1461), 'build.utils.logger.info', 'logger.info', (['"""Compiling final JSON"""'], {}), "('Compiling final JSON')\n", (1437, 1461), False, 'from build.utils import logger\n'), ((1654, 1712), 'build.utils.save_as_json', 'save_as_json', (['CONFIRMED_CASES_BY_COUNTIES_PATH', 'final_json'], {}), '(CONFIRMED_CASES_BY_COUNTIES_PATH, final_json)\n', (1666, 1712), False, 'from build.utils import save_as_json\n'), ((1740, 1778), 'build.utils.logger.info', 'logger.info', (['"""Finished update process"""'], {}), "('Finished update process')\n", (1751, 1778), False, 'from build.utils import logger\n')]