From b0d8fbe9cb167d649a58a0463fc8be07de1e2044 Mon Sep 17 00:00:00 2001 From: Finn Lidbetter Date: Sun, 27 Oct 2024 13:36:48 -0400 Subject: [PATCH] Add lines of code reporting --- crifx/contest_objects/problem.py | 19 +++++++++++++++++++ crifx/report_writer.py | 31 ++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/crifx/contest_objects/problem.py b/crifx/contest_objects/problem.py index 5da6405..b812480 100644 --- a/crifx/contest_objects/problem.py +++ b/crifx/contest_objects/problem.py @@ -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) diff --git a/crifx/report_writer.py b/crifx/report_writer.py index 6e1aded..d5462c1 100644 --- a/crifx/report_writer.py +++ b/crifx/report_writer.py @@ -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.""" @@ -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: @@ -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 "", @@ -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}"), ] ) @@ -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 ), @@ -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), ] )