Window dashboard Money Saved to 30-day average
This commit is contained in:
@@ -1040,11 +1040,16 @@ func (s *Store) GetDashboardStats(ctx context.Context) (*DashboardStats, error)
|
||||
`).Scan(&d.UnpricedCount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// "Money saved" compares each item's current best price against its recent
|
||||
// market average. The average is windowed to the last 30 days so stale
|
||||
// historical prices don't anchor the baseline; items whose only price
|
||||
// history predates the window simply don't contribute an estimate.
|
||||
rows, err := s.DB.QueryContext(ctx, `
|
||||
SELECT i.best_price, AVG(p.price) AS avg_price
|
||||
FROM items i
|
||||
JOIN price_history p ON p.item_id = i.id
|
||||
WHERE i.active = 1 AND i.best_price IS NOT NULL
|
||||
AND p.polled_at >= datetime('now', '-30 day')
|
||||
GROUP BY i.id
|
||||
`)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user