Slightly refactor analytics function calls.
This commit is contained in:
parent
ab69db64c0
commit
9508de5b55
|
@ -8,7 +8,6 @@ use App\Entity;
|
|||
use App\Environment;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterface;
|
||||
use DateTimeInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
|
||||
|
@ -246,20 +245,13 @@ class SongHistoryRepository extends Repository
|
|||
|
||||
/**
|
||||
* @param Entity\Station $station
|
||||
* @param int|DateTimeInterface $start
|
||||
* @param int|DateTimeInterface $end
|
||||
* @param int $start
|
||||
* @param int $end
|
||||
*
|
||||
* @return mixed[] [int $minimumListeners, int $maximumListeners, float $averageListeners]
|
||||
*/
|
||||
public function getStatsByTimeRange(Entity\Station $station, $start, $end): array
|
||||
public function getStatsByTimeRange(Entity\Station $station, int $start, int $end): array
|
||||
{
|
||||
if ($start instanceof DateTimeInterface) {
|
||||
$start = $start->getTimestamp();
|
||||
}
|
||||
if ($end instanceof DateTimeInterface) {
|
||||
$end = $end->getTimestamp();
|
||||
}
|
||||
|
||||
$historyTotals = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT AVG(sh.listeners_end) AS listeners_avg, MAX(sh.listeners_end) AS listeners_max,
|
||||
|
|
|
@ -68,7 +68,7 @@ class RunAnalyticsTask extends AbstractTask
|
|||
}
|
||||
|
||||
$now = CarbonImmutable::now('UTC');
|
||||
$day = $now->subDays(5)->setTime(0, 0);// Clear existing analytics in this segment
|
||||
$day = $now->subDays(5)->startOfDay();// Clear existing analytics in this segment
|
||||
|
||||
$this->analyticsRepo->cleanup();
|
||||
$this->analyticsRepo->clearAllAfterTime($day);
|
||||
|
@ -90,7 +90,11 @@ class RunAnalyticsTask extends AbstractTask
|
|||
$start = $hourUtc->shiftTimezone($stationTz);
|
||||
$end = $start->addHour();
|
||||
|
||||
[$min, $max, $avg] = $this->historyRepo->getStatsByTimeRange($station, $start, $end);
|
||||
[$min, $max, $avg] = $this->historyRepo->getStatsByTimeRange(
|
||||
$station,
|
||||
$start->getTimestamp(),
|
||||
$end->getTimestamp()
|
||||
);
|
||||
|
||||
$unique = null;
|
||||
if ($withListeners) {
|
||||
|
@ -154,8 +158,8 @@ class RunAnalyticsTask extends AbstractTask
|
|||
|
||||
[$dailyStationMin, $dailyStationMax, $dailyStationAverage] = $this->historyRepo->getStatsByTimeRange(
|
||||
$station,
|
||||
$stationDayStart,
|
||||
$stationDayEnd
|
||||
$stationDayStart->getTimestamp(),
|
||||
$stationDayEnd->getTimestamp()
|
||||
);
|
||||
|
||||
if (null === $dailyMin) {
|
||||
|
|
Loading…
Reference in New Issue