aastikny commited on
Commit
34f5fc2
·
verified ·
1 Parent(s): fc232db

Upload graders.py

Browse files
Files changed (1) hide show
  1. graders.py +74 -0
graders.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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 not rows:
12
+ return 0.0
13
+
14
+ correct_rows = 0
15
+ expected = [
16
+ ('Alice', '2022-12-31'),
17
+ ('Bob', '2023-01-15'),
18
+ ('Charlie', '2023-05-14'),
19
+ ('David', '2023-11-01')
20
+ ]
21
+
22
+ for actual, exp in zip(rows, expected):
23
+ if actual[0] == exp[0] and actual[1] == exp[1]:
24
+ correct_rows += 1
25
+
26
+ return float(correct_rows) / len(expected)
27
+ except sqlite3.Error:
28
+ return 0.0
29
+
30
+ def grade_medium_task(db_path: str) -> float:
31
+ """Agent must create 'customers' and 'orders' tables with proper references."""
32
+ score = 0.0
33
+ try:
34
+ with sqlite3.connect(db_path) as conn:
35
+ c = conn.cursor()
36
+
37
+ # Check if target tables exist (0.4 points)
38
+ c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name IN ('customers', 'orders')")
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()
65
+ # Check if the view exists and has the correct logic
66
+ c.execute("SELECT account_id, net_balance FROM account_balances ORDER BY account_id")
67
+ rows = c.fetchall()
68
+
69
+ expected = [(101, 250.0), (102, 1000.0)]
70
+ if rows == expected:
71
+ return 1.0
72
+ return 0.0
73
+ except sqlite3.Error:
74
+ return 0.0