Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| import random | |
| from typing import Dict | |
| class BotRandomizer: | |
| """ | |
| Encapsulates weighted random selection for bot generation style groups. | |
| """ | |
| def __init__(self, weights_cfg: Dict[str, Dict[str, int]]) -> None: | |
| # Shallow copy to avoid external mutation | |
| self._weights_cfg: Dict[str, Dict[str, int]] = dict(weights_cfg or {}) | |
| def choose_style(self) -> Dict[str, str]: | |
| selected: Dict[str, str] = {} | |
| for group_name, options in self._weights_cfg.items(): | |
| option_names = list(options.keys()) | |
| if not option_names: | |
| continue | |
| option_weights = [int(w) for w in options.values()] | |
| normalized = [w if w > 0 else 1 for w in option_weights] | |
| chosen = random.choices(option_names, weights=normalized, k=1)[0] | |
| selected[group_name] = chosen | |
| return selected | |