Spaces:
Sleeping
Sleeping
Upload server/graders.py with huggingface_hub
Browse files- server/graders.py +14 -14
server/graders.py
CHANGED
|
@@ -48,20 +48,20 @@ def grade_easy(
|
|
| 48 |
) -> float:
|
| 49 |
"""
|
| 50 |
Scoring:
|
| 51 |
-
0.
|
| 52 |
0.5 — query runs but output is partially correct
|
| 53 |
0.01 — query fails with an error
|
| 54 |
"""
|
| 55 |
if error is not None:
|
| 56 |
-
return 0
|
| 57 |
|
| 58 |
if _rows_match(output or [], reference):
|
| 59 |
-
return 0.
|
| 60 |
|
| 61 |
# Partial credit: right columns present, possible wrong filter
|
| 62 |
overlap = _partial_overlap(output or [], reference)
|
| 63 |
if overlap > 0:
|
| 64 |
-
return round(0.5 * overlap,
|
| 65 |
|
| 66 |
return 0.01
|
| 67 |
|
|
@@ -79,15 +79,15 @@ def grade_medium(
|
|
| 79 |
) -> float:
|
| 80 |
"""
|
| 81 |
Scoring:
|
| 82 |
-
0.
|
| 83 |
0.6 — only one of the two bugs is fixed AND output partially matches
|
| 84 |
0.2 — query runs but output is wrong
|
| 85 |
-
0.
|
| 86 |
-0.1 per error step (capped at 0.01 total)
|
| 87 |
"""
|
| 88 |
if error is not None:
|
| 89 |
penalty = 0.1 * cumulative_errors
|
| 90 |
-
return max(0
|
| 91 |
|
| 92 |
q = query_str.lower()
|
| 93 |
has_left_join = "left join" in q
|
|
@@ -106,7 +106,7 @@ def grade_medium(
|
|
| 106 |
base = 0.01
|
| 107 |
|
| 108 |
penalty = 0.1 * cumulative_errors
|
| 109 |
-
return max(0
|
| 110 |
|
| 111 |
|
| 112 |
# ---------------------------------------------------------------------------
|
|
@@ -124,11 +124,11 @@ def grade_hard(
|
|
| 124 |
0.99 — alias fixed AND GROUP BY present AND output matches reference
|
| 125 |
0.7 — alias fixed AND query runs but missing GROUP BY
|
| 126 |
0.4 — query runs with partial output correctness
|
| 127 |
-
0
|
| 128 |
+0.05 bonus if CTE (WITH clause) is used
|
| 129 |
"""
|
| 130 |
if error is not None:
|
| 131 |
-
return 0
|
| 132 |
|
| 133 |
q = query_str.lower()
|
| 134 |
has_group_by = "group by" in q
|
|
@@ -138,7 +138,7 @@ def grade_hard(
|
|
| 138 |
overlap = _partial_overlap(output or [], reference)
|
| 139 |
|
| 140 |
if exact_match and has_group_by:
|
| 141 |
-
base = 0.
|
| 142 |
elif has_group_by and overlap >= 0.5:
|
| 143 |
# Alias might be fixed but output not perfectly matching reference ordering
|
| 144 |
base = 0.7
|
|
@@ -147,7 +147,7 @@ def grade_hard(
|
|
| 147 |
elif not error:
|
| 148 |
base = 0.2
|
| 149 |
else:
|
| 150 |
-
base = 0.
|
| 151 |
|
| 152 |
-
bonus = 0.05 if has_cte else 0
|
| 153 |
-
return min(0.
|
|
|
|
| 48 |
) -> float:
|
| 49 |
"""
|
| 50 |
Scoring:
|
| 51 |
+
0.9 — query runs AND output matches reference exactly
|
| 52 |
0.5 — query runs but output is partially correct
|
| 53 |
0.01 — query fails with an error
|
| 54 |
"""
|
| 55 |
if error is not None:
|
| 56 |
+
return 0
|
| 57 |
|
| 58 |
if _rows_match(output or [], reference):
|
| 59 |
+
return 0.9
|
| 60 |
|
| 61 |
# Partial credit: right columns present, possible wrong filter
|
| 62 |
overlap = _partial_overlap(output or [], reference)
|
| 63 |
if overlap > 0:
|
| 64 |
+
return round(0.5 * overlap, 1)
|
| 65 |
|
| 66 |
return 0.01
|
| 67 |
|
|
|
|
| 79 |
) -> float:
|
| 80 |
"""
|
| 81 |
Scoring:
|
| 82 |
+
0.9 — LEFT JOIN used AND date >= '2024-01-01' AND output matches reference
|
| 83 |
0.6 — only one of the two bugs is fixed AND output partially matches
|
| 84 |
0.2 — query runs but output is wrong
|
| 85 |
+
0.1 — query fails
|
| 86 |
-0.1 per error step (capped at 0.01 total)
|
| 87 |
"""
|
| 88 |
if error is not None:
|
| 89 |
penalty = 0.1 * cumulative_errors
|
| 90 |
+
return max(0, 0 - penalty)
|
| 91 |
|
| 92 |
q = query_str.lower()
|
| 93 |
has_left_join = "left join" in q
|
|
|
|
| 106 |
base = 0.01
|
| 107 |
|
| 108 |
penalty = 0.1 * cumulative_errors
|
| 109 |
+
return max(0, round(base - penalty, 1))
|
| 110 |
|
| 111 |
|
| 112 |
# ---------------------------------------------------------------------------
|
|
|
|
| 124 |
0.99 — alias fixed AND GROUP BY present AND output matches reference
|
| 125 |
0.7 — alias fixed AND query runs but missing GROUP BY
|
| 126 |
0.4 — query runs with partial output correctness
|
| 127 |
+
0 — query fails to execute
|
| 128 |
+0.05 bonus if CTE (WITH clause) is used
|
| 129 |
"""
|
| 130 |
if error is not None:
|
| 131 |
+
return 0
|
| 132 |
|
| 133 |
q = query_str.lower()
|
| 134 |
has_group_by = "group by" in q
|
|
|
|
| 138 |
overlap = _partial_overlap(output or [], reference)
|
| 139 |
|
| 140 |
if exact_match and has_group_by:
|
| 141 |
+
base = 0.9
|
| 142 |
elif has_group_by and overlap >= 0.5:
|
| 143 |
# Alias might be fixed but output not perfectly matching reference ordering
|
| 144 |
base = 0.7
|
|
|
|
| 147 |
elif not error:
|
| 148 |
base = 0.2
|
| 149 |
else:
|
| 150 |
+
base = 0.1
|
| 151 |
|
| 152 |
+
bonus = 0.05 if has_cte else 0
|
| 153 |
+
return min(0.9, round(base + bonus, 1))
|