File size: 887 Bytes
b6df81f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)]