Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
mzuenni committed Feb 21, 2024
1 parent f5fa132 commit 9d9bf16
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
17 changes: 13 additions & 4 deletions bin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
36 changes: 23 additions & 13 deletions bin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []

Expand All @@ -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 = []

Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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:
Expand Down

0 comments on commit 9d9bf16

Please sign in to comment.