Download controllers/streak_controller.py from seba3y/SpeakLab: direct link, hf CLI and curl.
- Browser
- Download file 948 Bytes
-
https://huggingface.co/spaces/seba3y/SpeakLab/resolve/main/controllers/streak_controller.py
- Command line
-
hf download hf://spaces/seba3y/SpeakLab/controllers/streak_controller.py
-
curl -L -o streak_controller.py https://huggingface.co/spaces/seba3y/SpeakLab/resolve/main/controllers/streak_controller.py
948 Bytes
| """ | |
| StreakController — wraps StreakStore operations. | |
| Handles (de)serialisation to/from the BrowserState dict. | |
| """ | |
| from models.session_models import StreakStore, ModuleKey, FREE_MODULE_MAP | |
| class StreakController: | |
| def record(raw_store: dict | None, module_key: ModuleKey, duration_sec: int = 0) -> dict: | |
| """ | |
| Record a session and return the updated raw store dict. | |
| minimum 5 seconds (mirrors JS MIN_SESSION_SEC) — caller decides, | |
| but we still save the entry even if short; view shows the toast. | |
| """ | |
| store = StreakStore.from_raw(raw_store) | |
| store = store.record_session(module_key, duration_sec) | |
| return store.to_raw() | |
| def from_raw(raw: dict | None) -> StreakStore: | |
| return StreakStore.from_raw(raw) | |
| def free_module_to_key(choice: str) -> ModuleKey: | |
| return FREE_MODULE_MAP.get(choice, ModuleKey.JAM) | |