Slightly refactor analytics function calls.

This commit is contained in:
Buster "Silver Eagle" Neece 2021-02-08 22:50:25 -06:00
parent ab69db64c0
commit 9508de5b55
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
2 changed files with 11 additions and 15 deletions

View File

@ -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,

View File

@ -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) {