File size: 1,082 Bytes
d103a0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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