From 5de9c94d55252900c7666665f777e8b313627ef1 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Mon, 2 Jul 2018 22:38:39 +0100 Subject: [PATCH] Improve seeding of metric points --- .../Commands/DemoMetricPointSeederCommand.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/DemoMetricPointSeederCommand.php b/app/Console/Commands/DemoMetricPointSeederCommand.php index e169f8f3..7d246e23 100644 --- a/app/Console/Commands/DemoMetricPointSeederCommand.php +++ b/app/Console/Commands/DemoMetricPointSeederCommand.php @@ -66,16 +66,26 @@ class DemoMetricPointSeederCommand extends Command { MetricPoint::truncate(); - // Generate 11 hours of metric points - for ($i = 0; $i < 11; $i++) { - $metricTime = (new DateTime())->sub(new DateInterval('PT'.$i.'H')); + $points = []; - MetricPoint::create([ - 'metric_id' => 1, - 'value' => random_int(1, 10), - 'created_at' => $metricTime, - 'updated_at' => $metricTime, - ]); + // Generate 24 hours of metric points + for ($i = 0; $i <= 23; $i++) { + for ($j = 0; $j <= 59; $j++) { + $this->info("{$i}:{$j}"); + + $pointTime = date("Y-m-d {$i}:{$j}:00"); + + $points[] = [ + 'metric_id' => 1, + 'value' => random_int(1, 10), + 'created_at' => $pointTime, + 'updated_at' => $pointTime, + ]; + } + } + + foreach (array_chunk($points, 100) as $chunk) { + MetricPoint::insert($chunk); } }