Code formatting
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
4d3b3fd231
commit
ae703f98aa
5 changed files with 61 additions and 33 deletions
|
@ -10,11 +10,7 @@ import re
|
|||
OUTPUT_FILE = sys.argv[1]
|
||||
YEAR = sys.argv[2]
|
||||
|
||||
COLOURS = {
|
||||
"Golang": "#00ADD8",
|
||||
"Python": "#3572A5",
|
||||
"Nim": "#ffc200"
|
||||
}
|
||||
COLOURS = {"Golang": "#00ADD8", "Python": "#3572A5", "Nim": "#ffc200"}
|
||||
|
||||
MAX_Y_VALUE = 1
|
||||
|
||||
|
@ -23,12 +19,18 @@ challenge_dir_regex = re.compile("""(?m)^(\d{2})-([a-zA-Z]+)$""")
|
|||
directories = []
|
||||
path = os.path.join("challenges", YEAR)
|
||||
for filename in os.listdir(path):
|
||||
if os.path.isdir(os.path.join(path, filename)) and challenge_dir_regex.match(filename):
|
||||
if os.path.isdir(os.path.join(path, filename)) and challenge_dir_regex.match(
|
||||
filename
|
||||
):
|
||||
directories.append(filename)
|
||||
|
||||
files = [os.path.join(x, "benchmark.json") for x in directories]
|
||||
|
||||
benchmark_data = {"Python": {}, "Golang": {}, "Nim": {}} # adding dicts here sets the order of points being plotted
|
||||
benchmark_data = {
|
||||
"Python": {},
|
||||
"Golang": {},
|
||||
"Nim": {},
|
||||
} # adding dicts here sets the order of points being plotted
|
||||
|
||||
for filename in files:
|
||||
fpath = os.path.join(path, filename)
|
||||
|
@ -54,7 +56,7 @@ for lang in benchmark_data:
|
|||
day = int(key.split(".", 1)[0])
|
||||
all_days.add(day)
|
||||
|
||||
figure = plt.figure(figsize=(25/2, 5))
|
||||
figure = plt.figure(figsize=(25 / 2, 5))
|
||||
axp1 = figure.add_subplot(1, 2, 1)
|
||||
axp2 = figure.add_subplot(1, 2, 2, sharey=axp1)
|
||||
|
||||
|
@ -87,24 +89,38 @@ for i, language in enumerate(benchmark_data):
|
|||
for i, day in enumerate(days):
|
||||
if i + 1 >= len(days):
|
||||
continue
|
||||
if days[i+1] == day+1:
|
||||
axp1.plot((day, days[i+1]), (part_one_times[i], part_one_times[i+1]), "-", color=colour)
|
||||
axp2.plot((day, days[i+1]), (part_two_times[i], part_two_times[i+1]), "-", color=colour)
|
||||
if days[i + 1] == day + 1:
|
||||
axp1.plot(
|
||||
(day, days[i + 1]),
|
||||
(part_one_times[i], part_one_times[i + 1]),
|
||||
"-",
|
||||
color=colour,
|
||||
)
|
||||
axp2.plot(
|
||||
(day, days[i + 1]),
|
||||
(part_two_times[i], part_two_times[i + 1]),
|
||||
"-",
|
||||
color=colour,
|
||||
)
|
||||
|
||||
figure.suptitle(f"Average {YEAR} challenge running time")
|
||||
axp1.set_title("Part one")
|
||||
axp2.set_title("Part two")
|
||||
|
||||
|
||||
def do_auxillary_parts(axis):
|
||||
plt.sca(axis)
|
||||
plt.xticks(list(all_days), [str(y) for y in all_days])
|
||||
plt.ylabel("Running time (log seconds)")
|
||||
plt.yscale("log")
|
||||
plt.xlabel("Day")
|
||||
plt.legend(handles=[patches.Patch(color=COLOURS[label], label=label) for label in COLOURS])
|
||||
plt.legend(
|
||||
handles=[patches.Patch(color=COLOURS[label], label=label) for label in COLOURS]
|
||||
)
|
||||
# plt.ylim([0, MAX_Y_VALUE])
|
||||
# plt.legend(legends)
|
||||
|
||||
|
||||
do_auxillary_parts(axp1)
|
||||
do_auxillary_parts(axp2)
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ from collections.abc import Sequence
|
|||
|
||||
|
||||
class BaseChallenge:
|
||||
|
||||
@staticmethod
|
||||
def one(instr: str) -> Any:
|
||||
raise NotImplementedError
|
||||
|
@ -21,12 +20,14 @@ class BaseChallenge:
|
|||
T = TypeVar("T")
|
||||
U = TypeVar("U")
|
||||
|
||||
|
||||
def foldl(p: Callable[[U, T], U], i: Iterable[T], start: U) -> U:
|
||||
res = start
|
||||
for item in i:
|
||||
res = p(res, item)
|
||||
return res
|
||||
|
||||
|
||||
def foldr(p: Callable[[U, T], U], i: Iterable[T], start: U) -> U:
|
||||
return foldl(p, reversed(i), start)
|
||||
|
||||
|
@ -48,7 +49,9 @@ class Vector:
|
|||
|
||||
@staticmethod
|
||||
def _is_vector_tuple(o: Any) -> bool:
|
||||
return type(o) == tuple and len(o) == 2 and type(o[0]) == int and type(o[1]) == int
|
||||
return (
|
||||
type(o) == tuple and len(o) == 2 and type(o[0]) == int and type(o[1]) == int
|
||||
)
|
||||
|
||||
def manhattan_distance(self, o: Vector) -> int:
|
||||
return abs(self.x - o.x) + abs(self.y - o.y)
|
||||
|
@ -84,6 +87,7 @@ class Vector:
|
|||
def __hash__(self):
|
||||
return hash((self.x, self.y))
|
||||
|
||||
|
||||
class Consumer:
|
||||
x: Sequence[T]
|
||||
i: int
|
||||
|
@ -94,11 +98,12 @@ class Consumer:
|
|||
|
||||
def take(self) -> T:
|
||||
self.i += 1
|
||||
return self.x[self.i-1]
|
||||
return self.x[self.i - 1]
|
||||
|
||||
def undo(self):
|
||||
self.i -= 1
|
||||
|
||||
|
||||
class RepeatingConsumer(Consumer):
|
||||
def take(self) -> T:
|
||||
val = super().take()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import os.path
|
||||
|
||||
class SaveManager():
|
||||
|
||||
class SaveManager:
|
||||
def __init__(self, d):
|
||||
self.dir = d
|
||||
self.current_n = 0
|
||||
|
@ -8,5 +9,3 @@ class SaveManager():
|
|||
def save(self, im):
|
||||
im.save(os.path.join(self.dir, f"frame_{str(self.current_n).zfill(4)}.png"))
|
||||
self.current_n += 1
|
||||
|
||||
|
|
@ -6,13 +6,20 @@ import json
|
|||
# TASKS_STR = input()
|
||||
# TASKS = json.loads(TASKS_STR)
|
||||
|
||||
|
||||
def send_result(task_id, ok, output, duration):
|
||||
print(json.dumps({
|
||||
"task_id": task_id,
|
||||
"ok": ok,
|
||||
"output": str(output) if output is not None else "",
|
||||
"duration": float(duration),
|
||||
}), flush=True)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"task_id": task_id,
|
||||
"ok": ok,
|
||||
"output": str(output) if output is not None else "",
|
||||
"duration": float(duration),
|
||||
}
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
|
||||
|
||||
while True:
|
||||
task = json.loads(input())
|
||||
|
@ -39,10 +46,11 @@ while True:
|
|||
except Exception as e:
|
||||
err = f"{type(e)}: {e}"
|
||||
import traceback
|
||||
|
||||
err = f"{type(e)}: {e}\n{''.join(traceback.format_tb(e.__traceback__))}"
|
||||
end_time = time.time()
|
||||
|
||||
running_time = end_time-start_time
|
||||
running_time = end_time - start_time
|
||||
|
||||
if err is not None:
|
||||
send_result(task_id, False, err, running_time)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from typing import *
|
||||
from aocpy import BaseChallenge
|
||||
|
||||
class Challenge(BaseChallenge):
|
||||
|
||||
class Challenge(BaseChallenge):
|
||||
@staticmethod
|
||||
def one(instr: str) -> int:
|
||||
raise NotImplementedError
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue