Skip to content

Commit

Permalink
Add lines of code reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnLidbetter committed Oct 27, 2024
1 parent 2898ba9 commit b0d8fbe
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
19 changes: 19 additions & 0 deletions crifx/contest_objects/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ def independent_ac_count(self) -> int:
accepted_authors.append(submission.author)
return len(accepted_authors)

def ac_lines_of_code_min(self):
"""Get the minimum Lines of Code among AC submissions to this problem."""
ac_min = None
for submission in self.ac_submissions:
if ac_min is None or submission.lines_of_code < ac_min:
ac_min = submission.lines_of_code
return ac_min

def ac_lines_of_code_median(self):
"""Get the median Lines of Code among AC submissions to this problem."""
ac_loc_vals = []
for submission in self.ac_submissions:
ac_loc_vals.append(submission.lines_of_code)
ac_loc_vals.sort()
middle = len(ac_loc_vals) // 2
if len(ac_loc_vals) % 2 == 0:
return (ac_loc_vals[middle - 1] + ac_loc_vals[middle]) // 2
return ac_loc_vals[middle]

def ac_languages(self) -> defaultdict[ProgrammingLanguage, int]:
"""Get the number of AC submissions in each language."""
language_counts: defaultdict[ProgrammingLanguage, int] = defaultdict(int)
Expand Down
31 changes: 26 additions & 5 deletions crifx/report_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
]


def truncate(word, characters_max=10):
"""Get a truncated string representation."""
if len(word) > characters_max:
return word[: characters_max - 2] + "..."
return word


class LstListing(Environment):
"""LstListing environment."""

Expand Down Expand Up @@ -127,7 +134,7 @@ def _write_summary_table(self):
group_config.language_group for group_config in language_group_configs
]
requirements = self.crifx_config.review_requirements
num_columns = 7 + len(language_group_configs)
num_columns = 9 + len(language_group_configs)
column_spec = "|l|" + "c|" * (num_columns - 1)
with self.doc.create(Section("Submissions summary", numbering=False)):
with self.doc.create(Tabular(column_spec)) as table:
Expand All @@ -138,12 +145,14 @@ def _write_summary_table(self):
# Independent, Groups, language_groups, Sum
MultiColumn(
3 + len(language_group_configs),
align="c",
align="c|",
data=NoEscape(r"{\tiny Solutions}"),
),
# WA, TLE
MultiColumn(2, align="c|", data=NoEscape(r"{\tiny Non-solutions}")),
# AC LOC.
MultiColumn(
2, align="|c|", data=NoEscape(r"{\tiny Non-solutions}")
2, align="c|", data=NoEscape(r"{\tiny AC Lines of Code}")
),
# Test cases
"",
Expand All @@ -157,13 +166,19 @@ def _write_summary_table(self):
]
for language_group_config in language_group_configs:
header_row.append(
NoEscape(r"{\tiny " + language_group_config.identifier + r"}")
NoEscape(
r"{\tiny "
+ truncate(language_group_config.identifier, 10)
+ r"}"
)
)
header_row.extend(
[
NoEscape(r"{\tiny Sum}"),
NoEscape(r"{\tiny WA}"),
NoEscape(r"{\tiny TLE}"),
NoEscape(r"{\tiny Min.}"),
NoEscape(r"{\tiny Med.}"),
NoEscape(r"{\tiny Test Files}"),
]
)
Expand All @@ -174,7 +189,11 @@ def _write_summary_table(self):
table.add_hline()
for problem in self.problem_set.problems:
row = [
Command("hyperref", (problem.name,), (f"sec:{problem.name}",)),
Command(
"hyperref",
(truncate(problem.name, 16),),
(f"sec:{problem.name}",),
),
self._coloured_cell(
problem.independent_ac_count(), requirements.independent_ac
),
Expand All @@ -199,6 +218,8 @@ def _write_summary_table(self):
len(problem.ac_submissions),
len(problem.wa_submissions),
len(problem.tle_submissions),
str(problem.ac_lines_of_code_min()),
str(problem.ac_lines_of_code_median()),
len(problem.test_cases),
]
)
Expand Down

0 comments on commit b0d8fbe

Please sign in to comment.