mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
graduate card when user presses again or hard and has 0 learning steps (#3367)
* graduate card when user press hard and has 0 learning steps * fix error: useless conversion to the same type * do the same thing to again * fix expected `Option<u32>`, found integer * ./ninja format * Update to FSRS-rs v1.2.0 * if else -> match * Weight length check has been moved into FSRS (dae) * Don't mention the number of FSRS parameters (dae) It has changed, and may change again.
This commit is contained in:
parent
ce2f4136ea
commit
b7cb0c0d00
11 changed files with 81 additions and 71 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1901,9 +1901,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fsrs"
|
name = "fsrs"
|
||||||
version = "1.1.5"
|
version = "1.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f5b4e9d166a106007cc88e2ec7c01b107cf4999bbef71d74d32142cdf5277802"
|
checksum = "8a6f86707f3588ae410917427aa986e8b281fd0fad96480afd150f3e694c0d76"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"burn",
|
"burn",
|
||||||
"itertools 0.12.1",
|
"itertools 0.12.1",
|
||||||
|
|
|
@ -35,7 +35,7 @@ git = "https://github.com/ankitects/linkcheck.git"
|
||||||
rev = "184b2ca50ed39ca43da13f0b830a463861adb9ca"
|
rev = "184b2ca50ed39ca43da13f0b830a463861adb9ca"
|
||||||
|
|
||||||
[workspace.dependencies.fsrs]
|
[workspace.dependencies.fsrs]
|
||||||
version = "1.1.5"
|
version = "1.2.0"
|
||||||
# git = "https://github.com/open-spaced-repetition/fsrs-rs.git"
|
# git = "https://github.com/open-spaced-repetition/fsrs-rs.git"
|
||||||
# rev = "58ca25ed2bc4bb1dc376208bbcaed7f5a501b941"
|
# rev = "58ca25ed2bc4bb1dc376208bbcaed7f5a501b941"
|
||||||
# path = "../open-spaced-repetition/fsrs-rs"
|
# path = "../open-spaced-repetition/fsrs-rs"
|
||||||
|
|
|
@ -1252,7 +1252,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "fsrs",
|
"name": "fsrs",
|
||||||
"version": "1.1.5",
|
"version": "1.2.0",
|
||||||
"authors": "Open Spaced Repetition",
|
"authors": "Open Spaced Repetition",
|
||||||
"repository": "https://github.com/open-spaced-repetition/fsrs-rs",
|
"repository": "https://github.com/open-spaced-repetition/fsrs-rs",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
|
|
|
@ -335,7 +335,7 @@ deck-config-which-deck = Which deck would you like to display options for?
|
||||||
## Messages related to the FSRS scheduler
|
## Messages related to the FSRS scheduler
|
||||||
|
|
||||||
deck-config-updating-cards = Updating cards: { $current_cards_count }/{ $total_cards_count }...
|
deck-config-updating-cards = Updating cards: { $current_cards_count }/{ $total_cards_count }...
|
||||||
deck-config-invalid-weights = Parameters must be either left blank to use the defaults, or must be 17 comma-separated numbers.
|
deck-config-invalid-parameters = The provided FSRS parameters are invalid. Leave them blank to use the default parameters.
|
||||||
deck-config-not-enough-history = Insufficient review history to perform this operation.
|
deck-config-not-enough-history = Insufficient review history to perform this operation.
|
||||||
deck-config-unable-to-determine-desired-retention =
|
deck-config-unable-to-determine-desired-retention =
|
||||||
Unable to determine a minimum recommended retention.
|
Unable to determine a minimum recommended retention.
|
||||||
|
@ -512,3 +512,4 @@ deck-config-compute-optimal-retention-tooltip3 =
|
||||||
time for a greater recall rate. Setting your desired retention lower than the minimum is not recommended, as it will
|
time for a greater recall rate. Setting your desired retention lower than the minimum is not recommended, as it will
|
||||||
lead to a higher workload, because of the high forgetting rate.
|
lead to a higher workload, because of the high forgetting rate.
|
||||||
deck-config-seconds-to-show-question-tooltip-2 = When auto advance is activated, the number of seconds to wait before revealing the answer. Set to 0 to disable.
|
deck-config-seconds-to-show-question-tooltip-2 = When auto advance is activated, the number of seconds to wait before revealing the answer. Set to 0 to disable.
|
||||||
|
deck-config-invalid-weights = Parameters must be either left blank to use the defaults, or must be 17 comma-separated numbers.
|
||||||
|
|
|
@ -13,6 +13,7 @@ use anki_proto::deck_config::deck_configs_for_update::CurrentDeck;
|
||||||
use anki_proto::deck_config::UpdateDeckConfigsMode;
|
use anki_proto::deck_config::UpdateDeckConfigsMode;
|
||||||
use anki_proto::decks::deck::normal::DayLimit;
|
use anki_proto::decks::deck::normal::DayLimit;
|
||||||
use fsrs::DEFAULT_PARAMETERS;
|
use fsrs::DEFAULT_PARAMETERS;
|
||||||
|
use fsrs::FSRS;
|
||||||
|
|
||||||
use crate::config::I32ConfigKey;
|
use crate::config::I32ConfigKey;
|
||||||
use crate::config::StringKey;
|
use crate::config::StringKey;
|
||||||
|
@ -158,23 +159,13 @@ impl Collection {
|
||||||
|
|
||||||
// add/update provided configs
|
// add/update provided configs
|
||||||
for conf in &mut req.configs {
|
for conf in &mut req.configs {
|
||||||
let weight_len = conf.inner.fsrs_weights.len();
|
// we can remove this once https://github.com/open-spaced-repetition/fsrs-rs/pull/217/files
|
||||||
if weight_len == 19 {
|
// makes it into an FSRS release
|
||||||
for i in 0..19 {
|
if conf.inner.fsrs_weights.iter().any(|&w| !w.is_finite()) {
|
||||||
if !conf.inner.fsrs_weights[i].is_finite() {
|
|
||||||
return Err(AnkiError::FsrsWeightsInvalid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if weight_len == 17 {
|
|
||||||
for i in 0..17 {
|
|
||||||
if !conf.inner.fsrs_weights[i].is_finite() {
|
|
||||||
return Err(AnkiError::FsrsWeightsInvalid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
conf.inner.fsrs_weights.extend_from_slice(&[0.0, 0.0])
|
|
||||||
} else if weight_len != 0 {
|
|
||||||
return Err(AnkiError::FsrsWeightsInvalid);
|
return Err(AnkiError::FsrsWeightsInvalid);
|
||||||
}
|
}
|
||||||
|
// check the provided parameters are valid before we save them
|
||||||
|
FSRS::new(Some(&conf.inner.fsrs_weights))?;
|
||||||
self.add_or_update_deck_config(conf)?;
|
self.add_or_update_deck_config(conf)?;
|
||||||
configs_after_update.insert(conf.id, conf.clone());
|
configs_after_update.insert(conf.id, conf.clone());
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl AnkiError {
|
||||||
AnkiError::FsrsInsufficientReviews { count } => {
|
AnkiError::FsrsInsufficientReviews { count } => {
|
||||||
tr.deck_config_must_have_400_reviews(*count).into()
|
tr.deck_config_must_have_400_reviews(*count).into()
|
||||||
}
|
}
|
||||||
AnkiError::FsrsWeightsInvalid => tr.deck_config_invalid_weights().into(),
|
AnkiError::FsrsWeightsInvalid => tr.deck_config_invalid_parameters().into(),
|
||||||
AnkiError::SchedulerUpgradeRequired => {
|
AnkiError::SchedulerUpgradeRequired => {
|
||||||
tr.scheduling_update_required().replace("V2", "v3")
|
tr.scheduling_update_required().replace("V2", "v3")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ use anki_proto::scheduler::SimulateFsrsReviewRequest;
|
||||||
use anki_proto::scheduler::SimulateFsrsReviewResponse;
|
use anki_proto::scheduler::SimulateFsrsReviewResponse;
|
||||||
use fsrs::simulate;
|
use fsrs::simulate;
|
||||||
use fsrs::SimulatorConfig;
|
use fsrs::SimulatorConfig;
|
||||||
use fsrs::DEFAULT_PARAMETERS;
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::card::CardQueue;
|
use crate::card::CardQueue;
|
||||||
|
@ -48,19 +47,6 @@ impl Collection {
|
||||||
learn_limit: req.new_limit as usize,
|
learn_limit: req.new_limit as usize,
|
||||||
review_limit: req.review_limit as usize,
|
review_limit: req.review_limit as usize,
|
||||||
};
|
};
|
||||||
let parameters = if req.weights.is_empty() {
|
|
||||||
DEFAULT_PARAMETERS.to_vec()
|
|
||||||
} else if req.weights.len() != 19 {
|
|
||||||
if req.weights.len() == 17 {
|
|
||||||
let mut parameters = req.weights.to_vec();
|
|
||||||
parameters.extend_from_slice(&[0.0, 0.0]);
|
|
||||||
parameters
|
|
||||||
} else {
|
|
||||||
return Err(AnkiError::FsrsWeightsInvalid);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
req.weights.to_vec()
|
|
||||||
};
|
|
||||||
let (
|
let (
|
||||||
accumulated_knowledge_acquisition,
|
accumulated_knowledge_acquisition,
|
||||||
daily_review_count,
|
daily_review_count,
|
||||||
|
@ -68,11 +54,11 @@ impl Collection {
|
||||||
daily_time_cost,
|
daily_time_cost,
|
||||||
) = simulate(
|
) = simulate(
|
||||||
&config,
|
&config,
|
||||||
¶meters,
|
&req.weights,
|
||||||
req.desired_retention,
|
req.desired_retention,
|
||||||
None,
|
None,
|
||||||
Some(converted_cards),
|
Some(converted_cards),
|
||||||
);
|
)?;
|
||||||
Ok(SimulateFsrsReviewResponse {
|
Ok(SimulateFsrsReviewResponse {
|
||||||
accumulated_knowledge_acquisition: accumulated_knowledge_acquisition.to_vec(),
|
accumulated_knowledge_acquisition: accumulated_knowledge_acquisition.to_vec(),
|
||||||
daily_review_count: daily_review_count.iter().map(|x| *x as u32).collect_vec(),
|
daily_review_count: daily_review_count.iter().map(|x| *x as u32).collect_vec(),
|
||||||
|
|
|
@ -29,33 +29,65 @@ impl LearnState {
|
||||||
pub(crate) fn next_states(self, ctx: &StateContext) -> SchedulingStates {
|
pub(crate) fn next_states(self, ctx: &StateContext) -> SchedulingStates {
|
||||||
SchedulingStates {
|
SchedulingStates {
|
||||||
current: self.into(),
|
current: self.into(),
|
||||||
again: self.answer_again(ctx).into(),
|
again: self.answer_again(ctx),
|
||||||
hard: self.answer_hard(ctx).into(),
|
hard: self.answer_hard(ctx),
|
||||||
good: self.answer_good(ctx),
|
good: self.answer_good(ctx),
|
||||||
easy: self.answer_easy(ctx).into(),
|
easy: self.answer_easy(ctx).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn answer_again(self, ctx: &StateContext) -> LearnState {
|
fn answer_again(self, ctx: &StateContext) -> CardState {
|
||||||
|
let memory_state = ctx.fsrs_next_states.as_ref().map(|s| s.again.memory.into());
|
||||||
|
if let Some(again_delay) = ctx.steps.again_delay_secs_learn() {
|
||||||
LearnState {
|
LearnState {
|
||||||
remaining_steps: ctx.steps.remaining_for_failed(),
|
remaining_steps: ctx.steps.remaining_for_failed(),
|
||||||
scheduled_secs: ctx.steps.again_delay_secs_learn(),
|
scheduled_secs: again_delay,
|
||||||
elapsed_secs: 0,
|
elapsed_secs: 0,
|
||||||
memory_state: ctx.fsrs_next_states.as_ref().map(|s| s.again.memory.into()),
|
memory_state,
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
let (minimum, maximum) = ctx.min_and_max_review_intervals(1);
|
||||||
|
let interval = if let Some(states) = &ctx.fsrs_next_states {
|
||||||
|
states.again.interval
|
||||||
|
} else {
|
||||||
|
ctx.graduating_interval_good
|
||||||
|
};
|
||||||
|
ReviewState {
|
||||||
|
scheduled_days: ctx.with_review_fuzz(interval as f32, minimum, maximum),
|
||||||
|
ease_factor: ctx.initial_ease_factor,
|
||||||
|
memory_state,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn answer_hard(self, ctx: &StateContext) -> LearnState {
|
fn answer_hard(self, ctx: &StateContext) -> CardState {
|
||||||
|
let memory_state = ctx.fsrs_next_states.as_ref().map(|s| s.hard.memory.into());
|
||||||
|
if let Some(hard_delay) = ctx.steps.hard_delay_secs(self.remaining_steps) {
|
||||||
LearnState {
|
LearnState {
|
||||||
scheduled_secs: ctx
|
scheduled_secs: hard_delay,
|
||||||
.steps
|
|
||||||
.hard_delay_secs(self.remaining_steps)
|
|
||||||
// user has 0 learning steps, which the UI doesn't allow
|
|
||||||
.unwrap_or(60),
|
|
||||||
elapsed_secs: 0,
|
elapsed_secs: 0,
|
||||||
memory_state: ctx.fsrs_next_states.as_ref().map(|s| s.hard.memory.into()),
|
memory_state,
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
let (minimum, maximum) = ctx.min_and_max_review_intervals(1);
|
||||||
|
let interval = if let Some(states) = &ctx.fsrs_next_states {
|
||||||
|
states.hard.interval
|
||||||
|
} else {
|
||||||
|
ctx.graduating_interval_good
|
||||||
|
};
|
||||||
|
ReviewState {
|
||||||
|
scheduled_days: ctx.with_review_fuzz(interval as f32, minimum, maximum),
|
||||||
|
ease_factor: ctx.initial_ease_factor,
|
||||||
|
memory_state,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn answer_good(self, ctx: &StateContext) -> CardState {
|
fn answer_good(self, ctx: &StateContext) -> CardState {
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl RelearnState {
|
||||||
|
|
||||||
fn answer_again(self, ctx: &StateContext) -> CardState {
|
fn answer_again(self, ctx: &StateContext) -> CardState {
|
||||||
let (scheduled_days, memory_state) = self.review.failing_review_interval(ctx);
|
let (scheduled_days, memory_state) = self.review.failing_review_interval(ctx);
|
||||||
if let Some(again_delay) = ctx.relearn_steps.again_delay_secs_relearn() {
|
if let Some(again_delay) = ctx.relearn_steps.again_delay_secs_learn() {
|
||||||
RelearnState {
|
RelearnState {
|
||||||
learning: LearnState {
|
learning: LearnState {
|
||||||
remaining_steps: ctx.relearn_steps.remaining_for_failed(),
|
remaining_steps: ctx.relearn_steps.remaining_for_failed(),
|
||||||
|
|
|
@ -104,7 +104,7 @@ impl ReviewState {
|
||||||
memory_state,
|
memory_state,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(again_delay) = ctx.relearn_steps.again_delay_secs_relearn() {
|
if let Some(again_delay) = ctx.relearn_steps.again_delay_secs_learn() {
|
||||||
RelearnState {
|
RelearnState {
|
||||||
learning: LearnState {
|
learning: LearnState {
|
||||||
remaining_steps: ctx.relearn_steps.remaining_for_failed(),
|
remaining_steps: ctx.relearn_steps.remaining_for_failed(),
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
const DEFAULT_SECS_IF_MISSING: u32 = 60;
|
|
||||||
const DAY: u32 = 60 * 60 * 24;
|
const DAY: u32 = 60 * 60 * 24;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
@ -32,12 +31,7 @@ impl<'a> LearningSteps<'a> {
|
||||||
self.steps.get(index).copied().map(to_secs)
|
self.steps.get(index).copied().map(to_secs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cards in learning must always have at least one learning step.
|
pub(crate) fn again_delay_secs_learn(&self) -> Option<u32> {
|
||||||
pub(crate) fn again_delay_secs_learn(&self) -> u32 {
|
|
||||||
self.secs_at_index(0).unwrap_or(DEFAULT_SECS_IF_MISSING)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn again_delay_secs_relearn(&self) -> Option<u32> {
|
|
||||||
self.secs_at_index(0)
|
self.secs_at_index(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,16 +112,22 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn delay_secs() {
|
fn delay_secs() {
|
||||||
// if no other step, hard delay is 50% above again secs
|
// if no other step, hard delay is 50% above again secs
|
||||||
assert_delay_secs!([10.0], 1, 600, Some(900), None);
|
assert_delay_secs!([10.0], 1, Some(600), Some(900), None);
|
||||||
// but at most one day more than again secs
|
// but at most one day more than again secs
|
||||||
assert_delay_secs!([(3 * DAY / 60) as f32], 1, 3 * DAY, Some(4 * DAY), None);
|
assert_delay_secs!(
|
||||||
|
[(3 * DAY / 60) as f32],
|
||||||
|
1,
|
||||||
|
Some(3 * DAY),
|
||||||
|
Some(4 * DAY),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
|
||||||
assert_delay_secs!([1.0, 10.0], 2, 60, Some(330), Some(600));
|
assert_delay_secs!([1.0, 10.0], 2, Some(60), Some(330), Some(600));
|
||||||
assert_delay_secs!([1.0, 10.0], 1, 60, Some(600), None);
|
assert_delay_secs!([1.0, 10.0], 1, Some(60), Some(600), None);
|
||||||
|
|
||||||
assert_delay_secs!([1.0, 10.0, 100.0], 3, 60, Some(330), Some(600));
|
assert_delay_secs!([1.0, 10.0, 100.0], 3, Some(60), Some(330), Some(600));
|
||||||
assert_delay_secs!([1.0, 10.0, 100.0], 2, 60, Some(600), Some(6000));
|
assert_delay_secs!([1.0, 10.0, 100.0], 2, Some(60), Some(600), Some(6000));
|
||||||
assert_delay_secs!([1.0, 10.0, 100.0], 1, 60, Some(6000), None);
|
assert_delay_secs!([1.0, 10.0, 100.0], 1, Some(60), Some(6000), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue