EnAccess / micropowermanager

Management Tool for Decentralized Utilities.
http://micropowermanager.io/
MIT License
0 stars 0 forks source link

Provide MeterReading dummy data #153

Open dmohns opened 1 month ago

dmohns commented 1 month ago

Currently, dummy data does not include MeterReading. Please add this to the dummy data generation.

dmohns commented 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,
    ]);
}