Spaces:
Runtime error
Runtime error
cyberosa
commited on
Commit
Β·
7f9e80f
1
Parent(s):
577dd09
updated daily metrics graphs
Browse files- app.py +100 -34
- tabs/daily_graphs.py +9 -7
app.py
CHANGED
|
@@ -21,7 +21,7 @@ from tabs.trader_plots import (
|
|
| 21 |
from tabs.daily_graphs import (
|
| 22 |
get_current_week_data,
|
| 23 |
plot_daily_metrics,
|
| 24 |
-
|
| 25 |
default_daily_metric,
|
| 26 |
)
|
| 27 |
from scripts.utils import get_traders_family
|
|
@@ -242,7 +242,7 @@ with demo:
|
|
| 242 |
inputs=trader_na_details_selector,
|
| 243 |
outputs=na_trader_markets_plot,
|
| 244 |
)
|
| 245 |
-
with gr.TabItem("π
Daily metrics
|
| 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:
|
|
@@ -255,14 +255,13 @@ with demo:
|
|
| 255 |
live_metrics_by_market_creator = compute_daily_metrics_by_market_creator(
|
| 256 |
live_trades_current_week, trader_filter=None, live_metrics=True
|
| 257 |
)
|
| 258 |
-
|
| 259 |
-
print(live_metrics_by_market_creator.head())
|
| 260 |
with gr.Row():
|
| 261 |
gr.Markdown("# Daily live metrics for all trades")
|
| 262 |
with gr.Row():
|
| 263 |
trade_live_details_selector = gr.Dropdown(
|
| 264 |
label="Select a daily live metric",
|
| 265 |
-
choices=
|
| 266 |
value=default_daily_metric,
|
| 267 |
)
|
| 268 |
|
|
@@ -288,40 +287,107 @@ with demo:
|
|
| 288 |
)
|
| 289 |
|
| 290 |
with gr.Row():
|
| 291 |
-
gr.Markdown("# Daily
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 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
|
| 311 |
-
):
|
| 312 |
-
new_a_plot = plot_daily_metrics(
|
| 313 |
-
metric_name=trade_detail,
|
| 314 |
-
trades_df=daily_prof_metrics_by_market_creator,
|
| 315 |
)
|
| 316 |
-
|
|
|
|
| 317 |
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
| 322 |
)
|
| 323 |
-
|
| 324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
with gr.TabItem("πClosed Markets KullbackβLeibler divergence"):
|
| 327 |
with gr.Row():
|
|
|
|
| 21 |
from tabs.daily_graphs import (
|
| 22 |
get_current_week_data,
|
| 23 |
plot_daily_metrics,
|
| 24 |
+
trader_daily_metric_choices,
|
| 25 |
default_daily_metric,
|
| 26 |
)
|
| 27 |
from scripts.utils import get_traders_family
|
|
|
|
| 242 |
inputs=trader_na_details_selector,
|
| 243 |
outputs=na_trader_markets_plot,
|
| 244 |
)
|
| 245 |
+
with gr.TabItem("π
Daily metrics"):
|
| 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:
|
|
|
|
| 255 |
live_metrics_by_market_creator = compute_daily_metrics_by_market_creator(
|
| 256 |
live_trades_current_week, trader_filter=None, live_metrics=True
|
| 257 |
)
|
| 258 |
+
|
|
|
|
| 259 |
with gr.Row():
|
| 260 |
gr.Markdown("# Daily live metrics for all trades")
|
| 261 |
with gr.Row():
|
| 262 |
trade_live_details_selector = gr.Dropdown(
|
| 263 |
label="Select a daily live metric",
|
| 264 |
+
choices=trader_daily_metric_choices,
|
| 265 |
value=default_daily_metric,
|
| 266 |
)
|
| 267 |
|
|
|
|
| 287 |
)
|
| 288 |
|
| 289 |
with gr.Row():
|
| 290 |
+
gr.Markdown("# Daily live metrics for trader Agents π€")
|
| 291 |
+
with gr.Row():
|
| 292 |
+
a_trader_live_details_selector = gr.Dropdown(
|
| 293 |
+
label="Select a daily live metric",
|
| 294 |
+
choices=trader_daily_metric_choices,
|
| 295 |
+
value=default_daily_metric,
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
with gr.Row():
|
| 299 |
+
with gr.Column(scale=3):
|
| 300 |
+
a_trader_live_details_plot = plot_daily_metrics(
|
| 301 |
+
metric_name=default_daily_metric,
|
| 302 |
+
trades_df=live_metrics_by_market_creator,
|
| 303 |
+
trader_filter="agent",
|
| 304 |
)
|
| 305 |
+
with gr.Column(scale=1):
|
| 306 |
+
trade_details_text = get_metrics_text(daily=True)
|
| 307 |
+
|
| 308 |
+
def update_a_trader_live_details(trade_detail, a_trader_live_details_plot):
|
| 309 |
+
a_trader_plot = plot_daily_metrics(
|
| 310 |
+
metric_name=trade_detail,
|
| 311 |
+
trades_df=live_metrics_by_market_creator,
|
| 312 |
+
trader_filter="agent",
|
| 313 |
+
)
|
| 314 |
+
return a_trader_plot
|
| 315 |
+
|
| 316 |
+
a_trader_live_details_selector.change(
|
| 317 |
+
update_a_trader_live_details,
|
| 318 |
+
inputs=[a_trader_live_details_selector, a_trader_live_details_plot],
|
| 319 |
+
outputs=[a_trader_live_details_plot],
|
| 320 |
+
)
|
| 321 |
+
with gr.Row():
|
| 322 |
+
gr.Markdown("# Daily live metrics for Non-agent traders")
|
| 323 |
+
with gr.Row():
|
| 324 |
+
na_trader_live_details_selector = gr.Dropdown(
|
| 325 |
+
label="Select a daily live metric",
|
| 326 |
+
choices=trader_daily_metric_choices,
|
| 327 |
+
value=default_daily_metric,
|
| 328 |
+
)
|
| 329 |
|
| 330 |
+
with gr.Row():
|
| 331 |
+
with gr.Column(scale=3):
|
| 332 |
+
na_trader_live_details_plot = plot_daily_metrics(
|
| 333 |
+
metric_name=default_daily_metric,
|
| 334 |
+
trades_df=live_metrics_by_market_creator,
|
| 335 |
+
trader_filter="non_agent",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
)
|
| 337 |
+
with gr.Column(scale=1):
|
| 338 |
+
trade_details_text = get_metrics_text(daily=True)
|
| 339 |
|
| 340 |
+
def update_na_trader_live_details(
|
| 341 |
+
trade_detail, na_trader_live_details_plot
|
| 342 |
+
):
|
| 343 |
+
na_trader_plot = plot_daily_metrics(
|
| 344 |
+
metric_name=trade_detail,
|
| 345 |
+
trades_df=live_metrics_by_market_creator,
|
| 346 |
+
trader_filter="non_agent",
|
| 347 |
)
|
| 348 |
+
return na_trader_plot
|
| 349 |
+
|
| 350 |
+
na_trader_live_details_selector.change(
|
| 351 |
+
update_na_trader_live_details,
|
| 352 |
+
inputs=[na_trader_live_details_selector, na_trader_live_details_plot],
|
| 353 |
+
outputs=[na_trader_live_details_plot],
|
| 354 |
+
)
|
| 355 |
+
|
| 356 |
+
# with gr.Row():
|
| 357 |
+
# gr.Markdown("# Daily profitability metrics available for all trades")
|
| 358 |
+
# if len(current_week_trades) > 0:
|
| 359 |
+
# with gr.Row():
|
| 360 |
+
# trader_daily_details_selector = gr.Dropdown(
|
| 361 |
+
# label="Select a daily trade metric",
|
| 362 |
+
# choices=trader_metric_choices,
|
| 363 |
+
# value=default_trader_metric,
|
| 364 |
+
# )
|
| 365 |
+
|
| 366 |
+
# with gr.Row():
|
| 367 |
+
# with gr.Column(scale=3):
|
| 368 |
+
# trader_daily_details_plot = plot_daily_metrics(
|
| 369 |
+
# metric_name=default_trader_metric,
|
| 370 |
+
# trades_df=daily_prof_metrics_by_market_creator,
|
| 371 |
+
# )
|
| 372 |
+
# with gr.Column(scale=1):
|
| 373 |
+
# trader_details_text = get_metrics_text(daily=True)
|
| 374 |
+
|
| 375 |
+
# def update_trader_daily_details(
|
| 376 |
+
# trade_detail, trader_daily_details_plot
|
| 377 |
+
# ):
|
| 378 |
+
# new_a_plot = plot_daily_metrics(
|
| 379 |
+
# metric_name=trade_detail,
|
| 380 |
+
# trades_df=daily_prof_metrics_by_market_creator,
|
| 381 |
+
# )
|
| 382 |
+
# return new_a_plot
|
| 383 |
+
|
| 384 |
+
# trader_daily_details_selector.change(
|
| 385 |
+
# update_trader_daily_details,
|
| 386 |
+
# inputs=[trader_daily_details_selector, trader_daily_details_plot],
|
| 387 |
+
# outputs=[trader_daily_details_plot],
|
| 388 |
+
# )
|
| 389 |
+
# else:
|
| 390 |
+
# gr.Markdown("Data not available yet")
|
| 391 |
|
| 392 |
with gr.TabItem("πClosed Markets KullbackβLeibler divergence"):
|
| 393 |
with gr.Row():
|
tabs/daily_graphs.py
CHANGED
|
@@ -7,7 +7,7 @@ import plotly.graph_objects as go
|
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
from tqdm import tqdm
|
| 9 |
|
| 10 |
-
|
| 11 |
default_daily_metric = "collateral amount"
|
| 12 |
color_mapping = [
|
| 13 |
"darkviolet",
|
|
@@ -105,7 +105,9 @@ def plot_daily_metrics(
|
|
| 105 |
column_name = metric_name
|
| 106 |
yaxis_title = "Total gross profit per trader (xDAI)"
|
| 107 |
|
|
|
|
| 108 |
if trader_filter == "agent":
|
|
|
|
| 109 |
trades_filtered = trades_df.loc[trades_df["staking"] != "non_agent"]
|
| 110 |
elif trader_filter == "non_agent":
|
| 111 |
trades_filtered = trades_df.loc[trades_df["staking"] == "non_agent"]
|
|
@@ -123,8 +125,8 @@ def plot_daily_metrics(
|
|
| 123 |
trades_filtered,
|
| 124 |
x="creation_date",
|
| 125 |
y=column_name,
|
| 126 |
-
color="
|
| 127 |
-
color_discrete_sequence=
|
| 128 |
category_orders={
|
| 129 |
"market_creator": ["pearl", "quickstart", "all"],
|
| 130 |
"trader_market": [
|
|
@@ -136,7 +138,7 @@ def plot_daily_metrics(
|
|
| 136 |
("non_agent", "all"),
|
| 137 |
],
|
| 138 |
},
|
| 139 |
-
facet_col="market_creator",
|
| 140 |
)
|
| 141 |
fig.update_traces(boxmean=True)
|
| 142 |
fig.update_layout(
|
|
@@ -144,9 +146,9 @@ def plot_daily_metrics(
|
|
| 144 |
yaxis_title=yaxis_title,
|
| 145 |
legend=dict(yanchor="top", y=0.5),
|
| 146 |
)
|
| 147 |
-
for axis in fig.layout:
|
| 148 |
-
|
| 149 |
-
|
| 150 |
fig.update_xaxes(tickformat="%b %d")
|
| 151 |
return gr.Plot(
|
| 152 |
value=fig,
|
|
|
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
from tqdm import tqdm
|
| 9 |
|
| 10 |
+
trader_daily_metric_choices = ["mech calls", "collateral amount", "nr_trades"]
|
| 11 |
default_daily_metric = "collateral amount"
|
| 12 |
color_mapping = [
|
| 13 |
"darkviolet",
|
|
|
|
| 105 |
column_name = metric_name
|
| 106 |
yaxis_title = "Total gross profit per trader (xDAI)"
|
| 107 |
|
| 108 |
+
color_discrete_sequence = ["purple", "goldenrod", "darkgreen"]
|
| 109 |
if trader_filter == "agent":
|
| 110 |
+
color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
|
| 111 |
trades_filtered = trades_df.loc[trades_df["staking"] != "non_agent"]
|
| 112 |
elif trader_filter == "non_agent":
|
| 113 |
trades_filtered = trades_df.loc[trades_df["staking"] == "non_agent"]
|
|
|
|
| 125 |
trades_filtered,
|
| 126 |
x="creation_date",
|
| 127 |
y=column_name,
|
| 128 |
+
color="market_creator",
|
| 129 |
+
color_discrete_sequence=color_discrete_sequence,
|
| 130 |
category_orders={
|
| 131 |
"market_creator": ["pearl", "quickstart", "all"],
|
| 132 |
"trader_market": [
|
|
|
|
| 138 |
("non_agent", "all"),
|
| 139 |
],
|
| 140 |
},
|
| 141 |
+
# facet_col="market_creator",
|
| 142 |
)
|
| 143 |
fig.update_traces(boxmean=True)
|
| 144 |
fig.update_layout(
|
|
|
|
| 146 |
yaxis_title=yaxis_title,
|
| 147 |
legend=dict(yanchor="top", y=0.5),
|
| 148 |
)
|
| 149 |
+
# for axis in fig.layout:
|
| 150 |
+
# if axis.startswith("xaxis"):
|
| 151 |
+
# fig.layout[axis].update(title="Day")
|
| 152 |
fig.update_xaxes(tickformat="%b %d")
|
| 153 |
return gr.Plot(
|
| 154 |
value=fig,
|