Spaces:
Sleeping
Sleeping
| """Load project configuration from config.yaml.""" | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| import yaml | |
| _ROOT = Path(__file__).resolve().parent.parent | |
| _CONFIG_PATH = _ROOT / "config.yaml" | |
| class StreamConfig: | |
| phase_a_length: int | |
| phase_b_length: int | |
| phase_c_length: int | |
| drift_magnitude: float | |
| anomaly_rate: float | |
| point_ratio: float | |
| delay: float | |
| seed: int | |
| class DetectorConfig: | |
| n_trees: int | |
| height: int | |
| window_size: int | |
| threshold: float | |
| seed: int | |
| class DriftConfig: | |
| delta: float | |
| grace_period: int | |
| class ServerConfig: | |
| port: int | |
| replay_buffer_size: int | |
| class Config: | |
| stream: StreamConfig | |
| detector: DetectorConfig | |
| drift: DriftConfig | |
| server: ServerConfig | |
| def load_config(path: Path = _CONFIG_PATH) -> Config: | |
| with open(path) as f: | |
| raw = yaml.safe_load(f) | |
| return Config( | |
| stream=StreamConfig(**raw["stream"]), | |
| detector=DetectorConfig(**raw["detector"]), | |
| drift=DriftConfig(**raw["drift"]), | |
| server=ServerConfig(**raw["server"]), | |
| ) | |
| # Module-level singleton loaded once at import time | |
| settings: Config = load_config() | |