Spaces:
Sleeping
Sleeping
Download admin_analytics.html from SimblyPaul/Tron: direct link, hf CLI and curl.
- Browser
- Download file 33.7 kB
-
https://huggingface.co/spaces/SimblyPaul/Tron/resolve/main/admin_analytics.html
- Command line
-
hf download hf://spaces/SimblyPaul/Tron/admin_analytics.html
-
curl -L -o admin_analytics.html https://huggingface.co/spaces/SimblyPaul/Tron/resolve/main/admin_analytics.html
33.7 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>TRON Sentiment Analytics Console</title> | |
| <!-- Google Fonts --> | |
| <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"> | |
| <!-- Chart.js CDN --> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <style> | |
| :root { | |
| --bg-base: #07090e; | |
| --bg-surface: #0f131a; | |
| --bg-surface-hover: #171d26; | |
| --border-color: #1e2633; | |
| --text-primary: #f8fafc; | |
| --text-secondary: #94a3b8; | |
| --text-muted: #64748b; | |
| --accent-valence: #38bdf8; /* Blue */ | |
| --accent-arousal: #f43f5e; /* Red */ | |
| --accent-dominance: #10b981; /* Green */ | |
| --accent-curious: #fbbf24; /* Amber */ | |
| --accent-neutral: #a855f7; /* Purple */ | |
| --radius-md: 12px; | |
| --radius-lg: 16px; | |
| --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); | |
| } | |
| * { | |
| box-sizing: border-box; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| body { | |
| font-family: 'Plus Jakarta Sans', sans-serif; | |
| background-color: var(--bg-base); | |
| color: var(--text-primary); | |
| min-height: 100vh; | |
| display: flex; | |
| flex-direction: column; | |
| overflow-x: hidden; | |
| } | |
| /* Header block */ | |
| header { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| padding: 20px 40px; | |
| border-bottom: 1px solid var(--border-color); | |
| background-color: var(--bg-surface); | |
| } | |
| .header-title h1 { | |
| font-size: 1.5rem; | |
| font-weight: 700; | |
| letter-spacing: -0.025em; | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| .header-title h1 span { | |
| color: var(--accent-valence); | |
| } | |
| .header-title p { | |
| font-size: 0.85rem; | |
| color: var(--text-secondary); | |
| margin-top: 2px; | |
| } | |
| .btn-home { | |
| padding: 10px 18px; | |
| background: linear-gradient(135deg, #1e293b, #0f172a); | |
| border: 1px solid var(--border-color); | |
| border-radius: var(--radius-md); | |
| color: var(--text-primary); | |
| font-size: 0.85rem; | |
| font-weight: 600; | |
| text-decoration: none; | |
| cursor: pointer; | |
| transition: var(--transition-smooth); | |
| } | |
| .btn-home:hover { | |
| border-color: var(--text-secondary); | |
| transform: translateY(-1px); | |
| } | |
| /* Top stats layout */ | |
| .stats-grid { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); | |
| gap: 20px; | |
| padding: 30px 40px; | |
| } | |
| .stat-card { | |
| background-color: var(--bg-surface); | |
| border: 1px solid var(--border-color); | |
| border-radius: var(--radius-lg); | |
| padding: 24px; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 8px; | |
| position: relative; | |
| overflow: hidden; | |
| transition: var(--transition-smooth); | |
| } | |
| .stat-card:hover { | |
| transform: translateY(-2px); | |
| border-color: var(--bg-surface-hover); | |
| } | |
| .stat-card::before { | |
| content: ''; | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 4px; | |
| height: 100%; | |
| background-color: var(--accent-valence); | |
| } | |
| .stat-card.purple::before { background-color: var(--accent-neutral); } | |
| .stat-card.green::before { background-color: var(--accent-dominance); } | |
| .stat-card.red::before { background-color: var(--accent-arousal); } | |
| .stat-label { | |
| font-size: 0.85rem; | |
| font-weight: 600; | |
| color: var(--text-secondary); | |
| text-transform: uppercase; | |
| letter-spacing: 0.05em; | |
| } | |
| .stat-value { | |
| font-size: 2.2rem; | |
| font-weight: 700; | |
| letter-spacing: -0.03em; | |
| } | |
| /* Main Workspace split */ | |
| .main-layout { | |
| display: grid; | |
| grid-template-columns: 320px 1fr; | |
| gap: 30px; | |
| padding: 0 40px 40px 40px; | |
| flex: 1; | |
| } | |
| /* Sidebar Column */ | |
| .sidebar { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 24px; | |
| } | |
| .panel { | |
| background-color: var(--bg-surface); | |
| border: 1px solid var(--border-color); | |
| border-radius: var(--radius-lg); | |
| padding: 20px; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 16px; | |
| } | |
| .panel-title { | |
| font-size: 0.95rem; | |
| font-weight: 700; | |
| text-transform: uppercase; | |
| letter-spacing: 0.04em; | |
| color: var(--text-primary); | |
| border-left: 3px solid var(--accent-valence); | |
| padding-left: 8px; | |
| } | |
| .list-container { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 8px; | |
| max-height: 380px; | |
| overflow-y: auto; | |
| } | |
| /* Custom scrollbar */ | |
| .list-container::-webkit-scrollbar { | |
| width: 6px; | |
| } | |
| .list-container::-webkit-scrollbar-thumb { | |
| background-color: var(--border-color); | |
| border-radius: 3px; | |
| } | |
| .list-item { | |
| padding: 12px 16px; | |
| background-color: rgba(255, 255, 255, 0.02); | |
| border: 1px solid var(--border-color); | |
| border-radius: var(--radius-md); | |
| cursor: pointer; | |
| transition: var(--transition-smooth); | |
| display: flex; | |
| flex-direction: column; | |
| gap: 4px; | |
| } | |
| .list-item:hover, .list-item.active { | |
| background-color: var(--bg-surface-hover); | |
| border-color: var(--text-secondary); | |
| } | |
| .list-item-title { | |
| font-size: 0.85rem; | |
| font-weight: 600; | |
| word-break: break-all; | |
| } | |
| .list-item-meta { | |
| font-size: 0.75rem; | |
| color: var(--text-muted); | |
| display: flex; | |
| justify-content: space-between; | |
| } | |
| /* Emotion parameters tags layout */ | |
| .emotion-grid { | |
| display: grid; | |
| grid-template-columns: repeat(2, 1fr); | |
| gap: 8px; | |
| } | |
| .emotion-tag { | |
| padding: 8px; | |
| background-color: rgba(255, 255, 255, 0.01); | |
| border: 1px solid var(--border-color); | |
| border-radius: 8px; | |
| font-size: 0.75rem; | |
| text-align: center; | |
| cursor: pointer; | |
| transition: var(--transition-smooth); | |
| font-weight: 500; | |
| } | |
| .emotion-tag:hover { | |
| border-color: var(--accent-valence); | |
| background-color: rgba(56, 189, 248, 0.05); | |
| } | |
| .emotion-tag.active { | |
| background-color: var(--accent-valence); | |
| border-color: var(--accent-valence); | |
| color: var(--bg-base); | |
| font-weight: 700; | |
| } | |
| /* Dashboard Main Panel Column */ | |
| .workspace { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 30px; | |
| } | |
| .card { | |
| background-color: var(--bg-surface); | |
| border: 1px solid var(--border-color); | |
| border-radius: var(--radius-lg); | |
| padding: 30px; | |
| position: relative; | |
| } | |
| .card-header { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 24px; | |
| } | |
| .card-title h2 { | |
| font-size: 1.2rem; | |
| font-weight: 700; | |
| } | |
| .card-title p { | |
| font-size: 0.8rem; | |
| color: var(--text-secondary); | |
| margin-top: 2px; | |
| } | |
| /* Timeline waveform container */ | |
| .chart-container { | |
| position: relative; | |
| width: 100%; | |
| height: 380px; | |
| } | |
| /* Live geo sessions */ | |
| .geo-grid { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); | |
| gap: 20px; | |
| } | |
| .geo-card { | |
| background-color: rgba(255, 255, 255, 0.01); | |
| border: 1px solid var(--border-color); | |
| border-radius: var(--radius-md); | |
| padding: 16px; | |
| display: flex; | |
| align-items: center; | |
| gap: 16px; | |
| } | |
| .geo-dot { | |
| width: 12px; | |
| height: 12px; | |
| border-radius: 50%; | |
| background-color: var(--accent-valence); | |
| box-shadow: 0 0 10px var(--accent-valence); | |
| animation: pulse-glow 2s infinite alternate; | |
| } | |
| .geo-dot.anger { | |
| background-color: var(--accent-arousal); | |
| box-shadow: 0 0 10px var(--accent-arousal); | |
| } | |
| .geo-dot.curious { | |
| background-color: var(--accent-curious); | |
| box-shadow: 0 0 10px var(--accent-curious); | |
| } | |
| .geo-details { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 4px; | |
| } | |
| .geo-location { | |
| font-size: 0.85rem; | |
| font-weight: 700; | |
| } | |
| .geo-session-info { | |
| font-size: 0.75rem; | |
| color: var(--text-muted); | |
| } | |
| @keyframes pulse-glow { | |
| from { transform: scale(0.9); opacity: 0.6; } | |
| to { transform: scale(1.2); opacity: 1; } | |
| } | |
| /* Selected utterance details tooltip box */ | |
| .timeline-inspector { | |
| margin-top: 20px; | |
| background-color: var(--bg-base); | |
| border: 1px solid var(--border-color); | |
| border-radius: var(--radius-md); | |
| padding: 16px; | |
| display: none; | |
| } | |
| .timeline-inspector-header { | |
| font-size: 0.75rem; | |
| text-transform: uppercase; | |
| letter-spacing: 0.05em; | |
| color: var(--text-muted); | |
| margin-bottom: 8px; | |
| } | |
| .timeline-inspector-bubble { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 10px; | |
| } | |
| .dialogue-turn { | |
| padding: 10px; | |
| border-radius: 8px; | |
| font-size: 0.85rem; | |
| line-height: 1.4; | |
| } | |
| .dialogue-user { | |
| background-color: rgba(56, 189, 248, 0.05); | |
| border-left: 3px solid var(--accent-valence); | |
| } | |
| .dialogue-model { | |
| background-color: rgba(168, 85, 247, 0.05); | |
| border-left: 3px solid var(--accent-neutral); | |
| } | |
| .dialogue-metrics { | |
| display: flex; | |
| gap: 15px; | |
| font-size: 0.75rem; | |
| font-family: 'JetBrains Mono', monospace; | |
| color: var(--text-secondary); | |
| } | |
| .metric-val { | |
| font-weight: 600; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <header> | |
| <div class="header-title"> | |
| <h1>TRON <span>Sentiment Analytics Console</span></h1> | |
| <p>Granular Multidimensional Emotion & VAD Parameter Timeline Explorer</p> | |
| </div> | |
| <a class="btn-home" href="/">← Main Dashboard</a> | |
| </header> | |
| <!-- Top aggregated statistics --> | |
| <div class="stats-grid"> | |
| <div class="stat-card"> | |
| <div class="stat-label">Total Reader Sessions</div> | |
| <div class="stat-value" id="stat-sessions">0</div> | |
| </div> | |
| <div class="stat-card purple"> | |
| <div class="stat-label">Total Dialogue Turns</div> | |
| <div class="stat-value" id="stat-utterances">0</div> | |
| </div> | |
| <div class="stat-card green"> | |
| <div class="stat-label">Avg Grounded Valence</div> | |
| <div class="stat-value" id="stat-valence">0.00</div> | |
| </div> | |
| <div class="stat-card red"> | |
| <div class="stat-label">Active Fact Disputes</div> | |
| <div class="stat-value" id="stat-disputes">0</div> | |
| </div> | |
| </div> | |
| <!-- Workspace split --> | |
| <div class="main-layout"> | |
| <!-- Sidebar Navigation --> | |
| <div class="sidebar"> | |
| <!-- RAG Article List --> | |
| <div class="panel"> | |
| <div class="panel-title">Active TRON Articles</div> | |
| <div class="list-container" id="article-list"> | |
| <!-- Loaded dynamically --> | |
| </div> | |
| </div> | |
| <!-- Parameters Grid Selector --> | |
| <div class="panel"> | |
| <div class="panel-title">Filter by Emotion Parameter</div> | |
| <div class="emotion-grid" id="emotion-selector-grid"> | |
| <!-- Populated dynamically --> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Main Workspace --> | |
| <div class="workspace"> | |
| <!-- Timeline Chart Waveform --> | |
| <div class="card"> | |
| <div class="card-header"> | |
| <div class="card-title"> | |
| <h2 id="timeline-card-title">Emotional Waveform Timeline</h2> | |
| <p id="timeline-card-subtitle">Click dots on the timeline below to inspect the dialogue utterance</p> | |
| </div> | |
| <button id="btn-export" class="btn-home" style="background: linear-gradient(135deg, var(--accent-dominance), #059669); border-color: var(--border-color); color: #fff;"> | |
| 📥 Export Active Data | |
| </button> | |
| </div> | |
| <div class="chart-container"> | |
| <canvas id="timelineChart"></canvas> | |
| </div> | |
| <!-- Utterance dialogue inspector --> | |
| <div class="timeline-inspector" id="inspector-panel"> | |
| <div class="timeline-inspector-header">Selected Timeline Data Node</div> | |
| <div class="timeline-inspector-bubble"> | |
| <div class="dialogue-turn dialogue-user"> | |
| <strong>Reader: </strong><span id="inspect-user-text">---</span> | |
| </div> | |
| <div class="dialogue-turn dialogue-model"> | |
| <strong>Tron: </strong><span id="inspect-model-text">---</span> | |
| </div> | |
| <div class="dialogue-metrics"> | |
| <div>Primary: <span class="metric-val" id="inspect-primary-emotion" style="color: var(--accent-valence)">Neutral</span></div> | |
| <div>Valence: <span class="metric-val" id="inspect-valence">0.00</span></div> | |
| <div>Arousal: <span class="metric-val" id="inspect-arousal">0.00</span></div> | |
| <div>Dominance: <span class="metric-val" id="inspect-dominance">0.00</span></div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Geo-Location Activity Pins --> | |
| <div class="card"> | |
| <div class="card-header"> | |
| <div class="card-title"> | |
| <h2>Live Session Geolocation Stream</h2> | |
| <p>Global concurrency mapping of current active TRON user sessions</p> | |
| </div> | |
| </div> | |
| <div class="geo-grid" id="geo-pins-container"> | |
| <!-- Populated dynamically --> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // List of all 27 GoEmotions parameters for the selector grid | |
| const GO_EMOTIONS = [ | |
| "admiration", "amusement", "anger", "annoyance", "approval", "caring", | |
| "confusion", "curiosity", "desire", "disappointment", "disapproval", | |
| "disgust", "embarrassment", "excitement", "fear", "gratitude", "grief", | |
| "joy", "love", "nervousness", "optimism", "pride", "realization", | |
| "relief", "remorse", "sadness", "surprise", "neutral" | |
| ]; | |
| let currentChart = null; | |
| let selectedArticleId = null; | |
| // Resolve backend origin dynamically (supporting file:/// and cross-origin access) | |
| let backendOrigin = window.location.origin; | |
| if (window.location.protocol === 'file:') { | |
| backendOrigin = 'http://127.0.0.1:49999'; | |
| } else if ((window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') && window.location.port !== '49999') { | |
| backendOrigin = 'http://127.0.0.1:49999'; | |
| } | |
| // Initialize elements | |
| document.addEventListener("DOMContentLoaded", () => { | |
| renderEmotionGrid(); | |
| fetchDashboardData(); | |
| }); | |
| // Render parameters selector grid | |
| function renderEmotionGrid() { | |
| const container = document.getElementById("emotion-selector-grid"); | |
| container.innerHTML = ""; | |
| GO_EMOTIONS.forEach(emotion => { | |
| const btn = document.createElement("div"); | |
| btn.className = "emotion-tag"; | |
| btn.textContent = emotion; | |
| btn.onclick = () => filterByEmotion(emotion, btn); | |
| container.appendChild(btn); | |
| }); | |
| } | |
| // Fetch aggregated data | |
| async function fetchDashboardData() { | |
| try { | |
| const response = await fetch(`${backendOrigin}/api/analytics/data`); | |
| const data = await response.json(); | |
| // Set statistics counts | |
| document.getElementById("stat-sessions").textContent = data.stats.total_sessions || 0; | |
| document.getElementById("stat-utterances").textContent = data.stats.total_utterances || 0; | |
| // Aggregate overall valence | |
| let sumValence = 0; | |
| let countValence = 0; | |
| let disputeCount = 0; | |
| // Populate article list | |
| const articleList = document.getElementById("article-list"); | |
| articleList.innerHTML = ""; | |
| if (data.articles && data.articles.length > 0) { | |
| data.articles.forEach((art, idx) => { | |
| sumValence += (art.avg_valence || 0) * art.interactions; | |
| countValence += art.interactions; | |
| // Treat extremely negative valence combined with high arousal as disputes | |
| if (art.avg_valence < -0.3 && art.avg_arousal > 0.4) { | |
| disputeCount++; | |
| } | |
| const item = document.createElement("div"); | |
| item.className = "list-item" + (idx === 0 ? " active" : ""); | |
| item.innerHTML = ` | |
| <div class="list-item-title">${art.article_id}</div> | |
| <div class="list-item-meta"> | |
| <span>Turns: ${art.interactions}</span> | |
| <span>Valence: ${(art.avg_valence || 0).toFixed(2)}</span> | |
| </div> | |
| `; | |
| item.onclick = () => { | |
| document.querySelectorAll(".list-item").forEach(el => el.classList.remove("active")); | |
| item.classList.add("active"); | |
| loadArticleTimeline(art.article_id); | |
| }; | |
| articleList.appendChild(item); | |
| }); | |
| // Update dynamic stats card | |
| const globalValence = countValence > 0 ? (sumValence / countValence) : 0.00; | |
| document.getElementById("stat-valence").textContent = globalValence.toFixed(2); | |
| document.getElementById("stat-disputes").textContent = disputeCount; | |
| // Automatically load the timeline of the first article | |
| selectedArticleId = data.articles[0].article_id; | |
| loadArticleTimeline(selectedArticleId); | |
| } else { | |
| articleList.innerHTML = '<div class="text-slate-600 italic p-4">No active TRON articles found in database. Start a conversation to log data!</div>'; | |
| } | |
| // Populate Geolocations Stream | |
| const geoContainer = document.getElementById("geo-pins-container"); | |
| geoContainer.innerHTML = ""; | |
| if (data.geo_pins && data.geo_pins.length > 0) { | |
| data.geo_pins.forEach(pin => { | |
| const card = document.createElement("div"); | |
| card.className = "geo-card"; | |
| // Select indicator dot based on location or default | |
| let dotClass = ""; | |
| if (pin.session_id.charCodeAt(0) % 3 === 0) dotClass = "anger"; | |
| else if (pin.session_id.charCodeAt(0) % 3 === 1) dotClass = "curious"; | |
| card.innerHTML = ` | |
| <div class="geo-dot ${dotClass}"></div> | |
| <div class="geo-details"> | |
| <div class="geo-location">${pin.city}, ${pin.country}</div> | |
| <div class="geo-session-info">Article: ${pin.article_id.substring(0, 15)}...</div> | |
| </div> | |
| `; | |
| geoContainer.appendChild(card); | |
| }); | |
| } else { | |
| geoContainer.innerHTML = ` | |
| <div class="geo-card"> | |
| <div class="geo-dot"></div> | |
| <div class="geo-details"> | |
| <div class="geo-location">Mumbai, India</div> | |
| <div class="geo-session-info">Active session simulation</div> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| } catch (err) { | |
| console.error("[ERROR] Failed to fetch aggregated analytics:", err); | |
| } | |
| } | |
| // Reverse Parameter Lookup: Click emotion tag | |
| async function filterByEmotion(emotion, element) { | |
| document.querySelectorAll(".emotion-tag").forEach(el => el.classList.remove("active")); | |
| element.classList.add("active"); | |
| try { | |
| const response = await fetch(`${backendOrigin}/api/analytics/emotion/${emotion}`); | |
| const data = await response.json(); | |
| // Highlight articles matching this emotion in list container | |
| const listItems = document.querySelectorAll(".list-item"); | |
| listItems.forEach(item => { | |
| const articleTitle = item.querySelector(".list-item-title").textContent.trim(); | |
| const matches = data.find(d => d.article_id === articleTitle); | |
| if (matches) { | |
| item.style.borderColor = "var(--accent-valence)"; | |
| item.style.boxShadow = "0 0 5px rgba(56, 189, 248, 0.2)"; | |
| } else { | |
| item.style.borderColor = "var(--border-color)"; | |
| item.style.boxShadow = "none"; | |
| } | |
| }); | |
| document.getElementById("timeline-card-title").textContent = `Articles generating: "${emotion.toUpperCase()}"`; | |
| document.getElementById("timeline-card-subtitle").textContent = `Highlighted matches indicate footprint in list database`; | |
| } catch (err) { | |
| console.error("[ERROR] Failed to execute reverse search:", err); | |
| } | |
| } | |
| // Load timeline data for selected article | |
| async function loadArticleTimeline(articleId) { | |
| selectedArticleId = articleId; | |
| document.getElementById("timeline-card-title").textContent = `Emotional Waveform: ${articleId}`; | |
| document.getElementById("timeline-card-subtitle").textContent = `Click any data node coordinate below to inspect dialogue utterance details`; | |
| // Reset inspector panel | |
| document.getElementById("inspector-panel").style.display = "none"; | |
| try { | |
| // To fetch timelines, we retrieve all session timelines matching this article | |
| const response = await fetch(`${backendOrigin}/api/analytics/data`); | |
| const data = await response.json(); | |
| // Get the session ID matching this article | |
| const pin = data.geo_pins.find(p => p.article_id === articleId); | |
| if (!pin) return; | |
| const timelineResp = await fetch(`${backendOrigin}/api/analytics/timeline/${pin.session_id}`); | |
| const timelineData = await timelineResp.json(); | |
| if (timelineData && timelineData.length > 0) { | |
| renderTimelineChart(timelineData); | |
| } else { | |
| if (currentChart) currentChart.destroy(); | |
| const ctx = document.getElementById("timelineChart").getContext("2d"); | |
| ctx.clearRect(0, 0, 600, 400); | |
| } | |
| } catch (err) { | |
| console.error("[ERROR] Failed to load timeline:", err); | |
| } | |
| } | |
| // Render multi-line timeline chart using Chart.js | |
| function renderTimelineChart(data) { | |
| const ctx = document.getElementById("timelineChart").getContext("2d"); | |
| // Destroy previous chart if exists | |
| if (currentChart) { | |
| currentChart.destroy(); | |
| } | |
| const labels = data.map((d, idx) => `Turn ${idx + 1}`); | |
| const valences = data.map(d => d.valence); | |
| const arousals = data.map(d => d.arousal); | |
| const dominances = data.map(d => d.dominance); | |
| currentChart = new Chart(ctx, { | |
| type: 'line', | |
| data: { | |
| labels: labels, | |
| datasets: [ | |
| { | |
| label: 'Valence (Pleasantness)', | |
| data: valences, | |
| borderColor: '#38bdf8', | |
| backgroundColor: 'rgba(56, 189, 248, 0.1)', | |
| borderWidth: 3, | |
| tension: 0.3, | |
| pointRadius: 6, | |
| pointHoverRadius: 8 | |
| }, | |
| { | |
| label: 'Arousal (Agitation)', | |
| data: arousals, | |
| borderColor: '#f43f5e', | |
| backgroundColor: 'rgba(244, 63, 94, 0.1)', | |
| borderWidth: 3, | |
| tension: 0.3, | |
| pointRadius: 6, | |
| pointHoverRadius: 8 | |
| }, | |
| { | |
| label: 'Dominance (Defiance)', | |
| data: dominances, | |
| borderColor: '#10b981', | |
| backgroundColor: 'rgba(16, 185, 129, 0.1)', | |
| borderWidth: 3, | |
| tension: 0.3, | |
| pointRadius: 6, | |
| pointHoverRadius: 8 | |
| } | |
| ] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| onClick: (event, activeElements) => { | |
| if (activeElements && activeElements.length > 0) { | |
| const index = activeElements[0].index; | |
| inspectUtterance(data[index]); | |
| } | |
| }, | |
| plugins: { | |
| legend: { | |
| labels: { | |
| color: '#f8fafc', | |
| font: { | |
| family: 'Plus Jakarta Sans', | |
| weight: '600' | |
| } | |
| } | |
| } | |
| }, | |
| scales: { | |
| x: { | |
| grid: { color: 'rgba(255,255,255,0.05)' }, | |
| ticks: { color: '#94a3b8' } | |
| }, | |
| y: { | |
| min: -1.0, | |
| max: 1.0, | |
| grid: { color: 'rgba(255,255,255,0.05)' }, | |
| ticks: { color: '#94a3b8' } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // Show selected dialogue turn details in inspector bubble | |
| function inspectUtterance(turn) { | |
| document.getElementById("inspect-user-text").textContent = turn.user_text || "---"; | |
| document.getElementById("inspect-model-text").textContent = turn.model_text || "---"; | |
| document.getElementById("inspect-primary-emotion").textContent = (turn.primary_emotion || "neutral").toUpperCase(); | |
| document.getElementById("inspect-valence").textContent = (turn.valence || 0.0).toFixed(2); | |
| document.getElementById("inspect-arousal").textContent = (turn.arousal || 0.0).toFixed(2); | |
| document.getElementById("inspect-dominance").textContent = (turn.dominance || 0.0).toFixed(2); | |
| const panel = document.getElementById("inspector-panel"); | |
| panel.style.display = "block"; | |
| panel.scrollIntoView({ behavior: 'smooth' }); | |
| } | |
| // CSV/Excel Exporter for active dashboard choices | |
| document.getElementById("btn-export").onclick = () => { | |
| if (selectedArticleId) { | |
| exportArticleTimelineCSV(selectedArticleId); | |
| } else { | |
| exportGlobalStatsCSV(); | |
| } | |
| }; | |
| function downloadCSV(csvContent, fileName) { | |
| const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); | |
| const link = document.createElement("a"); | |
| if (link.download !== undefined) { | |
| const url = URL.createObjectURL(blob); | |
| link.setAttribute("href", url); | |
| link.setAttribute("download", fileName); | |
| link.style.visibility = 'hidden'; | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| } | |
| } | |
| async function exportArticleTimelineCSV(articleId) { | |
| try { | |
| const response = await fetch(`${backendOrigin}/api/analytics/data`); | |
| const data = await response.json(); | |
| const pin = data.geo_pins.find(p => p.article_id === articleId); | |
| if (!pin) { | |
| alert("No session logs found for this article."); | |
| return; | |
| } | |
| const timelineResp = await fetch(`${backendOrigin}/api/analytics/timeline/${pin.session_id}`); | |
| const timelineData = await timelineResp.json(); | |
| let csv = 'Timestamp,Turn,User Text,Model Text,Primary Emotion,Secondary Emotion,Valence,Arousal,Dominance\r\n'; | |
| timelineData.forEach((turn, idx) => { | |
| const userText = (turn.user_text || "").replace(/"/g, '""'); | |
| const modelText = (turn.model_text || "").replace(/"/g, '""'); | |
| csv += `"${turn.timestamp}",${idx+1},"${userText}","${modelText}","${turn.primary_emotion}","${turn.secondary_emotion}",${turn.valence},${turn.arousal},${turn.dominance}\r\n`; | |
| }); | |
| downloadCSV(csv, `TRON_Timeline_${articleId}.csv`); | |
| } catch (err) { | |
| console.error("Export timeline failed:", err); | |
| } | |
| } | |
| async function exportGlobalStatsCSV() { | |
| try { | |
| const response = await fetch(`${backendOrigin}/api/analytics/data`); | |
| const data = await response.json(); | |
| let csv = 'Article ID,Interactions Count,Avg Valence,Avg Arousal,Avg Dominance\r\n'; | |
| data.articles.forEach(art => { | |
| csv += `"${art.article_id}",${art.interactions},${art.avg_valence},${art.avg_arousal},${art.avg_dominance}\r\n`; | |
| }); | |
| downloadCSV(csv, `TRON_Global_Articles_Stats.csv`); | |
| } catch (err) { | |
| console.error("Export global stats failed:", err); | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> | |