Finish off the links between frontend and backend #10
@@ -63,11 +63,25 @@ class InteractionAnalysis:
|
|||||||
pairs.sort(key=lambda x: x[1], reverse=True)
|
pairs.sort(key=lambda x: x[1], reverse=True)
|
||||||
return pairs[:top_n]
|
return pairs[:top_n]
|
||||||
|
|
||||||
def initiator_ratio(self, df: pd.DataFrame):
|
def conversation_concentration(self, df: pd.DataFrame) -> dict:
|
||||||
starters = df["reply_to"].isna().sum()
|
if "type" not in df.columns:
|
||||||
total = len(df)
|
return {}
|
||||||
|
|
||||||
if total == 0:
|
comments = df[df["type"] == "comment"]
|
||||||
return 0
|
if comments.empty:
|
||||||
|
return {}
|
||||||
|
|
||||||
return round(starters / total, 2)
|
author_counts = comments["author"].value_counts()
|
||||||
|
total_comments = len(comments)
|
||||||
|
total_authors = len(author_counts)
|
||||||
|
|
||||||
|
top_10_pct_n = max(1, int(total_authors * 0.1))
|
||||||
|
top_10_pct_share = round(author_counts.head(top_10_pct_n).sum() / total_comments, 4)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"total_commenting_authors": total_authors,
|
||||||
|
"top_10pct_author_count": top_10_pct_n,
|
||||||
|
"top_10pct_comment_share": float(top_10_pct_share),
|
||||||
|
"single_comment_authors": int((author_counts == 1).sum()),
|
||||||
|
"single_comment_author_ratio": float(round((author_counts == 1).sum() / total_authors, 4)),
|
||||||
|
}
|
||||||
@@ -121,8 +121,8 @@ class StatGen:
|
|||||||
return {
|
return {
|
||||||
"average_thread_depth": self.interaction_analysis.average_thread_depth(filtered_df),
|
"average_thread_depth": self.interaction_analysis.average_thread_depth(filtered_df),
|
||||||
"top_interaction_pairs": self.interaction_analysis.top_interaction_pairs(filtered_df, top_n=100),
|
"top_interaction_pairs": self.interaction_analysis.top_interaction_pairs(filtered_df, top_n=100),
|
||||||
"initiator_ratio": self.interaction_analysis.initiator_ratio(filtered_df),
|
"interaction_graph": self.interaction_analysis.interaction_graph(filtered_df),
|
||||||
"interaction_graph": self.interaction_analysis.interaction_graph(filtered_df)
|
"conversation_concentration": self.interaction_analysis.conversation_concentration(filtered_df)
|
||||||
}
|
}
|
||||||
|
|
||||||
def cultural(self, df: pd.DataFrame, filters: dict | None = None) -> dict:
|
def cultural(self, df: pd.DataFrame, filters: dict | None = None) -> dict:
|
||||||
|
|||||||
Reference in New Issue
Block a user