summaryrefslogtreecommitdiffstats
path: root/flashcards-project/src/flashcards/scheduler.py
blob: a9d94707a8d1a70feae945e79cb03736150025c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from typing import Protocol
from abc import abstractmethod

from .card import Card

class Scheduler(Protocol):
    """
    Schedulers must implement this interface to be usable in a session.
    """
    @abstractmethod
    def __init__(self, cards: dict[str, Card], state: dict):
        """
        Create a new instance of the scheduler from a dictionary of
        Cards indexed by ID and a scheduler-specific state as a dict.
        """
        raise NotImplementedError

    @abstractmethod
    def practice(self, size: int) -> list[str]:
        """
        Return a list of card IDs of the requested size, if possible.
        This list is intended for practice.
        """
        raise NotImplementedError

    @abstractmethod
    def test(self, size: int) -> list[str]:
        """
        Return a list of card IDs of the requested size, if possible.
        This list is intended to test the player's knowledge.
        """
        raise NotImplementedError

    @abstractmethod
    def update(self, results: dict[str, int]) -> None:
        """
        Takes a dictionary of card IDs and integers, where the integer
        is 0 if the player failed to guess the other side of the card,
        of 1 if the player succeeded.
        """
        raise NotImplementedError

    @abstractmethod
    def getState(self) -> dict:
        """
        Return the scheduler's state for storage.
        """
        raise NotImplementedError

SCHEDULERS = ["brutal"]

def getSchedulerClass(name: str) -> Scheduler:
    """
    Returns the class object for the requested scheduler, if one exists.
    """
    match name:
        case "brutal":
            from .scheduler_brutal import SchedulerBrutal
            return SchedulerBrutal
        case _:
            raise Exception(f"Unknown scheduler: {name}")