Skip to content

Commit e3be501

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

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
@@ -89,19 +89,36 @@ def merge_execution_stats(first_stats, second_stats, concurrent=True):
8989
if first_stats is None:
9090
return second_stats.copy()
9191

92+
def safe_sum(x, y):
93+
if x is None:
94+
return y
95+
elif y is None:
96+
return x
97+
else:
98+
return x + y
99+
100+
def safe_max(x, y):
101+
if x is None:
102+
return y
103+
elif y is None:
104+
return x
105+
else:
106+
return max(x, y)
107+
92108
ret = first_stats.copy()
93109
ret["execution_time"] += second_stats["execution_time"]
94110

95111
if concurrent:
96112
ret["execution_wall_clock_time"] = max(
97113
ret["execution_wall_clock_time"],
98114
second_stats["execution_wall_clock_time"])
99-
ret["execution_memory"] += second_stats["execution_memory"]
115+
ret["execution_memory"] = safe_sum(ret["execution_memory"],
116+
second_stats["execution_memory"])
100117
else:
101118
ret["execution_wall_clock_time"] += \
102119
second_stats["execution_wall_clock_time"]
103-
ret["execution_memory"] = max(ret["execution_memory"],
104-
second_stats["execution_memory"])
120+
ret["execution_memory"] = safe_max(ret["execution_memory"],
121+
second_stats["execution_memory"])
105122

106123
if first_stats["exit_status"] == Sandbox.EXIT_OK:
107124
ret["exit_status"] = second_stats["exit_status"]

0 commit comments

Comments
 (0)