query("SELECT id, attribute1_name, choice1, attribute2_name, choice2 FROM panel_directives WHERE llm_checked = 0 LIMIT 5"); if (!$query || $query->num_rows === 0) { echo json_encode([ 'success' => true, 'has_more' => false, 'processed' => 0, 'progress' => ['total' => 0, 'processed' => 0, 'remaining' => 0, 'percentage' => 100], 'message' => 'All combinations processed' ]); exit; } $processed = 0; $results = []; // Process all combinations in this batch while ($combo = $query->fetch_assoc()) { // Process the combination $result = GptHelper::analyzeCombination( $combo['attribute1_name'], $combo['choice1'], $combo['attribute2_name'], $combo['choice2'] ); if ($result['success']) { $isImpossible = $result['is_impossible'] ? 1 : 0; $reasoning = $result['reasoning']; // Update database $updateStmt = $db->prepare("UPDATE panel_directives SET llm_checked = 1, is_impossible = ?, llm_reasoning = ? WHERE id = ?"); $updateStmt->bind_param('isi', $isImpossible, $reasoning, $combo['id']); $updateStmt->execute(); $processed++; $results[] = [ 'combination' => "{$combo['attribute1_name']}={$combo['choice1']} + {$combo['attribute2_name']}={$combo['choice2']}", 'result' => $isImpossible ? 'IMPOSSIBLE' : 'POSSIBLE' ]; } else { // If one fails, return error echo json_encode([ 'success' => false, 'has_more' => true, 'error' => $result['error'], 'progress' => ['total' => 0, 'processed' => 0, 'remaining' => 0, 'percentage' => 0] ]); exit; } } // Get updated counts $totalQuery = $db->query("SELECT COUNT(*) as total FROM panel_directives"); $total = $totalQuery->fetch_assoc()['total']; $processedQuery = $db->query("SELECT COUNT(*) as processed FROM panel_directives WHERE llm_checked = 1"); $totalProcessed = $processedQuery->fetch_assoc()['processed']; $hasMore = $totalProcessed < $total; $percentage = $total > 0 ? ($totalProcessed / $total) * 100 : 100; echo json_encode([ 'success' => true, 'has_more' => $hasMore, 'processed' => $processed, 'progress' => [ 'total' => (int)$total, 'processed' => (int)$totalProcessed, 'remaining' => (int)($total - $totalProcessed), 'percentage' => round($percentage, 1) ], 'results' => $results, 'batch_size' => $processed ]); } catch (Exception $e) { echo json_encode([ 'success' => false, 'has_more' => false, 'error' => $e->getMessage(), 'progress' => ['total' => 0, 'processed' => 0, 'remaining' => 0, 'percentage' => 0] ]); } exit; } // BROWSER MODE - HTML output ?>
View OptimAIze Dashboard | Back to Main Site
"; } else { if (isset($_GET['process'])) { echo "▶️ Start Processing (Batch of 5)
"; echo "Note: This will process 5 combinations at a time. Click multiple times to process all.
"; } } } catch (Exception $e) { echo "Check your configuration and try again.
"; } ?>