from typing import Iterator, Callable from card import Card from scheduler import getSchedulerClass from parser import parseFiles from state_json import load, save class Session: def __init__(self, scheduler_name: str, card_files: list[str], state_file: str): self._cards = parseFiles(card_files) self._state_file = state_file self._scheduler = getSchedulerClass(scheduler_name)(self._cards, load(state_file)) def practice(self, size: int) -> Iterator[Card]: ids = self._scheduler.practice(size) for id in ids: yield self._cards[id] def test(self, size: int) -> Iterator[tuple[Card, Callable]]: ids = self._scheduler.practice(size) results = {} for id in ids: def result(correct: bool) -> None: results[id] = int(correct) yield self._cards[id], result self._scheduler.update(results) save(self._state_file, self._scheduler.getState())