OptimAIze Analysis Debug Information";
echo "";
echo "
";
// Check 1: Database Tables
echo "1. Database Tables Status ";
$tables = ['optimization_analysis_state', 'panel_directives', 'attributes'];
foreach ($tables as $table) {
$result = $db->query("SHOW TABLES LIKE '$table'");
if ($result && $result->num_rows > 0) {
$count = $db->query("SELECT COUNT(*) as count FROM $table")->fetch_assoc()['count'];
echo "✅ Table '$table' exists with $count records
";
} else {
echo "❌ Table '$table' missing
";
}
}
// Check 2: Analysis State
echo "2. Current Analysis State ";
$stateResult = $db->query("SELECT * FROM optimization_analysis_state ORDER BY id DESC LIMIT 1");
if ($stateResult && $stateResult->num_rows > 0) {
$state = $stateResult->fetch_assoc();
echo "";
echo "Field Value ";
foreach ($state as $key => $value) {
echo "$key $value ";
}
echo "
";
if ($state['is_running']) {
echo "⚠️ Analysis is currently marked as RUNNING
";
} else {
echo "ℹ️ Analysis is not running
";
}
} else {
echo "❌ No analysis state found
";
}
// Check 3: Panel Directives Breakdown
echo "3. Panel Directives Breakdown ";
$stats = [
'Total Directives' => "SELECT COUNT(*) as count FROM panel_directives",
'Checked by LLM' => "SELECT COUNT(*) as count FROM panel_directives WHERE llm_checked = 1",
'Not Checked' => "SELECT COUNT(*) as count FROM panel_directives WHERE llm_checked = 0",
'Impossible Found' => "SELECT COUNT(*) as count FROM panel_directives WHERE is_impossible = 1",
'Possible Found' => "SELECT COUNT(*) as count FROM panel_directives WHERE is_impossible = 0 AND llm_checked = 1",
'Approved' => "SELECT COUNT(*) as count FROM panel_directives WHERE status = 'approved'",
'Declined' => "SELECT COUNT(*) as count FROM panel_directives WHERE status = 'declined'",
'Pending' => "SELECT COUNT(*) as count FROM panel_directives WHERE status = 'pending'"
];
echo "";
echo "Category Count ";
foreach ($stats as $label => $query) {
$result = $db->query($query);
$count = $result ? $result->fetch_assoc()['count'] : 0;
echo "$label $count ";
}
echo "
";
// Check 4: Recent Activity
echo "4. Recent Analysis Activity ";
$recentQuery = $db->query("
SELECT id, attribute1_name, choice1, attribute2_name, choice2, is_impossible,
llm_reasoning, updated_at, llm_checked
FROM panel_directives
WHERE llm_checked = 1
ORDER BY updated_at DESC
LIMIT 10
");
if ($recentQuery && $recentQuery->num_rows > 0) {
echo "";
echo "ID Combination Result Reasoning Updated ";
while ($row = $recentQuery->fetch_assoc()) {
$combination = $row['attribute1_name'] . "=" . $row['choice1'] . " + " . $row['attribute2_name'] . "=" . $row['choice2'];
$result = $row['is_impossible'] ? 'IMPOSSIBLE ' : 'POSSIBLE ';
$reasoning = substr($row['llm_reasoning'], 0, 100) . '...';
echo "{$row['id']} $combination $result $reasoning {$row['updated_at']} ";
}
echo "
";
} else {
echo "⚠️ No recent analysis activity found
";
}
// Check 5: Attributes Available
echo "5. Attributes Available ";
$attrQuery = $db->query("SELECT id, name, choice_type FROM attributes ORDER BY id ASC");
if ($attrQuery && $attrQuery->num_rows > 0) {
echo "";
echo "ID Name Type Choices Count ";
while ($attr = $attrQuery->fetch_assoc()) {
$choicesQuery = $db->query("SELECT choices FROM attributes WHERE id = " . $attr['id']);
$choices = json_decode($choicesQuery->fetch_assoc()['choices'], true);
$choicesCount = is_array($choices) ? count($choices) : 0;
echo "{$attr['id']} {$attr['name']} {$attr['choice_type']} $choicesCount ";
}
echo "
";
} else {
echo "❌ No attributes found
";
}
// Check 6: Log File
echo "6. Analysis Log ";
$logFile = __DIR__ . '/optimization_analysis.log';
if (file_exists($logFile)) {
$logContent = file_get_contents($logFile);
$logLines = explode("\n", $logContent);
$recentLines = array_slice($logLines, -20); // Last 20 lines
echo "✅ Log file exists (" . filesize($logFile) . " bytes)
";
echo "Recent Log Entries: ";
echo "";
foreach ($recentLines as $line) {
if (trim($line)) {
echo htmlspecialchars($line) . " ";
}
}
echo "
";
} else {
echo "⚠️ Log file not found at: $logFile
";
}
// Check 7: GPT Configuration
echo "7. GPT Configuration ";
if (defined('OPENAI_API_KEY') && !empty(OPENAI_API_KEY)) {
$keyLength = strlen(OPENAI_API_KEY);
$maskedKey = substr(OPENAI_API_KEY, 0, 8) . str_repeat('*', $keyLength - 12) . substr(OPENAI_API_KEY, -4);
echo "✅ OpenAI API Key configured: $maskedKey
";
} else {
echo "❌ OpenAI API Key not configured
";
}
if (class_exists('GptHelper')) {
echo "✅ GptHelper class available
";
} else {
echo "❌ GptHelper class missing
";
}
// Check 8: File Permissions
echo "8. File Permissions ";
$files = [
'process_optimization_analysis.php',
'get_optimization_progress.php',
'start_optimization_analysis.php'
];
foreach ($files as $file) {
if (file_exists($file)) {
$perms = fileperms($file);
$permString = substr(sprintf('%o', $perms), -4);
echo "✅ $file exists (permissions: $permString)
";
} else {
echo "❌ $file missing
";
}
}
// Check 9: Manual Test Button
echo "9. Manual Actions ";
echo "Use these buttons to test functionality:
";
echo "Test Progress API ";
echo "Force Stop Analysis ";
echo "Reset Analysis State ";
echo "
";
// Check 10: Recommendations
echo "10. Recommendations ";
$totalDirectives = $db->query("SELECT COUNT(*) as count FROM panel_directives")->fetch_assoc()['count'];
$checkedDirectives = $db->query("SELECT COUNT(*) as count FROM panel_directives WHERE llm_checked = 1")->fetch_assoc()['count'];
$progress = $totalDirectives > 0 ? ($checkedDirectives / $totalDirectives) * 100 : 0;
if ($totalDirectives == 0) {
echo "❌ No directives found. Run 'Start Analysis' first to generate combinations.
";
} elseif ($progress < 1) {
echo "⚠️ Analysis seems stuck. Try the 'Reset Analysis State' button above and restart.
";
} elseif ($progress < 100) {
echo "ℹ️ Analysis is " . number_format($progress, 1) . "% complete. Be patient, this process takes time.
";
} else {
echo "✅ Analysis is complete! You can now review impossible combinations.
";
}
echo "";
?>