Schedulers

Helpers

flashcards_core.schedulers.get_available_schedulers()

Returns a list of the known algorithm (scheduler) names.

flashcards_core.schedulers.get_scheduler_class(algorithm_name: str)

Returns the scheduler class corresponding to the given name.

flashcards_core.schedulers.get_scheduler_for_deck(session, deck)

Returns a ready-to-use scheduler for the algorithm assigned to this deck.

Parameters
  • session – the session (see flashcards_core.database:init_db()).

  • deck – the deck this scheduler is generated for

Returns

a subclass of BaseScheduler

BaseScheduler (base class)

class flashcards_core.schedulers.base.BaseScheduler(session: sqlalchemy.orm.session.Session, deck: flashcards_core.database.models.decks.Deck)

Bases: abc.ABC

deck

The deck we’re studying

abstract next_card() flashcards_core.database.models.cards.Card
Returns

the next card to review

abstract process_test_result(card: flashcards_core.database.models.cards.Card, result: Any)

Creates a Review for the card, storing the test result.

Different implementations might use a different type for the results, therefore this parameter is not typed.

Parameters
  • card – the card that was reviewed

  • result – the results of the test

Returns

None

session

The session to use to interact with the database

RandomScheduler (random order)

flashcards_core.schedulers.random.LAST_REVIEWED_CARD = 'last_reviewed_card'

ID of the last card reviewed

flashcards_core.schedulers.random.NEVER_REPEAT = 'never_repeat'

Never pick the same card twice in a row, if there is more than one card in the deck

class flashcards_core.schedulers.random.RandomScheduler(session: sqlalchemy.orm.session.Session, deck: flashcards_core.database.models.decks.Deck)

Bases: flashcards_core.schedulers.base.BaseScheduler

next_card() flashcards_core.database.models.cards.Card

Returns the next card to review.

In a Random deck, this is any random card. If the deck is configured to give priority to unseen cards (unseen_first: true) then the new card is chosen among the new ones, if any. If the deck is configured to never show the same card twice in a row (never_repeat: true), and the deck has more than one card, then this method makes sure this constraints is respected.

Parameters

deck – the deck to pick the next card from

Returns

the next Card to study

process_test_result(card: flashcards_core.database.models.cards.Card, result: Any) None

Creates a Review for the card, storing the test result.

In a Random deck there is no further processing to do, except storing a pointer to the last card in case the deck is configured to never show the same card twice in a row. In addition, storing Reviews is useful to keep track of unseen cards, if so requested, and for later statistics.

A Random deck will probably store boolean results, but in practice this is not mandatory and the frontend can choose to send any value here. Therefore, the results field is not typed.

Parameters
  • card – the card that was reviewed

  • result – the results of the test

Returns

None

Raise

ValueError if the card does not belong to the deck

flashcards_core.schedulers.random.UNSEEN_FIRST = 'unseen_first'

Pick the next card from the unseen ones, if any