feat: smart shopping extended horizon for staple items (closes #98)
Products used ≥ 4x/month (daily staples: latte, pane, uova) now appear in the smart shopping list when stock will deplete within 28 days (instead of 14). Products used ≥ 2x/month (weekly staples: yogurt, frutta, carne) appear within 21 days. The existing ≥1.5x/month rule at 14 days is unchanged. No manual pin or UI needed: frequency is detected automatically from transaction history. justRestocked guard prevents noise for freshly bought items.
This commit is contained in:
@@ -8622,6 +8622,24 @@ function smartShopping(PDO $db): void {
|
||||
}
|
||||
}
|
||||
|
||||
// Extended predictive horizon for staple items (high-frequency products).
|
||||
// The default predictive block triggers at daysLeft <= 14 for isFrequent (≥1.5/month).
|
||||
// Very frequent items (daily-ish: ≥4/month) or weekly items (≥2/month) should appear
|
||||
// in the shopping list earlier, so the user always has them on their radar when shopping.
|
||||
// ≥ 4/month → 28-day horizon (daily staples: latte, pane, uova…)
|
||||
// ≥ 2/month → 21-day horizon (weekly staples: yogurt, frutta, carne…)
|
||||
if ($urgency === 'none' && $dailyRate > 0 && $isRecent && !$justRestocked) {
|
||||
if ($usesPerMonth >= 4 && $daysLeft <= 28) {
|
||||
$urgency = 'low';
|
||||
$reasons[] = 'Finisce tra ~' . (int)round($daysLeft) . 'gg';
|
||||
$score += 20;
|
||||
} elseif ($usesPerMonth >= 2 && $daysLeft <= 21) {
|
||||
$urgency = 'low';
|
||||
$reasons[] = 'Finisce tra ~' . (int)round($daysLeft) . 'gg';
|
||||
$score += 15;
|
||||
}
|
||||
}
|
||||
|
||||
if ($urgency === 'none') continue;
|
||||
|
||||
// Family stock coverage: suppress items covered by other products in the same generic family.
|
||||
|
||||
Reference in New Issue
Block a user