File size: 13,362 Bytes
36d1c5d 5d50b4b 36d1c5d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | <?php
$title = 'Analytics Dashboard - Research Document Archive';
$content = '';
ob_start();
$sectionNames = [
'cia_declassified' => 'CIA Declassified',
'cia_mkultra' => 'CIA MKUltra',
'cia_stargate' => 'CIA Stargate',
'doj_disclosures' => 'DOJ Disclosures',
'house_resolutions' => 'House Resolutions',
'jfk_assassination' => 'JFK Assassination',
'lincoln_archives' => 'Lincoln Archives',
];
$sectionColors = [
'cia_declassified' => 'bg-red-500',
'cia_mkultra' => 'bg-purple-500',
'cia_stargate' => 'bg-indigo-500',
'doj_disclosures' => 'bg-amber-500',
'house_resolutions' => 'bg-blue-500',
'jfk_assassination' => 'bg-orange-500',
'lincoln_archives' => 'bg-emerald-500',
];
?>
<div class="mb-6">
<h1 class="text-2xl font-bold text-gray-900">Analytics Dashboard</h1>
<p class="mt-1 text-sm text-gray-600">Cross-collection analysis, topic profiles, and key findings across <?= number_format(array_sum(array_column($collectionSummary, 'docs'))) ?> documents.</p>
</div>
<!-- Collection Overview Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
<?php foreach ($collectionSummary as $section => $stats):
$color = $sectionColors[$section] ?? 'bg-gray-500';
?>
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-4">
<div class="flex items-center justify-between mb-2">
<h3 class="text-sm font-semibold text-gray-900"><?= htmlspecialchars($sectionNames[$section] ?? $section) ?></h3>
<div class="w-3 h-3 rounded-full <?= $color ?>"></div>
</div>
<div class="grid grid-cols-2 gap-2 text-xs">
<div>
<span class="text-gray-500">Documents</span>
<p class="font-semibold text-gray-900"><?= number_format($stats['docs'] ?? 0) ?></p>
</div>
<div>
<span class="text-gray-500">Pages</span>
<p class="font-semibold text-gray-900"><?= number_format($stats['pages'] ?? 0) ?></p>
</div>
<?php if (($stats['top_secret'] ?? 0) > 0): ?>
<div>
<span class="text-gray-500">TOP SECRET</span>
<p class="font-semibold text-red-700"><?= number_format($stats['top_secret']) ?></p>
</div>
<?php endif; ?>
<?php if (($stats['secret'] ?? 0) > 0): ?>
<div>
<span class="text-gray-500">SECRET</span>
<p class="font-semibold text-orange-700"><?= number_format($stats['secret']) ?></p>
</div>
<?php endif; ?>
<?php if (($stats['redacted_docs'] ?? 0) > 0): ?>
<div>
<span class="text-gray-500">Redacted</span>
<p class="font-semibold text-gray-800"><?= number_format($stats['redacted_docs']) ?></p>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<!-- Classification Stamps -->
<?php if (!empty($stamps)): ?>
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-4 mb-8">
<h2 class="text-sm font-semibold text-gray-700 mb-4">Classification Stamps Detected</h2>
<div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3">
<?php
$stampColors = [
'TOP SECRET' => 'border-red-300 bg-red-50 text-red-800',
'SECRET' => 'border-orange-300 bg-orange-50 text-orange-800',
'CONFIDENTIAL' => 'border-yellow-300 bg-yellow-50 text-yellow-800',
'CLASSIFIED' => 'border-amber-300 bg-amber-50 text-amber-800',
'UNCLASSIFIED' => 'border-green-300 bg-green-50 text-green-800',
'DECLASSIFIED' => 'border-emerald-300 bg-emerald-50 text-emerald-800',
'EYES ONLY' => 'border-red-300 bg-red-50 text-red-800',
'NOFORN' => 'border-rose-300 bg-rose-50 text-rose-800',
'REDACTED' => 'border-gray-600 bg-gray-800 text-white',
];
foreach ($stamps as $s):
$sColor = $stampColors[$s['classification']] ?? 'border-gray-300 bg-gray-50 text-gray-700';
?>
<div class="border rounded-lg p-3 text-center <?= $sColor ?>">
<p class="text-[10px] font-bold uppercase"><?= htmlspecialchars($s['classification']) ?></p>
<p class="text-lg font-bold mt-1"><?= number_format((int)$s['doc_count']) ?></p>
<p class="text-[10px] opacity-70">documents</p>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<!-- Topic Profiles -->
<?php if (!empty($topicProfiles)): ?>
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-4 mb-8">
<h2 class="text-sm font-semibold text-gray-700 mb-4">Topic Profiles by Collection</h2>
<div class="overflow-x-auto">
<table class="min-w-full text-xs">
<thead>
<tr class="border-b border-gray-200">
<th class="px-3 py-2 text-left font-semibold text-gray-500 uppercase">Collection</th>
<th class="px-3 py-2 text-left font-semibold text-gray-500 uppercase" colspan="3">Top Topics</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
<?php foreach ($topicProfiles as $section => $topics):
arsort($topics);
$top3 = array_slice($topics, 0, 3, true);
?>
<tr>
<td class="px-3 py-2.5 font-medium text-gray-900">
<?= htmlspecialchars($sectionNames[$section] ?? $section) ?>
</td>
<?php foreach ($top3 as $topic => $pct): ?>
<td class="px-3 py-2.5">
<div class="flex items-center gap-2">
<div class="w-16 bg-gray-200 rounded-full h-1.5">
<div class="bg-blue-500 h-1.5 rounded-full" style="width: <?= min(100, $pct * 100) ?>%"></div>
</div>
<span class="text-gray-700"><?= htmlspecialchars($topic) ?></span>
<span class="text-gray-400"><?= number_format($pct * 100, 1) ?>%</span>
</div>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<!-- Sentiment Analysis -->
<?php if (!empty($sentimentSummary)): ?>
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-4 mb-8">
<h2 class="text-sm font-semibold text-gray-700 mb-4">Sentiment Analysis by Collection</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<?php foreach ($sentimentSummary as $section => $sent):
$pol = $sent['avg_polarity'];
$sub = $sent['avg_subjectivity'];
// Color based on polarity
if ($pol > 0.05) { $polColor = 'text-green-700'; $polBg = 'bg-green-100'; $polLabel = 'Positive'; }
elseif ($pol < -0.05) { $polColor = 'text-red-700'; $polBg = 'bg-red-100'; $polLabel = 'Negative'; }
else { $polColor = 'text-gray-700'; $polBg = 'bg-gray-100'; $polLabel = 'Neutral'; }
?>
<div class="border border-gray-200 rounded-lg p-3">
<h3 class="text-xs font-semibold text-gray-900 mb-2"><?= htmlspecialchars($sectionNames[$section] ?? $section) ?></h3>
<div class="space-y-2">
<div>
<div class="flex justify-between text-[10px] text-gray-500 mb-0.5">
<span>Polarity</span>
<span class="font-medium <?= $polColor ?>"><?= $polLabel ?> (<?= number_format($pol, 3) ?>)</span>
</div>
<div class="relative w-full bg-gray-200 rounded-full h-2">
<div class="absolute left-1/2 w-0.5 h-2 bg-gray-400"></div>
<div class="<?= $pol >= 0 ? 'bg-green-400' : 'bg-red-400' ?> h-2 rounded-full absolute"
style="<?= $pol >= 0 ? 'left:50%;width:'.min(50,$pol*500).'%' : 'right:50%;width:'.min(50,abs($pol)*500).'%' ?>"></div>
</div>
</div>
<div>
<div class="flex justify-between text-[10px] text-gray-500 mb-0.5">
<span>Subjectivity</span>
<span class="font-medium"><?= number_format($sub, 3) ?></span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2">
<div class="bg-blue-400 h-2 rounded-full" style="width: <?= min(100, $sub * 100) ?>%"></div>
</div>
</div>
</div>
<p class="text-[10px] text-gray-400 mt-1"><?= number_format($sent['doc_count']) ?> documents</p>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
<!-- Collection Similarity -->
<?php if (!empty($similarities)): ?>
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-4">
<h2 class="text-sm font-semibold text-gray-700 mb-4">Collection Similarity (Jaccard Index)</h2>
<div class="space-y-2">
<?php foreach (array_slice($similarities, 0, 15) as $s):
$pct = $s['jaccard'] * 100;
$barWidth = min(100, $pct * 50); // scale up for visibility
?>
<div>
<div class="flex justify-between items-center text-xs mb-0.5">
<span class="text-gray-700">
<?= htmlspecialchars($sectionNames[$s['section_a']] ?? $s['section_a']) ?>
↔
<?= htmlspecialchars($sectionNames[$s['section_b']] ?? $s['section_b']) ?>
</span>
<span class="text-gray-500 font-mono">
<?= number_format($s['shared_count']) ?> shared
</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-1.5">
<div class="bg-indigo-500 h-1.5 rounded-full" style="width: <?= $barWidth ?>%"></div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<!-- Bridge Entities -->
<?php if (!empty($bridgePersons)): ?>
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-4">
<h2 class="text-sm font-semibold text-gray-700 mb-4">Bridge Entities (People Across Collections)</h2>
<div class="space-y-2 max-h-96 overflow-y-auto">
<?php foreach (array_slice($bridgePersons, 0, 25) as $bp): ?>
<div class="flex items-center justify-between py-1 border-b border-gray-100">
<div>
<span class="text-sm font-medium text-gray-900"><?= htmlspecialchars($bp['entity']) ?></span>
<span class="text-xs text-gray-500 ml-2"><?= $bp['doc_count'] ?> docs</span>
</div>
<div class="flex gap-1">
<?php foreach ($bp['sections'] ?? [] as $sec): ?>
<span class="inline-block w-2 h-2 rounded-full <?= $sectionColors[$sec] ?? 'bg-gray-400' ?>"
title="<?= htmlspecialchars($sectionNames[$sec] ?? $sec) ?>"></span>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
<!-- Bridge Organizations -->
<?php if (!empty($bridgeOrgs)): ?>
<div class="bg-white border border-gray-200 rounded-lg shadow-sm p-4 mb-8">
<h2 class="text-sm font-semibold text-gray-700 mb-4">Bridge Entities (Organizations Across Collections)</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2">
<?php foreach (array_slice($bridgeOrgs, 0, 30) as $bo): ?>
<div class="flex items-center justify-between py-1.5 px-2 rounded hover:bg-gray-50">
<span class="text-xs font-medium text-gray-800 truncate"><?= htmlspecialchars($bo['entity']) ?></span>
<div class="flex items-center gap-1.5 flex-shrink-0 ml-2">
<span class="text-[10px] text-gray-400"><?= $bo['collections'] ?> cols</span>
<?php foreach ($bo['sections'] ?? [] as $sec): ?>
<span class="inline-block w-1.5 h-1.5 rounded-full <?= $sectionColors[$sec] ?? 'bg-gray-400' ?>"></span>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php
$content = ob_get_clean();
include __DIR__ . '/layout.php';
?>
|