From 3f07b0b8f1a40b5b94622433b349c44267faca4f Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Wed, 25 Sep 2024 22:27:29 +0200 Subject: CLI uses session class --- src/flashcard_cli.py | 37 +++++++++++-------------------------- 1 file 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() -- cgit v1.2.3