cyberosa commited on
Commit
3058723
·
1 Parent(s): 63c3662

some layout fixes

Browse files
app.py CHANGED
@@ -414,6 +414,15 @@ with demo:
414
  with gr.TabItem("🪝 Retention metrics (WIP)"):
415
  with gr.Row():
416
  gr.Markdown("# Wow retention by trader type")
 
 
 
 
 
 
 
 
 
417
  with gr.Row():
418
  with gr.Column(scale=1):
419
  gr.Markdown("## Wow retention in Pearl markets")
 
414
  with gr.TabItem("🪝 Retention metrics (WIP)"):
415
  with gr.Row():
416
  gr.Markdown("# Wow retention by trader type")
417
+ with gr.Row():
418
+ gr.Markdown(
419
+ """
420
+ - Olas trader: agent using Mech, with a service ID and the corresponding safe in the registry
421
+ - Non-Olas trader: agent using Mech, with no service ID
422
+ - Unclassified trader: agent (safe/EOAs) not using Mechs
423
+ """
424
+ )
425
+
426
  with gr.Row():
427
  with gr.Column(scale=1):
428
  gr.Markdown("## Wow retention in Pearl markets")
notebooks/retention_metrics.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
scripts/retention_metrics.py CHANGED
@@ -64,18 +64,19 @@ def calculate_wow_retention_by_type(
64
 
65
  # Cohort Retention
66
  def calculate_cohort_retention(
67
- df: pd.DataFrame, market_creator: str, trader_type: str, max_weeks=12
68
  ) -> pd.DataFrame:
69
  df_filtered = df.loc[
70
  (df["market_creator"] == market_creator) & (df["trader_type"] == trader_type)
71
  ]
 
72
  # Get first week for each trader
73
- first_trades = (
74
  df_filtered.groupby("trader_address")
75
  .agg({"creation_timestamp": "min", "month_year_week": "first"})
76
  .reset_index()
77
  )
78
- first_trades.columns = ["trader_address", "first_trade", "cohort_week"]
79
 
80
  # Get ordered list of unique weeks - converting to datetime for proper sorting
81
  all_weeks = df_filtered["month_year_week"].unique()
@@ -89,7 +90,7 @@ def calculate_cohort_retention(
89
  # Merge back to get all activities
90
  cohort_data = pd.merge(
91
  df_filtered,
92
- first_trades[["trader_address", "cohort_week"]],
93
  on="trader_address",
94
  )
95
 
@@ -114,10 +115,6 @@ def calculate_cohort_retention(
114
  retention_matrix.index = pd.to_datetime(retention_matrix.index)
115
  retention_matrix = retention_matrix.sort_index()
116
 
117
- # Limit to max_weeks if specified
118
- if max_weeks is not None and max_weeks < retention_matrix.shape[1]:
119
- retention_matrix = retention_matrix.iloc[:, :max_weeks]
120
-
121
  return retention_matrix.round(2)
122
 
123
 
 
64
 
65
  # Cohort Retention
66
  def calculate_cohort_retention(
67
+ df: pd.DataFrame, market_creator: str, trader_type: str
68
  ) -> pd.DataFrame:
69
  df_filtered = df.loc[
70
  (df["market_creator"] == market_creator) & (df["trader_type"] == trader_type)
71
  ]
72
+ df_filtered = df_filtered.sort_values(by="creation_timestamp", ascending=True)
73
  # Get first week for each trader
74
+ first_activity = (
75
  df_filtered.groupby("trader_address")
76
  .agg({"creation_timestamp": "min", "month_year_week": "first"})
77
  .reset_index()
78
  )
79
+ first_activity.columns = ["trader_address", "first_activity", "cohort_week"]
80
 
81
  # Get ordered list of unique weeks - converting to datetime for proper sorting
82
  all_weeks = df_filtered["month_year_week"].unique()
 
90
  # Merge back to get all activities
91
  cohort_data = pd.merge(
92
  df_filtered,
93
+ first_activity[["trader_address", "cohort_week"]],
94
  on="trader_address",
95
  )
96
 
 
115
  retention_matrix.index = pd.to_datetime(retention_matrix.index)
116
  retention_matrix = retention_matrix.sort_index()
117
 
 
 
 
 
118
  return retention_matrix.round(2)
119
 
120
 
tabs/retention_plots.py CHANGED
@@ -84,8 +84,8 @@ def plot_cohort_retention_heatmap(retention_matrix: pd.DataFrame, cmap: str):
84
 
85
  # Customize the plot
86
  plt.title("Cohort Retention Analysis", pad=20, size=14)
87
- plt.xlabel("Weeks Since First Trade", size=12)
88
- plt.ylabel("Cohort Starting Week", size=12)
89
 
90
  # Format week numbers on x-axis
91
  x_labels = [f"Week {i}" for i in retention_matrix.columns]
 
84
 
85
  # Customize the plot
86
  plt.title("Cohort Retention Analysis", pad=20, size=14)
87
+ plt.xlabel("Weeks Since First Activiy", size=12)
88
+ plt.ylabel("Cohort First Day of the Week", size=12)
89
 
90
  # Format week numbers on x-axis
91
  x_labels = [f"Week {i}" for i in retention_matrix.columns]