Exemple #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
Exemple #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
Exemple #3
0
def _retrieve_benchmarks_mp() -> 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] = {}

        days = get_full_day_paths(year_path)
        results = []

        with ProcessPoolExecutor(max_workers=8) as executor:
            for day in days:
                result = executor.submit(_retrieve_benchmarks_for_day_mp, day,
                                         year)
                results.append(result)

        for result in results:
            benchmarks[year].update(result.result())

    return benchmarks
Exemple #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_year(path, expected):
    assert expected == clean_year(path)