# `Scheduler`

class mnemosyne.libmnemosyne.scheduler.Scheduler(component_manager, **kwds)
  active_count()
  adjusted_now(now=None)

    Timezone information and ‘day_starts_at’ will only become relevant when the queue is built, not at schedule time, to allow for moving to a different timezone after a card has been scheduled. Cards are due when ‘adjusted_now >= next_rep’, and this function makes sure that happens at h:00 local time (with h being ‘day_starts_at’).

  avoid_sister_cards(card)

    Change card.next_rep to make sure that the card is not scheduled on the same day as a sister card.

    Factored out here to allow this to be used by e.g. MnemoGogo.

  card_count_scheduled_n_days_from_now(n)

    Yesterday: n=-1, today: n=0, tomorrow: n=1, … .

    Is not implemented in the database, because this could need internal scheduler information.

  component_type = 'scheduler'
  grade_answer(card, new_grade, dry_run=False)
  is_in_queue(card)

    To check whether the queue needs to be rebuilt, e.g. if it contains a card that was deleted in the GUI.

  is_prefetch_allowed()

    Can we display a new card before having processed the grading of the previous one?

  last_rep_to_interval_string(last_rep, now=None)

    Converts next_rep to a string like ‘yesterday’, ‘2 weeks ago’, …

  midnight_UTC(timestamp)

    Round a timestamp to a value with resolution of a day, storing it in a timezone independent way, as a POSIX timestamp corresponding to midnight UTC on that date.

    E.g. if the scheduler sets ‘next_rep’ to 2012/1/1 12:14 local time, this function will return the timestamp corresponding to 2012/1/1 00;00 UTC.

    Important: the timestamp needs to have the meaning of local time, not e.g. UTC, so calling midnight_UTC twice will give unexpected results.

  name = ''
  next_card(learn_ahead=False)
  next_rep_to_interval_string(next_rep, now=None)

    Converts next_rep to a string like ‘tomorrow’, ‘in 2 weeks’, …

  non_memorised_count()
  rebuild_queue(learn_ahead=False)

    Called by the rest of the library when an existing queue risks becoming invalid, e.g. when cards have been deleted in the GUI. ‘next_card’ also makes use of this in certain implementations.

  remove_from_queue_if_present(card)
  reset()

    Called when starting the scheduler for the first time.

  scheduled_count()
  set_initial_grade(cards, grade)

    Sets the initial grades for a set of sister cards, making sure their next repetitions do no fall on the same day.

    Called when cards are given their initial grade outside of the review process, e.g. when the user gives an initial grade when adding a new card in the GUI. Therefore, ‘unseen’ is still left to True, as this card has not yet been seen in the interactive review process.

    Cards which don’t have initial grade information available (e.g. for cards created during import or conversion from different card type), get their initial grade when they are encountered in the interactive review process for the first time.

    In both cases, this initial grading is seen as the first repetition.

    In this way, both types of cards are treated in the same way. (There is an ineffectual asymmetry left in the log messages they generate, but all the relevant information can still be parsed from them.)