beewock

Untitled

Jul 9th, 2025
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. /**
  2.  * Generate progressive warm-up schedule.
  3.  *
  4.  * @param int $targetVolumePerIp  Total email per IP selama masa warm-up
  5.  * @param int $days               Jumlah hari warm-up (default: 14)
  6.  * @return array                  Volume harian (progressive)
  7.  */
  8. function generateProgressiveWarmupSchedule(int $targetVolumePerIp, int $days = 14): array
  9. {
  10.     // Distribusi bobot eksponensial per hari (misalnya pangkat 1.5)
  11.     $weights = [];
  12.     $sumWeights = 0;
  13.  
  14.     for ($i = 1; $i <= $days; $i++) {
  15.         $weight = pow($i, 1.5); // makin ke akhir makin besar
  16.         $weights[] = $weight;
  17.         $sumWeights += $weight;
  18.     }
  19.  
  20.     // Hitung volume per hari berdasarkan proporsi bobot
  21.     $schedule = [];
  22.     $accumulated = 0;
  23.  
  24.     for ($i = 0; $i < $days; $i++) {
  25.         $volume = floor(($weights[$i] / $sumWeights) * $targetVolumePerIp);
  26.         $schedule[] = $volume;
  27.         $accumulated += $volume;
  28.     }
  29.  
  30.     // Distribusi sisa (akibat pembulatan) ke hari-hari akhir
  31.     $remainder = $targetVolumePerIp - $accumulated;
  32.     for ($i = $days - 1; $i >= 0 && $remainder > 0; $i--) {
  33.         $schedule[$i]++;
  34.         $remainder--;
  35.     }
  36.  
  37.     return $schedule;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment