cyberosa
commited on
Commit
Β·
577dd09
1
Parent(s):
0e538d2
new aggregation level and fixed metrics text
Browse files- app.py +32 -10
- data/daily_info.parquet +2 -2
- scripts/trades_volume_per_market.py +0 -38
- tabs/daily_graphs.py +8 -8
- tabs/market_plots.py +63 -0
- tabs/trader_plots.py +9 -186
app.py
CHANGED
@@ -25,8 +25,11 @@ from tabs.daily_graphs import (
|
|
25 |
default_daily_metric,
|
26 |
)
|
27 |
from scripts.utils import get_traders_family
|
28 |
-
from
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
def get_logger():
|
@@ -148,7 +151,7 @@ with demo:
|
|
148 |
)
|
149 |
|
150 |
with gr.Tabs():
|
151 |
-
with gr.TabItem("π₯ Weekly metrics"):
|
152 |
with gr.Row():
|
153 |
gr.Markdown("# Weekly metrics of all traders")
|
154 |
with gr.Row():
|
@@ -180,7 +183,7 @@ with demo:
|
|
180 |
)
|
181 |
# Agentic traders graph
|
182 |
with gr.Row():
|
183 |
-
gr.Markdown("# Weekly metrics of trader Agents")
|
184 |
with gr.Row():
|
185 |
trader_a_details_selector = gr.Dropdown(
|
186 |
label="Select a weekly trader metric",
|
@@ -239,7 +242,7 @@ with demo:
|
|
239 |
inputs=trader_na_details_selector,
|
240 |
outputs=na_trader_markets_plot,
|
241 |
)
|
242 |
-
with gr.TabItem("π
Daily
|
243 |
current_week_trades = get_current_week_data(trades_df=trader_agents_data)
|
244 |
live_trades_current_week = get_current_week_data(trades_df=daily_info)
|
245 |
if len(current_week_trades) > 0:
|
@@ -247,6 +250,7 @@ with demo:
|
|
247 |
compute_daily_metrics_by_market_creator(current_week_trades)
|
248 |
)
|
249 |
else:
|
|
|
250 |
daily_prof_metrics_by_market_creator = pd.DataFrame()
|
251 |
live_metrics_by_market_creator = compute_daily_metrics_by_market_creator(
|
252 |
live_trades_current_week, trader_filter=None, live_metrics=True
|
@@ -269,7 +273,7 @@ with demo:
|
|
269 |
trades_df=live_metrics_by_market_creator,
|
270 |
)
|
271 |
with gr.Column(scale=1):
|
272 |
-
trade_details_text = get_metrics_text()
|
273 |
|
274 |
def update_trade_live_details(trade_detail, trade_live_details_plot):
|
275 |
new_a_plot = plot_daily_metrics(
|
@@ -300,7 +304,7 @@ with demo:
|
|
300 |
trades_df=daily_prof_metrics_by_market_creator,
|
301 |
)
|
302 |
with gr.Column(scale=1):
|
303 |
-
trader_details_text = get_metrics_text()
|
304 |
|
305 |
def update_trader_daily_details(
|
306 |
trade_detail, trader_daily_details_plot
|
@@ -342,16 +346,34 @@ with demo:
|
|
342 |
)
|
343 |
with gr.Row():
|
344 |
total_bet_amount = plot_total_bet_amount(trader_agents_data)
|
345 |
-
|
346 |
with gr.Row():
|
347 |
gr.Markdown(
|
348 |
-
"# Weekly
|
349 |
)
|
350 |
|
351 |
with gr.Row():
|
352 |
-
trades_volume_plot =
|
353 |
trader_agents_data
|
354 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
|
356 |
with gr.TabItem("ποΈWeekly winning trades % per trader"):
|
357 |
with gr.Row():
|
|
|
25 |
default_daily_metric,
|
26 |
)
|
27 |
from scripts.utils import get_traders_family
|
28 |
+
from tabs.market_plots import (
|
29 |
+
plot_kl_div_per_market,
|
30 |
+
plot_total_bet_amount,
|
31 |
+
plot_nr_trades_per_trader_per_market,
|
32 |
+
)
|
33 |
|
34 |
|
35 |
def get_logger():
|
|
|
151 |
)
|
152 |
|
153 |
with gr.Tabs():
|
154 |
+
with gr.TabItem("π₯ Weekly profitability metrics"):
|
155 |
with gr.Row():
|
156 |
gr.Markdown("# Weekly metrics of all traders")
|
157 |
with gr.Row():
|
|
|
183 |
)
|
184 |
# Agentic traders graph
|
185 |
with gr.Row():
|
186 |
+
gr.Markdown("# Weekly metrics of trader Agents π€")
|
187 |
with gr.Row():
|
188 |
trader_a_details_selector = gr.Dropdown(
|
189 |
label="Select a weekly trader metric",
|
|
|
242 |
inputs=trader_na_details_selector,
|
243 |
outputs=na_trader_markets_plot,
|
244 |
)
|
245 |
+
with gr.TabItem("π
Daily metrics (WIP)"):
|
246 |
current_week_trades = get_current_week_data(trades_df=trader_agents_data)
|
247 |
live_trades_current_week = get_current_week_data(trades_df=daily_info)
|
248 |
if len(current_week_trades) > 0:
|
|
|
250 |
compute_daily_metrics_by_market_creator(current_week_trades)
|
251 |
)
|
252 |
else:
|
253 |
+
print("No profitability info about the current week")
|
254 |
daily_prof_metrics_by_market_creator = pd.DataFrame()
|
255 |
live_metrics_by_market_creator = compute_daily_metrics_by_market_creator(
|
256 |
live_trades_current_week, trader_filter=None, live_metrics=True
|
|
|
273 |
trades_df=live_metrics_by_market_creator,
|
274 |
)
|
275 |
with gr.Column(scale=1):
|
276 |
+
trade_details_text = get_metrics_text(daily=True)
|
277 |
|
278 |
def update_trade_live_details(trade_detail, trade_live_details_plot):
|
279 |
new_a_plot = plot_daily_metrics(
|
|
|
304 |
trades_df=daily_prof_metrics_by_market_creator,
|
305 |
)
|
306 |
with gr.Column(scale=1):
|
307 |
+
trader_details_text = get_metrics_text(daily=True)
|
308 |
|
309 |
def update_trader_daily_details(
|
310 |
trade_detail, trader_daily_details_plot
|
|
|
346 |
)
|
347 |
with gr.Row():
|
348 |
total_bet_amount = plot_total_bet_amount(trader_agents_data)
|
349 |
+
with gr.TabItem("πΉ Metrics at the market level"):
|
350 |
with gr.Row():
|
351 |
gr.Markdown(
|
352 |
+
"# Weekly nr of trades per trader per market for all traders"
|
353 |
)
|
354 |
|
355 |
with gr.Row():
|
356 |
+
trades_volume_plot = plot_nr_trades_per_trader_per_market(
|
357 |
trader_agents_data
|
358 |
)
|
359 |
+
with gr.Row():
|
360 |
+
gr.Markdown(
|
361 |
+
"# Weekly nr of trades per trader per market for trader Agents π€"
|
362 |
+
)
|
363 |
+
|
364 |
+
with gr.Row():
|
365 |
+
trades_volume_plot = plot_nr_trades_per_trader_per_market(
|
366 |
+
trader_agents_data, trader_filter="agent"
|
367 |
+
)
|
368 |
+
with gr.Row():
|
369 |
+
gr.Markdown(
|
370 |
+
"# Weekly nr of trades per trader per market for non-Agent traders"
|
371 |
+
)
|
372 |
+
|
373 |
+
with gr.Row():
|
374 |
+
trades_volume_plot = plot_nr_trades_per_trader_per_market(
|
375 |
+
trader_agents_data, trader_filter="non_agent"
|
376 |
+
)
|
377 |
|
378 |
with gr.TabItem("ποΈWeekly winning trades % per trader"):
|
379 |
with gr.Row():
|
data/daily_info.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3efc44de285c7f330661d31354843e5c95f89323a04d32774971576bdf049dba
|
3 |
+
size 390502
|
scripts/trades_volume_per_market.py
DELETED
@@ -1,38 +0,0 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import gradio as gr
|
3 |
-
import plotly.express as px
|
4 |
-
|
5 |
-
|
6 |
-
def plot_weekly_trades_volume_by_trader_family(
|
7 |
-
trader_agents_data: pd.DataFrame,
|
8 |
-
) -> gr.Plot:
|
9 |
-
"""Function to compute the metrics at the trader level per week
|
10 |
-
and with different categories by market creator"""
|
11 |
-
|
12 |
-
weekly_trades_volume = (
|
13 |
-
trader_agents_data.groupby(
|
14 |
-
["month_year_week", "title", "trader_family"], sort=False
|
15 |
-
)["trader_address"]
|
16 |
-
.size()
|
17 |
-
.reset_index(name="trades")
|
18 |
-
)
|
19 |
-
|
20 |
-
fig = px.box(
|
21 |
-
weekly_trades_volume,
|
22 |
-
x="month_year_week",
|
23 |
-
y="trades",
|
24 |
-
color="trader_family",
|
25 |
-
color_discrete_sequence=["darkviolet", "goldenrod", "gray"],
|
26 |
-
category_orders={
|
27 |
-
"trader_family": ["pearl_agent", "quickstart_agent", "non_agent"]
|
28 |
-
},
|
29 |
-
)
|
30 |
-
|
31 |
-
fig.update_layout(
|
32 |
-
xaxis_title="Week",
|
33 |
-
yaxis_title="Weekly trades volume in each market per trader family type",
|
34 |
-
legend=dict(yanchor="top", y=0.5),
|
35 |
-
)
|
36 |
-
# fig.update_layout(width=WIDTH, height=HEIGHT)
|
37 |
-
fig.update_xaxes(tickformat="%b %d\n%Y")
|
38 |
-
return gr.Plot(value=fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tabs/daily_graphs.py
CHANGED
@@ -9,6 +9,14 @@ from tqdm import tqdm
|
|
9 |
|
10 |
trade_daily_metric_choices = ["mech calls", "collateral amount", "nr_trades"]
|
11 |
default_daily_metric = "collateral amount"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
def plot_daily_trades(trades_df: pd.DataFrame) -> gr.Plot:
|
@@ -103,14 +111,6 @@ def plot_daily_metrics(
|
|
103 |
trades_filtered = trades_df.loc[trades_df["staking"] == "non_agent"]
|
104 |
else:
|
105 |
trades_filtered = trades_df
|
106 |
-
color_mapping = [
|
107 |
-
"darkviolet",
|
108 |
-
"purple",
|
109 |
-
"goldenrod",
|
110 |
-
"darkgoldenrod",
|
111 |
-
"green",
|
112 |
-
"darkgreen",
|
113 |
-
]
|
114 |
|
115 |
# Create binary staking category
|
116 |
trades_filtered["trader_type"] = trades_filtered["staking"].apply(
|
|
|
9 |
|
10 |
trade_daily_metric_choices = ["mech calls", "collateral amount", "nr_trades"]
|
11 |
default_daily_metric = "collateral amount"
|
12 |
+
color_mapping = [
|
13 |
+
"darkviolet",
|
14 |
+
"purple",
|
15 |
+
"goldenrod",
|
16 |
+
"darkgoldenrod",
|
17 |
+
"green",
|
18 |
+
"darkgreen",
|
19 |
+
]
|
20 |
|
21 |
|
22 |
def plot_daily_trades(trades_df: pd.DataFrame) -> gr.Plot:
|
|
|
111 |
trades_filtered = trades_df.loc[trades_df["staking"] == "non_agent"]
|
112 |
else:
|
113 |
trades_filtered = trades_df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
# Create binary staking category
|
116 |
trades_filtered["trader_type"] = trades_filtered["staking"].apply(
|
tabs/market_plots.py
CHANGED
@@ -5,6 +5,7 @@ import plotly.graph_objects as go
|
|
5 |
from plotly.subplots import make_subplots
|
6 |
import matplotlib.pyplot as plt
|
7 |
import seaborn as sns
|
|
|
8 |
|
9 |
|
10 |
def plot_kl_div_per_market(closed_markets: pd.DataFrame) -> gr.Plot:
|
@@ -146,3 +147,65 @@ def plot_total_bet_amount(trades_df: pd.DataFrame) -> gr.Plot:
|
|
146 |
return gr.Plot(
|
147 |
value=fig,
|
148 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
from plotly.subplots import make_subplots
|
6 |
import matplotlib.pyplot as plt
|
7 |
import seaborn as sns
|
8 |
+
from tabs.daily_graphs import color_mapping
|
9 |
|
10 |
|
11 |
def plot_kl_div_per_market(closed_markets: pd.DataFrame) -> gr.Plot:
|
|
|
147 |
return gr.Plot(
|
148 |
value=fig,
|
149 |
)
|
150 |
+
|
151 |
+
|
152 |
+
def plot_nr_trades_per_trader_per_market(
|
153 |
+
traders_data: pd.DataFrame, trader_filter: str = "all"
|
154 |
+
) -> gr.Plot:
|
155 |
+
"""Function to paint the plot with the metric nr_trades_per_market by trader type and market creator"""
|
156 |
+
|
157 |
+
traders_all = traders_data.copy(deep=True)
|
158 |
+
traders_all["market_creator"] = "all"
|
159 |
+
|
160 |
+
# merging both dataframes
|
161 |
+
final_traders = pd.concat([traders_all, traders_data], ignore_index=True)
|
162 |
+
final_traders = final_traders.sort_values(by="creation_date", ascending=True)
|
163 |
+
|
164 |
+
# Create binary staking category
|
165 |
+
final_traders["trader_type"] = final_traders["staking"].apply(
|
166 |
+
lambda x: "non_agent" if x == "non_agent" else "agent"
|
167 |
+
)
|
168 |
+
final_traders["trader_market"] = final_traders.apply(
|
169 |
+
lambda x: (x["trader_type"], x["market_creator"]), axis=1
|
170 |
+
)
|
171 |
+
color_discrete_sequence = ["purple", "goldenrod", "darkgreen"]
|
172 |
+
if trader_filter == "agent":
|
173 |
+
color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
|
174 |
+
final_traders = final_traders.loc[final_traders["trader_type"] == "agent"]
|
175 |
+
elif trader_filter == "non_agent":
|
176 |
+
final_traders = final_traders.loc[final_traders["trader_type"] != "agent"]
|
177 |
+
|
178 |
+
fig = px.box(
|
179 |
+
final_traders,
|
180 |
+
x="month_year_week",
|
181 |
+
y="nr_trades_per_market",
|
182 |
+
color="market_creator",
|
183 |
+
color_discrete_sequence=color_discrete_sequence,
|
184 |
+
category_orders={
|
185 |
+
"market_creator": ["pearl", "quickstart", "all"],
|
186 |
+
"trader_market": [
|
187 |
+
("agent", "pearl"),
|
188 |
+
("non_agent", "pearl"),
|
189 |
+
("agent", "quickstart"),
|
190 |
+
("non_agent", "quickstart"),
|
191 |
+
("agent", "all"),
|
192 |
+
("non_agent", "all"),
|
193 |
+
],
|
194 |
+
},
|
195 |
+
# facet_col="trader_type",
|
196 |
+
)
|
197 |
+
fig.update_traces(boxmean=True)
|
198 |
+
fig.update_layout(
|
199 |
+
xaxis_title="Week",
|
200 |
+
yaxis_title="Nr trades per trader per market",
|
201 |
+
legend=dict(yanchor="top", y=0.5),
|
202 |
+
width=1000, # Adjusted for better fit on laptop screens
|
203 |
+
height=600, # Adjusted for better fit on laptop screens
|
204 |
+
)
|
205 |
+
# for axis in fig.layout:
|
206 |
+
# if axis.startswith("xaxis"):
|
207 |
+
# fig.layout[axis].update(title="Week")
|
208 |
+
fig.update_xaxes(tickformat="%b %d\n%Y")
|
209 |
+
return gr.Plot(
|
210 |
+
value=fig,
|
211 |
+
)
|
tabs/trader_plots.py
CHANGED
@@ -13,7 +13,7 @@ trader_metric_choices = [
|
|
13 |
default_trader_metric = "ROI"
|
14 |
|
15 |
|
16 |
-
def get_metrics_text() -> gr.Markdown:
|
17 |
metric_text = """
|
18 |
## Metrics at the graph
|
19 |
These metrics are computed weekly. The statistical measures are:
|
@@ -21,7 +21,14 @@ def get_metrics_text() -> gr.Markdown:
|
|
21 |
* the upper and lower fences to delimit possible outliers
|
22 |
* the average values as the dotted lines
|
23 |
"""
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
return gr.Markdown(metric_text)
|
26 |
|
27 |
|
@@ -144,190 +151,6 @@ def plot_trader_daily_metrics_by_market_creator(
|
|
144 |
)
|
145 |
|
146 |
|
147 |
-
def plot_median_roi_by_creation_date(traders_df: pd.DataFrame) -> gr.Plot:
|
148 |
-
traders_df["creation_date"] = traders_df["creation_timestamp"].dt.date
|
149 |
-
|
150 |
-
traders_all = traders_df.copy(deep=True)
|
151 |
-
traders_all["market_creator"] = "all"
|
152 |
-
|
153 |
-
# merging both dataframes
|
154 |
-
final_traders = pd.concat([traders_all, traders_df], ignore_index=True)
|
155 |
-
final_traders = final_traders.sort_values(by="creation_date", ascending=True)
|
156 |
-
roi_daily_metrics = (
|
157 |
-
final_traders.groupby(
|
158 |
-
["creation_date", "market_creator", "trader_address"], sort=False
|
159 |
-
)
|
160 |
-
.agg(
|
161 |
-
median_roi=("roi", "median"),
|
162 |
-
mean_roi=("roi", "mean"),
|
163 |
-
total_trades=("roi", "count"),
|
164 |
-
)
|
165 |
-
.reset_index()
|
166 |
-
)
|
167 |
-
# Create the scatter plot with facets for each market_creator
|
168 |
-
fig = px.scatter(
|
169 |
-
roi_daily_metrics,
|
170 |
-
x="creation_date",
|
171 |
-
y="median_roi",
|
172 |
-
facet_col="market_creator",
|
173 |
-
color="market_creator",
|
174 |
-
color_discrete_map={
|
175 |
-
"pearl": "purple",
|
176 |
-
"quickstart": "goldenrod",
|
177 |
-
"all": "darkgreen",
|
178 |
-
},
|
179 |
-
title="Median ROI Over Time by Market Creator",
|
180 |
-
labels={
|
181 |
-
"creation_date": "Creation Date",
|
182 |
-
"median_roi": "Median ROI (%)",
|
183 |
-
"market_creator": "Market Creator",
|
184 |
-
},
|
185 |
-
hover_data={
|
186 |
-
"creation_date": "|%B %d, %Y", # Custom date format in hover
|
187 |
-
"median_roi": True,
|
188 |
-
"mean_roi": True,
|
189 |
-
"total_trades": True,
|
190 |
-
},
|
191 |
-
category_orders={"market_creator": ["pearl", "quickstart", "all"]},
|
192 |
-
# trendline=None, # Ensure no trendlines are added
|
193 |
-
)
|
194 |
-
|
195 |
-
# Customize the layout for better aesthetics
|
196 |
-
fig.update_layout(
|
197 |
-
template="plotly_white",
|
198 |
-
hovermode="closest",
|
199 |
-
showlegend=False, # Disable the legend as each facet has its own context
|
200 |
-
)
|
201 |
-
|
202 |
-
# Update each subplot's x-axis to share the same range
|
203 |
-
fig.update_xaxes(matches="x") # Link x-axes across facets
|
204 |
-
fig.update_yaxes(matches="y") # Link y-axes across facets
|
205 |
-
|
206 |
-
# Add a vertical dashed line in dark red at the specified date
|
207 |
-
vline_date = "2024-09-29"
|
208 |
-
vline_datetime = pd.to_datetime(vline_date, format="%Y-%m-%d")
|
209 |
-
fig.add_vline(
|
210 |
-
x=vline_datetime,
|
211 |
-
line_dash="dash",
|
212 |
-
line_color="darkred",
|
213 |
-
)
|
214 |
-
return gr.Plot(
|
215 |
-
value=fig,
|
216 |
-
)
|
217 |
-
|
218 |
-
|
219 |
-
import plotly.express as px
|
220 |
-
|
221 |
-
|
222 |
-
def create_median_roi_plot(roi_daily_metrics):
|
223 |
-
"""
|
224 |
-
Creates a Plotly scatter plot for median ROI over time, colored by market_creator.
|
225 |
-
|
226 |
-
Parameters:
|
227 |
-
- roi_daily_metrics (pd.DataFrame): Aggregated ROI metrics with columns:
|
228 |
-
['creation_date', 'market_creator', 'trader_address', 'median_roi', 'mean_roi', 'total_trades']
|
229 |
-
|
230 |
-
Returns:
|
231 |
-
- fig (plotly.graph_objs._figure.Figure): The Plotly figure object.
|
232 |
-
"""
|
233 |
-
# Ensure 'creation_date' is in datetime format
|
234 |
-
roi_daily_metrics["creation_date"] = pd.to_datetime(
|
235 |
-
roi_daily_metrics["creation_date"]
|
236 |
-
)
|
237 |
-
|
238 |
-
# Create the line plot with scatter markers
|
239 |
-
fig = px.line(
|
240 |
-
roi_daily_metrics,
|
241 |
-
x="creation_date",
|
242 |
-
y="median_roi",
|
243 |
-
color="market_creator",
|
244 |
-
markers=True, # Add markers to lines
|
245 |
-
title="Median ROI Over Time by Market Creator",
|
246 |
-
labels={
|
247 |
-
"creation_date": "Creation Date",
|
248 |
-
"median_roi": "Median ROI (%)",
|
249 |
-
"market_creator": "Market Creator",
|
250 |
-
},
|
251 |
-
hover_data={
|
252 |
-
"creation_date": "|%B %d, %Y", # Custom date format in hover
|
253 |
-
"median_roi": True,
|
254 |
-
"mean_roi": True,
|
255 |
-
"total_trades": True,
|
256 |
-
},
|
257 |
-
)
|
258 |
-
|
259 |
-
# Customize the layout for better aesthetics
|
260 |
-
fig.update_layout(
|
261 |
-
xaxis_title="Creation Date",
|
262 |
-
yaxis_title="Median ROI (%)",
|
263 |
-
legend_title="Market Creator",
|
264 |
-
template="plotly_white",
|
265 |
-
hovermode="x unified",
|
266 |
-
)
|
267 |
-
|
268 |
-
# Optional: Add vertical lines for specific events (e.g., "multibet release")
|
269 |
-
# Example:
|
270 |
-
# fig.add_vline(
|
271 |
-
# x=pd.to_datetime("2023-01-02"),
|
272 |
-
# line_dash="dash",
|
273 |
-
# line_color="red",
|
274 |
-
# annotation_text="Multibet Release",
|
275 |
-
# annotation_position="top left",
|
276 |
-
# annotation=dict(
|
277 |
-
# bgcolor="white",
|
278 |
-
# font_size=12,
|
279 |
-
# font_color="red"
|
280 |
-
# )
|
281 |
-
# )
|
282 |
-
|
283 |
-
return fig
|
284 |
-
|
285 |
-
|
286 |
-
def plot_trader_metrics_by_trader_type(metric_name: str, traders_df: pd.DataFrame):
|
287 |
-
"""Plots the weekly trader metrics."""
|
288 |
-
|
289 |
-
if metric_name == "mech calls":
|
290 |
-
metric_name = "mech_calls"
|
291 |
-
column_name = "nr_mech_calls"
|
292 |
-
yaxis_title = "Total nr of mech calls per trader"
|
293 |
-
elif metric_name == "ROI":
|
294 |
-
column_name = "roi"
|
295 |
-
yaxis_title = "Total ROI (net profit/cost)"
|
296 |
-
elif metric_name == "bet amount":
|
297 |
-
metric_name = "bet_amount"
|
298 |
-
column_name = metric_name
|
299 |
-
yaxis_title = "Total bet amount per trader (xDAI)"
|
300 |
-
elif metric_name == "net earnings":
|
301 |
-
metric_name = "net_earnings"
|
302 |
-
column_name = metric_name
|
303 |
-
yaxis_title = "Total net profit per trader (xDAI)"
|
304 |
-
else: # earnings
|
305 |
-
column_name = metric_name
|
306 |
-
yaxis_title = "Total gross profit per trader (xDAI)"
|
307 |
-
|
308 |
-
traders_filtered = traders_df[["month_year_week", "trader_type", column_name]]
|
309 |
-
|
310 |
-
fig = px.box(
|
311 |
-
traders_filtered,
|
312 |
-
x="month_year_week",
|
313 |
-
y=column_name,
|
314 |
-
color="trader_type",
|
315 |
-
color_discrete_sequence=["gray", "orange", "darkblue"],
|
316 |
-
category_orders={"trader_type": ["singlebet", "multibet", "all"]},
|
317 |
-
)
|
318 |
-
fig.update_traces(boxmean=True)
|
319 |
-
fig.update_layout(
|
320 |
-
xaxis_title="Week",
|
321 |
-
yaxis_title=yaxis_title,
|
322 |
-
legend=dict(yanchor="top", y=0.5),
|
323 |
-
)
|
324 |
-
fig.update_xaxes(tickformat="%b %d\n%Y")
|
325 |
-
|
326 |
-
return gr.Plot(
|
327 |
-
value=fig,
|
328 |
-
)
|
329 |
-
|
330 |
-
|
331 |
def plot_winning_metric_per_trader(traders_winning_df: pd.DataFrame) -> gr.Plot:
|
332 |
fig = px.box(
|
333 |
traders_winning_df,
|
|
|
13 |
default_trader_metric = "ROI"
|
14 |
|
15 |
|
16 |
+
def get_metrics_text(daily: bool = False) -> gr.Markdown:
|
17 |
metric_text = """
|
18 |
## Metrics at the graph
|
19 |
These metrics are computed weekly. The statistical measures are:
|
|
|
21 |
* the upper and lower fences to delimit possible outliers
|
22 |
* the average values as the dotted lines
|
23 |
"""
|
24 |
+
if daily:
|
25 |
+
metric_text = """
|
26 |
+
## Metrics at the graph
|
27 |
+
These metrics are computed daily. The statistical measures are:
|
28 |
+
* min, max, 25th(q1), 50th(median) and 75th(q2) percentiles
|
29 |
+
* the upper and lower fences to delimit possible outliers
|
30 |
+
* the average values as the dotted lines
|
31 |
+
"""
|
32 |
return gr.Markdown(metric_text)
|
33 |
|
34 |
|
|
|
151 |
)
|
152 |
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
def plot_winning_metric_per_trader(traders_winning_df: pd.DataFrame) -> gr.Plot:
|
155 |
fig = px.box(
|
156 |
traders_winning_df,
|