Update graders.py
Browse files- graders.py +44 -33
graders.py
CHANGED
|
@@ -2,30 +2,35 @@ import sqlite3
|
|
| 2 |
|
| 3 |
def grade_easy_task(db_path: str) -> float:
|
| 4 |
"""Agent must trim whitespace from names and standardize dates to YYYY-MM-DD."""
|
|
|
|
| 5 |
try:
|
| 6 |
with sqlite3.connect(db_path) as conn:
|
| 7 |
c = conn.cursor()
|
| 8 |
c.execute("SELECT name, signup_date FROM customers ORDER BY id")
|
| 9 |
rows = c.fetchall()
|
| 10 |
|
| 11 |
-
if
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return float(correct_rows) / len(expected)
|
| 27 |
except sqlite3.Error:
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
def grade_medium_task(db_path: str) -> float:
|
| 31 |
"""Agent must create 'customers' and 'orders' tables with proper references."""
|
|
@@ -39,26 +44,28 @@ def grade_medium_task(db_path: str) -> float:
|
|
| 39 |
tables = [row[0] for row in c.fetchall()]
|
| 40 |
if 'customers' in tables and 'orders' in tables:
|
| 41 |
score += 0.4
|
| 42 |
-
else:
|
| 43 |
-
return score # Can't proceed if tables don't exist
|
| 44 |
-
|
| 45 |
-
# Check if customers are deduplicated correctly (0.3 points)
|
| 46 |
-
c.execute("SELECT COUNT(*) FROM customers")
|
| 47 |
-
if c.fetchone()[0] == 2: # Alice and Bob
|
| 48 |
-
score += 0.3
|
| 49 |
-
|
| 50 |
-
# Check if orders map correctly to customers (0.3 points)
|
| 51 |
-
# Assuming 'orders' has a 'customer_id' or 'customer_email' foreign key
|
| 52 |
-
c.execute("SELECT COUNT(*) FROM orders")
|
| 53 |
-
if c.fetchone()[0] == 3:
|
| 54 |
-
score += 0.3
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
except sqlite3.Error:
|
| 57 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
return score
|
| 59 |
|
|
|
|
| 60 |
def grade_hard_task(db_path: str) -> float:
|
| 61 |
"""Agent must create a view 'account_balances' calculating net balance (credit - debit)."""
|
|
|
|
| 62 |
try:
|
| 63 |
with sqlite3.connect(db_path) as conn:
|
| 64 |
c = conn.cursor()
|
|
@@ -68,7 +75,11 @@ def grade_hard_task(db_path: str) -> float:
|
|
| 68 |
|
| 69 |
expected = [(101, 250.0), (102, 1000.0)]
|
| 70 |
if rows == expected:
|
| 71 |
-
|
| 72 |
-
return 0.0
|
| 73 |
except sqlite3.Error:
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def grade_easy_task(db_path: str) -> float:
|
| 4 |
"""Agent must trim whitespace from names and standardize dates to YYYY-MM-DD."""
|
| 5 |
+
actual_score = 0.0
|
| 6 |
try:
|
| 7 |
with sqlite3.connect(db_path) as conn:
|
| 8 |
c = conn.cursor()
|
| 9 |
c.execute("SELECT name, signup_date FROM customers ORDER BY id")
|
| 10 |
rows = c.fetchall()
|
| 11 |
|
| 12 |
+
if rows:
|
| 13 |
+
correct_rows = 0
|
| 14 |
+
expected = [
|
| 15 |
+
('Alice', '2022-12-31'),
|
| 16 |
+
('Bob', '2023-01-15'),
|
| 17 |
+
('Charlie', '2023-05-14'),
|
| 18 |
+
('David', '2023-11-01')
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
for actual, exp in zip(rows, expected):
|
| 22 |
+
if actual[0] == exp[0] and actual[1] == exp[1]:
|
| 23 |
+
correct_rows += 1
|
| 24 |
+
|
| 25 |
+
actual_score = float(correct_rows) / len(expected)
|
|
|
|
|
|
|
| 26 |
except sqlite3.Error:
|
| 27 |
+
actual_score = 0.0
|
| 28 |
+
|
| 29 |
+
# THE VALIDATOR CLAMP
|
| 30 |
+
if actual_score >= 1.0: return 0.99
|
| 31 |
+
if actual_score <= 0.0: return 0.01
|
| 32 |
+
return actual_score
|
| 33 |
+
|
| 34 |
|
| 35 |
def grade_medium_task(db_path: str) -> float:
|
| 36 |
"""Agent must create 'customers' and 'orders' tables with proper references."""
|
|
|
|
| 44 |
tables = [row[0] for row in c.fetchall()]
|
| 45 |
if 'customers' in tables and 'orders' in tables:
|
| 46 |
score += 0.4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
# Check if customers are deduplicated correctly (0.3 points)
|
| 49 |
+
c.execute("SELECT COUNT(*) FROM customers")
|
| 50 |
+
if c.fetchone()[0] == 2: # Alice and Bob
|
| 51 |
+
score += 0.3
|
| 52 |
+
|
| 53 |
+
# Check if orders map correctly to customers (0.3 points)
|
| 54 |
+
c.execute("SELECT COUNT(*) FROM orders")
|
| 55 |
+
if c.fetchone()[0] == 3:
|
| 56 |
+
score += 0.3
|
| 57 |
except sqlite3.Error:
|
| 58 |
pass
|
| 59 |
+
|
| 60 |
+
# THE VALIDATOR CLAMP
|
| 61 |
+
if score >= 1.0: return 0.99
|
| 62 |
+
if score <= 0.0: return 0.01
|
| 63 |
return score
|
| 64 |
|
| 65 |
+
|
| 66 |
def grade_hard_task(db_path: str) -> float:
|
| 67 |
"""Agent must create a view 'account_balances' calculating net balance (credit - debit)."""
|
| 68 |
+
actual_score = 0.0
|
| 69 |
try:
|
| 70 |
with sqlite3.connect(db_path) as conn:
|
| 71 |
c = conn.cursor()
|
|
|
|
| 75 |
|
| 76 |
expected = [(101, 250.0), (102, 1000.0)]
|
| 77 |
if rows == expected:
|
| 78 |
+
actual_score = 1.0
|
|
|
|
| 79 |
except sqlite3.Error:
|
| 80 |
+
actual_score = 0.0
|
| 81 |
+
|
| 82 |
+
# THE VALIDATOR CLAMP
|
| 83 |
+
if actual_score >= 1.0: return 0.99
|
| 84 |
+
if actual_score <= 0.0: return 0.01
|
| 85 |
+
return actual_score
|