🔍 OptimAIze Diagnostic Script"; echo ""; try { $db = Database::getInstance(); echo "
✅ Database connected
"; // Check 1: Current analysis state echo "

1. Current Analysis State

"; $stateQuery = $db->query("SELECT * FROM optimization_analysis_state ORDER BY id DESC LIMIT 1"); if ($stateQuery && $stateQuery->num_rows > 0) { $state = $stateQuery->fetch_assoc(); echo "
" . json_encode($state, JSON_PRETTY_PRINT) . "
"; if ($state['is_running']) { echo "
âš ī¸ Analysis is marked as running
"; } else { echo "
â„šī¸ Analysis is not running
"; } } else { echo "
âš ī¸ No analysis state found - creating initial state
"; $db->query("INSERT INTO optimization_analysis_state (total_combinations, processed_combinations, is_running) VALUES (0, 0, 0)"); } // Check 2: Panel directives status echo "

2. Panel Directives Status

"; $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"); $processed = $processedQuery->fetch_assoc()['processed']; $pendingQuery = $db->query("SELECT COUNT(*) as pending FROM panel_directives WHERE llm_checked = 0"); $pending = $pendingQuery->fetch_assoc()['pending']; echo "
📊 Total combinations: " . number_format($total) . "
"; echo "
📊 Processed: " . number_format($processed) . "
"; echo "
📊 Pending: " . number_format($pending) . "
"; if ($pending === 0) { echo "
✅ All combinations have been processed!
"; } else { echo "
âš ī¸ $pending combinations still need processing
"; } // Check 3: Test database updates echo "

3. Test Database Updates

"; echo ""; echo "
"; // Check 4: Test single API call echo "

4. Test API Call

"; echo ""; echo "
"; // Check 5: Show recent log entries echo "

5. Recent Log Entries

"; $logFile = 'logs/processor_debug.log'; if (file_exists($logFile)) { $logContent = file_get_contents($logFile); $lines = explode("\n", $logContent); $recentLines = array_slice($lines, -20); // Last 20 lines echo "
" . htmlspecialchars(implode("\n", $recentLines)) . "
"; } else { echo "
âš ī¸ No log file found at: $logFile
"; } // Check 6: Manual processing test echo "

6. Manual Processing Test

"; if ($pending > 0) { echo ""; echo "
"; } else { echo "
â„šī¸ No pending combinations to test
"; } } catch (Exception $e) { echo "
❌ Error: " . htmlspecialchars($e->getMessage()) . "
"; } ?> query("UPDATE optimization_analysis_state SET processed_combinations = processed_combinations + 1 WHERE id = 1"); if ($testUpdate) { echo "
✅ Database update successful
"; // Get current state $stateQuery = $db->query("SELECT * FROM optimization_analysis_state WHERE id = 1"); if ($stateQuery) { $state = $stateQuery->fetch_assoc(); echo "
" . json_encode($state, JSON_PRETTY_PRINT) . "
"; } } else { echo "
❌ Database update failed: " . $db->error . "
"; } } catch (Exception $e) { echo "
❌ Exception: " . htmlspecialchars($e->getMessage()) . "
"; } exit; } if ($_GET['action'] === 'test_api') { try { $result = GptHelper::analyzeCombination('Age', '5 years', 'Education', 'PhD'); if ($result['success']) { echo "
✅ API call successful
"; echo "
Result: " . ($result['is_impossible'] ? 'IMPOSSIBLE' : 'POSSIBLE') . "
"; echo "
Reasoning: " . htmlspecialchars($result['reasoning']) . "
"; if (isset($result['daily_cost'])) { echo "
Daily cost: $" . number_format($result['daily_cost'], 4) . "
"; } } else { echo "
❌ API call failed: " . htmlspecialchars($result['error']) . "
"; } } catch (Exception $e) { echo "
❌ Exception: " . htmlspecialchars($e->getMessage()) . "
"; } exit; } } ?>