Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(load balancer): update due dates histogram after review #1141

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/algorithms/osr/note-scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export function osrSchedule(
else if (interval < 30) fuzz = Math.max(2, Math.floor(interval * 0.15));
else fuzz = Math.max(4, Math.floor(interval * 0.05));

const fuzzedInterval = dueDateHistogram.findLeastUsedIntervalOverRange(interval, fuzz);
interval = fuzzedInterval;
interval = dueDateHistogram.findLeastUsedIntervalOverRange(interval, fuzz);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/flashcard-review-sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ISrsAlgorithm } from "src/algorithms/base/isrs-algorithm";
import { RepItemScheduleInfo } from "src/algorithms/base/rep-item-schedule-info";
import { ReviewResponse } from "src/algorithms/base/repetition-item";
import { Card } from "src/card";
import { TICKS_PER_DAY } from "src/constants";
import { DataStore } from "src/data-stores/base/data-store";
import { CardListType, Deck } from "src/deck";
import { IDeckTreeIterator } from "src/deck-tree-iterator";
Expand All @@ -11,6 +12,7 @@ import { Question, QuestionText } from "src/question";
import { IQuestionPostponementList } from "src/question-postponement-list";
import { SRSettings } from "src/settings";
import { TopicPath } from "src/topic-path";
import { globalDateProvider } from "src/utils/dates";

export interface IFlashcardReviewSequencer {
get hasCurrentCard(): boolean;
Expand Down Expand Up @@ -146,6 +148,8 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {

async processReviewReviewMode(response: ReviewResponse): Promise<void> {
if (response != ReviewResponse.Reset || this.currentCard.hasSchedule) {
const oldSchedule = this.currentCard.scheduleInfo;

// We need to update the schedule if:
// (1) the user reviewed with easy/good/hard (either a new or due card),
// (2) or reset a due card
Expand All @@ -154,6 +158,16 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {

// Update the source file with the updated schedule
await DataStore.getInstance().questionWriteSchedule(this.currentQuestion);

if (oldSchedule) {
const today: number = globalDateProvider.today.valueOf();
const nDays: number = Math.ceil(
(oldSchedule.dueDateAsUnix - today) / TICKS_PER_DAY,
);

this.dueDateFlashcardHistogram.decrement(nDays);
}
this.dueDateFlashcardHistogram.increment(this.currentCard.scheduleInfo.interval);
}

// Move/delete the card
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/scheduling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test("Test load balancing, small interval (load balancing disabled)", () => {
const newInterval: number = 3;
const dueDates = new DueDateHistogram({
0: 1,
1: 1, // key = originalInterval
1: 1,
2: 1,
3: 4,
});
Expand All @@ -121,9 +121,9 @@ test("Test load balancing, small interval (load balancing disabled)", () => {
expect(dueDates).toEqual(
new DueDateHistogram({
0: 1,
1: 0, // One less than before
1: 0,
2: 1,
3: 5, // One more than before
3: 5,
}),
);
});
Expand Down