darshsingh1 commited on
Commit
3f77f57
·
verified ·
1 Parent(s): 2e07a31

Upload server/graders.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. server/graders.py +19 -19
server/graders.py CHANGED
@@ -48,22 +48,22 @@ def grade_easy(
48
  ) -> float:
49
  """
50
  Scoring:
51
- 1.0 — query runs AND output matches reference exactly
52
- 0.5 — query runs but output is partially correct
53
- 0.0 — query fails with an error
54
  """
55
  if error is not None:
56
- return 0.0
57
 
58
  if _rows_match(output or [], reference):
59
- return 1.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, 4)
65
 
66
- return 0.0
67
 
68
 
69
  # ---------------------------------------------------------------------------
@@ -79,15 +79,15 @@ def grade_medium(
79
  ) -> float:
80
  """
81
  Scoring:
82
- 1.0 — 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.0 — query fails
86
- -0.1 per error step (capped at 0.0 total)
87
  """
88
  if error is not None:
89
  penalty = 0.1 * cumulative_errors
90
- return max(0.0, 0.0 - penalty)
91
 
92
  q = query_str.lower()
93
  has_left_join = "left join" in q
@@ -97,16 +97,16 @@ def grade_medium(
97
  one_fixed = has_left_join or has_gte_date
98
 
99
  if both_fixed and _rows_match(output or [], reference):
100
- base = 1.0
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.0
107
 
108
  penalty = 0.1 * cumulative_errors
109
- return max(0.0, round(base - penalty, 4))
110
 
111
 
112
  # ---------------------------------------------------------------------------
@@ -121,14 +121,14 @@ def grade_hard(
121
  ) -> float:
122
  """
123
  Scoring:
124
- 1.0 — 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.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.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 = 1.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.0
151
 
152
  bonus = 0.05 if has_cte else 0.0
153
- return min(1.0, round(base + bonus, 4))
 
48
  ) -> float:
49
  """
50
  Scoring:
51
+ 0.99 — 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.01
57
 
58
  if _rows_match(output or [], reference):
59
+ return 0.99
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, 4)
65
 
66
+ return 0.01
67
 
68
 
69
  # ---------------------------------------------------------------------------
 
79
  ) -> float:
80
  """
81
  Scoring:
82
+ 0.99 — 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.01 — 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.01, 0.01 - penalty)
91
 
92
  q = query_str.lower()
93
  has_left_join = "left join" in q
 
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.01, round(base - penalty, 4))
110
 
111
 
112
  # ---------------------------------------------------------------------------
 
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.01 — query fails to execute
128
  +0.05 bonus if CTE (WITH clause) is used
129
  """
130
  if error is not None:
131
+ return 0.01
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.99
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.01
151
 
152
  bonus = 0.05 if has_cte else 0.0
153
+ return min(0.99, round(base + bonus, 4))