Skip to content

Commit

Permalink
refactor: make fuzzing less aggressive
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nmw committed Oct 21, 2024
1 parent e201b84 commit 552876b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
13 changes: 8 additions & 5 deletions src/algorithms/osr/note-scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ export function osrSchedule(
if (settings.loadBalance && dueDateHistogram !== undefined) {
interval = Math.round(interval);
// disable fuzzing for small intervals
if (interval > 4) {
let fuzz = 0;
if (interval < 7) fuzz = 1;
else if (interval < 30) fuzz = Math.max(2, Math.floor(interval * 0.15));
else fuzz = Math.max(4, Math.floor(interval * 0.05));
if (interval > 7) {
let fuzz: number;
// 3 day window: day - 1 <= x <= day + 1
if (interval <= 21) fuzz = 1;
// up to a week window: day - 3 <= x <= day + 3
else if (interval <= 180) fuzz = Math.min(3, Math.floor(interval * 0.05));
// up to a 2 weeks window: day - 7 <= x <= day + 7
else fuzz = Math.min(7, Math.floor(interval * 0.025));

interval = dueDateHistogram.findLeastUsedIntervalOverRange(interval, fuzz);
}
Expand Down
58 changes: 52 additions & 6 deletions tests/unit/scheduling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ test("Test load balancing, small interval (load balancing disabled)", () => {
});

test("Test load balancing", () => {
// interval < 7
// interval <= 7
let dueDates = new DueDateHistogram({
5: 2,
});
Expand All @@ -144,12 +144,33 @@ test("Test load balancing", () => {
),
).toEqual({
ease: DEFAULT_SETTINGS.baseEase,
interval: 4,
interval: 5,
});

// 7 < interval <= 21
dueDates = new DueDateHistogram({
17: 4,
18: 5,
19: 3,
});
expect(
osrSchedule(
ReviewResponse.Good,
7,
DEFAULT_SETTINGS.baseEase,
0,
DEFAULT_SETTINGS,
dueDates,
),
).toEqual({
ease: DEFAULT_SETTINGS.baseEase,
interval: 19,
});

// 7 <= interval < 30
// 21 < interval <= 180
dueDates = new DueDateHistogram({
25: 2,
23: 5,
26: 1,
});
expect(
osrSchedule(
Expand All @@ -162,10 +183,9 @@ test("Test load balancing", () => {
),
).toEqual({
ease: DEFAULT_SETTINGS.baseEase,
interval: 24,
interval: 25,
});

// interval >= 30
dueDates = new DueDateHistogram({
2: 5,
59: 8,
Expand All @@ -191,6 +211,32 @@ test("Test load balancing", () => {
ease: DEFAULT_SETTINGS.baseEase,
interval: 66,
});

// interval > 180
dueDates = new DueDateHistogram({
1245: 7,
1246: 4,
1248: 9,
1249: 5,
1250: 4,
1251: 1,
1252: 1,
1253: 1,
1254: 1,
});
expect(
osrSchedule(
ReviewResponse.Good,
500,
DEFAULT_SETTINGS.baseEase,
0,
DEFAULT_SETTINGS,
dueDates,
),
).toEqual({
ease: DEFAULT_SETTINGS.baseEase,
interval: 1250,
});
});

test("Test textInterval - desktop", () => {
Expand Down

0 comments on commit 552876b

Please sign in to comment.