Skip to content

Commit 33a5df6

Browse files
authored
Merge branch 'main' into restricted-feedback
2 parents ace0d0d + e5a8718 commit 33a5df6

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

cms/grading/steps/stats.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,40 @@ def merge_execution_stats(
103103
if first_stats is None:
104104
return second_stats.copy()
105105

106+
Stat = typing.TypeVar('Stat', int, float)
107+
108+
def safe_sum(x: Stat | None, y: Stat | None) -> Stat | None:
109+
if x is None:
110+
return y
111+
elif y is None:
112+
return x
113+
else:
114+
return x + y
115+
116+
def safe_max(x: Stat | None, y: Stat | None) -> Stat | None:
117+
if x is None:
118+
return y
119+
elif y is None:
120+
return x
121+
else:
122+
return max(x, y)
123+
106124
ret = first_stats.copy()
107-
ret["execution_time"] += second_stats["execution_time"]
125+
ret["execution_time"] = safe_sum(ret["execution_time"],
126+
second_stats["execution_time"])
108127

109128
if concurrent:
110-
ret["execution_wall_clock_time"] = max(
129+
ret["execution_wall_clock_time"] = safe_max(
111130
ret["execution_wall_clock_time"],
112131
second_stats["execution_wall_clock_time"])
113-
ret["execution_memory"] += second_stats["execution_memory"]
132+
ret["execution_memory"] = safe_sum(ret["execution_memory"],
133+
second_stats["execution_memory"])
114134
else:
115-
ret["execution_wall_clock_time"] += \
116-
second_stats["execution_wall_clock_time"]
117-
ret["execution_memory"] = max(ret["execution_memory"],
118-
second_stats["execution_memory"])
135+
ret["execution_wall_clock_time"] = safe_sum(
136+
ret["execution_wall_clock_time"],
137+
second_stats["execution_wall_clock_time"])
138+
ret["execution_memory"] = safe_max(ret["execution_memory"],
139+
second_stats["execution_memory"])
119140

120141
if first_stats["exit_status"] == Sandbox.EXIT_OK:
121142
ret["exit_status"] = second_stats["exit_status"]

cms/log.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,16 @@ def process(self, msg: str, kwargs: dict):
393393

394394

395395
# Install a shell handler.
396-
shell_handler = StreamHandler(sys.stdout)
396+
shell_handler = StreamHandler(sys.stderr)
397397
shell_handler.setLevel(logging.INFO)
398-
shell_handler.setFormatter(CustomFormatter(has_color_support(sys.stdout)))
398+
shell_handler.setFormatter(CustomFormatter(has_color_support(sys.stderr)))
399399
root_logger.addHandler(shell_handler)
400400

401401

402402
def set_detailed_logs(detailed: bool):
403403
"""Set or unset the shell logs to detailed."""
404404
global shell_handler
405-
color = has_color_support(sys.stdout)
405+
color = has_color_support(sys.stderr)
406406
formatter = DetailedFormatter(color) \
407407
if detailed else CustomFormatter(color)
408408
shell_handler.setFormatter(formatter)

cmsranking/Logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ def format(self, record):
243243
root_logger.setLevel(logging.DEBUG)
244244

245245
# Define the stream handler to output on stderr.
246-
shell_handler = StreamHandler(sys.stdout)
246+
shell_handler = StreamHandler(sys.stderr)
247247
shell_handler.setLevel(logging.INFO)
248-
shell_handler.setFormatter(CustomFormatter(has_color_support(sys.stdout)))
248+
shell_handler.setFormatter(CustomFormatter(has_color_support(sys.stderr)))
249249
root_logger.addHandler(shell_handler)
250250

251251

0 commit comments

Comments
 (0)