(runs: MaintainRun[], nowMs: number)
| 131 | |
| 132 | /** Week-over-week self-improvement report from run timestamps. PURE (pass `nowMs`). */ |
| 133 | export function weeklyReport(runs: MaintainRun[], nowMs: number): MaintainWeekly { |
| 134 | const DAY = 86_400_000; |
| 135 | const inWindow = (r: MaintainRun, from: number, to: number) => { |
| 136 | const t = r.at ? Date.parse(r.at) : NaN; |
| 137 | return Number.isFinite(t) && t >= from && t < to; |
| 138 | }; |
| 139 | const thisWeek = runs.filter(r => inWindow(r, nowMs - 7 * DAY, nowMs)); |
| 140 | const priorWeek = runs.filter(r => inWindow(r, nowMs - 14 * DAY, nowMs - 7 * DAY)); |
| 141 | const opened = thisWeek.filter(r => r.status === 'opened'); |
| 142 | return { |
| 143 | opened: opened.length, |
| 144 | blocked: thisWeek.filter(r => r.status === 'blocked').length, |
| 145 | filesCleaned: opened.reduce((a, r) => a + (r.filesChanged || 0), 0), |
| 146 | minutesSaved: opened.length * 5, |
| 147 | priorOpened: priorWeek.filter(r => r.status === 'opened').length, |
| 148 | openedDelta: opened.length - priorWeek.filter(r => r.status === 'opened').length, |
| 149 | }; |
| 150 | } |
no test coverage detected