Open dmohns opened 1 month ago
Put this function into DummyDataCreator.php
and call it in line number 82. Then run command
php artisan dummy:create-data 100 --company-id={your companyId}
private function generateMeterConsumptionData(): void
{
try {
// get randomly a user
$randomMeter = $this->meter::inRandomOrder()->with([
'device',
'tariff',
])->limit(1)->firstOrFail();
} catch (ModelNotFoundException $x) {
echo 'failed to find a random meter';
return;
} catch (\Exception $x) {
echo 'boom';
return;
}
$readingDate = date('Y-m-d', strtotime('-'.mt_rand(0, 30).' days'));
$meterId = $randomMeter->id;
$totalConsumption = mt_rand(1, 1000)/ 10;
$dailyConsumption = mt_rand(1, 10) / 10;
$creditOnMeter = mt_rand(1, 10) / 10;
$meterConsumption = MeterConsumption::query()->create([
'meter_id' => $meterId,
'reading_date' => $readingDate,
'total_consumption' => $totalConsumption,
'daily_consumption' => $dailyConsumption,
'credit_on_meter' => $creditOnMeter,
]);
}
Currently, dummy data does not include MeterReading. Please add this to the dummy data generation.