Files
pricebuddy/app/Services/Insights/DailyBestSeriesBuilder.php
Jeremy d1a8f1d009 feat: product insights tab
Add a Product Insights tab backed by a suite of price-analysis calculators and a
redesigned price history chart.

- Insights calculators: listing-history and daily best-price series builders,
  price stats, percentile, deal score, distribution, drop events, store showdown,
  seasonality, availability timeline, and target tracker
- ProductInsights aggregator service composing the calculators
- Price history chart: best-price and target datasets, best-price line honours the
  unit/retail filter, horizontal scroll on mobile
- Rename the History tab to Insights with consistent heading styling
- Feature and unit test coverage, plus review-feedback fixes
2026-06-18 23:13:14 +10:00

33 lines
763 B
PHP

<?php
namespace App\Services\Insights;
use App\Dto\Insights\ListingHistory;
use Illuminate\Support\Collection;
class DailyBestSeriesBuilder
{
/**
* @param Collection<int, ListingHistory> $listings
* @return Collection<string, float>
*/
public function fromListings(Collection $listings): Collection
{
$daily = [];
foreach ($listings as $listing) {
foreach ($listing->history as $date => $price) {
$price = (float) $price;
if ($price <= 0) {
continue;
}
$daily[$date] = isset($daily[$date]) ? min($daily[$date], $price) : $price;
}
}
ksort($daily);
return collect($daily);
}
}