Skip to content

Commit

Permalink
Fix/checking scheduling states (#14)
Browse files Browse the repository at this point in the history
* fix ignore relearning

* merge learning and relearning

* fix checking state of cards
  • Loading branch information
L-M-Sherlock authored Sep 22, 2022
1 parent d12ca3f commit eccd894
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fsrs4anki_optimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# FSRS4Anki v1.3.1 Optimizer"
"# FSRS4Anki v1.3.2 Optimizer"
]
},
{
Expand Down
64 changes: 58 additions & 6 deletions fsrs4anki_scheduler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// FSRS4Anki v1.3.1 Scheduler
// FSRS4Anki v1.3.2 Scheduler
// The latest version will be released on https://github.com/open-spaced-repetition/fsrs4anki

// Default parameters of FSRS4Anki
Expand All @@ -23,7 +23,7 @@ debugger;
const intervalModifier = Math.log(requestRetention) / Math.log(0.9);

// For new cards
if (states.current.normal?.new !== undefined | Object.hasOwn(states.current.filtered?.rescheduling?.originalState, 'new')) {
if (is_new()) {
customData.again.d = defaultDifficulty + 2;
customData.again.s = defaultStability * 0.25;
customData.hard.d = defaultDifficulty + 1;
Expand All @@ -33,8 +33,8 @@ if (states.current.normal?.new !== undefined | Object.hasOwn(states.current.filt
customData.easy.d = defaultDifficulty - 1;
customData.easy.s = defaultStability * 2;
states.easy.normal.review.scheduledDays = constrain_interval(customData.easy.s);
// For learing cards
} else if (states.current.normal?.learning !== undefined | Object.hasOwn(states.current.filtered?.rescheduling?.originalState, 'learning')) {
// For learning/relearning cards
} else if (is_learning()) {
const good_interval = constrain_interval(customData.good.s);
const easy_interval = Math.max(constrain_interval(customData.easy.s * easyBonus), good_interval + 1);
if (states.good.normal?.review) {
Expand All @@ -44,7 +44,7 @@ if (states.current.normal?.new !== undefined | Object.hasOwn(states.current.filt
states.easy.normal.review.scheduledDays = easy_interval;
}
// For review cards
} else if (states.current.normal?.review !== undefined | Object.hasOwn(states.current.filtered?.rescheduling?.originalState, 'review')) {
} else if (is_review()) {
// Convert the interval and factor to stability and difficulty if the card didn't contain customData
if (!customData.again.d) {
const old_d = constrain_difficulty(10 / states.current.normal.review.easeFactor);
Expand Down Expand Up @@ -102,4 +102,56 @@ function constrain_interval(interval) {

function next_stability(d, s, r) {
return s * (1 + Math.exp(increaseFactor) * Math.pow(d, difficultyDecay) * Math.pow(s, stabilityDecay) * (Math.exp((1 - r) * retrievabilityFactor) - 1));
}
}

function is_new() {
if (states.current.normal?.new !== undefined) {
if (states.current.normal?.new !== null) {
return true;
}
}
if (states.current.filtered?.rescheduling?.originalState !== undefined) {
if (Object.hasOwn(states.current.filtered?.rescheduling?.originalState, 'new')) {
return true;
}
}
return false;
}

function is_learning() {
if (states.current.normal?.learning !== undefined) {
if (states.current.normal?.learning !== null) {
return true;
}
}
if (states.current.filtered?.rescheduling?.originalState !== undefined) {
if (Object.hasOwn(states.current.filtered?.rescheduling?.originalState, 'learning')) {
return true;
}
}
if (states.current.normal?.relearning !== undefined) {
if (states.current.normal?.relearning !== null) {
return true;
}
}
if (states.current.filtered?.rescheduling?.originalState !== undefined) {
if (Object.hasOwn(states.current.filtered?.rescheduling?.originalState, 'relearning')) {
return true;
}
}
return false;
}

function is_review() {
if (states.current.normal?.review !== undefined) {
if (states.current.normal?.review !== null) {
return true;
}
}
if (states.current.filtered?.rescheduling?.originalState !== undefined) {
if (Object.hasOwn(states.current.filtered?.rescheduling?.originalState, 'review')) {
return true;
}
}
return false;
}
2 changes: 1 addition & 1 deletion fsrs4anki_simulator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"id": "jmXx-hS9ZMVj"
},
"source": [
"# FSRS4Anki v1.3.1 Simulator"
"# FSRS4Anki v1.3.2 Simulator"
]
},
{
Expand Down

0 comments on commit eccd894

Please sign in to comment.