Skip to content

Commit f112ed7

Browse files
committed
improved UI
1 parent dd8fa17 commit f112ed7

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

scripts/timings.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,23 @@ def __init__(self, db: sqlite3.Connection):
127127
self.user_inputs[crc].add(user)
128128

129129
self.solutions = defaultdict(lambda: defaultdict(dict))
130-
for year, day, crc, _prog, lang, elapsed, status in db.execute(
130+
for year, day, crc, prog, lang, elapsed, status in db.execute(
131131
"select year,day,crc,prog,lang,elapsed,status from solutions"
132132
):
133-
if status == "ok":
133+
# if answers are ok and not an alternative solution
134+
if status == "ok" and "_" not in prog:
134135
elapsed /= 1_000_000_000
135136

136137
# manage multiple solutions in different dayXX_xxx directories
137138
day_sols = self.solutions[year, day][lang]
138139
other_elapsed = day_sols.get(crc, float("inf"))
139140
day_sols[crc] = min(elapsed, other_elapsed)
140141

142+
def get_languages(self) -> set[str]:
143+
"""Extract and return a set of all unique programming languages from the solutions."""
144+
return set(lang for sol in self.solutions.values() for lang in sol)
145+
146+
@lru_cache(maxsize=None)
141147
def get_stats(self, user: str, lang: str, tablefmt: str) -> Stats:
142148
"""
143149
Compute and return execution timing statistics for a given user and language.
@@ -281,23 +287,22 @@ def main():
281287

282288
languages = (
283289
"Rust",
284-
# "Python",
290+
"Python",
285291
"Py3.10",
286292
"Py3.11",
287293
"Py3.12",
288294
"Py3.13",
289-
# "Py3.13t",
295+
"Py3.13t",
290296
"Py3.14",
291-
# "Py3.14t",
292-
"Python",
293-
"C",
294-
"C++",
297+
"Py3.14t",
295298
"Go",
296299
)
297-
current_language = 0
298300

299-
done = False
301+
available_languages = timings.get_languages()
302+
languages = list(filter(lambda lang: lang.lower() in available_languages, languages))
300303

304+
current_language = 0
305+
done = False
301306
while not done:
302307
print(end="\033[H\033[2J")
303308

@@ -307,7 +312,8 @@ def main():
307312
timings.print_stats(users[current_user], languages[current_language].casefold())
308313

309314
print()
310-
print("← → : switch user ↓ ↑ : switch language")
315+
print("\033[7m ← → : switch user ↓ ↑ : switch language \033[0m", end="\033[?25l")
316+
sys.stdout.flush()
311317

312318
with curtsies.Input(keynames="curses") as input_generator:
313319
for e in input_generator:
@@ -333,6 +339,9 @@ def main():
333339
except KeyboardInterrupt:
334340
pass
335341

342+
finally:
343+
print("\033[?25h")
344+
336345
db.close()
337346

338347

0 commit comments

Comments
 (0)