Spaces:
Runtime error
Runtime error
cyberosa
commited on
Commit
Β·
2dc3f1e
1
Parent(s):
7bb8323
updating 2weeks avg roi graph
Browse files- app.py +16 -6
- tabs/agent_graphs.py +6 -77
app.py
CHANGED
|
@@ -162,7 +162,15 @@ def load_all_data():
|
|
| 162 |
repo_type="dataset",
|
| 163 |
)
|
| 164 |
df10 = pd.read_parquet(weekly_avg_roi_pearl_agents)
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
|
| 168 |
def prepare_data():
|
|
@@ -178,6 +186,7 @@ def prepare_data():
|
|
| 178 |
daa_qs_df,
|
| 179 |
daa_pearl_df,
|
| 180 |
weekly_avg_roi_pearl_agents,
|
|
|
|
| 181 |
) = load_all_data()
|
| 182 |
all_trades["creation_timestamp"] = all_trades["creation_timestamp"].dt.tz_convert(
|
| 183 |
"UTC"
|
|
@@ -256,6 +265,7 @@ def prepare_data():
|
|
| 256 |
daa_qs_df,
|
| 257 |
daa_pearl_df,
|
| 258 |
weekly_avg_roi_pearl_agents,
|
|
|
|
| 259 |
)
|
| 260 |
|
| 261 |
|
|
@@ -270,6 +280,7 @@ def prepare_data():
|
|
| 270 |
daa_qs_df,
|
| 271 |
daa_pearl_df,
|
| 272 |
weekly_avg_roi_pearl_agents,
|
|
|
|
| 273 |
) = prepare_data()
|
| 274 |
|
| 275 |
retention_df = prepare_retention_dataset(
|
|
@@ -571,11 +582,10 @@ with demo:
|
|
| 571 |
with gr.Row():
|
| 572 |
gr.Markdown("# 2-weeks rolling average ROI for Pearl agents")
|
| 573 |
with gr.Row():
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
print("WIP")
|
| 579 |
with gr.Row():
|
| 580 |
gr.Markdown("# Average weekly ROI for Pearl agents")
|
| 581 |
with gr.Row():
|
|
|
|
| 162 |
repo_type="dataset",
|
| 163 |
)
|
| 164 |
df10 = pd.read_parquet(weekly_avg_roi_pearl_agents)
|
| 165 |
+
|
| 166 |
+
# two_weeks_avg_roi_pearl_agents.parquet
|
| 167 |
+
two_weeks_avg_roi_pearl_agents = hf_hub_download(
|
| 168 |
+
repo_id="valory/Olas-predict-dataset",
|
| 169 |
+
filename="two_weeks_avg_roi_pearl_agents.parquet",
|
| 170 |
+
repo_type="dataset",
|
| 171 |
+
)
|
| 172 |
+
df11 = pd.read_parquet(two_weeks_avg_roi_pearl_agents)
|
| 173 |
+
return df1, df2, df3, df4, df5, df6, df7, df8, df9, df10, df11
|
| 174 |
|
| 175 |
|
| 176 |
def prepare_data():
|
|
|
|
| 186 |
daa_qs_df,
|
| 187 |
daa_pearl_df,
|
| 188 |
weekly_avg_roi_pearl_agents,
|
| 189 |
+
two_weeks_avg_roi_pearl_agents,
|
| 190 |
) = load_all_data()
|
| 191 |
all_trades["creation_timestamp"] = all_trades["creation_timestamp"].dt.tz_convert(
|
| 192 |
"UTC"
|
|
|
|
| 265 |
daa_qs_df,
|
| 266 |
daa_pearl_df,
|
| 267 |
weekly_avg_roi_pearl_agents,
|
| 268 |
+
two_weeks_avg_roi_pearl_agents,
|
| 269 |
)
|
| 270 |
|
| 271 |
|
|
|
|
| 280 |
daa_qs_df,
|
| 281 |
daa_pearl_df,
|
| 282 |
weekly_avg_roi_pearl_agents,
|
| 283 |
+
two_weeks_avg_roi_pearl_agents,
|
| 284 |
) = prepare_data()
|
| 285 |
|
| 286 |
retention_df = prepare_retention_dataset(
|
|
|
|
| 582 |
with gr.Row():
|
| 583 |
gr.Markdown("# 2-weeks rolling average ROI for Pearl agents")
|
| 584 |
with gr.Row():
|
| 585 |
+
pearl_rolling_avg_plot = plot_rolling_average_roi(
|
| 586 |
+
two_weeks_avg_roi_pearl_agents
|
| 587 |
+
)
|
| 588 |
+
|
|
|
|
| 589 |
with gr.Row():
|
| 590 |
gr.Markdown("# Average weekly ROI for Pearl agents")
|
| 591 |
with gr.Row():
|
tabs/agent_graphs.py
CHANGED
|
@@ -24,37 +24,20 @@ def plot_rolling_average_dune(
|
|
| 24 |
)
|
| 25 |
|
| 26 |
|
| 27 |
-
def plot_rolling_average_roi(
|
| 28 |
-
|
| 29 |
-
) -> gr.Plot:
|
| 30 |
-
"""Function to plot the rolling average of ROI for pearl agents"""
|
| 31 |
-
# Get the list of unique addresses from the daa_pearl_df
|
| 32 |
-
unique_addresses = pearl_agents["safe_address"].unique()
|
| 33 |
-
# Filter the weekly_roi_df to include only those addresses
|
| 34 |
-
filtered_traders_data = traders_data[
|
| 35 |
-
traders_data["trader_address"].isin(unique_addresses)
|
| 36 |
-
].copy()
|
| 37 |
-
# create the date column
|
| 38 |
-
filtered_traders_data["creation_timestamp"] = pd.to_datetime(
|
| 39 |
-
filtered_traders_data["creation_timestamp"]
|
| 40 |
-
)
|
| 41 |
-
filtered_traders_data["creation_date"] = filtered_traders_data[
|
| 42 |
-
"creation_timestamp"
|
| 43 |
-
].dt.date
|
| 44 |
|
| 45 |
-
# Get the 2-week rolling average of ROI
|
| 46 |
-
rolling_avg_roi_df = get_twoweeks_rolling_average_roi(filtered_traders_data)
|
| 47 |
print("Rolling average ROI DataFrame:")
|
| 48 |
-
print(
|
| 49 |
|
| 50 |
fig2 = px.bar(
|
| 51 |
-
|
| 52 |
x="creation_date",
|
| 53 |
-
y="
|
| 54 |
)
|
| 55 |
fig2.update_layout(
|
| 56 |
xaxis_title="Week",
|
| 57 |
-
yaxis_title="2-week rolling average
|
| 58 |
)
|
| 59 |
|
| 60 |
return gr.Plot(
|
|
@@ -62,60 +45,6 @@ def plot_rolling_average_roi(
|
|
| 62 |
)
|
| 63 |
|
| 64 |
|
| 65 |
-
def get_twoweeks_rolling_average_roi(traders_data: pd.DataFrame) -> pd.DataFrame:
|
| 66 |
-
"""Function to get the 2-week rolling average of the ROI by market_creator and total"""
|
| 67 |
-
|
| 68 |
-
# Create a copy to avoid SettingWithCopyWarning
|
| 69 |
-
local_df = traders_data.copy()
|
| 70 |
-
|
| 71 |
-
# Ensure creation_date is datetime64[ns]
|
| 72 |
-
# Since creation_date comes from .dt.date, it's a date object, not datetime
|
| 73 |
-
local_df["creation_date"] = pd.to_datetime(local_df["creation_date"])
|
| 74 |
-
|
| 75 |
-
# Aggregate ROI at the date level
|
| 76 |
-
daily_avg2 = local_df.groupby("creation_date")["roi"].mean().reset_index()
|
| 77 |
-
|
| 78 |
-
# Set the datetime index
|
| 79 |
-
daily_avg2 = daily_avg2.set_index("creation_date")
|
| 80 |
-
|
| 81 |
-
# Now resample and rolling average
|
| 82 |
-
weekly_avg2 = daily_avg2.resample("W").mean()
|
| 83 |
-
rolling_avg = weekly_avg2.rolling(window=2).mean().reset_index()
|
| 84 |
-
|
| 85 |
-
return rolling_avg
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
def get_weekly_average_roi(traders_data: pd.DataFrame) -> pd.DataFrame:
|
| 89 |
-
"""Function to get the weekly average ROI by market_creator and total"""
|
| 90 |
-
|
| 91 |
-
# Create a copy to avoid SettingWithCopyWarning
|
| 92 |
-
local_df = traders_data.copy()
|
| 93 |
-
|
| 94 |
-
# Ensure creation_date is datetime64[ns]
|
| 95 |
-
# Since creation_date comes from .dt.date, it's a date object, not datetime
|
| 96 |
-
local_df["creation_date"] = pd.to_datetime(local_df["creation_date"])
|
| 97 |
-
# take the daily mean roi at the trader_address level
|
| 98 |
-
daily_mean_roi = (
|
| 99 |
-
local_df.groupby(["trader_address", "creation_date"])["roi"]
|
| 100 |
-
.mean()
|
| 101 |
-
.reset_index()
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
# Aggregate ROI at the date level first
|
| 105 |
-
daily_avg = daily_mean_roi.groupby("creation_date")["roi"].mean().reset_index()
|
| 106 |
-
|
| 107 |
-
# Set the datetime index
|
| 108 |
-
daily_avg = daily_avg.set_index("creation_date")
|
| 109 |
-
|
| 110 |
-
# Resample to weekly frequency and calculate mean
|
| 111 |
-
weekly_avg = daily_avg.resample("W").mean().reset_index()
|
| 112 |
-
|
| 113 |
-
# Remove NaN values
|
| 114 |
-
weekly_avg = weekly_avg.dropna(subset=["roi"])
|
| 115 |
-
|
| 116 |
-
return weekly_avg
|
| 117 |
-
|
| 118 |
-
|
| 119 |
def plot_weekly_average_roi(weekly_avg_roi_df: pd.DataFrame) -> gr.Plot:
|
| 120 |
"""Function to plot the weekly average of ROI for pearl agents"""
|
| 121 |
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
|
| 27 |
+
def plot_rolling_average_roi(two_weeks_avg_roi_pearl_agents: pd.DataFrame) -> gr.Plot:
|
| 28 |
+
"""Function to plot the 2-weeks rolling average ROI for pearl agents"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|
|
|
|
|
| 30 |
print("Rolling average ROI DataFrame:")
|
| 31 |
+
print(two_weeks_avg_roi_pearl_agents.head())
|
| 32 |
|
| 33 |
fig2 = px.bar(
|
| 34 |
+
two_weeks_avg_roi_pearl_agents,
|
| 35 |
x="creation_date",
|
| 36 |
+
y="two_weeks_avg_roi",
|
| 37 |
)
|
| 38 |
fig2.update_layout(
|
| 39 |
xaxis_title="Week",
|
| 40 |
+
yaxis_title="2-week rolling average ROI of pearl agents",
|
| 41 |
)
|
| 42 |
|
| 43 |
return gr.Plot(
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
def plot_weekly_average_roi(weekly_avg_roi_df: pd.DataFrame) -> gr.Plot:
|
| 49 |
"""Function to plot the weekly average of ROI for pearl agents"""
|
| 50 |
|