From f136e7b7c806d70dc9c7b8b43b02f94abb94fd07 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Sun, 8 Feb 2026 15:41:57 +0000 Subject: [PATCH] feat: add count into emotion per topic --- server/stat_gen.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/stat_gen.py b/server/stat_gen.py index f2f5ae6..b63d377 100644 --- a/server/stat_gen.py +++ b/server/stat_gen.py @@ -198,6 +198,15 @@ class StatGen: if col.startswith("emotion_") and col != "emotion_neutral" ] + counts = ( + self.df[ + (self.df["topic"] != "Misc") + ] + .groupby("topic") + .size() + .rename("n") + ) + avg_emotion_by_topic = ( self.df[ (self.df["topic"] != "Misc") @@ -207,6 +216,11 @@ class StatGen: .reset_index() ) + avg_emotion_by_topic = avg_emotion_by_topic.merge( + counts, + on="topic" + ) + return { "word_frequencies": word_frequencies.to_dict(orient='records'), "average_emotion_by_topic": avg_emotion_by_topic.to_dict(orient='records')