Spaces:
Sleeping
Sleeping
File size: 2,935 Bytes
2f8e591 8b7db34 2f8e591 8b7db34 2f8e591 8b7db34 2f8e591 8b7db34 2f8e591 8b7db34 2f8e591 8b7db34 2f8e591 8b7db34 2f8e591 8b7db34 2f8e591 8b7db34 efc488b 8b7db34 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | """
Graders for each OpenENV SQL task.
All grader functions return a float in [0.0, 1.0].
Grader signatures:
grade_easy(output, reference, error) -> float
grade_medium(output, reference, error, query_str, step_errors) -> float
grade_hard(output, reference, error, query_str) -> float
"""
from typing import Optional
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def _normalize_rows(rows: list) -> list:
"""Normalize a list-of-tuples to lowercase stripped strings for comparison."""
return [tuple(str(v).strip().lower() if v is not None else "none" for v in row) for row in rows]
def _rows_match(a: list, b: list) -> bool:
"""Return True if two result sets are equal (order-insensitive)."""
return sorted(_normalize_rows(a)) == sorted(_normalize_rows(b))
def _partial_overlap(a: list, b: list) -> float:
"""
Return fraction of reference rows that appear in agent output.
Used for partial credit scoring.
"""
if not b:
return 0.9 if not a else 0.1
norm_a = set(map(tuple, _normalize_rows(a)))
norm_b = set(map(tuple, _normalize_rows(b)))
overlap = len(norm_a & norm_b)
return overlap / len(norm_b)
# ---------------------------------------------------------------------------
# Task 1: fix-syntax (Easy)
# ---------------------------------------------------------------------------
def grade_easy(
output: Optional[list],
reference: list,
error: Optional[str],
) -> float:
if error is not None:
return 0.1
if _rows_match(output or [], reference):
return 0.9
return 0.1
# ---------------------------------------------------------------------------
# Task 2: fix-logic (Medium)
# ---------------------------------------------------------------------------
def grade_medium(
output: Optional[list],
reference: list,
error: Optional[str],
query_str: str,
cumulative_errors: int = 0,
) -> float:
if error is not None:
return 0.1
q = query_str.lower()
has_left_join = "left join" in q
has_gte_date = ">= '2024-01-01'" in q or ">='2024-01-01'" in q
both_fixed = has_left_join and has_gte_date
if both_fixed and _rows_match(output or [], reference):
return 0.9
return 0.1
# ---------------------------------------------------------------------------
# Task 3: fix-and-optimize (Hard)
# ---------------------------------------------------------------------------
def grade_hard(
output: Optional[list],
reference: list,
error: Optional[str],
query_str: str,
) -> float:
if error is not None:
return 0.1
q = query_str.lower()
has_group_by = "group by" in q
exact_match = _rows_match(output or [], reference)
if exact_match and has_group_by:
return 0.9
return 0.1
|