forked from st3v3nmw/obsidian-spaced-repetition
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
260 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { RepetitionItem } from "src/dataStore/repetitionItem"; | ||
import { DateUtils, debug } from "src/util/utils_recall"; | ||
|
||
export function postponeItems( | ||
items: RepetitionItem[], | ||
cnt?: number, | ||
days?: number, | ||
): RepetitionItem[] { | ||
const now = Date.now(); | ||
const newdue: number = days ? now + days * DateUtils.DAYS_TO_MILLIS : undefined; | ||
const fltItems = items | ||
.filter((item) => item.isTracked && item.nextReview < DateUtils.StartofToday) | ||
.sort((a, b) => currentRetention(a) - currentRetention(b)) | ||
// https://github.com/open-spaced-repetition/fsrs4anki-helper/blob/58bcfcf8b5eeb60835c5cbde1d0d0ef769af62b0/schedule/postpone.py#L73 | ||
.filter((item) => { | ||
// currentR>0.65 | ||
// const rate = (1 / currentRetention(item) - 1) / (1 / 0.9 - 1) - 1; | ||
// const rate = currentRetention(item) / 0.9 - 1; | ||
console.debug("current R:", currentRetention(item), 1 / currentRetention(item) - 1); | ||
return currentRetention(item) > 0.65; | ||
}); | ||
const safe_cnt = fltItems.length; | ||
debug("postpone", 0, { safe_cnt }); | ||
postpone(fltItems, newdue); | ||
return items; | ||
} | ||
|
||
function elapsed_days(item: RepetitionItem) { | ||
const delay = (Date.now() - item.nextReview) / DateUtils.DAYS_TO_MILLIS; | ||
return item.interval + delay; | ||
} | ||
function currentRetention(item: RepetitionItem) { | ||
// from fsrs.js repeat retrievability | ||
return Math.pow(1 + elapsed_days(item) / (9 * item.interval), -1); | ||
} | ||
|
||
function postpone(items: RepetitionItem[], newdue?: number): RepetitionItem[] { | ||
let cnt = 0; | ||
items.map((item) => { | ||
let newitvl: number, | ||
olastview = item.hasDue ? item.nextReview - item.interval*DateUtils.DAYS_TO_MILLIS : Date.now(); | ||
|
||
// reschedule, request Retention=0.9 | ||
// let interval = item.interval * 9 * (1 / 0.9 - 1); | ||
// newitvl = Math.min(Math.max(Math.round(interval), 1), 3650); | ||
|
||
const delay = (Date.now() - olastview) / DateUtils.DAYS_TO_MILLIS - item.interval; | ||
newitvl = Math.min( | ||
Math.max(1, Math.ceil(item.interval * (1.05 + 0.05 * Math.random())) + delay), | ||
36500, | ||
); | ||
// newdue = newdue ? newdue : Date.now() + newitvl * DateUtils.DAYS_TO_MILLIS; | ||
if (newitvl !== item.interval) { | ||
cnt++; | ||
item.updateDueInterval(newitvl, newdue); | ||
} | ||
}); | ||
debug("postpone", 0, { cnt }); | ||
return items; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { RepetitionItem } from "src/dataStore/repetitionItem"; | ||
import { DateUtils, debug } from "src/util/utils_recall"; | ||
import { SrsAlgorithm } from "../algorithms"; | ||
import { FsrsAlgorithm, FsrsData } from "../fsrs"; | ||
|
||
export function reschedule(items: RepetitionItem[]): RepetitionItem[] { | ||
let reCnt = 0; | ||
console.group(`reschedule`); | ||
if (items[0].isFsrs) { | ||
const result = reschedule_fsrs(items); | ||
reCnt = result.reCnt; | ||
} else { | ||
reCnt=reschedule_default(items).reCnt; | ||
} | ||
console.groupEnd(); | ||
debug("reschedule", 0, { items, reCnt }); | ||
return items; | ||
} | ||
|
||
function reschedule_default(items: RepetitionItem[]) { | ||
let reCnt = 0; | ||
|
||
items.map((item) => { | ||
let newitvl: number; | ||
|
||
let interval = item.interval * 9 * (1 / 0.9 - 1); | ||
newitvl = Math.min(Math.max(Math.round(interval), 1), 3650); | ||
if (newitvl !== item.interval) { | ||
reCnt++; | ||
item.updateDueInterval(newitvl); | ||
} | ||
}); | ||
|
||
// debug("reschedule", 0, { items, reCnt }); | ||
return { items, reCnt }; | ||
} | ||
|
||
function reschedule_fsrs(items: RepetitionItem[]) { | ||
let reCnt = 0; | ||
let fsrs = (SrsAlgorithm.getInstance() as FsrsAlgorithm).fsrs; | ||
|
||
items.map((item) => { | ||
let newitvl: number; | ||
if (!item.isTracked) return; | ||
const data = item.data as FsrsData; | ||
newitvl = fsrs.next_interval(data.stability); | ||
if (newitvl !== data.scheduled_days) { | ||
reCnt++; | ||
item.updateDueInterval(newitvl); | ||
} | ||
}); | ||
|
||
return { items, reCnt }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.