cyberosa commited on
Commit
8c99d65
·
1 Parent(s): 88f9d70

Adding first prototype of top three tools percentage of reqs

Browse files
Files changed (2) hide show
  1. app.py +12 -0
  2. tabs/tool_accuracy.py +86 -0
app.py CHANGED
@@ -34,6 +34,7 @@ from tabs.tool_accuracy import (
34
  plot_tools_weighted_accuracy_rotated_graph,
35
  plot_tools_accuracy_rotated_graph,
36
  compute_weighted_accuracy,
 
37
  )
38
 
39
  from tabs.invalid_markets import (
@@ -536,6 +537,17 @@ with demo:
536
  with gr.Row():
537
  _ = plot_tools_weighted_accuracy_rotated_graph(tools_accuracy_info)
538
 
 
 
 
 
 
 
 
 
 
 
 
539
  with gr.TabItem("⛔ Invalid Markets Dashboard"):
540
  with gr.Row():
541
  gr.Markdown("# Daily distribution of invalid trades")
 
34
  plot_tools_weighted_accuracy_rotated_graph,
35
  plot_tools_accuracy_rotated_graph,
36
  compute_weighted_accuracy,
37
+ plot_mech_requests_topthree_tools,
38
  )
39
 
40
  from tabs.invalid_markets import (
 
537
  with gr.Row():
538
  _ = plot_tools_weighted_accuracy_rotated_graph(tools_accuracy_info)
539
 
540
+ with gr.Row():
541
+ gr.Markdown(
542
+ "# Mech requests percentage of the top three tools from the daily total"
543
+ )
544
+ with gr.Row():
545
+ _ = plot_mech_requests_topthree_tools(
546
+ daily_mech_requests=daily_mech_requests,
547
+ tools_accuracy_info=tools_accuracy_info,
548
+ top=3,
549
+ )
550
+
551
  with gr.TabItem("⛔ Invalid Markets Dashboard"):
552
  with gr.Row():
553
  gr.Markdown("# Daily distribution of invalid trades")
tabs/tool_accuracy.py CHANGED
@@ -4,6 +4,7 @@ import matplotlib.pyplot as plt
4
  import seaborn as sns
5
  from typing import Tuple
6
  import plotly.express as px
 
7
 
8
  VOLUME_FACTOR_REGULARIZATION = 0.5
9
  UNSCALED_WEIGHTED_ACCURACY_INTERVAL = (-0.5, 100.5)
@@ -150,3 +151,88 @@ def plot_tools_weighted_accuracy_rotated_graph(
150
  return gr.Plot(
151
  value=fig,
152
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import seaborn as sns
5
  from typing import Tuple
6
  import plotly.express as px
7
+ import numpy as np
8
 
9
  VOLUME_FACTOR_REGULARIZATION = 0.5
10
  UNSCALED_WEIGHTED_ACCURACY_INTERVAL = (-0.5, 100.5)
 
151
  return gr.Plot(
152
  value=fig,
153
  )
154
+
155
+
156
+ def plot_mech_requests_topthree_tools(
157
+ daily_mech_requests: pd.DataFrame, tools_accuracy_info: pd.DataFrame, top: int
158
+ ):
159
+ """Function to plot the percentage of mech requests from the top three tools"""
160
+ # Get the top three tools
161
+ top_tools = tools_accuracy_info.sort_values(
162
+ by="tool_accuracy", ascending=False
163
+ ).head(top)
164
+ top_tools = top_tools.tool.tolist()
165
+ # Filter the daily mech requests for the top three tools
166
+ daily_mech_requests_local_copy = daily_mech_requests.copy()
167
+ daily_mech_requests_local_copy = daily_mech_requests_local_copy[
168
+ daily_mech_requests_local_copy["market_creator"] == "all"
169
+ ]
170
+ # Get the daily total of mech requests no matter the tool
171
+ total_daily_mech_requests = (
172
+ daily_mech_requests_local_copy.groupby(["request_date"])
173
+ .agg({"total_mech_requests": "sum"})
174
+ .reset_index()
175
+ )
176
+ print("total_daily_mech_requests", total_daily_mech_requests.head())
177
+ total_daily_mech_requests.rename(
178
+ columns={"total_mech_requests": "total_daily_mech_requests"},
179
+ inplace=True,
180
+ )
181
+ # Merge the total daily mech requests with the daily mech requests
182
+ daily_mech_requests_local_copy = pd.merge(
183
+ daily_mech_requests_local_copy,
184
+ total_daily_mech_requests,
185
+ on="request_date",
186
+ how="left",
187
+ )
188
+ # Compute the percentage of mech requests for each tool
189
+ daily_mech_requests_local_copy["percentage"] = (
190
+ daily_mech_requests_local_copy["total_mech_requests"]
191
+ / daily_mech_requests_local_copy["total_daily_mech_requests"]
192
+ ) * 100
193
+
194
+ daily_mech_requests_local_copy = daily_mech_requests_local_copy[
195
+ daily_mech_requests_local_copy.tool.isin(top_tools)
196
+ ]
197
+
198
+ # remove the market_creator column
199
+ daily_mech_requests_local_copy = daily_mech_requests_local_copy.drop(
200
+ columns=["market_creator"]
201
+ )
202
+
203
+ # Create a pivot table to get the total mech requests per tool
204
+ pivoted = daily_mech_requests_local_copy.pivot(
205
+ index="request_date", columns="tool", values="percentage"
206
+ )
207
+ # Sort the columns for each row independently
208
+ sorted_values = np.sort(pivoted.values, axis=1)[
209
+ :, ::-1
210
+ ] # sort and reverse (descending)
211
+ sorted_columns = np.argsort(pivoted.values, axis=1)[:, ::-1] # get sorting indices
212
+
213
+ sorted_df = pd.DataFrame(
214
+ sorted_values,
215
+ index=pivoted.index,
216
+ columns=[
217
+ pivoted.columns[i] for i in sorted_columns[0]
218
+ ], # use first row's order
219
+ )
220
+
221
+ sorted_long = sorted_df.reset_index().melt(
222
+ id_vars=["request_date"], var_name="tool", value_name="percentage"
223
+ )
224
+
225
+ fig = px.bar(
226
+ sorted_long,
227
+ x="request_date",
228
+ y="percentage",
229
+ color="tool",
230
+ color_discrete_map=tools_palette,
231
+ )
232
+ fig.update_layout(
233
+ xaxis_title="Day of the request",
234
+ yaxis_title="Percentage of Total daily mech requests",
235
+ legend=dict(yanchor="top", y=0.5),
236
+ )
237
+ fig.update_layout(width=WIDTH, height=HEIGHT)
238
+ return gr.Plot(value=fig)