Spaces:
Sleeping
Sleeping
| import sqlite3 | |
| from .base import BaseTask | |
| class MonthlySignupsTask(BaseTask): | |
| """Task 1 — Easy: Count users who signed up in the last 30 days.""" | |
| task_id = "monthly_signups" | |
| difficulty = "easy" | |
| max_steps = 10 | |
| question = "How many users signed up in the last 30 days?" | |
| relevant_tables = ["users"] | |
| sql_hint = "COUNT(*) with WHERE clause on created_at" | |
| def compute_ground_truth(self, conn: sqlite3.Connection) -> None: | |
| result = conn.execute( | |
| "SELECT COUNT(*) FROM users WHERE created_at >= DATE('now', '-30 days')" | |
| ).fetchone() | |
| self.ground_truth = result[0] if result else 0 | |
| def grade(self, submitted_answer: str) -> float: | |
| try: | |
| val = int(submitted_answer.strip().replace(",", "")) | |
| if val == self.ground_truth: | |
| return 1.0 | |
| if abs(val - self.ground_truth) <= 3: | |
| return 0.6 | |
| if abs(val - self.ground_truth) <= 10: | |
| return 0.3 | |
| except (ValueError, AttributeError): | |
| pass | |
| return 0.0 | |