cyberosa commited on
Commit
e376aff
·
1 Parent(s): c571577

updated graphs after missing non_Olas group

Browse files
Files changed (1) hide show
  1. app.py +140 -101
app.py CHANGED
@@ -101,15 +101,27 @@ def get_all_data():
101
  FROM read_parquet('./data/retention_activity.parquet')
102
  """
103
  df5 = con.execute(query5).fetchdf()
 
 
 
 
 
 
 
104
  con.close()
105
- return df1, df2, df3, df4, df5
106
 
107
 
108
  def prepare_data():
109
 
110
- all_trades, closed_markets, daily_info, unknown_traders, retention_df = (
111
- get_all_data()
112
- )
 
 
 
 
 
113
 
114
  all_trades["creation_date"] = all_trades["creation_timestamp"].dt.date
115
 
@@ -150,12 +162,24 @@ def prepare_data():
150
  .dt.to_period("W")
151
  .dt.start_time.dt.strftime("%b-%d-%Y")
152
  )
153
- return traders_data, closed_markets, daily_info, unknown_traders, retention_df
 
 
 
 
 
 
 
154
 
155
 
156
- traders_data, closed_markets, daily_info, unknown_traders, raw_retention_df = (
157
- prepare_data()
158
- )
 
 
 
 
 
159
  retention_df = prepare_retention_dataset(
160
  retention_df=raw_retention_df, unknown_df=unknown_traders
161
  )
@@ -170,9 +194,11 @@ weekly_metrics_by_market_creator = compute_weekly_metrics_by_market_creator(
170
  weekly_o_metrics_by_market_creator = compute_weekly_metrics_by_market_creator(
171
  traders_data, trader_filter="Olas"
172
  )
173
- weekly_non_olas_metrics_by_market_creator = compute_weekly_metrics_by_market_creator(
174
- traders_data, trader_filter="non_Olas"
175
- )
 
 
176
  weekly_unknown_trader_metrics_by_market_creator = None
177
  if len(unknown_traders) > 0:
178
  weekly_unknown_trader_metrics_by_market_creator = (
@@ -181,10 +207,18 @@ if len(unknown_traders) > 0:
181
  )
182
  )
183
 
184
- weekly_winning_metrics = compute_winning_metrics_by_trader(traders_data=traders_data)
185
- weekly_non_olas_winning_metrics = compute_winning_metrics_by_trader(
186
- traders_data=traders_data, trader_filter="non_Olas"
 
 
 
187
  )
 
 
 
 
 
188
 
189
  with demo:
190
  gr.HTML("<h1>Traders monitoring dashboard </h1>")
@@ -251,37 +285,37 @@ with demo:
251
  inputs=trader_o_details_selector,
252
  outputs=o_trader_markets_plot,
253
  )
 
 
 
 
 
 
 
 
 
 
254
 
255
- # Non-Olas traders graph
256
- with gr.Row():
257
- gr.Markdown("# Weekly metrics of Non-Olas traders")
258
- with gr.Row():
259
- trader_no_details_selector = gr.Dropdown(
260
- label="Select a weekly trader metric",
261
- choices=trader_metric_choices,
262
- value=default_trader_metric,
263
- )
264
 
265
- with gr.Row():
266
- with gr.Column(scale=3):
267
- trader_no_markets_plot = plot_trader_metrics_by_market_creator(
268
- metric_name=default_trader_metric,
269
  traders_df=weekly_non_olas_metrics_by_market_creator,
270
  )
271
- with gr.Column(scale=1):
272
- trade_details_text = get_metrics_text(trader_type="non_Olas")
273
 
274
- def update_no_trader_details(trader_detail):
275
- return plot_trader_metrics_by_market_creator(
276
- metric_name=trader_detail,
277
- traders_df=weekly_non_olas_metrics_by_market_creator,
278
  )
279
-
280
- trader_no_details_selector.change(
281
- update_no_trader_details,
282
- inputs=trader_no_details_selector,
283
- outputs=trader_no_markets_plot,
284
- )
285
  # Unknown traders graph
286
  if weekly_unknown_trader_metrics_by_market_creator is not None:
287
  with gr.Row():
@@ -453,7 +487,7 @@ with demo:
453
  )
454
 
455
  with gr.Row():
456
- gr.Markdown("# Cohort retention in pearl traders")
457
  with gr.Row():
458
  gr.Markdown(
459
  "The Cohort groups are organized by cohort weeks. A trader is part of a cohort group/week where it was detected the FIRST activity ever of that trader."
@@ -470,7 +504,8 @@ with demo:
470
  )
471
  with gr.Row():
472
  with gr.Column(scale=1):
473
- gr.Markdown("## Cohort retention of 🌊 Olas traders")
 
474
  cohort_retention_olas_pearl = calculate_cohort_retention(
475
  df=retention_df, market_creator="pearl", trader_type="Olas"
476
  )
@@ -478,34 +513,8 @@ with demo:
478
  retention_matrix=cohort_retention_olas_pearl, cmap="Purples"
479
  )
480
  with gr.Column(scale=1):
481
- gr.Markdown("## Cohort retention of Non-Olas traders")
482
- # non_Olas
483
- cohort_retention_non_olas_pearl = calculate_cohort_retention(
484
- df=retention_df, market_creator="pearl", trader_type="non_Olas"
485
- )
486
- cohort_retention_plot2 = plot_cohort_retention_heatmap(
487
- retention_matrix=cohort_retention_non_olas_pearl,
488
- cmap=sns.color_palette("light:goldenrod", as_cmap=True),
489
- )
490
- with gr.Row():
491
- with gr.Column(scale=1):
492
- gr.Markdown("## Cohort retention of unclassified traders")
493
- cohort_retention_unclassified_pearl = calculate_cohort_retention(
494
- df=retention_df,
495
- market_creator="pearl",
496
- trader_type="unclassified",
497
- )
498
- cohort_retention_plot3 = plot_cohort_retention_heatmap(
499
- retention_matrix=cohort_retention_unclassified_pearl,
500
- cmap="Greens",
501
- )
502
- with gr.Column(scale=1):
503
- print("Adding explanatory text")
504
- with gr.Row():
505
- gr.Markdown("# Cohort retention in quickstart traders")
506
- with gr.Row():
507
- with gr.Column(scale=1):
508
- gr.Markdown("## Cohort retention of 🌊 Olas traders")
509
  cohort_retention_olas_qs = calculate_cohort_retention(
510
  df=retention_df, market_creator="quickstart", trader_type="Olas"
511
  )
@@ -513,43 +522,66 @@ with demo:
513
  retention_matrix=cohort_retention_olas_qs,
514
  cmap="Purples",
515
  )
 
 
 
 
 
 
 
 
 
 
 
516
  with gr.Column(scale=1):
517
- gr.Markdown("## Cohort retention of Non-Olas traders")
518
- # non_Olas
519
- cohort_retention_non_olas_qs = calculate_cohort_retention(
520
  df=retention_df,
521
- market_creator="quickstart",
522
- trader_type="non_Olas",
523
- )
524
- cohort_retention_plot5 = plot_cohort_retention_heatmap(
525
- retention_matrix=cohort_retention_non_olas_qs,
526
- cmap=sns.color_palette("light:goldenrod", as_cmap=True),
527
  )
528
- with gr.Row():
 
 
 
 
 
529
  with gr.Column(scale=1):
530
- gr.Markdown("## Cohort retention of unclassified traders")
531
  cohort_retention_unclassified_qs = calculate_cohort_retention(
532
  df=retention_df,
533
  market_creator="quickstart",
534
  trader_type="unclassified",
535
  )
536
- cohort_retention_plot6 = plot_cohort_retention_heatmap(
537
- retention_matrix=cohort_retention_unclassified_qs,
538
- cmap="Greens",
539
- )
540
- with gr.Column(scale=1):
541
- print("Adding explanatory text")
 
 
 
 
 
 
 
 
 
 
 
 
542
  with gr.TabItem("⚙️ Active traders"):
543
  with gr.Row():
544
  gr.Markdown("# Active traders for all markets by trader categories")
545
  with gr.Row():
546
- active_traders_plot = plot_active_traders(traders_data, unknown_traders)
547
 
548
  with gr.Row():
549
  gr.Markdown("# Active traders for Pearl markets by trader categories")
550
  with gr.Row():
551
- active_traders_plot = plot_active_traders(
552
- traders_data, unknown_traders, market_creator="pearl"
553
  )
554
 
555
  with gr.Row():
@@ -557,8 +589,8 @@ with demo:
557
  "# Active traders for Quickstart markets by trader categories"
558
  )
559
  with gr.Row():
560
- active_traders_plot = plot_active_traders(
561
- traders_data, unknown_traders, market_creator="quickstart"
562
  )
563
 
564
  with gr.TabItem("📉 Markets Kullback–Leibler divergence"):
@@ -581,6 +613,7 @@ with demo:
581
  with gr.TabItem("💰 Money invested per trader type"):
582
  with gr.Row():
583
  gr.Markdown("# Weekly total bet amount per trader type for all markets")
 
584
  with gr.Row():
585
  total_bet_amount = plot_total_bet_amount(
586
  traders_data, market_filter="all"
@@ -607,6 +640,7 @@ with demo:
607
  with gr.TabItem("💰 Money invested per market"):
608
  with gr.Row():
609
  gr.Markdown("# Weekly bet amounts per market for all traders")
 
610
  with gr.Row():
611
  bet_amounts = plot_total_bet_amount_per_trader_per_market(traders_data)
612
 
@@ -637,16 +671,21 @@ with demo:
637
  with gr.Row():
638
  metrics_text = get_metrics_text()
639
  with gr.Row():
640
- winning_metric = plot_winning_metric_per_trader(weekly_winning_metrics)
641
-
642
- # non_Olasic traders
643
- with gr.Row():
644
- gr.Markdown("# Weekly winning trades percentage from Non-Olas traders")
645
- with gr.Row():
646
- metrics_text = get_metrics_text()
647
- with gr.Row():
648
- winning_metric = plot_winning_metric_per_trader(
649
- weekly_non_olas_winning_metrics
650
  )
651
 
 
 
 
 
 
 
 
 
 
 
 
 
 
652
  demo.queue(default_concurrency_limit=40).launch()
 
101
  FROM read_parquet('./data/retention_activity.parquet')
102
  """
103
  df5 = con.execute(query5).fetchdf()
104
+
105
+ # Query to fetch active traders data
106
+ query6 = f"""
107
+ SELECT *
108
+ FROM read_parquet('./data/active_traders.parquet')
109
+ """
110
+ df6 = con.execute(query6).fetchdf()
111
  con.close()
112
+ return df1, df2, df3, df4, df5, df6
113
 
114
 
115
  def prepare_data():
116
 
117
+ (
118
+ all_trades,
119
+ closed_markets,
120
+ daily_info,
121
+ unknown_traders,
122
+ retention_df,
123
+ active_traders,
124
+ ) = get_all_data()
125
 
126
  all_trades["creation_date"] = all_trades["creation_timestamp"].dt.date
127
 
 
162
  .dt.to_period("W")
163
  .dt.start_time.dt.strftime("%b-%d-%Y")
164
  )
165
+ return (
166
+ traders_data,
167
+ closed_markets,
168
+ daily_info,
169
+ unknown_traders,
170
+ retention_df,
171
+ active_traders,
172
+ )
173
 
174
 
175
+ (
176
+ traders_data,
177
+ closed_markets,
178
+ daily_info,
179
+ unknown_traders,
180
+ raw_retention_df,
181
+ active_traders,
182
+ ) = prepare_data()
183
  retention_df = prepare_retention_dataset(
184
  retention_df=raw_retention_df, unknown_df=unknown_traders
185
  )
 
194
  weekly_o_metrics_by_market_creator = compute_weekly_metrics_by_market_creator(
195
  traders_data, trader_filter="Olas"
196
  )
197
+ weekly_non_olas_metrics_by_market_creator = pd.DataFrame()
198
+ if len(traders_data.loc[traders_data["staking"] == "non_Olas"]) > 0:
199
+ weekly_non_olas_metrics_by_market_creator = (
200
+ compute_weekly_metrics_by_market_creator(traders_data, trader_filter="non_Olas")
201
+ )
202
  weekly_unknown_trader_metrics_by_market_creator = None
203
  if len(unknown_traders) > 0:
204
  weekly_unknown_trader_metrics_by_market_creator = (
 
207
  )
208
  )
209
 
210
+ # just for all traders
211
+ weekly_winning_metrics = compute_winning_metrics_by_trader(
212
+ traders_data=traders_data, unknown_info=unknown_traders
213
+ )
214
+ weekly_winning_metrics_olas = compute_winning_metrics_by_trader(
215
+ traders_data=traders_data, unknown_info=unknown_traders, trader_filter="Olas"
216
  )
217
+ weekly_non_olas_winning_metrics = pd.DataFrame()
218
+ if len(traders_data.loc[traders_data["staking"] == "non_Olas"]) > 0:
219
+ weekly_non_olas_winning_metrics = compute_winning_metrics_by_trader(
220
+ traders_data=traders_data, trader_filter="non_Olas"
221
+ )
222
 
223
  with demo:
224
  gr.HTML("<h1>Traders monitoring dashboard </h1>")
 
285
  inputs=trader_o_details_selector,
286
  outputs=o_trader_markets_plot,
287
  )
288
+ if len(weekly_non_olas_metrics_by_market_creator) > 0:
289
+ # Non-Olas traders graph
290
+ with gr.Row():
291
+ gr.Markdown("# Weekly metrics of Non-Olas traders")
292
+ with gr.Row():
293
+ trader_no_details_selector = gr.Dropdown(
294
+ label="Select a weekly trader metric",
295
+ choices=trader_metric_choices,
296
+ value=default_trader_metric,
297
+ )
298
 
299
+ with gr.Row():
300
+ with gr.Column(scale=3):
301
+ trader_no_markets_plot = plot_trader_metrics_by_market_creator(
302
+ metric_name=default_trader_metric,
303
+ traders_df=weekly_non_olas_metrics_by_market_creator,
304
+ )
305
+ with gr.Column(scale=1):
306
+ trade_details_text = get_metrics_text(trader_type="non_Olas")
 
307
 
308
+ def update_no_trader_details(trader_detail):
309
+ return plot_trader_metrics_by_market_creator(
310
+ metric_name=trader_detail,
 
311
  traders_df=weekly_non_olas_metrics_by_market_creator,
312
  )
 
 
313
 
314
+ trader_no_details_selector.change(
315
+ update_no_trader_details,
316
+ inputs=trader_no_details_selector,
317
+ outputs=trader_no_markets_plot,
318
  )
 
 
 
 
 
 
319
  # Unknown traders graph
320
  if weekly_unknown_trader_metrics_by_market_creator is not None:
321
  with gr.Row():
 
487
  )
488
 
489
  with gr.Row():
490
+ gr.Markdown("# Cohort retention graphs")
491
  with gr.Row():
492
  gr.Markdown(
493
  "The Cohort groups are organized by cohort weeks. A trader is part of a cohort group/week where it was detected the FIRST activity ever of that trader."
 
504
  )
505
  with gr.Row():
506
  with gr.Column(scale=1):
507
+ gr.Markdown("## Cohort retention of pearl traders")
508
+ gr.Markdown("### Cohort retention of 🌊 Olas traders")
509
  cohort_retention_olas_pearl = calculate_cohort_retention(
510
  df=retention_df, market_creator="pearl", trader_type="Olas"
511
  )
 
513
  retention_matrix=cohort_retention_olas_pearl, cmap="Purples"
514
  )
515
  with gr.Column(scale=1):
516
+ gr.Markdown("## Cohort retention of quickstart traders")
517
+ gr.Markdown("### Cohort retention of 🌊 Olas traders")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
518
  cohort_retention_olas_qs = calculate_cohort_retention(
519
  df=retention_df, market_creator="quickstart", trader_type="Olas"
520
  )
 
522
  retention_matrix=cohort_retention_olas_qs,
523
  cmap="Purples",
524
  )
525
+ # # non_Olas
526
+ # cohort_retention_non_olas_pearl = calculate_cohort_retention(
527
+ # df=retention_df, market_creator="pearl", trader_type="non_Olas"
528
+ # )
529
+ # if len(cohort_retention_non_olas_pearl) > 0:
530
+ # gr.Markdown("## Cohort retention of Non-Olas traders")
531
+ # cohort_retention_plot2 = plot_cohort_retention_heatmap(
532
+ # retention_matrix=cohort_retention_non_olas_pearl,
533
+ # cmap=sns.color_palette("light:goldenrod", as_cmap=True),
534
+ # )
535
+ with gr.Row():
536
  with gr.Column(scale=1):
537
+ gr.Markdown("## Cohort retention of pearl traders")
538
+ cohort_retention_unclassified_pearl = calculate_cohort_retention(
 
539
  df=retention_df,
540
+ market_creator="pearl",
541
+ trader_type="unclassified",
 
 
 
 
542
  )
543
+ if len(cohort_retention_unclassified_pearl) > 0:
544
+ gr.Markdown("### Cohort retention of unclassified traders")
545
+ cohort_retention_plot3 = plot_cohort_retention_heatmap(
546
+ retention_matrix=cohort_retention_unclassified_pearl,
547
+ cmap="Greens",
548
+ )
549
  with gr.Column(scale=1):
550
+ gr.Markdown("## Cohort retention in quickstart traders")
551
  cohort_retention_unclassified_qs = calculate_cohort_retention(
552
  df=retention_df,
553
  market_creator="quickstart",
554
  trader_type="unclassified",
555
  )
556
+ if len(cohort_retention_unclassified_qs) > 0:
557
+ gr.Markdown("### Cohort retention of unclassified traders")
558
+ cohort_retention_plot6 = plot_cohort_retention_heatmap(
559
+ retention_matrix=cohort_retention_unclassified_qs,
560
+ cmap="Greens",
561
+ )
562
+ # # non_Olas
563
+ # cohort_retention_non_olas_qs = calculate_cohort_retention(
564
+ # df=retention_df,
565
+ # market_creator="quickstart",
566
+ # trader_type="non_Olas",
567
+ # )
568
+ # if len(cohort_retention_non_olas_qs) > 0:
569
+ # gr.Markdown("## Cohort retention of Non-Olas traders")
570
+ # cohort_retention_plot5 = plot_cohort_retention_heatmap(
571
+ # retention_matrix=cohort_retention_non_olas_qs,
572
+ # cmap=sns.color_palette("light:goldenrod", as_cmap=True),
573
+ # )
574
  with gr.TabItem("⚙️ Active traders"):
575
  with gr.Row():
576
  gr.Markdown("# Active traders for all markets by trader categories")
577
  with gr.Row():
578
+ active_traders_plot = plot_active_traders(active_traders)
579
 
580
  with gr.Row():
581
  gr.Markdown("# Active traders for Pearl markets by trader categories")
582
  with gr.Row():
583
+ active_traders_plot_pearl = plot_active_traders(
584
+ active_traders, market_creator="pearl"
585
  )
586
 
587
  with gr.Row():
 
589
  "# Active traders for Quickstart markets by trader categories"
590
  )
591
  with gr.Row():
592
+ active_traders_plot_qs = plot_active_traders(
593
+ active_traders, market_creator="quickstart"
594
  )
595
 
596
  with gr.TabItem("📉 Markets Kullback–Leibler divergence"):
 
613
  with gr.TabItem("💰 Money invested per trader type"):
614
  with gr.Row():
615
  gr.Markdown("# Weekly total bet amount per trader type for all markets")
616
+ gr.Markdown("## Computed only for trader agents using the mech service")
617
  with gr.Row():
618
  total_bet_amount = plot_total_bet_amount(
619
  traders_data, market_filter="all"
 
640
  with gr.TabItem("💰 Money invested per market"):
641
  with gr.Row():
642
  gr.Markdown("# Weekly bet amounts per market for all traders")
643
+ gr.Markdown("## Computed only for trader agents using the mech service")
644
  with gr.Row():
645
  bet_amounts = plot_total_bet_amount_per_trader_per_market(traders_data)
646
 
 
671
  with gr.Row():
672
  metrics_text = get_metrics_text()
673
  with gr.Row():
674
+ winning_metric_olas = plot_winning_metric_per_trader(
675
+ weekly_winning_metrics_olas
 
 
 
 
 
 
 
 
676
  )
677
 
678
+ # # non_Olas traders
679
+ # if len(weekly_non_olas_winning_metrics) > 0:
680
+ # with gr.Row():
681
+ # gr.Markdown(
682
+ # "# Weekly winning trades percentage from Non-Olas traders"
683
+ # )
684
+ # with gr.Row():
685
+ # metrics_text = get_metrics_text()
686
+ # with gr.Row():
687
+ # winning_metric = plot_winning_metric_per_trader(
688
+ # weekly_non_olas_winning_metrics
689
+ # )
690
+
691
  demo.queue(default_concurrency_limit=40).launch()