cyberosa commited on
Commit
00d49a3
Β·
1 Parent(s): 3498a52

updating money invested tab with other level of aggregation

Browse files
Files changed (2) hide show
  1. app.py +9 -7
  2. tabs/trader_plots.py +35 -17
app.py CHANGED
@@ -406,28 +406,30 @@ with demo:
406
  with gr.Column(scale=1):
407
  interpretation = get_interpretation_text()
408
 
409
- with gr.TabItem("πŸ’° Money invested per trader"):
410
  with gr.Row():
411
- gr.Markdown("# Weekly total bet amount per trader for all traders")
412
  with gr.Row():
413
- total_bet_amount = plot_total_bet_amount(trader_agents_data)
 
 
414
 
415
  with gr.Row():
416
  gr.Markdown(
417
- "# Weekly total bet amount per trader for traders Agents πŸ€–"
418
  )
419
  with gr.Row():
420
  a_trader_total_bet_amount = plot_total_bet_amount(
421
- trader_agents_data, trader_filter="agent"
422
  )
423
 
424
  with gr.Row():
425
  gr.Markdown(
426
- "# Weekly total bet amount per trader for Non-agent traders"
427
  )
428
  with gr.Row():
429
  na_trader_total_bet_amount = plot_total_bet_amount(
430
- trader_agents_data, trader_filter="non_agent"
431
  )
432
  with gr.TabItem("πŸ’° Money invested per market"):
433
  with gr.Row():
 
406
  with gr.Column(scale=1):
407
  interpretation = get_interpretation_text()
408
 
409
+ with gr.TabItem("πŸ’° Money invested per trader type"):
410
  with gr.Row():
411
+ gr.Markdown("# Weekly total bet amount per trader type for all markets")
412
  with gr.Row():
413
+ total_bet_amount = plot_total_bet_amount(
414
+ trader_agents_data, market_filter="all"
415
+ )
416
 
417
  with gr.Row():
418
  gr.Markdown(
419
+ "# Weekly total bet amount per trader type for Pearl markets"
420
  )
421
  with gr.Row():
422
  a_trader_total_bet_amount = plot_total_bet_amount(
423
+ trader_agents_data, market_filter="pearl"
424
  )
425
 
426
  with gr.Row():
427
  gr.Markdown(
428
+ "# Weekly total bet amount per trader type for Quickstart markets"
429
  )
430
  with gr.Row():
431
  na_trader_total_bet_amount = plot_total_bet_amount(
432
+ trader_agents_data, market_filter="quickstart"
433
  )
434
  with gr.TabItem("πŸ’° Money invested per market"):
435
  with gr.Row():
tabs/trader_plots.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import plotly.express as px
 
4
 
5
  trader_metric_choices = [
6
  "mech calls",
@@ -176,7 +177,7 @@ def plot_winning_metric_per_trader(traders_winning_df: pd.DataFrame) -> gr.Plot:
176
 
177
 
178
  def plot_total_bet_amount(
179
- trades_df: pd.DataFrame, trader_filter: str = "all"
180
  ) -> gr.Plot:
181
  """Plots the trade metrics."""
182
  traders_all = trades_df.copy(deep=True)
@@ -190,37 +191,54 @@ def plot_total_bet_amount(
190
  lambda x: "non_agent" if x == "non_agent" else "agent"
191
  )
192
 
193
- color_discrete_sequence = ["purple", "goldenrod", "darkgreen"]
194
- if trader_filter == "agent":
195
- color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
196
- final_traders = final_traders.loc[final_traders["trader_type"] == "agent"]
197
- elif trader_filter == "non_agent":
198
- final_traders = final_traders.loc[final_traders["trader_type"] != "agent"]
199
-
200
  total_bet_amount = (
201
  final_traders.groupby(
202
- ["month_year_week", "market_creator", "trader_address"], sort=False
203
  )["collateral_amount"]
204
  .sum()
205
  .reset_index(name="total_bet_amount")
206
  )
207
-
208
- fig = px.box(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  total_bet_amount,
210
  x="month_year_week",
211
  y="total_bet_amount",
212
- color="market_creator",
213
- color_discrete_sequence=color_discrete_sequence,
214
  category_orders={
215
  "market_creator": ["pearl", "quickstart", "all"],
 
 
 
 
 
 
 
 
216
  },
217
- # barmode="group",
218
- # facet_col="market_creator",
219
  )
220
- fig.update_traces(boxmean=True)
221
  fig.update_layout(
222
  xaxis_title="Week",
223
- yaxis_title="Weekly total bet amount",
224
  legend=dict(yanchor="top", y=0.5),
225
  )
226
  # for axis in fig.layout:
 
1
  import gradio as gr
2
  import pandas as pd
3
  import plotly.express as px
4
+ from tabs.market_plots import color_mapping
5
 
6
  trader_metric_choices = [
7
  "mech calls",
 
177
 
178
 
179
  def plot_total_bet_amount(
180
+ trades_df: pd.DataFrame, market_filter: str = "all"
181
  ) -> gr.Plot:
182
  """Plots the trade metrics."""
183
  traders_all = trades_df.copy(deep=True)
 
191
  lambda x: "non_agent" if x == "non_agent" else "agent"
192
  )
193
 
 
 
 
 
 
 
 
194
  total_bet_amount = (
195
  final_traders.groupby(
196
+ ["month_year_week", "market_creator", "trader_type"], sort=False
197
  )["collateral_amount"]
198
  .sum()
199
  .reset_index(name="total_bet_amount")
200
  )
201
+ total_bet_amount["trader_market"] = total_bet_amount.apply(
202
+ lambda x: (x["trader_type"], x["market_creator"]), axis=1
203
+ )
204
+ color_discrete_sequence = ["purple", "goldenrod", "darkgreen"]
205
+ if market_filter == "pearl":
206
+ color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
207
+ total_bet_amount = total_bet_amount.loc[
208
+ total_bet_amount["market_creator"] == "pearl"
209
+ ]
210
+ elif market_filter == "quickstart":
211
+ total_bet_amount = total_bet_amount.loc[
212
+ total_bet_amount["market_creator"] == "quickstart"
213
+ ]
214
+ else:
215
+ total_bet_amount = total_bet_amount.loc[
216
+ total_bet_amount["market_creator"] == "all"
217
+ ]
218
+
219
+ fig = px.bar(
220
  total_bet_amount,
221
  x="month_year_week",
222
  y="total_bet_amount",
223
+ color="trader_market",
224
+ color_discrete_sequence=color_mapping,
225
  category_orders={
226
  "market_creator": ["pearl", "quickstart", "all"],
227
+ "trader_market": [
228
+ ("agent", "pearl"),
229
+ ("non_agent", "pearl"),
230
+ ("agent", "quickstart"),
231
+ ("non_agent", "quickstart"),
232
+ ("agent", "all"),
233
+ ("non_agent", "all"),
234
+ ],
235
  },
236
+ barmode="group",
 
237
  )
238
+
239
  fig.update_layout(
240
  xaxis_title="Week",
241
+ yaxis_title="Weekly total bet amount per trader type",
242
  legend=dict(yanchor="top", y=0.5),
243
  )
244
  # for axis in fig.layout: