Spaces:
Running
Running
Commit Β·
29c44a0
1
Parent(s): 58af184
errors fixed
Browse files
server/graders/__pycache__/grader_easy.cpython-310.pyc
CHANGED
|
Binary files a/server/graders/__pycache__/grader_easy.cpython-310.pyc and b/server/graders/__pycache__/grader_easy.cpython-310.pyc differ
|
|
|
server/graders/__pycache__/grader_hard.cpython-310.pyc
CHANGED
|
Binary files a/server/graders/__pycache__/grader_hard.cpython-310.pyc and b/server/graders/__pycache__/grader_hard.cpython-310.pyc differ
|
|
|
server/graders/grader_easy.py
CHANGED
|
@@ -98,7 +98,15 @@ def grade_easy(fixed_code: str, task: dict) -> Tuple[float, int, int, str, List[
|
|
| 98 |
results.append({"test_id": i+1, "passed": False, "expected": str(expected), "got": str(got)})
|
| 99 |
feedback_lines.append(f"Test {i+1}: β Failed\n Input : {inp!r}\n Expected : {expected!r}\n Got : {got!r}")
|
| 100 |
|
| 101 |
-
reward =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
feedback = "\n".join(feedback_lines)
|
| 103 |
feedback += "\nπ All tests passed! Full reward." if passed == total else f"\n{passed}/{total} tests passed."
|
| 104 |
|
|
|
|
| 98 |
results.append({"test_id": i+1, "passed": False, "expected": str(expected), "got": str(got)})
|
| 99 |
feedback_lines.append(f"Test {i+1}: β Failed\n Input : {inp!r}\n Expected : {expected!r}\n Got : {got!r}")
|
| 100 |
|
| 101 |
+
reward = passed / total
|
| 102 |
+
|
| 103 |
+
# ensure strict (0,1) range
|
| 104 |
+
if reward <= 0:
|
| 105 |
+
reward = 0.01
|
| 106 |
+
elif reward >= 1:
|
| 107 |
+
reward = 0.99
|
| 108 |
+
|
| 109 |
+
reward = round(reward, 2)
|
| 110 |
feedback = "\n".join(feedback_lines)
|
| 111 |
feedback += "\nπ All tests passed! Full reward." if passed == total else f"\n{passed}/{total} tests passed."
|
| 112 |
|
server/graders/grader_hard.py
CHANGED
|
@@ -14,7 +14,7 @@ def _score_explanation(explanation: Optional[str], keywords: List[str], instruct
|
|
| 14 |
- Partial credit for any relevant mention
|
| 15 |
"""
|
| 16 |
if not explanation or len(explanation.strip()) < 15:
|
| 17 |
-
return 0.
|
| 18 |
|
| 19 |
exp_lower = explanation.lower()
|
| 20 |
hits = [kw for kw in keywords if kw.lower() in exp_lower]
|
|
@@ -44,11 +44,11 @@ def _score_explanation(explanation: Optional[str], keywords: List[str], instruct
|
|
| 44 |
needed = max(1, len(keywords) // 2)
|
| 45 |
|
| 46 |
if total_hits == 0:
|
| 47 |
-
score = 0.1 if len(explanation.strip()) > 50 else 0.
|
| 48 |
elif total_hits >= needed:
|
| 49 |
-
score =
|
| 50 |
else:
|
| 51 |
-
score =
|
| 52 |
|
| 53 |
if score >= 1.0:
|
| 54 |
feedback = f"β
Explanation excellent! Covered: {', '.join(synonym_hits)}"
|
|
@@ -61,6 +61,7 @@ def _score_explanation(explanation: Optional[str], keywords: List[str], instruct
|
|
| 61 |
else:
|
| 62 |
feedback = f"β Explanation too vague. Explain: {', '.join(keywords[:3])}"
|
| 63 |
|
|
|
|
| 64 |
return round(score, 2), feedback
|
| 65 |
|
| 66 |
|
|
@@ -72,7 +73,8 @@ def grade_hard(fixed_code: str, task: dict, explanation: Optional[str] = None) -
|
|
| 72 |
keywords = task.get("explanation_keywords", [])
|
| 73 |
instructions = task.get("instructions", "")
|
| 74 |
exp_score, exp_feedback = _score_explanation(explanation, keywords, instructions)
|
| 75 |
-
final_reward =
|
|
|
|
| 76 |
|
| 77 |
feedback = (
|
| 78 |
f"--- Code Score (70%): {test_reward:.2f} ---\n"
|
|
|
|
| 14 |
- Partial credit for any relevant mention
|
| 15 |
"""
|
| 16 |
if not explanation or len(explanation.strip()) < 15:
|
| 17 |
+
return 0.01, "β No explanation provided. Hard tasks require explanation field."
|
| 18 |
|
| 19 |
exp_lower = explanation.lower()
|
| 20 |
hits = [kw for kw in keywords if kw.lower() in exp_lower]
|
|
|
|
| 44 |
needed = max(1, len(keywords) // 2)
|
| 45 |
|
| 46 |
if total_hits == 0:
|
| 47 |
+
score = 0.1 if len(explanation.strip()) > 50 else 0.01
|
| 48 |
elif total_hits >= needed:
|
| 49 |
+
score = 0.99
|
| 50 |
else:
|
| 51 |
+
score = total_hits / needed
|
| 52 |
|
| 53 |
if score >= 1.0:
|
| 54 |
feedback = f"β
Explanation excellent! Covered: {', '.join(synonym_hits)}"
|
|
|
|
| 61 |
else:
|
| 62 |
feedback = f"β Explanation too vague. Explain: {', '.join(keywords[:3])}"
|
| 63 |
|
| 64 |
+
score = max(0.01, min(score, 0.99))
|
| 65 |
return round(score, 2), feedback
|
| 66 |
|
| 67 |
|
|
|
|
| 73 |
keywords = task.get("explanation_keywords", [])
|
| 74 |
instructions = task.get("instructions", "")
|
| 75 |
exp_score, exp_feedback = _score_explanation(explanation, keywords, instructions)
|
| 76 |
+
final_reward = 0.7 * test_reward + 0.3 * exp_score
|
| 77 |
+
final_reward = round(max(0.01, min(final_reward, 0.99)), 2)
|
| 78 |
|
| 79 |
feedback = (
|
| 80 |
f"--- Code Score (70%): {test_reward:.2f} ---\n"
|