darshsingh1 commited on
Commit
efc488b
·
verified ·
1 Parent(s): 17c9292

Upload server/graders.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. server/graders.py +10 -58
server/graders.py CHANGED
@@ -46,24 +46,13 @@ def grade_easy(
46
  reference: list,
47
  error: Optional[str],
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
 
68
 
69
  # ---------------------------------------------------------------------------
@@ -77,36 +66,19 @@ def grade_medium(
77
  query_str: str,
78
  cumulative_errors: int = 0,
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
94
  has_gte_date = ">= '2024-01-01'" in q or ">='2024-01-01'" in q
95
 
96
  both_fixed = has_left_join and has_gte_date
97
- one_fixed = has_left_join or has_gte_date
98
 
99
  if both_fixed and _rows_match(output or [], reference):
100
- base = 0.99
101
- elif one_fixed and _partial_overlap(output or [], reference) >= 0.5:
102
- base = 0.6
103
- elif not error:
104
- base = 0.2
105
- else:
106
- base = 0.01
107
 
108
- penalty = 0.1 * cumulative_errors
109
- return max(0, round(base - penalty, 1))
110
 
111
 
112
  # ---------------------------------------------------------------------------
@@ -119,35 +91,15 @@ def grade_hard(
119
  error: Optional[str],
120
  query_str: str,
121
  ) -> float:
122
- """
123
- Scoring:
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
135
- has_cte = q.lstrip().startswith("with ")
136
 
137
  exact_match = _rows_match(output or [], reference)
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
145
- elif not error and overlap > 0:
146
- base = 0.4
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))
 
46
  reference: list,
47
  error: Optional[str],
48
  ) -> float:
 
 
 
 
 
 
49
  if error is not None:
50
+ return 0.0
51
 
52
  if _rows_match(output or [], reference):
53
+ return 1.0
54
 
55
+ return 0.0
 
 
 
 
 
56
 
57
 
58
  # ---------------------------------------------------------------------------
 
66
  query_str: str,
67
  cumulative_errors: int = 0,
68
  ) -> float:
 
 
 
 
 
 
 
 
69
  if error is not None:
70
+ return 0.0
 
71
 
72
  q = query_str.lower()
73
  has_left_join = "left join" in q
74
  has_gte_date = ">= '2024-01-01'" in q or ">='2024-01-01'" in q
75
 
76
  both_fixed = has_left_join and has_gte_date
 
77
 
78
  if both_fixed and _rows_match(output or [], reference):
79
+ return 1.0
 
 
 
 
 
 
80
 
81
+ return 0.0
 
82
 
83
 
84
  # ---------------------------------------------------------------------------
 
91
  error: Optional[str],
92
  query_str: str,
93
  ) -> float:
 
 
 
 
 
 
 
 
94
  if error is not None:
95
+ return 0.0
96
 
97
  q = query_str.lower()
98
  has_group_by = "group by" in q
 
99
 
100
  exact_match = _rows_match(output or [], reference)
 
101
 
102
  if exact_match and has_group_by:
103
+ return 1.0
104
+
105
+ return 0.0