diff --git a/src/algorithms/osr/note-scheduling.ts b/src/algorithms/osr/note-scheduling.ts index 3df9ef7c..0fd90b4a 100644 --- a/src/algorithms/osr/note-scheduling.ts +++ b/src/algorithms/osr/note-scheduling.ts @@ -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); } diff --git a/tests/unit/scheduling.test.ts b/tests/unit/scheduling.test.ts index 984f9dcb..557d093a 100644 --- a/tests/unit/scheduling.test.ts +++ b/tests/unit/scheduling.test.ts @@ -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, }); @@ -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( @@ -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, @@ -191,6 +211,32 @@ test("Test load balancing", () => { ease: DEFAULT_SETTINGS.baseEase, interval: 66, }); + + // interval > 180 + dueDates = new DueDateHistogram({ + 1245: 7, + 1246: 4, + 1247: 2, + 1248: 9, + 1249: 5, + 1250: 4, + 1251: 1, + 1252: 1, + 1254: 1, + }); + expect( + osrSchedule( + ReviewResponse.Good, + 500, + DEFAULT_SETTINGS.baseEase, + 0, + DEFAULT_SETTINGS, + dueDates, + ), + ).toEqual({ + ease: DEFAULT_SETTINGS.baseEase, + interval: 1253, + }); }); test("Test textInterval - desktop", () => {