SpeakLab / controllers /streak_controller.py
seba3y's picture
Upload 30 files
a695f69 verified
Raw
History Blame Contribute Delete
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:
@staticmethod
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()
@staticmethod
def from_raw(raw: dict | None) -> StreakStore:
return StreakStore.from_raw(raw)
@staticmethod
def free_module_to_key(choice: str) -> ModuleKey:
return FREE_MODULE_MAP.get(choice, ModuleKey.JAM)