Spaces:
Sleeping
Sleeping
Commit ·
78b7e6b
1
Parent(s): 51fdbe8
Update grading logic to strict (0,1) ratio fallback
Browse files- server/grader.py +13 -19
server/grader.py
CHANGED
|
@@ -1,24 +1,18 @@
|
|
| 1 |
from .models import ExecutionResult, TaskInfo
|
| 2 |
|
| 3 |
def calculate_reward(exec_result: ExecutionResult, task_info: TaskInfo) -> float:
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
0.3 * compile_score + 0.4 * test_pass_ratio + 0.3 * efficiency_score
|
| 7 |
-
"""
|
| 8 |
-
compile_score = 1.0 if exec_result.compile_success else 0.0
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
# Efficiency is only tracked if tests completely pass to prevent 1-line failure from being "efficient"
|
| 16 |
-
if exec_result.test_total > 0 and exec_result.test_passed == exec_result.test_total:
|
| 17 |
-
if exec_result.execution_time_seconds <= task_info.optimal_time_seconds:
|
| 18 |
-
efficiency_score = 1.0
|
| 19 |
-
else:
|
| 20 |
-
# Proportional efficiency dropoff
|
| 21 |
-
efficiency_score = task_info.optimal_time_seconds / max(exec_result.execution_time_seconds, 0.001)
|
| 22 |
-
|
| 23 |
-
reward = (0.3 * compile_score) + (0.4 * test_pass_ratio) + (0.3 * efficiency_score)
|
| 24 |
-
return max(0.0, min(1.0, reward))
|
|
|
|
| 1 |
from .models import ExecutionResult, TaskInfo
|
| 2 |
|
| 3 |
def calculate_reward(exec_result: ExecutionResult, task_info: TaskInfo) -> float:
|
| 4 |
+
passed_tests = exec_result.test_passed
|
| 5 |
+
total_tests = exec_result.test_total
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
if total_tests > 0:
|
| 8 |
+
reward = passed_tests / total_tests
|
| 9 |
+
else:
|
| 10 |
+
reward = 0.0
|
| 11 |
+
|
| 12 |
+
# enforce valid range
|
| 13 |
+
if reward <= 0:
|
| 14 |
+
reward = 0.1
|
| 15 |
+
elif reward >= 1:
|
| 16 |
+
reward = 0.9
|
| 17 |
|
| 18 |
+
return reward
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|