Skip to content

Commit

Permalink
Show intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
xiety committed May 24, 2024
1 parent 598d746 commit bcca668
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
7 changes: 5 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<tr v-for="dataset in data.datasets">
<td>{{ dataset.label }}</td>
<td v-for="item in dataset.data">
{{ item.y.toFixed(2) }}
{{ item.stability.toFixed(2) }}
</td>
</tr>
</table>
Expand Down Expand Up @@ -148,7 +148,9 @@ watch(animation, a => {
}
});
const options = createOptions();
const options = createOptions((item: MyData) => {
return `${item.y} (${item.stability.toFixed(2)})`;
});
function getDataLabel(card: Card) {
const names = ["", "Again", "Hard", "Good", "Easy"];
Expand All @@ -159,6 +161,7 @@ function convertCardToMyData(card: Card): MyData {
return {
x: 0.0, //unused but required
y: card[mode.value] as number,
stability: card.stability,
label: getDataLabel(card)
};
}
Expand Down
9 changes: 5 additions & 4 deletions src/chartOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const zoomOptions: ZoomPluginOptions = {
}
};

export function createOptions(): ChartOptions<'line'> {
export function createOptions(tooltip: (raw: any) => string): ChartOptions<'line'> {
return {
responsive: true,
maintainAspectRatio: false,
Expand All @@ -35,8 +35,8 @@ export function createOptions(): ChartOptions<'line'> {
max: 75,
ticks: {
format: {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
minimumFractionDigits: 0,
maximumFractionDigits: 0,
},
}
}
Expand All @@ -56,7 +56,7 @@ export function createOptions(): ChartOptions<'line'> {
tooltip: {
callbacks: {
label: function (this: TooltipModel<"line">, tooltipItem: TooltipItem<"line">) {
return `${tooltipItem.parsed.y.toFixed(2)}`;
return tooltip(tooltipItem.raw);
}
}
},
Expand All @@ -71,4 +71,5 @@ export interface MyData {
x: number,
y: number,
label: string,
stability: number,
}
4 changes: 2 additions & 2 deletions src/fsrsCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class FsrsCalculator implements IFsrsCalculator {
}

calcInterval(r: number, s: number): number {
return (s / this.factor) * (Math.pow(r, 1.0 / this.decay) - 1.0);
return Math.max(1, Math.round((s / this.factor) * (Math.pow(r, 1.0 / this.decay) - 1.0)));
}

calcRetention(interval: number, s: number): number {
Expand Down Expand Up @@ -66,7 +66,7 @@ export class FsrsCalculator implements IFsrsCalculator {
if (grade < 1 || grade > 4)
return card;

const retention = this.calcRetention(Math.max(1, Math.round(card.interval)), card.stability);
const retention = this.calcRetention(card.interval, card.stability);
const difficulty = this.calcNextDifficulty(card, grade);
const stability = this.calcNextStability(card, grade, retention);
const displayDifficulty = this.calcDisplayDifficulty(difficulty);
Expand Down
21 changes: 7 additions & 14 deletions src/tsFsrsCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ import { Card, type IFsrsCalculator } from "./IFsrsCalculator";
export class TsFsrsCalculator implements IFsrsCalculator {
readonly w: number[];
readonly desiredR: number;
readonly decay: number;
readonly factor: number;

public constructor(w: number[], m: number[]) {
this.w = w;
this.desiredR = m[0];
this.decay = -0.5;
this.factor = 19.0 / 81.0;
}

calcInterval(r: number, s: number): number {
return (s / this.factor) * (Math.pow(r, 1.0 / this.decay) - 1.0);
}

calcDisplayDifficulty(d: number) {
Expand All @@ -29,21 +21,22 @@ export class TsFsrsCalculator implements IFsrsCalculator {
let card = new Card(true, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
const list = [];

const f = fsrs(generatorParameters({ w: this.w }));
const f = fsrs(generatorParameters({
w: this.w,
request_retention: this.desiredR
}));

for (const review of reviews) {
const date = fsrs_card.due;
const scheduling_cards = f.repeat(fsrs_card, date);
const scheduling_cards = f.repeat(fsrs_card, fsrs_card.due);
fsrs_card = scheduling_cards[<Grade>review].card;

const displayDifficulty = this.calcDisplayDifficulty(fsrs_card.difficulty);
const interval = this.calcInterval(this.desiredR, fsrs_card.stability);
const interval = f.next_interval(fsrs_card.stability, 0)
const cumulativeInterval = card.cumulativeInterval + interval;

if (fsrs_card.state != State.Review) {
fsrs_card.state = State.Review;
const days = Math.max(1, Math.round(interval));
fsrs_card.due = new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
fsrs_card.due = new Date(fsrs_card.due.getTime() + interval * 24 * 60 * 60 * 1000);
}

card = new Card(false, fsrs_card.difficulty, displayDifficulty, fsrs_card.stability, interval, cumulativeInterval, review);
Expand Down

0 comments on commit bcca668

Please sign in to comment.