import Card from "./Card"; import StatsStyling from "../styles/stats_styling"; import type { CulturalAnalysisResponse } from "../types/ApiTypes"; import { buildCertaintySpec, buildDeonticSpec, buildEntitySpec, buildHedgeSpec, buildIdentityBucketSpec, buildPermissionSpec, type CorpusExplorerSpec, } from "../utils/corpusExplorer"; const styles = StatsStyling; const exploreButtonStyle = { padding: "4px 8px", fontSize: 12 }; type CulturalStatsProps = { data: CulturalAnalysisResponse; onExplore: (spec: CorpusExplorerSpec) => void; }; const renderExploreButton = (onClick: () => void) => ( ); const CulturalStats = ({ data, onExplore }: CulturalStatsProps) => { const identity = data.identity_markers; const stance = data.stance_markers; const inGroupWords = identity?.in_group_usage ?? 0; const outGroupWords = identity?.out_group_usage ?? 0; const totalGroupWords = inGroupWords + outGroupWords; const inGroupWordRate = typeof identity?.in_group_ratio === "number" ? identity.in_group_ratio * 100 : null; const outGroupWordRate = typeof identity?.out_group_ratio === "number" ? identity.out_group_ratio * 100 : null; const rawEntities = data.avg_emotion_per_entity?.entity_emotion_avg ?? {}; const entities = Object.entries(rawEntities) .sort((a, b) => b[1].post_count - a[1].post_count) .slice(0, 20); const topEmotion = (emotionAvg: Record | undefined) => { const entries = Object.entries(emotionAvg ?? {}); if (!entries.length) { return "-"; } entries.sort((a, b) => b[1] - a[1]); const dominant = entries[0] ?? ["emotion_unknown", 0]; const dominantLabel = dominant[0].replace("emotion_", ""); return `${dominantLabel} (${(dominant[1] * 100).toFixed(1)}%)`; }; return (

Community Framing Overview

Simple view of how often people use "us" words vs "them" words, and the tone around that language.

onExplore(buildIdentityBucketSpec("in")), )} style={{ gridColumn: "span 3" }} /> onExplore(buildIdentityBucketSpec("out")), )} style={{ gridColumn: "span 3" }} /> onExplore(buildIdentityBucketSpec("tie")), )} style={{ gridColumn: "span 3" }} /> onExplore(buildHedgeSpec()))} style={{ gridColumn: "span 3" }} /> onExplore(buildCertaintySpec()))} style={{ gridColumn: "span 3" }} /> onExplore(buildDeonticSpec()))} style={{ gridColumn: "span 3" }} /> onExplore(buildPermissionSpec()))} style={{ gridColumn: "span 3" }} />

Mood in "Us" Posts

Most likely emotion when in-group wording is stronger.

{topEmotion(identity?.in_group_emotion_avg)}

Mood in "Them" Posts

Most likely emotion when out-group wording is stronger.

{topEmotion(identity?.out_group_emotion_avg)}

Entity Mood Snapshot

Most mentioned entities and the mood that appears most with each.

{!entities.length ? (
No entity-level cultural data available.
) : (
{entities.map(([entity, aggregate]) => (
onExplore(buildEntitySpec(entity))} >
{entity}
{aggregate.post_count.toLocaleString()} posts • Likely mood:{" "} {topEmotion(aggregate.emotion_avg)}
))}
)}
); }; export default CulturalStats;