fix: weekly chart prediction and data pipeline extraction#2014
fix: weekly chart prediction and data pipeline extraction#2014jycouet wants to merge 4 commits intonpmx-dev:mainfrom
Conversation
- extend estimation support to weekly (and daily) granularity - add linear regression prediction based on recent data points - extract prediction logic into chart-data-prediction utility - add configurable prediction points slider (0–30, default 4) - apply prediction before smoothing so partial periods don't skew curves
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughReplaces the legacy data-correction path in TrendsChart.vue with a new data-prediction pipeline (applyDataPipeline), adds bucket-aware utilities and extrapolation logic for partial periods (daily/weekly/monthly/yearly) in a new module app/utils/chart-data-prediction.ts, threads predictionPoints through settings and UI (persisted default 4, control 0–30), updates multi-series and single-series processing to use the pipeline, removes old extrapolation helpers, and adds an i18n key for "prediction". Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8518dbe0-f937-49f5-955e-3349033f19e0
📒 Files selected for processing (5)
app/components/Package/TrendsChart.vueapp/composables/useSettings.tsapp/utils/chart-data-prediction.tsi18n/locales/en.jsoni18n/schema.json
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
1dc9041 to
626d233
Compare
|
Sorry @graphieros when trying to address
Could you check it again? :/ Note: could you add the link to the package with modal & range, it goes faster to find it. Thx |
graphieros
left a comment
There was a problem hiding this comment.
These changes appear to fix the weekly estimations when start date is =! mod 7, but you will need to check if it's ok ^^
Also I feel this file should deserve a test too
| // --------------------------------------------------------------------------- | ||
| // Bucket boundaries (UTC) | ||
| // --------------------------------------------------------------------------- | ||
|
|
There was a problem hiding this comment.
const DAY_MS = 86_400_000
function getUtcDayStart(ts: number): number {
const d = new Date(ts)
return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate())
}
// Monday-based week start in UTC
function getWeeklyBucketStartUtc(ts: number): number {
const dayStart = getUtcDayStart(ts)
const day = new Date(dayStart).getUTCDay()
const diffFromMonday = (day + 6) % 7
return dayStart - diffFromMonday * DAY_MS
}| export function getBucketStartUtc(ts: number, g: ChartTimeGranularity): number { | ||
| const d = new Date(ts) | ||
| if (g === 'yearly') return Date.UTC(d.getUTCFullYear(), 0, 1) | ||
| if (g === 'monthly') return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1) |
There was a problem hiding this comment.
Now with
if (g === 'weekly') return getWeeklyBucketStartUtc(ts)
app/utils/chart-data-prediction.ts
Outdated
| const d = new Date(ts) | ||
| if (g === 'yearly') return Date.UTC(d.getUTCFullYear() + 1, 0, 1) | ||
| if (g === 'monthly') return Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 1) | ||
| if (g === 'weekly') return getBucketStartUtc(ts, 'daily') + 7 * 86_400_000 |
There was a problem hiding this comment.
Replaced with
if (g === 'weekly') return getWeeklyBucketStartUtc(ts) + 7 * DAY_MS
app/utils/chart-data-prediction.ts
Outdated
| const last = series.at(-1) ?? 0 | ||
|
|
||
| // Weekly dates are stored as timestampEnd; bucket start is 6 days earlier | ||
| const bucketTs = granularity === 'weekly' ? lastDateMs - 6 * 86_400_000 : lastDateMs |
There was a problem hiding this comment.
const bucketTs = lastDateMs






🔗 Linked issue
Closes: #2013
🧭 Context
Weekly chart displayed partial last-week buckets with very low values (1–2 days instead of 7), and prediction/estimation was only available for monthly & yearly granularity.
📚 Description
TrendsChart.vueinto a newchart-data-prediction.tsutilityapplyDataPipelinethat orchestrates: prediction → data correction (smoothing/averaging)Before
After