summaryrefslogtreecommitdiffstats
path: root/flashcards-project/src/flashcards/scheduler.py
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2024-09-26 10:02:15 +0200
committerEddy Pedroni <epedroni@pm.me>2024-09-26 10:02:15 +0200
commite65bef9c22244fc9bcd22a37d335f5f76ba16ff5 (patch)
tree9af6fa41bfee6fc03c3ab30cf1b23a82bdf8f2e7 /flashcards-project/src/flashcards/scheduler.py
parentce76b00d7b2ccac6843732f92becfabb753864a0 (diff)
Create separate packages for library and CLI
Diffstat (limited to 'flashcards-project/src/flashcards/scheduler.py')
-rw-r--r--flashcards-project/src/flashcards/scheduler.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/flashcards-project/src/flashcards/scheduler.py b/flashcards-project/src/flashcards/scheduler.py
new file mode 100644
index 0000000..a9d9470
--- /dev/null
+++ b/flashcards-project/src/flashcards/scheduler.py
@@ -0,0 +1,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}")
+