File size: 1,746 Bytes
8ab6a5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03114ab
 
 
 
 
8ab6a5f
 
 
 
 
03114ab
8ab6a5f
 
 
38ee4ab
19b4563
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
from tasks.base_task import BaseTask


class TopRevenueCategoryTask(BaseTask):
    """Easy task: find the product category with the highest total revenue.

    The agent must group the dataset by category, sum the total_price column,
    and identify which category has the highest revenue.
    """

    @property
    def task_id(self) -> int:
        """Return the task identifier."""
        return 1

    @property
    def difficulty(self) -> str:
        """Return the difficulty level."""
        return "easy"

    @property
    def description(self) -> str:
        """Return the task question."""
        return (
            "What is the top-selling product category by total revenue? "
            "Submit just the category name as your answer."
        )

    def expected_answer(self) -> str:
        """Compute the top revenue category from the dataset.

        Returns:
            The name of the category with the highest total_price sum.
        """
        return self.df.groupby("category")["total_price"].sum().idxmax()

    def grade(self, answer: str) -> float:
        """Grade the answer by case-insensitive containment check.

        Accepts the answer if the expected category name appears anywhere in
        the submitted string, so responses like 'The top category is Clothing'
        or 'Clothing ($74,792.74)' still receive full credit.

        Args:
            answer: The agent's submitted category name.

        Returns:
            1.0 if the expected category appears in the answer, 0.0 otherwise.
        """
        expected = self.expected_answer().strip().lower()
        submitted = answer.strip().lower()
        raw = 1.0 if expected in submitted else 0.0
        return max(0.05, min(0.95, raw))