summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/flashcard_cli.py37
1 files changed, 11 insertions, 26 deletions
diff --git a/src/flashcard_cli.py b/src/flashcard_cli.py
index 7f5da34..8017c4d 100644
--- a/src/flashcard_cli.py
+++ b/src/flashcard_cli.py
@@ -1,10 +1,9 @@
import click
from random import shuffle
+from scheduler import SCHEDULERS
+from session import Session
from card import Card
-from scheduler import getSchedulerClass, SCHEDULERS
-from parser import parseFiles
-from state_json import save, load
@click.group()
def cli():
@@ -20,17 +19,12 @@ def practice(state_file, card_files, scheduler_name, count, random_flip):
"""
Run a practice session with the specified scheduler, using the provided state and card files.
"""
- all_cards = parseFiles(card_files)
- state = load(state_file)
+ session = Session(scheduler_name, card_files, state_file)
- scheduler = getSchedulerClass(scheduler_name)(all_cards, state)
-
- cards = scheduler.practice(count)
+ for i, card in enumerate(session.practice(count)):
+ click.echo(click.style(f"{i + 1} ===========================================================", fg="blue"))
- for i, id in enumerate(cards):
- click.echo(click.style(f"{i + 1}/{len(cards)} ===========================================================", fg="blue"))
-
- faces = [all_cards[id].front, all_cards[id].back]
+ faces = [card.front, card.back]
if random_flip:
shuffle(faces)
@@ -49,18 +43,12 @@ def test(state_file, card_files, scheduler_name, count, random_flip):
"""
Run a test session with the specified scheduler, using the provided state and card files.
"""
- all_cards = parseFiles(card_files)
- state = load(state_file)
-
- scheduler = getSchedulerClass(scheduler_name)(all_cards, state)
-
- cards = scheduler.test(count)
- results = {}
+ session = Session(scheduler_name, card_files, state_file)
- for i, id in enumerate(cards):
- click.echo(click.style(f"{i + 1}/{len(cards)} ===========================================================", fg="blue"))
+ for i, (card, correct) in enumerate(session.test(count)):
+ click.echo(click.style(f"{i + 1} ===========================================================", fg="blue"))
- faces = [all_cards[id].front, all_cards[id].back]
+ faces = [card.front, card.back]
if random_flip:
shuffle(faces)
@@ -70,10 +58,7 @@ def test(state_file, card_files, scheduler_name, count, random_flip):
click.echo(faces.pop(0))
click.echo()
- results[id] = int(click.confirm(click.style("Correct?", bold=True)))
-
- scheduler.update(results)
- save(state_file, scheduler.getState())
+ correct(click.confirm(click.style("Correct?", bold=True)))
if __name__ == '__main__':
cli()