Skip to content

Commit

Permalink
Fix/update FSRS-4.5 params into FSRS-5 properly (#132)
Browse files Browse the repository at this point in the history
* Fix/update FSRS-4.5 param into FSRS-5 properly

* bump version to 4.4.2
  • Loading branch information
ishiko732 authored Oct 21, 2024
1 parent aaa1543 commit 2adce32
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions __tests__/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe('default params', () => {
it('default_enable_fuzz ', () => {
expect(params.enable_fuzz).toEqual(default_enable_fuzz)
})

it('convert FSRS 4.5 to FSRS-5', () => {
const params = generatorParameters({
w: [
0.4, 0.6, 2.4, 5.8, 4.93, 0.94, 0.86, 0.01, 1.49, 0.14, 0.94, 2.18,
0.05, 0.34, 1.26, 0.29, 2.61,
],
})
expect(params.w).toEqual([
0.4, 0.6, 2.4, 5.8, 6.81, 0.44675014, 0.86, 0.01, 1.49, 0.14, 0.94, 2.18,
0.05, 0.34, 1.26, 0.29, 2.61, 0.0, 0.0,
])
})
})

describe('default Card', () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-fsrs",
"version": "4.4.1",
"version": "4.4.2",
"description": "ts-fsrs is a versatile package based on TypeScript that supports ES modules, CommonJS, and UMD. It implements the Free Spaced Repetition Scheduler (FSRS) algorithm, enabling developers to integrate FSRS into their flashcard applications to enhance the user learning experience.",
"main": "dist/index.cjs",
"umd": "dist/index.umd.js",
Expand Down
4 changes: 3 additions & 1 deletion src/fsrs/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const default_w = [
export const default_enable_fuzz = false
export const default_enable_short_term = true

export const FSRSVersion: string = 'v4.4.1 using FSRS V5.0'
export const FSRSVersion: string = 'v4.4.2 using FSRS V5.0'

export const generatorParameters = (
props?: Partial<FSRSParameters>
Expand All @@ -22,6 +22,8 @@ export const generatorParameters = (
w = props?.w
} else if (props.w.length === 17) {
w = props?.w.concat([0.0, 0.0])
w[4] = +(w[5] * 2.0 + w[4]).toFixed(8)
w[5] = +(Math.log(w[5] * 3.0 + 1.0) / 3.0).toFixed(8)
console.debug('[FSRS V5]auto fill w to 19 length')
}
}
Expand Down

0 comments on commit 2adce32

Please sign in to comment.