Skip to content

Commit

Permalink
add --overview
Browse files Browse the repository at this point in the history
  • Loading branch information
mzuenni committed Feb 22, 2024
1 parent 9d9bf16 commit e56b9c2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
grep -Ev '^(h|jobs|time|verbose)$' | sed "s/^/'/;s/$/',/" | tr '\n' ' ' | sed 's/^/args_list = [/;s/, $/]\n/'
"""
# fmt: off
args_list = ['1', 'add_unlisted', 'all', 'answer', 'api', 'author', 'check_deterministic', 'clean', 'clean_generated', 'cleanup_generated', 'colors', 'contest', 'contest_id', 'contestname', 'cp', 'cpp_flags', 'default_solution', 'directory', 'error', 'force', 'force_build', 'language', 'no_validators', 'input', 'interaction', 'interactive', 'invalid', 'kattis', 'memory', 'move_to', 'no_bar', 'no_generate', 'no_solutions', 'no_timelimit', 'order', 'order_from_ccs', 'password', 'post_freeze', 'problem', 'problemname', 'remove', 'samples', 'skel', 'skip', 'no_solution', 'no_testcase_sanity_checks', 'no_visualizer', 'submissions', 'table', 'testcases', 'timelimit', 'timeout', 'token', 'username', 'validation', 'watch', 'web']
args_list = ['1', 'add_unlisted', 'all', 'answer', 'api', 'author', 'check_deterministic', 'clean', 'clean_generated', 'cleanup_generated', 'colors', 'contest', 'contest_id', 'contestname', 'cp', 'cpp_flags', 'default_solution', 'directory', 'error', 'force', 'force_build', 'language', 'no_validators', 'input', 'interaction', 'interactive', 'invalid', 'kattis', 'memory', 'move_to', 'no_bar', 'no_generate', 'no_solutions', 'no_timelimit', 'order', 'order_from_ccs', 'overview', 'password', 'post_freeze', 'problem', 'problemname', 'remove', 'samples', 'skel', 'skip', 'no_solution', 'no_testcase_sanity_checks', 'no_visualizer', 'submissions', 'table', 'testcases', 'timelimit', 'timeout', 'token', 'username', 'validation', 'watch', 'web']
# fmt: on


Expand Down
3 changes: 3 additions & 0 deletions bin/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ def build_parser():
runparser.add_argument(
'--table', action='store_true', help='Print a submissions x testcases table for analysis.'
)
runparser.add_argument(
'--overview', '-o', action='store_true', help='Print a live overview for the judgings.'
)
runparser.add_argument(
'--timeout',
type=int,
Expand Down
44 changes: 40 additions & 4 deletions bin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,12 @@ def finalize(self, *, print_done=True, message=None):

class VerdictTable:
def __init__(
self, submissions, testcases, width=shutil.get_terminal_size().columns, max_name_width=50
self,
submissions,
testcases,
width=shutil.get_terminal_size().columns,
height=shutil.get_terminal_size().lines,
max_name_width=50,
):
self.submissions = [
submission.name for verdict in submissions for submission in submissions[verdict]
Expand All @@ -476,6 +481,38 @@ def __init__(
self.width = width if width >= self.name_width + 2 + 10 else -1
self.last_printed = []

self.print_without_force = (
not config.args.no_bar and config.args.overview and self.width >= 0
)
if self.print_without_force:
# generate example lines for one submission
name = 'x' * self.name_width
lines = [f'{Style.DIM}{Fore.CYAN}{name}{Fore.WHITE}:']

verdicts = []
for t, testcase in enumerate(self.testcases):
if t % 10 == 0:
verdicts.append([0, ''])
verdicts[-1][0] += 1
verdicts[-1][1] += '-'

printed = self.name_width + 1
for length, tmp in verdicts:
if printed + 1 + length > self.width:
lines.append(f'{str():{self.name_width+1}}', end='', file=sys.stderr)
printed = self.name_width + 1
lines[-1] += f' {tmp}'
printed += length + 1

# dont print table if it fills to much of the screen
self.print_without_force = len(lines) * len(submissions) + 5 < height
if not self.print_without_force or True:
print(
f'{Fore.YELLOW}WARNING: Overview too large for terminal, skipping live updates{Style.RESET_ALL}',
file=sys.stderr,
)
print(*lines, '[...]', Style.RESET_ALL, sep='\n', end='\n', file=sys.stderr)

def next_submission(self):
self.results.append(dict())
self.current_testcases = set()
Expand All @@ -488,7 +525,7 @@ def finish_testcase(self, testcase, verdict):
self.current_testcases.discard(testcase)

def clear(self, *, force=True, clear=True):
if force or not config.args.no_bar:
if force or self.print_without_force:
if self.last_printed:
actual_width = shutil.get_terminal_size().columns
lines = 0
Expand All @@ -515,9 +552,8 @@ def _get_verdict(self, s, testcase):
return Style.DIM + Fore.BLUE + '?' + Style.RESET_ALL
return Style.DIM + Fore.WHITE + '-' + Style.RESET_ALL

# TODO only print this if a flag is given! (config.args.???)
def print(self, *, force=True, new_lines=2):
if force or not config.args.no_bar:
if force or self.print_without_force:
self.clear(force=True, clear=False)
print('\n' * new_lines, end='', file=sys.stderr)
self.last_printed.extend([1] * new_lines)
Expand Down

0 comments on commit e56b9c2

Please sign in to comment.