diff --git a/server/analysis/interactional.py b/server/analysis/interactional.py index 44f1e4a..0d7785c 100644 --- a/server/analysis/interactional.py +++ b/server/analysis/interactional.py @@ -123,4 +123,26 @@ class InteractionAnalysis: interactions[a][b] = interactions[a].get(b, 0) + 1 - return interactions \ No newline at end of file + return interactions + + def average_thread_depth(self): + depths = [] + id_to_reply = self.df.set_index("id")["reply_to"].to_dict() + for _, row in self.df.iterrows(): + depth = 0 + current_id = row["id"] + + while True: + reply_to = id_to_reply.get(current_id) + if pd.isna(reply_to) or reply_to == "": + break + + depth += 1 + current_id = reply_to + + depths.append(depth) + + if not depths: + return 0 + + return round(sum(depths) / len(depths), 2) \ No newline at end of file