2021-11-03 11:18:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
|
|
|
|
use App\Models\Brand;
|
|
|
|
|
use App\Models\BrandStat;
|
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
|
|
|
|
class BrandStatSeeder extends Seeder
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Run the database seeds.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-07-24 11:32:12 +02:00
|
|
|
public function run(): void
|
2021-11-03 11:18:19 +01:00
|
|
|
{
|
|
|
|
|
BrandStat::truncate();
|
2021-12-19 15:57:24 +01:00
|
|
|
// * On génère 1 an pour chaque marque.
|
2021-11-03 11:18:19 +01:00
|
|
|
$brands = Brand::all();
|
|
|
|
|
/** @var \App\Models\Brand $brand*/
|
|
|
|
|
foreach ($brands as $brand) {
|
|
|
|
|
$startDay = Carbon::now();
|
|
|
|
|
$total = rand(100, 99999);
|
2021-11-03 11:36:38 +01:00
|
|
|
$active = rand(2, 20) / 100;
|
|
|
|
|
$new = rand(10, 30) / 100;
|
2021-11-05 09:04:24 +01:00
|
|
|
for ($i = 365; $i > 0; $i--) {
|
2021-11-03 11:18:19 +01:00
|
|
|
$total += floor($i / 2);
|
2021-12-19 15:57:24 +01:00
|
|
|
// * Pourcentage active.
|
2021-11-05 09:04:24 +01:00
|
|
|
$pActive = $active + ($i * 100 / 365) / 100 - 0.2;
|
2021-11-03 16:27:00 +01:00
|
|
|
$pActive = $pActive < 0.3 ? 0.3 : $pActive;
|
2021-11-03 11:36:38 +01:00
|
|
|
$pInactive = 1 - $pActive;
|
2021-12-19 15:57:24 +01:00
|
|
|
// * Pourcentage nouveau.
|
2021-11-03 11:36:38 +01:00
|
|
|
$pNew = $new;
|
|
|
|
|
$pOld = 1 - $pNew;
|
2021-11-03 11:18:19 +01:00
|
|
|
|
|
|
|
|
$brandStat = new BrandStat([
|
2025-07-24 11:32:12 +02:00
|
|
|
'active' => \floor($total * $pActive),
|
|
|
|
|
'inactive' => \ceil($total * $pInactive),
|
|
|
|
|
'old_accounts' => \ceil($total * $pOld),
|
|
|
|
|
'new_accounts' => \floor($total * $pNew),
|
2021-11-03 11:18:19 +01:00
|
|
|
'total_accounts' => $total,
|
2021-12-19 15:57:24 +01:00
|
|
|
// 15% optin
|
2025-07-24 11:32:12 +02:00
|
|
|
'total_opt_in' => ceil($total * 0.15)
|
2021-11-03 11:18:19 +01:00
|
|
|
]);
|
|
|
|
|
$brandStat->brand()->associate($brand);
|
|
|
|
|
$brandStat->created_at = $startDay;
|
2021-12-19 15:57:24 +01:00
|
|
|
$brandStat->saveOrFail();
|
2021-11-03 11:18:19 +01:00
|
|
|
$startDay = $startDay->subDay();
|
2021-12-19 15:57:24 +01:00
|
|
|
}//end for
|
|
|
|
|
}//end foreach
|
2021-11-03 11:18:19 +01:00
|
|
|
}
|
|
|
|
|
}
|