From 9d9bf16cd365e53dd3b5e5fe40b4abcf65903f74 Mon Sep 17 00:00:00 2001 From: mzuenni Date: Wed, 21 Feb 2024 21:02:11 +0100 Subject: [PATCH] format --- bin/problem.py | 17 +++++++++++++---- bin/util.py | 36 +++++++++++++++++++++++------------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/bin/problem.py b/bin/problem.py index 12e6625b..08d5c31b 100644 --- a/bin/problem.py +++ b/bin/problem.py @@ -516,7 +516,9 @@ def run_submissions(problem): for submission in submissions[verdict]: verdict_table.next_submission() submission_ok, printed_newline = submission.run_all_testcases( - max_submission_len, verdict_table=verdict_table, needs_leading_newline=needs_leading_newline + max_submission_len, + verdict_table=verdict_table, + needs_leading_newline=needs_leading_newline, ) needs_leading_newline = not printed_newline ok &= submission_ok @@ -596,12 +598,17 @@ def single_verdict(row, testcase): for testcase in testcases: # Skip all AC testcases - if all(map(lambda row: testcase.name in row and row[testcase.name] == 'ACCEPTED', verdict_table)): + if all( + map( + lambda row: testcase.name in row and row[testcase.name] == 'ACCEPTED', + verdict_table, + ) + ): continue name = testcase.name if len(name) > name_col_width: - name = '...' + name[-name_col_width+3:] + name = '...' + name[-name_col_width + 3 :] padding = ' ' * (name_col_width - len(name)) print(f'{Fore.CYAN}{name}{Style.RESET_ALL}:{padding}', end=' ', file=sys.stderr) @@ -612,7 +619,9 @@ def single_verdict(row, testcase): color = Fore.RED resultant = make_verdict(testcase) print(resultant, end=' ', file=sys.stderr) - print(f'{color}{scores[testcase.name]:0.3f}{Style.RESET_ALL} ', end='', file=sys.stderr) + print( + f'{color}{scores[testcase.name]:0.3f}{Style.RESET_ALL} ', end='', file=sys.stderr + ) if resultant in resultant_id: print(str.format('(Type {})', resultant_id[resultant]), end='', file=sys.stderr) print(end='\n', file=sys.stderr) diff --git a/bin/util.py b/bin/util.py index fbbc90dc..f4a4ffd8 100644 --- a/bin/util.py +++ b/bin/util.py @@ -418,9 +418,11 @@ def finalize(self, *, print_done=True, message=None): return self.global_logged -class TableProgressBar(ProgressBar): +class TableProgressBar(ProgressBar): def __init__(self, table, prefix, max_len, count, *, items, needs_leading_newline): - super().__init__(prefix, max_len, count, items=items, needs_leading_newline=needs_leading_newline) + super().__init__( + prefix, max_len, count, items=items, needs_leading_newline=needs_leading_newline + ) self.table = table # at the begin of any IO the progress bar locks so we can clear the table at this point @@ -459,12 +461,18 @@ 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 = [submission.name for verdict in submissions for submission in submissions[verdict]] + def __init__( + self, submissions, testcases, width=shutil.get_terminal_size().columns, max_name_width=50 + ): + self.submissions = [ + submission.name for verdict in submissions for submission in submissions[verdict] + ] self.testcases = [testcase.name for testcase in testcases] self.results = [] self.current_testcases = set() - self.name_width = min(max_name_width, max([len(submission) for submission in self.submissions])) + self.name_width = min( + max_name_width, max([len(submission) for submission in self.submissions]) + ) self.width = width if width >= self.name_width + 2 + 10 else -1 self.last_printed = [] @@ -486,12 +494,12 @@ def clear(self, *, force=True, clear=True): lines = 0 for printed in self.last_printed: lines += (printed + actual_width - 1) // actual_width - print(f'\033[{lines}A\r', end = '', file=sys.stderr) + print(f'\033[{lines}A\r', end='', file=sys.stderr) if clear: for printed in self.last_printed: print(' ' * printed, file=sys.stderr) - print(f'\033[{lines}A\r', end = '', file=sys.stderr) + print(f'\033[{lines}A\r', end='', file=sys.stderr) self.last_printed = [] @@ -507,7 +515,7 @@ 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.???) + # 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: self.clear(force=True, clear=False) @@ -517,7 +525,7 @@ def print(self, *, force=True, new_lines=2): # pad/truncate submission names to not break table layout name = submission if len(name) > self.name_width: - name = '...' + name[-self.name_width+3:] + name = '...' + name[-self.name_width + 3 :] padding = ' ' * (self.name_width - len(name)) print(f'{Fore.CYAN}{name}{Style.RESET_ALL}:{padding}', end='', file=sys.stderr) @@ -539,14 +547,16 @@ def print(self, *, force=True, new_lines=2): print(f' {tmp}', end='', file=sys.stderr) printed += length + 1 - self.last_printed.append(printed) print(end='\n', file=sys.stderr) print(end='', flush=True, file=sys.stderr) - def ProgressBar(self, prefix, max_len=None, count=None, *, items=None, needs_leading_newline=False): - return TableProgressBar(self, prefix, max_len, count, items=items, needs_leading_newline=needs_leading_newline) - + def ProgressBar( + self, prefix, max_len=None, count=None, *, items=None, needs_leading_newline=False + ): + return TableProgressBar( + self, prefix, max_len, count, items=items, needs_leading_newline=needs_leading_newline + ) # Given a command line argument, return the first match: