Skip to content

Commit

Permalink
Feat/grades (#43)
Browse files Browse the repository at this point in the history
* Feat/Grades

* 3.0.6
  • Loading branch information
ishiko732 authored Nov 4, 2023
1 parent 13dbecb commit 55c7ab5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
41 changes: 19 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cp .env.local.example .env.local
# Example

```typescript
import {createEmptyCard, formatDate, fsrs, generatorParameters, Rating} from 'ts-fsrs';
import {createEmptyCard, formatDate, fsrs, generatorParameters, Rating, Grades} from 'ts-fsrs';

const params = generatorParameters({ enable_fuzz: true });
const f = fsrs(params);
Expand All @@ -30,28 +30,25 @@ const now = new Date('2022-2-2 10:00:00');// new Date();
const scheduling_cards = f.repeat(card, now);

// console.log(scheduling_cards);
Object.keys(Rating)
.filter(key => !isNaN(Number(key)))
.map(key => Number(key) as Rating) // [Rating.Again, Rating.Hard, Rating.Good, Rating.Easy]
.forEach(grade => {
const { log, card } = scheduling_cards[grade];
console.group(`${Rating[grade]}`);
console.table({
[`card_${Rating[grade]}`]: {
...card,
due: formatDate(card.due),
last_review: formatDate(card.last_review as Date),
},
});
console.table({
[`log_${Rating[grade]}`]: {
...log,
review: formatDate(log.review),
},
});
console.groupEnd();
console.log('----------------------------------------------------------------');
Grades.forEach(grade => { // [Rating.Again, Rating.Hard, Rating.Good, Rating.Easy]
const { log, card } = scheduling_cards[grade];
console.group(`${Rating[grade]}`);
console.table({
[`card_${Rating[grade]}`]: {
...card,
due: formatDate(card.due),
last_review: formatDate(card.last_review as Date),
},
});
console.table({
[`log_${Rating[grade]}`]: {
...log,
review: formatDate(log.review),
},
});
console.groupEnd();
console.log('----------------------------------------------------------------');
});
```

> More examples refer to the [Example](https://github.com/ishiko732/ts-fsrs/blob/master/example/index.ts)
Expand Down
8 changes: 3 additions & 5 deletions __tests__/FSRSV4.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import {
generatorParameters,
FSRS,
createEmptyCard,
Grades,
} from "../src/fsrs";

describe("initial FSRS V4", () => {
const params = generatorParameters();
const f: FSRS = fsrs(params);
const Ratings = Object.keys(Rating)
.filter((key) => !isNaN(Number(key)))
.map((key) => Number(key) as Rating);
it("initial stability ", () => {
Ratings.forEach((grade) => {
Grades.forEach((grade) => {
const s = f.init_stability(grade);
expect(s).toEqual(params.w[grade - 1]);
});
Expand All @@ -26,7 +24,7 @@ describe("initial FSRS V4", () => {
});

it("initial difficulty ", () => {
Ratings.forEach((grade) => {
Grades.forEach((grade) => {
const s = f.init_difficulty(grade);
expect(s).toEqual(params.w[4] - (grade - 3) * params.w[5]);
});
Expand Down
5 changes: 5 additions & 0 deletions __tests__/help.tsts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Grades, Rating } from "../src/fsrs";

test("FSRS-Grades", () => {
expect(Grades).toStrictEqual([Rating.Again, Rating.Hard, Rating.Good, Rating.Easy]);
});
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": "3.0.5",
"version": "3.0.6",
"description": "ts-fsrs is a TypeScript package used to implement the Free Spaced Repetition Scheduler (FSRS) algorithm. It helps developers apply FSRS to their flashcard applications, thereby improving the user learning experience.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/fsrs/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const default_w = envParams.FSRS_W || [
];
export const default_enable_fuzz = envParams.FSRS_ENABLE_FUZZ || false;

export const FSRSVersion: string = "3.0.5";
export const FSRSVersion: string = "3.0.6";

export const generatorParameters = (props?: Partial<FSRSParameters>): FSRSParameters => {
return {
Expand Down
2 changes: 2 additions & 0 deletions src/fsrs/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,5 @@ export function fixRating(value: unknown): Rating {
}
throw new Error(`Invalid rating:[${value}]`);
}

export const Grades = [Rating.Again, Rating.Hard, Rating.Good, Rating.Easy];
1 change: 1 addition & 0 deletions src/fsrs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export {
date_diff,
formatDate,
show_diff_message,
Grades
} from "./help";

export type { int, double } from "./type";
Expand Down

0 comments on commit 55c7ab5

Please sign in to comment.