Improve seeding of metric points

This commit is contained in:
James Brooks 2018-07-02 22:38:39 +01:00
parent f98ae4d38e
commit 5de9c94d55

View File

@ -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);
}
}