SolusOps's picture
feat: storage package
b6df81f verified
Raw
History Blame Contribute Delete
887 Bytes
from __future__ import annotations
from typing import Dict, List
from storage.local_db import DB
from quiz.scoring import compute_mastery_delta, should_unlock_revision_quest
class MasteryStore:
def __init__(self, db: DB): self._db = db
def update(self, topic: str, correct: int, total: int) -> float:
self._db.upsert_mastery(topic, correct, total)
return self.get(topic)
def get(self, topic: str) -> float:
row = self._db.get_mastery_row(topic)
return 0.0 if row is None else compute_mastery_delta(row["correct"], row["total"])
def all_mastery(self) -> Dict[str, float]:
return {r["topic"]: compute_mastery_delta(r["correct"], r["total"])
for r in self._db.all_mastery_rows()}
def weak_topics(self) -> List[str]:
return [t for t, s in self.all_mastery().items() if should_unlock_revision_quest(s)]