isLoggedIn()) { throw new Exception('Unauthorized'); } $db = Database::getInstance(); // Load GptHelper if (!class_exists('GptHelper')) { require_once 'includes/GptHelper.php'; } if (!class_exists('GptHelper')) { throw new Exception('GptHelper class not found'); } // Get a small batch to process $batchSize = 3; // Small batch for reliability $query = $db->query(" SELECT id, attribute1_id, attribute2_id, choice1, choice2, attribute1_name, attribute2_name FROM panel_directives WHERE llm_checked = 0 ORDER BY id ASC LIMIT $batchSize "); $combinations = []; $processed = 0; $errors = 0; if ($query && $query->num_rows > 0) { while ($combination = $query->fetch_assoc()) { try { $result = processCombination($combination, $db); $combinations[] = [ 'id' => $combination['id'], 'combination' => "{$combination['attribute1_name']}={$combination['choice1']} + {$combination['attribute2_name']}={$combination['choice2']}", 'result' => $result['success'] ? ($result['is_impossible'] ? 'IMPOSSIBLE' : 'POSSIBLE') : 'ERROR', 'reasoning' => $result['success'] ? substr($result['reasoning'], 0, 100) : $result['error'] ]; if ($result['success']) { $processed++; } else { $errors++; } } catch (Exception $e) { $errors++; $combinations[] = [ 'id' => $combination['id'], 'combination' => "{$combination['attribute1_name']}={$combination['choice1']} + {$combination['attribute2_name']}={$combination['choice2']}", 'result' => 'ERROR', 'reasoning' => $e->getMessage() ]; } } } // Check if more combinations exist $remainingQuery = $db->query("SELECT COUNT(*) as count FROM panel_directives WHERE llm_checked = 0"); $remaining = $remainingQuery->fetch_assoc()['count']; // Get total progress $totalQuery = $db->query("SELECT COUNT(*) as count FROM panel_directives"); $total = $totalQuery->fetch_assoc()['count']; $processedTotal = $db->query("SELECT COUNT(*) as count FROM panel_directives WHERE llm_checked = 1")->fetch_assoc()['count']; echo json_encode([ 'success' => true, 'processed' => $processed, 'errors' => $errors, 'combinations' => $combinations, 'has_more' => $remaining > 0, 'progress' => [ 'total' => $total, 'processed' => $processedTotal, 'remaining' => $remaining, 'percentage' => $total > 0 ? round(($processedTotal / $total) * 100, 2) : 0 ] ]); } catch (Exception $e) { echo json_encode([ 'success' => false, 'message' => $e->getMessage(), 'error_type' => 'exception' ]); } exit; } // Regular page display try { $auth = new Auth(); if (!$auth->isLoggedIn()) { die("❌ Please log in first"); } $db = Database::getInstance(); // Get current statistics $totalQuery = $db->query("SELECT COUNT(*) as count FROM panel_directives"); $total = $totalQuery->fetch_assoc()['count']; $processedQuery = $db->query("SELECT COUNT(*) as count FROM panel_directives WHERE llm_checked = 1"); $processed = $processedQuery->fetch_assoc()['count']; $impossibleQuery = $db->query("SELECT COUNT(*) as count FROM panel_directives WHERE llm_checked = 1 AND is_impossible = 1"); $impossible = $impossibleQuery->fetch_assoc()['count']; $remaining = $total - $processed; $percentage = $total > 0 ? round(($processed / $total) * 100, 2) : 0; } catch (Exception $e) { die("❌ Error: " . htmlspecialchars($e->getMessage())); } ?> Simple Foreground Processor

🚀 Simple Foreground Processor

📊 Current Statistics

Total Combinations
Processed
Impossible Found
Remaining
% Complete

🎮 Processing Controls

Ready to start processing

📋 Processing Log

Ready to start processing. Click "Start Processing" to begin.

🔗 Navigation

Back to OptimAIze Page Back to Diagnostics
'system', 'content' => 'You are an expert demographic analyst. Analyze if the given combination is logically possible.' ], [ 'role' => 'user', 'content' => $prompt ] ]; $response = GptHelper::makeRequest($messages, 'gpt-4', 0.1); if (!$response['success']) { throw new Exception("GPT request failed: " . $response['error']); } $content = trim($response['response']); $isImpossible = stripos($content, 'IMPOSSIBLE') === 0 ? 1 : 0; // Extract reasoning $reasoning = trim(str_ireplace(['POSSIBLE', 'IMPOSSIBLE'], '', $content)); if (empty($reasoning)) { $reasoning = $content; } // Update database $stmt = $db->prepare("UPDATE panel_directives SET llm_checked = 1, is_impossible = ?, llm_reasoning = ?, updated_at = NOW() WHERE id = ?"); $stmt->bind_param('isi', $isImpossible, $reasoning, $combination['id']); if (!$stmt->execute()) { throw new Exception("Database update failed"); } return [ 'success' => true, 'is_impossible' => $isImpossible, 'reasoning' => $reasoning ]; } catch (Exception $e) { return [ 'success' => false, 'error' => $e->getMessage() ]; } } ?>