cyberosa
commited on
Commit
·
9c51f62
1
Parent(s):
65733ce
updating ROI Agents graph
Browse files- app.py +1 -1
- tabs/agent_graphs.py +17 -27
app.py
CHANGED
@@ -572,7 +572,7 @@ with demo:
|
|
572 |
gr.Markdown("# 2-weeks rolling average ROI for Pearl agents")
|
573 |
with gr.Row():
|
574 |
pearl_rolling_avg_plot = plot_rolling_average_roi(
|
575 |
-
|
576 |
pearl_agents=pearl_agents_df,
|
577 |
)
|
578 |
with gr.Row():
|
|
|
572 |
gr.Markdown("# 2-weeks rolling average ROI for Pearl agents")
|
573 |
with gr.Row():
|
574 |
pearl_rolling_avg_plot = plot_rolling_average_roi(
|
575 |
+
traders_data=traders_data,
|
576 |
pearl_agents=pearl_agents_df,
|
577 |
)
|
578 |
with gr.Row():
|
tabs/agent_graphs.py
CHANGED
@@ -77,26 +77,22 @@ def get_sevenday_rolling_average(daa_df: pd.DataFrame) -> pd.DataFrame:
|
|
77 |
|
78 |
|
79 |
def plot_rolling_average_roi(
|
80 |
-
|
81 |
) -> gr.Plot:
|
82 |
"""Function to plot the rolling average of ROI for pearl agents"""
|
83 |
# Get the list of unique addresses from the daa_pearl_df
|
84 |
unique_addresses = pearl_agents["safe_address"].unique()
|
85 |
# Filter the weekly_roi_df to include only those addresses
|
86 |
-
|
87 |
-
|
88 |
]
|
89 |
-
#
|
90 |
-
|
91 |
-
|
92 |
-
].
|
93 |
-
# Remove duplicates
|
94 |
-
filtered_weekly_roi_df = filtered_weekly_roi_df.drop_duplicates(
|
95 |
-
subset=["month_year_week", "trader_address"]
|
96 |
-
)
|
97 |
|
98 |
# Get the 2-week rolling average of ROI
|
99 |
-
rolling_avg_roi_df = get_twoweeks_rolling_average_roi(
|
100 |
print(rolling_avg_roi_df.head())
|
101 |
# Ensure 'month_year_week' is a column, not an index
|
102 |
if "month_year_week" not in rolling_avg_roi_df.columns:
|
@@ -116,24 +112,18 @@ def plot_rolling_average_roi(
|
|
116 |
)
|
117 |
|
118 |
|
119 |
-
def get_twoweeks_rolling_average_roi(
|
120 |
"""Function to get the 2-week rolling average of the ROI by market_creator and total"""
|
121 |
-
# Create a local copy of the dataframe
|
122 |
-
local_df = weekly_roi_df.copy()
|
123 |
|
124 |
-
#
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
local_df.resample("W")["roi"].mean().rolling(window=2).mean().reset_index()
|
134 |
-
)
|
135 |
-
trader_rolling_avg_roi.rename(columns={"roi": "rolling_avg_roi"}, inplace=True)
|
136 |
-
return trader_rolling_avg_roi
|
137 |
|
138 |
|
139 |
def get_weekly_average_roi(weekly_roi_df: pd.DataFrame) -> pd.DataFrame:
|
|
|
77 |
|
78 |
|
79 |
def plot_rolling_average_roi(
|
80 |
+
traders_data: pd.DataFrame, pearl_agents: pd.DataFrame
|
81 |
) -> gr.Plot:
|
82 |
"""Function to plot the rolling average of ROI for pearl agents"""
|
83 |
# Get the list of unique addresses from the daa_pearl_df
|
84 |
unique_addresses = pearl_agents["safe_address"].unique()
|
85 |
# Filter the weekly_roi_df to include only those addresses
|
86 |
+
filtered_traders_data = traders_data[
|
87 |
+
traders_data["trader_address"].isin(unique_addresses)
|
88 |
]
|
89 |
+
# create the date column
|
90 |
+
filtered_traders_data["creation_date"] = filtered_traders_data[
|
91 |
+
"creation_timestamp"
|
92 |
+
].dt.date
|
|
|
|
|
|
|
|
|
93 |
|
94 |
# Get the 2-week rolling average of ROI
|
95 |
+
rolling_avg_roi_df = get_twoweeks_rolling_average_roi(filtered_traders_data)
|
96 |
print(rolling_avg_roi_df.head())
|
97 |
# Ensure 'month_year_week' is a column, not an index
|
98 |
if "month_year_week" not in rolling_avg_roi_df.columns:
|
|
|
112 |
)
|
113 |
|
114 |
|
115 |
+
def get_twoweeks_rolling_average_roi(traders_data: pd.DataFrame) -> pd.DataFrame:
|
116 |
"""Function to get the 2-week rolling average of the ROI by market_creator and total"""
|
|
|
|
|
117 |
|
118 |
+
# Aggregate ROI at the date level
|
119 |
+
daily_avg = traders_data.groupby("creation_date")["roi"].mean().reset_index()
|
120 |
+
daily_avg = daily_avg.set_index("creation_date")
|
121 |
+
# Now resample and rolling
|
122 |
+
weekly_avg = daily_avg.resample("W").mean()
|
123 |
+
rolling_avg = weekly_avg.rolling(window=2).mean().reset_index()
|
124 |
|
125 |
+
rolling_avg.rename(columns={"roi": "rolling_avg_roi"}, inplace=True)
|
126 |
+
return rolling_avg
|
|
|
|
|
|
|
|
|
127 |
|
128 |
|
129 |
def get_weekly_average_roi(weekly_roi_df: pd.DataFrame) -> pd.DataFrame:
|