Load some InfluxDB data in the fixtures so the charts aren't empty.
This commit is contained in:
parent
5cf2b35ef6
commit
43c28f3d6f
|
@ -1,11 +1,14 @@
|
|||
<?php
|
||||
namespace App\Console\Command;
|
||||
|
||||
use App\Entity\Station;
|
||||
use Azura\Console\Command\CommandAbstract;
|
||||
use Cake\Chronos\Chronos;
|
||||
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
|
||||
use Doctrine\Common\DataFixtures\Loader;
|
||||
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use InfluxDB\Database;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -36,6 +39,47 @@ class SetupFixtures extends CommandAbstract
|
|||
$executor = new ORMExecutor($em, $purger);
|
||||
$executor->execute($loader->getFixtures());
|
||||
|
||||
// Preload sample data.
|
||||
|
||||
$stations = $em->getRepository(Station::class)->findAll();
|
||||
|
||||
/** @var Database $influx */
|
||||
$influx = $this->get(Database::class);
|
||||
|
||||
$midnight_utc = Chronos::now('UTC')->setTime(0, 0);
|
||||
$influx_points = [];
|
||||
|
||||
for($i = 1; $i <= 14; $i++) {
|
||||
$day = $midnight_utc->subDays($i)->getTimestamp();
|
||||
|
||||
$day_listeners = 0;
|
||||
|
||||
foreach($stations as $station) {
|
||||
/** @var Station $station */
|
||||
|
||||
$station_listeners = random_int(1, 20);
|
||||
$day_listeners += $station_listeners;
|
||||
|
||||
$influx_points[] = new \InfluxDB\Point(
|
||||
'station.' . $station->getId() . '.listeners',
|
||||
$station_listeners,
|
||||
[],
|
||||
['station' => $station->getId()],
|
||||
$day
|
||||
);
|
||||
}
|
||||
|
||||
$influx_points[] = new \InfluxDB\Point(
|
||||
'station.all.listeners',
|
||||
$day_listeners,
|
||||
[],
|
||||
['station' => 0],
|
||||
$day
|
||||
);
|
||||
}
|
||||
|
||||
$influx->writePoints($influx_points, \InfluxDB\Database::PRECISION_SECONDS, '1d');
|
||||
|
||||
$output->writeln('Fixtures loaded.');
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue