datamatters24's picture
Upload web/src/views/dashboard.php with huggingface_hub
5d50b4b verified
<?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']) ?>
&harr;
<?= 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';
?>