cyberosa commited on
Commit
3a34298
·
1 Parent(s): 4e4eb03

fixing Agents ROI graph

Browse files
Files changed (1) hide show
  1. tabs/agent_graphs.py +20 -9
tabs/agent_graphs.py CHANGED
@@ -117,19 +117,30 @@ def plot_rolling_average_roi(
117
 
118
  def get_twoweeks_rolling_average_roi(traders_data: pd.DataFrame) -> pd.DataFrame:
119
  """Function to get the 2-week rolling average of the ROI by market_creator and total"""
120
-
121
- # Aggregate ROI at the date level
122
- daily_avg = traders_data.groupby("creation_date")["roi"].mean().reset_index()
 
123
  # Ensure creation_date is datetime64[ns]
124
- daily_avg["creation_date"] = pd.to_datetime(daily_avg["creation_date"])
 
 
 
 
 
 
125
  daily_avg = daily_avg.set_index("creation_date")
126
- # Now resample and rolling
 
127
  weekly_avg = daily_avg.resample("W").mean()
128
  rolling_avg = weekly_avg.rolling(window=2).mean().reset_index()
129
-
130
- rolling_avg.rename(columns={"roi": "rolling_avg_roi"}, inplace=True)
131
- # Optionally, rename the date column for clarity
132
- rolling_avg.rename(columns={"creation_date": "month_year_week"}, inplace=True)
 
 
 
133
  return rolling_avg
134
 
135
 
 
117
 
118
  def get_twoweeks_rolling_average_roi(traders_data: pd.DataFrame) -> pd.DataFrame:
119
  """Function to get the 2-week rolling average of the ROI by market_creator and total"""
120
+
121
+ # Create a copy to avoid SettingWithCopyWarning
122
+ local_df = traders_data.copy()
123
+
124
  # Ensure creation_date is datetime64[ns]
125
+ # Since creation_date comes from .dt.date, it's a date object, not datetime
126
+ local_df["creation_date"] = pd.to_datetime(local_df["creation_date"])
127
+
128
+ # Aggregate ROI at the date level
129
+ daily_avg = local_df.groupby("creation_date")["roi"].mean().reset_index()
130
+
131
+ # Set the datetime index
132
  daily_avg = daily_avg.set_index("creation_date")
133
+
134
+ # Now resample and rolling average
135
  weekly_avg = daily_avg.resample("W").mean()
136
  rolling_avg = weekly_avg.rolling(window=2).mean().reset_index()
137
+
138
+ # Rename columns
139
+ rolling_avg.rename(columns={
140
+ "roi": "rolling_avg_roi",
141
+ "creation_date": "month_year_week"
142
+ }, inplace=True)
143
+
144
  return rolling_avg
145
 
146