File size: 1,267 Bytes
b0add2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""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"


@dataclass
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


@dataclass
class DetectorConfig:
    n_trees: int
    height: int
    window_size: int
    threshold: float
    seed: int


@dataclass
class DriftConfig:
    delta: float
    grace_period: int


@dataclass
class ServerConfig:
    port: int
    replay_buffer_size: int


@dataclass
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()