From 63adcd8e315db1acc931b244874241be37305caa Mon Sep 17 00:00:00 2001 From: ishiko Date: Sat, 7 Sep 2024 03:06:58 +0800 Subject: [PATCH] bump ts-fsrs to 4.1.3 --- package-lock.json | 20 +++++--------------- package.json | 2 +- src/tsFsrsCalculator.ts | 21 +++++++++++---------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index f7a65ac..a061a4f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "chart.js": "^4.4.3", "chartjs-plugin-datalabels": "^2.2.0", "chartjs-plugin-zoom": "^2.0.1", - "ts-fsrs": "^3.5.7", + "ts-fsrs": "^4.1.3", "vue": "^3.4.30", "vue-chartjs": "^5.3.1" }, @@ -1376,12 +1376,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/seedrandom": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz", - "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==", - "license": "MIT" - }, "node_modules/semver": { "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", @@ -1438,15 +1432,11 @@ } }, "node_modules/ts-fsrs": { - "version": "3.5.7", - "resolved": "https://registry.npmjs.org/ts-fsrs/-/ts-fsrs-3.5.7.tgz", - "integrity": "sha512-xA18Igi1adkuCNgNjKkorjYgZq842+HdgRjatQPDERcrAWMlzM+3BwIbrF/Q0ijYEyw3NcTp3yJIMSO7agBLKQ==", - "license": "MIT", - "dependencies": { - "seedrandom": "^3.0.5" - }, + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/ts-fsrs/-/ts-fsrs-4.1.3.tgz", + "integrity": "sha512-UKZnDtATocNnZy/BaEE328Tn7DpEEl2Z/ocKqrGsvw1RgGw3B5i9OM/i5Gs87sXNP2eKOBqVMgw2vmiGY+4TVA==", "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" } }, "node_modules/typescript": { diff --git a/package.json b/package.json index 4413102..b52aada 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "chart.js": "^4.4.3", "chartjs-plugin-datalabels": "^2.2.0", "chartjs-plugin-zoom": "^2.0.1", - "ts-fsrs": "^3.5.7", + "ts-fsrs": "^4.1.3", "vue": "^3.4.30", "vue-chartjs": "^5.3.1" }, diff --git a/src/tsFsrsCalculator.ts b/src/tsFsrsCalculator.ts index 13c43de..cc09bef 100644 --- a/src/tsFsrsCalculator.ts +++ b/src/tsFsrsCalculator.ts @@ -24,24 +24,25 @@ export class TsFsrsCalculator implements IFsrsCalculator { const f = fsrs(generatorParameters({ w: this.w, - request_retention: this.desiredR + request_retention: this.desiredR, + enable_short_term: this.enableShortTerm })); for (const review of reviews) { const date = fsrs_card.due - const scheduling_cards = f.repeat(fsrs_card, date); - fsrs_card = scheduling_cards[review].card; + fsrs_card = f.next(fsrs_card, date, review, (recordItem) => { + const { card } = recordItem; + const interval = f.next_interval(card.stability, card.elapsed_days) + card.due = new Date(date.getTime() + interval * 24 * 60 * 60 * 1000); + card.scheduled_days = interval; + return card + }); const displayDifficulty = this.calcDisplayDifficulty(fsrs_card.difficulty); - const interval = f.next_interval(fsrs_card.stability, 0) + const interval = fsrs_card.scheduled_days; const cumulativeInterval = card.cumulativeInterval + interval; - if (fsrs_card.state != State.Review) { - fsrs_card.state = State.Review; - fsrs_card.due = new Date(date.getTime() + interval * 24 * 60 * 60 * 1000); - } - - list.push(new Card(0, fsrs_card.difficulty, displayDifficulty, fsrs_card.stability, interval, cumulativeInterval, review)); + list.push(new Card(fsrs_card.state, fsrs_card.difficulty, displayDifficulty, fsrs_card.stability, interval, cumulativeInterval, review)); } return list;