From 2225ae6b409a734c6f0c23ea5561e4090ec9c9b3 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Thu, 28 Oct 2021 20:40:04 +0200 Subject: [PATCH] Refactoring --- src/update_results_table.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/update_results_table.py b/src/update_results_table.py index a9927ac..fec145f 100644 --- a/src/update_results_table.py +++ b/src/update_results_table.py @@ -24,27 +24,28 @@ def write_md(results): with open("../dummy.md", "w") as f: f.write(results) +def _file_stem(f): + return f[-5:] + +def get_problems(path=None, ext=None): + os.chdir(Path(path)) + return sorted([script.as_posix() for script in Path(".").rglob(f"*[0-9].{ext}")], key=_file_stem) + def execute(): """ Execute script and return output """ - def _file_stem(f): - return f[-5:] - - # os.chdir(Path("Python/")) - os.chdir(Path("Julia/")) - # scripts = sorted([script.as_posix() for script in Path(".").rglob("*[0-9].py")], key=_file_stem) - scripts = sorted([script.as_posix() for script in Path(".").rglob("*[0-9].jl")], key=_file_stem) - # print(scripts) + # scripts = get_problems(path="Python", ext="py") + scripts = get_problems(path="Julia", ext="jl") + # print(scripts[:5]) python_timings, python_results = [], [] julia_problem_numbers, julia_timings, julia_results = [], [], [] for script in scripts[:5]: # _res = run(["python3", f"{script}"], capture_output=True, text=True).stdout.split("\n") + # python_timings.append(_res[0]) + # python_results.append(_res[2]) _res = run(["julia", f"{script}"], capture_output=True, text=True).stdout.split("\n") - # print(_res) - # python_timings.append(_res[0]) - # python_results.append(_res[2]) julia_problem_numbers.append(_res[0]) julia_timings.append(_res[1].split("(")[0]) julia_results.append(_res[3]) @@ -52,9 +53,9 @@ def execute(): writer = MarkdownTableWriter( table_name="Project Euler Solutions", # headers=["Problem #", "Result", "Execution time (Python)"], + # value_matrix=[[f"{int(t[25:28]):03d}", int(r[22:]), t[29:]] for t,r in zip(python_timings, python_results)], headers=["Problem #", "Result", "Execution time (Julia)"], - # value_matrix=[[f"{int(t[26:28]):003d}", int(r[23:]), t[29:]] for t,r in zip(python_timings, python_results)], - value_matrix=[[f"{int(p[-2:-1]):03d}", int(r[23:]), t] for p,t,r in zip(julia_problem_numbers, julia_timings, julia_results)], + value_matrix=[[f"{int(p[-5:-1]):03d}", int(r[23:]), t] for p,t,r in zip(julia_problem_numbers, julia_timings, julia_results)], column_styles=[ Style(align="center"), Style(align="right", thousand_separator="_"),