diff --git a/src/Console/Command/SetupFixtures.php b/src/Console/Command/SetupFixtures.php index 4451101ad..d79a0017d 100644 --- a/src/Console/Command/SetupFixtures.php +++ b/src/Console/Command/SetupFixtures.php @@ -1,11 +1,14 @@ 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;