Anki/rslib/src/revlog.rs
Damien Elmes 704b5e581a Rework reschedule tool
The old rescheduling dialog's two options have been split into two
separate menu items, "Forget", and "Set Due Date"

For cards that are not review cards, "Set Due Date" behaves like the
old reschedule option, changing the cards into a review card, and
and setting both the interval and due date to the provided number of
days.

When "Set Due Date" is applied to a review card, it no longer resets
the card's interval. Instead, it looks at how much the provided number
of days will change the original interval, and adjusts the interval by
that amount, so that cards that are answered earlier receive a smaller
next interval, and cards that are answered after a longer delay receive
a bonus.

For example, imagine a card was answered on day 5, and given an interval
of 10 days, so it has a due date of day 15.

- if on day 10 the due date is changed to day 12 (today+2), the card
is being scheduled 3 days earlier than it was supposed to be, so the
interval will be adjusted to 7 days.
- and if on day 10 the due date is changed to day 20, the interval will
be changed from 10 days to 15 days.

There is no separate option to reset the interval of a review card, but
it can be accomplished by forgetting the card(s), and then setting the
desired due date.

Other notes:

- Added the action to the review screen as well.
- Set the shortcut to Ctrl+Shift+D, and changed the existing Delete
Tags shortcut to Ctrl+Alt+Shift+A.
2021-02-07 21:57:51 +10:00

84 lines
2.7 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use crate::serde::{default_on_invalid, deserialize_int_from_number};
use crate::{define_newtype, prelude::*};
use num_enum::TryFromPrimitive;
use serde::Deserialize;
use serde_repr::{Deserialize_repr, Serialize_repr};
use serde_tuple::Serialize_tuple;
define_newtype!(RevlogID, i64);
#[derive(Serialize_tuple, Deserialize, Debug, Default, PartialEq)]
pub struct RevlogEntry {
pub id: TimestampMillis,
pub cid: CardID,
pub usn: Usn,
/// - In the V1 scheduler, 3 represents easy in the learning case.
/// - 0 represents manual rescheduling.
#[serde(rename = "ease")]
pub button_chosen: u8,
/// Positive values are in days, negative values in seconds.
#[serde(rename = "ivl", deserialize_with = "deserialize_int_from_number")]
pub interval: i32,
/// Positive values are in days, negative values in seconds.
#[serde(rename = "lastIvl", deserialize_with = "deserialize_int_from_number")]
pub last_interval: i32,
/// Card's ease after answering, stored as 10x the %, eg 2500 represents 250%.
#[serde(rename = "factor", deserialize_with = "deserialize_int_from_number")]
pub ease_factor: u32,
/// Amount of milliseconds taken to answer the card.
#[serde(rename = "time", deserialize_with = "deserialize_int_from_number")]
pub taken_millis: u32,
#[serde(rename = "type", default, deserialize_with = "default_on_invalid")]
pub review_kind: RevlogReviewKind,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, TryFromPrimitive, Clone, Copy)]
#[repr(u8)]
pub enum RevlogReviewKind {
Learning = 0,
Review = 1,
Relearning = 2,
EarlyReview = 3,
Manual = 4,
}
impl Default for RevlogReviewKind {
fn default() -> Self {
RevlogReviewKind::Learning
}
}
impl RevlogEntry {
pub(crate) fn interval_secs(&self) -> u32 {
(if self.interval > 0 {
self.interval * 86_400
} else {
-self.interval
}) as u32
}
}
impl Collection {
pub(crate) fn log_manually_scheduled_review(
&mut self,
card: &Card,
original: &Card,
usn: Usn,
) -> Result<()> {
let entry = RevlogEntry {
id: TimestampMillis::now(),
cid: card.id,
usn,
button_chosen: 0,
interval: card.interval as i32,
last_interval: original.interval as i32,
ease_factor: card.ease_factor as u32,
taken_millis: 0,
review_kind: RevlogReviewKind::Manual,
};
self.storage.add_revlog_entry(&entry)
}
}