db = Database::getInstance(); $this->loadExistingData(); $this->loadStatistics(); $this->loadAttributes(); } private function loadExistingData() { $result = $this->db->query("SELECT COUNT(*) as count FROM panel_data"); $this->existingCount = $result->fetch_assoc()['count']; // Load existing percentages if records exist if ($this->existingCount > 0) { // Calculate current percentages for each statistic // Store in $this->existingPercentages } } public function calculateOptimalCount() { $denominators = []; // Process all statistics foreach ($this->statistics as $stat) { $combinations = $this->getStatisticCombinations($stat['id']); foreach ($combinations as $combo) { $decimal = fmod($combo['percentage'], 1); if ($decimal > 0) { $denominators[] = 1 / $decimal; } } } // Calculate LCM of all denominators $optimalCount = $this->calculateLCM($denominators); // If existing records, calculate additional needed if ($this->existingCount > 0) { $nextMultiple = ceil($this->existingCount / $optimalCount) * $optimalCount; return $nextMultiple - $this->existingCount; } return $optimalCount; } public function generatePanelData($count) { $processedCount = 0; $batchSize = 100; // Process in batches for better performance while ($processedCount < $count) { $currentBatch = min($batchSize, $count - $processedCount); $this->generateBatch($currentBatch); $processedCount += $currentBatch; // Update progress $progress = ($processedCount / $count) * 100; $this->updateProgress($progress); } } private function generateBatch($size) { // Generate records that satisfy all statistical constraints // Use linear programming or similar algorithm to ensure all percentages are met } }