feat(#2): адаптивный шедулер — сдвигает напоминания на «хорошие» часы из истории
This commit is contained in:
@@ -6,6 +6,7 @@ import { getExercises, getHistory, getSettings, updateExercise } from './store'
|
||||
import { fireReminder } from './notifications'
|
||||
import { broadcastState } from './state-actions'
|
||||
import { isMeetingActiveSync, refreshMeetingState } from './meeting-detect'
|
||||
import { adjustNextFireAt } from './adaptive'
|
||||
|
||||
/**
|
||||
* Сколько reps пользователь сделал по упражнению `ex` за сегодня (local day).
|
||||
@@ -57,10 +58,12 @@ function checkDueExercises(): void {
|
||||
|
||||
const now = Date.now()
|
||||
const exercises = getExercises()
|
||||
// history запрашивается только если хотя бы у одного упражнения есть
|
||||
// dailyGoal — для большинства pure-interval упражнений не нужна.
|
||||
const anyGoal = exercises.some((e) => e.dailyGoal !== undefined)
|
||||
const history = anyGoal ? getHistory() : []
|
||||
// history запрашивается если у какого-нибудь упражнения есть
|
||||
// dailyGoal или adaptive: false — иначе экономим IPC-нагрузку.
|
||||
const needsHistory = exercises.some(
|
||||
(e) => e.dailyGoal !== undefined || e.adaptive
|
||||
)
|
||||
const history = needsHistory ? getHistory() : []
|
||||
let anyFired = false
|
||||
for (const ex of exercises) {
|
||||
if (!ex.enabled) continue
|
||||
@@ -77,9 +80,13 @@ function checkDueExercises(): void {
|
||||
continue
|
||||
}
|
||||
}
|
||||
const updated = updateExercise(ex.id, {
|
||||
nextFireAt: now + ex.intervalMinutes * 60_000
|
||||
})
|
||||
// Базовый candidate. Если adaptive — сдвигаем на «хороший» час
|
||||
// по исторической статистике успеха/скипов.
|
||||
let nextFireAt = now + ex.intervalMinutes * 60_000
|
||||
if (ex.adaptive) {
|
||||
nextFireAt = adjustNextFireAt(ex, nextFireAt, history)
|
||||
}
|
||||
const updated = updateExercise(ex.id, { nextFireAt })
|
||||
if (updated) {
|
||||
anyFired = true
|
||||
fireReminder(updated, settings.notificationMode)
|
||||
|
||||
Reference in New Issue
Block a user