rosacastillo commited on
Commit
5ded199
·
1 Parent(s): 5b05a90

new error graphs with markets

Browse files
Files changed (2) hide show
  1. app.py +26 -22
  2. tabs/error.py +140 -1
app.py CHANGED
@@ -19,8 +19,6 @@ from tabs.metrics import (
19
  default_trade_metric,
20
  default_tool_metric,
21
  plot_trade_metrics,
22
- WIDTH,
23
- HEIGHT,
24
  get_trade_metrics_text,
25
  )
26
 
@@ -44,11 +42,11 @@ from tabs.invalid_markets import (
44
  )
45
 
46
  from tabs.error import (
47
- get_error_data,
48
- get_error_data_overall,
49
- plot_error_data,
50
- plot_tool_error_data,
51
- plot_week_error_data,
52
  )
53
  from tabs.about import about_olas_predict, about_this_dashboard
54
 
@@ -169,9 +167,10 @@ tools_df, trades_df, tools_accuracy_info, invalid_trades = prepare_data()
169
 
170
 
171
  demo = gr.Blocks()
 
 
 
172
 
173
- error_df = get_error_data(tools_df=tools_df, inc_tools=INC_TOOLS)
174
- error_overall_df = get_error_data_overall(error_df=error_df)
175
  winning_df = get_tool_winning_rate_by_market(tools_df, inc_tools=INC_TOOLS)
176
  # preparing data for the trades graph
177
  trades_count_df = get_overall_trades(trades_df=trades_df)
@@ -336,11 +335,6 @@ with demo:
336
  with gr.Row():
337
  daily_trades = plot_daily_dist_invalid_trades(invalid_trades)
338
 
339
- # with gr.Row():
340
- # gr.Markdown("# Ratio of invalid trades per market")
341
- # with gr.Row():
342
- # plot_ratio_invalid_trades_per_market(invalid_trades)
343
-
344
  with gr.Row():
345
  gr.Markdown("# Top markets with invalid trades")
346
  with gr.Row():
@@ -355,7 +349,9 @@ with demo:
355
  with gr.Row():
356
  gr.Markdown("# All tools errors")
357
  with gr.Row():
358
- error_overall_plot = plot_error_data(error_all_df=error_overall_df)
 
 
359
  with gr.Row():
360
  gr.Markdown("# Error percentage per tool")
361
  with gr.Row():
@@ -364,12 +360,14 @@ with demo:
364
  )
365
 
366
  with gr.Row():
367
- tool_error_plot = plot_tool_error_data(
368
- error_df=error_df, tool=INC_TOOLS[0]
369
  )
370
 
371
  def update_tool_error_plot(tool):
372
- return plot_tool_error_data(error_df=error_df, tool=tool)
 
 
373
 
374
  sel_tool.change(
375
  update_tool_error_plot, inputs=sel_tool, outputs=tool_error_plot
@@ -383,7 +381,11 @@ with demo:
383
  gr.Markdown("# Tools distribution of errors per week")
384
 
385
  with gr.Row():
386
- choices = error_overall_df["request_month_year_week"].unique().tolist()
 
 
 
 
387
  # sort the choices by the latest week to be on the top
388
  choices = sorted(choices)
389
  sel_week = gr.Dropdown(
@@ -391,12 +393,14 @@ with demo:
391
  )
392
 
393
  with gr.Row():
394
- week_error_plot = plot_week_error_data(
395
- error_df=error_df, week=choices[-1]
396
  )
397
 
398
  def update_week_error_plot(selected_week):
399
- return plot_week_error_data(error_df=error_df, week=selected_week)
 
 
400
 
401
  sel_tool.change(
402
  update_tool_error_plot, inputs=sel_tool, outputs=tool_error_plot
 
19
  default_trade_metric,
20
  default_tool_metric,
21
  plot_trade_metrics,
 
 
22
  get_trade_metrics_text,
23
  )
24
 
 
42
  )
43
 
44
  from tabs.error import (
45
+ plot_week_error_data_by_market,
46
+ plot_error_data_by_market,
47
+ get_error_data_by_market,
48
+ get_error_data_overall_by_market,
49
+ plot_tool_error_data_by_market,
50
  )
51
  from tabs.about import about_olas_predict, about_this_dashboard
52
 
 
167
 
168
 
169
  demo = gr.Blocks()
170
+ # preparing data for the errors
171
+ error_by_markets = get_error_data_by_market(tools_df=tools_df, inc_tools=INC_TOOLS)
172
+ error_overall_by_markets = get_error_data_overall_by_market(error_df=error_by_markets)
173
 
 
 
174
  winning_df = get_tool_winning_rate_by_market(tools_df, inc_tools=INC_TOOLS)
175
  # preparing data for the trades graph
176
  trades_count_df = get_overall_trades(trades_df=trades_df)
 
335
  with gr.Row():
336
  daily_trades = plot_daily_dist_invalid_trades(invalid_trades)
337
 
 
 
 
 
 
338
  with gr.Row():
339
  gr.Markdown("# Top markets with invalid trades")
340
  with gr.Row():
 
349
  with gr.Row():
350
  gr.Markdown("# All tools errors")
351
  with gr.Row():
352
+ error_overall_plot = plot_error_data_by_market(
353
+ error_all_df=error_overall_by_markets
354
+ )
355
  with gr.Row():
356
  gr.Markdown("# Error percentage per tool")
357
  with gr.Row():
 
360
  )
361
 
362
  with gr.Row():
363
+ tool_error_plot = plot_tool_error_data_by_market(
364
+ error_df=error_by_markets, tool=INC_TOOLS[0]
365
  )
366
 
367
  def update_tool_error_plot(tool):
368
+ return plot_tool_error_data_by_market(
369
+ error_df=error_by_markets, tool=tool
370
+ )
371
 
372
  sel_tool.change(
373
  update_tool_error_plot, inputs=sel_tool, outputs=tool_error_plot
 
381
  gr.Markdown("# Tools distribution of errors per week")
382
 
383
  with gr.Row():
384
+ choices = (
385
+ error_overall_by_markets["request_month_year_week"]
386
+ .unique()
387
+ .tolist()
388
+ )
389
  # sort the choices by the latest week to be on the top
390
  choices = sorted(choices)
391
  sel_week = gr.Dropdown(
 
393
  )
394
 
395
  with gr.Row():
396
+ week_error_plot = plot_week_error_data_by_market(
397
+ error_df=error_by_markets, week=choices[-1]
398
  )
399
 
400
  def update_week_error_plot(selected_week):
401
+ return plot_week_error_data_by_market(
402
+ error_df=error_by_markets, week=selected_week
403
+ )
404
 
405
  sel_tool.change(
406
  update_tool_error_plot, inputs=sel_tool, outputs=tool_error_plot
tabs/error.py CHANGED
@@ -1,6 +1,8 @@
1
  import pandas as pd
2
  import gradio as gr
3
  from typing import List
 
 
4
 
5
 
6
  HEIGHT = 600
@@ -22,6 +24,25 @@ def get_error_data(tools_df: pd.DataFrame, inc_tools: List[str]) -> pd.DataFrame
22
  return error
23
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def get_error_data_overall(error_df: pd.DataFrame) -> pd.DataFrame:
26
  """Gets the error data for the given tools and calculates the error percentage."""
27
  error_total = (
@@ -35,6 +56,19 @@ def get_error_data_overall(error_df: pd.DataFrame) -> pd.DataFrame:
35
  return error_total
36
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  def plot_error_data(error_all_df: pd.DataFrame) -> gr.BarPlot:
39
  """Plots the error data for the given tools and calculates the error percentage."""
40
  return gr.BarPlot(
@@ -53,6 +87,44 @@ def plot_error_data(error_all_df: pd.DataFrame) -> gr.BarPlot:
53
  )
54
 
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  def plot_tool_error_data(error_df: pd.DataFrame, tool: str) -> gr.BarPlot:
57
  """Plots the error data for the given tool."""
58
  error_tool = error_df[error_df["tool"] == tool]
@@ -62,7 +134,7 @@ def plot_tool_error_data(error_df: pd.DataFrame, tool: str) -> gr.BarPlot:
62
  return gr.BarPlot(
63
  title="Error Percentage",
64
  x_title="Week",
65
- y_title="Error Percentage",
66
  show_label=True,
67
  interactive=True,
68
  show_actions_button=True,
@@ -75,6 +147,47 @@ def plot_tool_error_data(error_df: pd.DataFrame, tool: str) -> gr.BarPlot:
75
  )
76
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  def plot_week_error_data(error_df: pd.DataFrame, week: str) -> gr.BarPlot:
79
  """Plots the error data for the given week."""
80
  error_week = error_df[error_df["request_month_year_week"] == week]
@@ -94,3 +207,29 @@ def plot_week_error_data(error_df: pd.DataFrame, week: str) -> gr.BarPlot:
94
  height=HEIGHT,
95
  width=WIDTH,
96
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
  import gradio as gr
3
  from typing import List
4
+ import plotly.express as px
5
+ from tabs.tool_win import sort_key
6
 
7
 
8
  HEIGHT = 600
 
24
  return error
25
 
26
 
27
+ def get_error_data_by_market(
28
+ tools_df: pd.DataFrame, inc_tools: List[str]
29
+ ) -> pd.DataFrame:
30
+ """Gets the error data for the given tools and calculates the error percentage."""
31
+ tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
32
+ error = (
33
+ tools_inc.groupby(
34
+ ["tool", "request_month_year_week", "market_creator", "error"], sort=False
35
+ )
36
+ .size()
37
+ .unstack()
38
+ .fillna(0)
39
+ .reset_index()
40
+ )
41
+ error["error_perc"] = (error[1] / (error[0] + error[1])) * 100
42
+ error["total_requests"] = error[0] + error[1]
43
+ return error
44
+
45
+
46
  def get_error_data_overall(error_df: pd.DataFrame) -> pd.DataFrame:
47
  """Gets the error data for the given tools and calculates the error percentage."""
48
  error_total = (
 
56
  return error_total
57
 
58
 
59
+ def get_error_data_overall_by_market(error_df: pd.DataFrame) -> pd.DataFrame:
60
+ """Gets the error data for the given tools and calculates the error percentage."""
61
+ error_total = (
62
+ error_df.groupby(["request_month_year_week", "market_creator"], sort=False)
63
+ .agg({"total_requests": "sum", 1: "sum", 0: "sum"})
64
+ .reset_index()
65
+ )
66
+ error_total["error_perc"] = (error_total[1] / error_total["total_requests"]) * 100
67
+ error_total.columns = error_total.columns.astype(str)
68
+ error_total["error_perc"] = error_total["error_perc"].apply(lambda x: round(x, 4))
69
+ return error_total
70
+
71
+
72
  def plot_error_data(error_all_df: pd.DataFrame) -> gr.BarPlot:
73
  """Plots the error data for the given tools and calculates the error percentage."""
74
  return gr.BarPlot(
 
87
  )
88
 
89
 
90
+ def plot_error_data_by_market(error_all_df: pd.DataFrame) -> gr.Plot:
91
+
92
+ # Sort the unique values of request_month_year_week
93
+ sorted_categories = sorted(
94
+ error_all_df["request_month_year_week"].unique(), key=sort_key
95
+ )
96
+ # Create a categorical type with a specific order
97
+ error_all_df["request_month_year_week"] = pd.Categorical(
98
+ error_all_df["request_month_year_week"],
99
+ categories=sorted_categories,
100
+ ordered=True,
101
+ )
102
+
103
+ # Sort the DataFrame based on the new categorical column
104
+ error_all_df = error_all_df.sort_values("request_month_year_week")
105
+
106
+ fig = px.bar(
107
+ error_all_df,
108
+ x="request_month_year_week",
109
+ y="error_perc",
110
+ color="market_creator",
111
+ barmode="group",
112
+ color_discrete_sequence=["purple", "goldenrod", "darkgreen"],
113
+ category_orders={
114
+ "market_creator": ["pearl", "quickstart", "all"],
115
+ "request_month_year_week": sorted_categories,
116
+ },
117
+ )
118
+ fig.update_layout(
119
+ xaxis_title="Week",
120
+ yaxis_title="Error Percentage",
121
+ legend=dict(yanchor="top", y=0.5),
122
+ )
123
+ fig.update_layout(width=WIDTH, height=HEIGHT)
124
+ fig.update_xaxes(tickformat="%b %d\n%Y")
125
+ return gr.Plot(value=fig)
126
+
127
+
128
  def plot_tool_error_data(error_df: pd.DataFrame, tool: str) -> gr.BarPlot:
129
  """Plots the error data for the given tool."""
130
  error_tool = error_df[error_df["tool"] == tool]
 
134
  return gr.BarPlot(
135
  title="Error Percentage",
136
  x_title="Week",
137
+ y_title="Error Percentage %",
138
  show_label=True,
139
  interactive=True,
140
  show_actions_button=True,
 
147
  )
148
 
149
 
150
+ def plot_tool_error_data_by_market(error_df: pd.DataFrame, tool: str) -> gr.Plot:
151
+ error_tool = error_df[error_df["tool"] == tool]
152
+ error_tool.columns = error_tool.columns.astype(str)
153
+ error_tool["error_perc"] = error_tool["error_perc"].apply(lambda x: round(x, 4))
154
+
155
+ # Sort the unique values of request_month_year_week
156
+ sorted_categories = sorted(
157
+ error_tool["request_month_year_week"].unique(), key=sort_key
158
+ )
159
+ # Create a categorical type with a specific order
160
+ error_tool["request_month_year_week"] = pd.Categorical(
161
+ error_tool["request_month_year_week"],
162
+ categories=sorted_categories,
163
+ ordered=True,
164
+ )
165
+
166
+ # Sort the DataFrame based on the new categorical column
167
+ error_tool = error_tool.sort_values("request_month_year_week")
168
+
169
+ fig = px.bar(
170
+ error_tool,
171
+ x="request_month_year_week",
172
+ y="error_perc",
173
+ color="market_creator",
174
+ barmode="group",
175
+ color_discrete_sequence=["purple", "goldenrod", "darkgreen"],
176
+ category_orders={
177
+ "market_creator": ["pearl", "quickstart", "all"],
178
+ "request_month_year_week": sorted_categories,
179
+ },
180
+ )
181
+ fig.update_layout(
182
+ xaxis_title="Week",
183
+ yaxis_title="Error Percentage %",
184
+ legend=dict(yanchor="top", y=0.5),
185
+ )
186
+ fig.update_layout(width=WIDTH, height=HEIGHT)
187
+ fig.update_xaxes(tickformat="%b %d\n%Y")
188
+ return gr.Plot(value=fig)
189
+
190
+
191
  def plot_week_error_data(error_df: pd.DataFrame, week: str) -> gr.BarPlot:
192
  """Plots the error data for the given week."""
193
  error_week = error_df[error_df["request_month_year_week"] == week]
 
207
  height=HEIGHT,
208
  width=WIDTH,
209
  )
210
+
211
+
212
+ def plot_week_error_data_by_market(error_df: pd.DataFrame, week: str) -> gr.Plot:
213
+ error_week = error_df[error_df["request_month_year_week"] == week]
214
+ error_week.columns = error_week.columns.astype(str)
215
+ error_week["error_perc"] = error_week["error_perc"].apply(lambda x: round(x, 4))
216
+
217
+ fig = px.bar(
218
+ error_week,
219
+ x="tool",
220
+ y="error_perc",
221
+ color="market_creator",
222
+ barmode="group",
223
+ color_discrete_sequence=["purple", "goldenrod", "darkgreen"],
224
+ category_orders={
225
+ "market_creator": ["pearl", "quickstart", "all"],
226
+ },
227
+ )
228
+ fig.update_layout(
229
+ xaxis_title="Tool",
230
+ yaxis_title="Error Percentage %",
231
+ legend=dict(yanchor="top", y=0.5),
232
+ )
233
+ fig.update_layout(width=WIDTH, height=HEIGHT)
234
+ fig.update_xaxes(tickformat="%b %d\n%Y")
235
+ return gr.Plot(value=fig)