File size: 1,256 Bytes
529b5a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Base task class for CloudSense tasks."""

import json
from abc import ABC, abstractmethod
from pathlib import Path

from env.models import ActionType, CloudResource


DATA_DIR = Path(__file__).parent.parent / "data"


class BaseTask(ABC):
    task_id: str
    difficulty: str
    max_steps: int
    description: str
    data_file: str
    optimal_cost: float

    @abstractmethod
    def get_correct_actions(self) -> dict[str, ActionType]:
        """Returns mapping of resource_id -> correct action type."""

    @abstractmethod
    def get_critical_resources(self) -> set[str]:
        """Resources that should be SKIPPED (prod, critical)."""

    @abstractmethod
    def get_action_savings(self) -> dict[str, float]:
        """resource_id -> expected $ savings if correct action taken."""

    def load_account(self) -> list[CloudResource]:
        """Load and return resources from JSON file."""
        path = DATA_DIR / self.data_file
        with open(path) as f:
            data = json.load(f)
        return [CloudResource(**r) for r in data]

    def load_account_raw(self) -> list[dict]:
        """Load raw dict data from JSON file."""
        path = DATA_DIR / self.data_file
        with open(path) as f:
            return json.load(f)