Spaces:
Sleeping
Sleeping
Download env/tasks/base_task.py from Jaswanth-K/cloudsense: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/Jaswanth-K/cloudsense/resolve/main/env/tasks/base_task.py
- Command line
-
hf download hf://spaces/Jaswanth-K/cloudsense/env/tasks/base_task.py
-
curl -L -o base_task.py https://huggingface.co/spaces/Jaswanth-K/cloudsense/resolve/main/env/tasks/base_task.py
1.26 kB
| """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 | |
| def get_correct_actions(self) -> dict[str, ActionType]: | |
| """Returns mapping of resource_id -> correct action type.""" | |
| def get_critical_resources(self) -> set[str]: | |
| """Resources that should be SKIPPED (prod, critical).""" | |
| 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) | |