Esempio n. 1
0
def _retrieve_benchmarks() -> Benchmarks:
    config.RUNNING_BENCHMARKS = True
    benchmarks: Benchmarks = {}

    for year_path in get_full_year_paths():
        year_dir = year_dir_from_path(year_path)
        year = clean_year(year_dir)
        benchmarks[year] = {}

        for day_file in get_full_day_paths(year_path):
            day = clean_day(day_file)
            benchmarks[year][day] = {}

            module_name = get_full_module_from_day_file(day_file)
            module = __import__(module_name, fromlist=["object"])

            try:
                _run_day(module, year, day, benchmarks)
            except FileNotFoundError:
                console.print(
                    f"[blue]{year} day {day:02}: [red]input file not found")

    config.RUNNING_BENCHMARKS = False
    console.log("finished running benchmarks")
    return benchmarks
Esempio n. 2
0
def run_all() -> None:
    """
    Gathers all year_*.day_* files and executes the
    part_one and part_two functions in those files.

    If input file is not found, or a function is not found, it will be printed to console
    """
    config.RUNNING_ALL = True

    for year_path in get_full_year_paths():
        year_dir = year_dir_from_path(year_path)
        year = clean_year(year_dir)
        console.print(year)

        for day_file in get_full_day_paths(year_path):
            day = clean_day(day_file)
            module_name = get_full_module_from_day_file(day_file)
            module = __import__(module_name, fromlist=["object"])

            try:
                _run_day(module, year, day)
            except FileNotFoundError:
                console.print(
                    f"[blue]{year} day {day:02}: [red]input file not found")

    config.RUNNING_ALL = False
Esempio n. 3
0
def _retrieve_benchmarks_for_day_mp(day_file: str,
                                    year: int) -> Dict[int, Dict[str, float]]:
    config.RUNNING_BENCHMARKS = True
    day = clean_day(day_file)
    benchmarks: Dict[int, Dict[str, float]] = {day: {}}

    module_name = get_full_module_from_day_file(day_file)
    module = __import__(module_name, fromlist=["object"])

    try:
        _run_day_mp(module, year, day, benchmarks)
    except FileNotFoundError:
        console.print(f"[blue]{year} day {day:02}: [red]input file not found")

    return benchmarks
Esempio n. 4
0
def _find_completed_days() -> YearDayType:
    """
    Loops through all the year directories, all the day files
    and checks if the file contains functions 'part_one' and 'part_two'

    Returns the results as a Dict
    """
    items: YearDayType = {}

    for year_path in get_full_year_paths():
        year = clean_year(year_path)
        items[year] = {}

        for day_file in get_full_day_paths(year_path):
            day = clean_day(day_file)
            items[year][day] = {}
            funcs = get_functions_from_day_file(day_file)

            items[year][day]["part_one"] = "part_one" in funcs
            items[year][day]["part_two"] = "part_two" in funcs

    return items
def test_clean_day(path, expected):
    assert expected == clean_day(path)