42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Features\Dashboard\Services;
|
|
|
|
use App\Contracts\PriceRepository;
|
|
use App\Features\Dashboard\Data\DashboardData;
|
|
use Carbon\Carbon;
|
|
|
|
class DashboardService
|
|
{
|
|
public function __construct(
|
|
public PriceRepository $repository
|
|
) {}
|
|
|
|
public function getDashboardData(): DashboardData
|
|
{
|
|
$now = Carbon::now();
|
|
|
|
$electricity = $this->repository->retrieveElectricity();
|
|
|
|
$eNow = $electricity->whereBetween('startDate', [$now->copy()->subHour(), $now])->first();
|
|
$eCheapest = $electricity->where('totalPriceTaxIncluded', $electricity->min('totalPriceTaxIncluded'))->first();
|
|
$eDurable = $electricity->where('sustainabilityScore', $electricity->max('sustainabilityScore'))->first();
|
|
$ePriciest = $electricity->where('totalPriceTaxIncluded', $electricity->max('totalPriceTaxIncluded'))->first();
|
|
|
|
$gas = $this->repository->retrieveGas();
|
|
$gNow = $gas->whereBetween('startDate', [$now->copy()->setHour(0), $now])->first();
|
|
$gCheapest = $gas->where('totalPriceTaxIncluded', $gas->min('totalPriceTaxIncluded'))->first();
|
|
$gPriciest = $gas->where('totalPriceTaxIncluded', $gas->max('totalPriceTaxIncluded'))->first();
|
|
|
|
return new DashboardData(
|
|
$eNow,
|
|
$eCheapest,
|
|
$eDurable,
|
|
$ePriciest,
|
|
$gNow,
|
|
$gCheapest,
|
|
$gPriciest
|
|
);
|
|
}
|
|
}
|