Skip to content

Commit a750f92

Browse files
committed
Merging of statistics must cope with execution time stats being unavailable
Closes #1380.
1 parent 05a3b8d commit a750f92

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

cms/grading/steps/stats.py

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

106+
def safe_sum(x, y):
107+
if x is None:
108+
return y
109+
elif y is None:
110+
return x
111+
else:
112+
return x + y
113+
114+
def safe_max(x, y):
115+
if x is None:
116+
return y
117+
elif y is None:
118+
return x
119+
else:
120+
return max(x, y)
121+
106122
ret = first_stats.copy()
107123
ret["execution_time"] += second_stats["execution_time"]
108124

109125
if concurrent:
110126
ret["execution_wall_clock_time"] = max(
111127
ret["execution_wall_clock_time"],
112128
second_stats["execution_wall_clock_time"])
113-
ret["execution_memory"] += second_stats["execution_memory"]
129+
ret["execution_memory"] = safe_sum(ret["execution_memory"],
130+
second_stats["execution_memory"])
114131
else:
115132
ret["execution_wall_clock_time"] += \
116133
second_stats["execution_wall_clock_time"]
117-
ret["execution_memory"] = max(ret["execution_memory"],
118-
second_stats["execution_memory"])
134+
ret["execution_memory"] = safe_max(ret["execution_memory"],
135+
second_stats["execution_memory"])
119136

120137
if first_stats["exit_status"] == Sandbox.EXIT_OK:
121138
ret["exit_status"] = second_stats["exit_status"]

0 commit comments

Comments
 (0)