mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 06:06:10 +00:00
Turn a metric's history into a small, bucketed, AI-ready shape: the last ~21 days verbatim at daily granularity, the ~10 weeks before that as ISO-week means, the ~12 months before that as calendar-month means, and everything older as yearly buckets with a least-squares trend slope. ~30-45 rows per metric regardless of history depth, never an individual reading beyond the recent window. A pure in-memory builder folds raw points; a rollup-backed builder sources the monthly/yearly slices from the pre-aggregated MONTH/YEAR tier (readBestGranularityRollups) and the recent/weekly slices from a bounded ~90-day raw read, so the coarse rollup tier finally earns its write amplification. The recent/weekly bucketing mirrors the coach's timeline split, duplicated here so the coach contract stays put.