From f6d612ca5e86c3737ff941cf7cce6d9c87a3a9ba Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Sun, 8 Feb 2026 15:37:18 +0000 Subject: [PATCH] feat: add average emotion per topic endpoint --- server/stat_gen.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server/stat_gen.py b/server/stat_gen.py index 35abb08..f2f5ae6 100644 --- a/server/stat_gen.py +++ b/server/stat_gen.py @@ -192,8 +192,24 @@ class StatGen: .reset_index(drop=True) ) + # avearge emotion by topic (excluding neutral) + emotion_cols = [ + col for col in self.df.columns + if col.startswith("emotion_") and col != "emotion_neutral" + ] + + avg_emotion_by_topic = ( + self.df[ + (self.df["topic"] != "Misc") + ] + .groupby("topic")[emotion_cols] + .mean() + .reset_index() + ) + return { - "word_frequencies": word_frequencies.to_dict(orient='records') + "word_frequencies": word_frequencies.to_dict(orient='records'), + "average_emotion_by_topic": avg_emotion_by_topic.to_dict(orient='records') } def user_analysis(self) -> dict: