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 84aa9e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 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));

Check warning on line 47 in src/algorithms/osr/note-scheduling.ts

View check run for this annotation

Codecov / codecov/patch

src/algorithms/osr/note-scheduling.ts#L47

Added line #L47 was not covered by tests

interval = dueDateHistogram.findLeastUsedIntervalOverRange(interval, fuzz);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/scheduling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ test("Test load balancing", () => {
),
).toEqual({
ease: DEFAULT_SETTINGS.baseEase,
interval: 4,
interval: 5,
});

// 7 <= interval < 30
Expand Down

0 comments on commit 84aa9e8

Please sign in to comment.