import type { ContentAnalysisResponse } from "../types/ApiTypes" import StatsStyling from "../styles/stats_styling"; const styles = StatsStyling; type EmotionalStatsProps = { contentData: ContentAnalysisResponse; } const EmotionalStats = ({contentData}: EmotionalStatsProps) => { const rows = contentData.average_emotion_by_topic ?? []; const emotionKeys = rows.length ? Object.keys(rows[0]).filter((key) => key.startsWith("emotion_")) : []; const strongestPerTopic = rows.map((row) => { let maxKey = ""; let maxValue = Number.NEGATIVE_INFINITY; emotionKeys.forEach((key) => { const value = Number(row[key] ?? 0); if (value > maxValue) { maxValue = value; maxKey = key; } }); return { topic: String(row.topic), count: Number(row.n ?? 0), emotion: maxKey.replace("emotion_", "") || "unknown", value: maxValue > Number.NEGATIVE_INFINITY ? maxValue : 0 }; }); const formatEmotion = (value: string) => { if (!value) return "Unknown"; return value.charAt(0).toUpperCase() + value.slice(1); }; if (!rows.length) { return (
No topic emotion data available.
Mean emotion scores for each detected topic