arshy commited on
Commit
120d6b7
·
1 Parent(s): 0869b01

second commit

Browse files
app copy.py DELETED
@@ -1,135 +0,0 @@
1
- import gradio as gr
2
- import pandas as pd
3
-
4
- tools = pd.read_csv("./data/tools.csv")
5
- # all_trades = pd.read_csv('./data/all_trades_profitability.csv')
6
-
7
- demo = gr.Blocks()
8
-
9
- INC_TOOLS = [
10
- 'prediction-online',
11
- 'prediction-offline',
12
- 'claude-prediction-online',
13
- 'claude-prediction-offline',
14
- 'prediction-offline-sme',
15
- 'prediction-online-sme',
16
- 'prediction-request-rag',
17
- 'prediction-request-reasoning',
18
- 'prediction-url-cot-claude',
19
- 'prediction-request-rag-claude',
20
- 'prediction-request-reasoning-claude'
21
- ]
22
-
23
- def set_error(row):
24
- if row.error not in [True, False]:
25
- if not row.prompt_response:
26
- return True
27
- return False
28
- return row.error
29
-
30
- def get_error_data():
31
- tools_inc = tools[tools['tool'].isin(INC_TOOLS)]
32
- tools_inc['error'] = tools_inc.apply(set_error, axis=1)
33
- error = tools_inc.groupby(['tool', 'request_month_year_week', 'error']).size().unstack().fillna(0).reset_index()
34
- error['error_perc'] = (error[True] / (error[False] + error[True]))*100
35
- error['total_requests'] = error[False] + error[True]
36
-
37
- return error
38
-
39
- def get_error_data_all(error):
40
- error_total = error.groupby('request_month_year_week').agg({'total_requests': 'sum', False: 'sum', True:'sum'}).reset_index()
41
- error_total['error_perc'] = (error_total[True] / error_total['total_requests'])*100
42
- # convert column name to string
43
- error_total.columns = error_total.columns.astype(str)
44
- # format all values to 4 decimal places for error_perc
45
- error_total['error_perc'] = error_total['error_perc'].apply(lambda x: round(x, 4))
46
- return error_total
47
-
48
- error = get_error_data()
49
- error_all = get_error_data_all(error)
50
- print(error_all.head())
51
-
52
- with demo:
53
- gr.HTML("<h1>Olas Predict Actual Performance</h1>")
54
- gr.Markdown("This app shows the actual performance of Olas Predict tools on the live market.")
55
-
56
- with gr.Tabs():
57
- with gr.TabItem("🔥 Error Dashboard"):
58
- with gr.Row():
59
- gr.Markdown("This plot shows the percentage of requests that resulted in an error.")
60
- with gr.Row():
61
- # plot
62
- with gr.Column():
63
- gr.LinePlot(
64
- value=error_all,
65
- x="request_month_year_week",
66
- y="error_perc",
67
- title="Error Percentage",
68
- x_title="Week",
69
- y_title="Error Percentage",
70
- height=400,
71
- show_label=True
72
- )
73
- gr.Markdown("This plot shows the percentage of requests that resulted in an error.")
74
-
75
- # Dropdown for selecting the tool
76
- sel_tool = gr.Dropdown(
77
- value="prediction-online",
78
- choices=INC_TOOLS,
79
- label="Select a tool"
80
- )
81
- plot_tool_error = gr.LinePlot(
82
- title="Error Percentage",
83
- x_title="Week",
84
- y_title="Error Percentage",
85
- render=False
86
- )
87
-
88
- # Dropdown for selecting the week
89
- sel_week = gr.Dropdown(
90
- value=error['request_month_year_week'].iloc[-1],
91
- choices=error['request_month_year_week'].unique().tolist(),
92
- label="Select a week"
93
- )
94
- plot_week_error = gr.BarPlot(
95
- title="Error Percentage",
96
- x_title="Tool",
97
- y_title="Error Percentage",
98
- render=False
99
- )
100
-
101
- def update_tool_plot(selected_tool):
102
- filtered_data = error[error['tool'] == selected_tool]
103
- # convert column name to string
104
- filtered_data.columns = filtered_data.columns.astype(str)
105
- # conver error_perc to 4 decimal place
106
- filtered_data['error_perc'] = filtered_data['error_perc'].apply(lambda x: round(x, 4))
107
- print(filtered_data.head())
108
- return {
109
- "x": filtered_data['request_month_year_week'].tolist(),
110
- "y": filtered_data['error_perc'].tolist(),
111
- }
112
-
113
- def update_week_plot(selected_week):
114
- filtered_data = error[error['request_month_year_week'] == selected_week]
115
- filtered_data.columns = filtered_data.columns.astype(str)
116
- filtered_data['error_perc'] = filtered_data['error_perc'].apply(lambda x: round(x, 4))
117
- print(filtered_data.head())
118
- return {
119
- "x": filtered_data['tool'].tolist(),
120
- "y": filtered_data['error_perc'].tolist(),
121
- }
122
-
123
- sel_tool.change(fn=update_tool_plot, inputs=sel_tool, outputs=plot_tool_error)
124
- sel_week.change(fn=update_week_plot, inputs=sel_week, outputs=plot_week_error)
125
-
126
- with gr.Row():
127
- plot_tool_error.render()
128
- with gr.Row():
129
- plot_week_error.render()
130
-
131
- with gr.TabItem("ℹ️ About"):
132
- with gr.Accordion("About the Benchmark", open=False):
133
- gr.Markdown("This app shows the actual performance of Olas Predict tools on the live market.")
134
-
135
- demo.queue(default_concurrency_limit=40).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,7 +1,30 @@
1
  import gradio as gr
2
  import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- tools = pd.read_csv("./data/tools.csv")
 
 
5
 
6
  demo = gr.Blocks()
7
 
@@ -19,78 +42,195 @@ INC_TOOLS = [
19
  'prediction-request-reasoning-claude'
20
  ]
21
 
22
- def set_error(row):
23
- if row.error not in [True, False]:
24
- if not row.prompt_response:
25
- return True
26
- return False
27
- return row.error
28
-
29
- def get_error_data():
30
- tools_inc = tools[tools['tool'].isin(INC_TOOLS)]
31
- tools_inc['error'] = tools_inc.apply(set_error, axis=1)
32
- error = tools_inc.groupby(['tool', 'request_month_year_week', 'error']).size().unstack().fillna(0).reset_index()
33
- error['error_perc'] = (error[True] / (error[False] + error[True])) * 100
34
- error['total_requests'] = error[False] + error[True]
35
- return error
36
-
37
- def get_error_data_all(error):
38
- error_total = error.groupby('request_month_year_week').agg({'total_requests': 'sum', False: 'sum', True: 'sum'}).reset_index()
39
- error_total['error_perc'] = (error_total[True] / error_total['total_requests']) * 100
40
- error_total.columns = error_total.columns.astype(str)
41
- error_total['error_perc'] = error_total['error_perc'].apply(lambda x: round(x, 4))
42
- return error_total
43
-
44
- error = get_error_data()
45
- error_all = get_error_data_all(error)
46
 
47
  with demo:
48
  gr.HTML("<h1>Olas Predict Actual Performance</h1>")
49
  gr.Markdown("This app shows the actual performance of Olas Predict tools on the live market.")
50
 
51
  with gr.Tabs():
52
- with gr.TabItem("🔥 Error Dashboard"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  with gr.Row():
54
  gr.Markdown("# Plot showing overall error")
55
  with gr.Row():
56
- # plot
57
- with gr.Column():
58
- gr.BarPlot(
59
- value=error_all,
60
- x="request_month_year_week",
61
- y="error_perc",
62
- title="Error Percentage",
63
- x_title="Week",
64
- y_title="Error Percentage",
65
- height=800,
66
- show_label=True,
67
- interactive=True,
68
- show_actions_button=True,
69
- tooltip=["request_month_year_week", "error_perc"]
70
- )
71
  with gr.Row():
72
  gr.Markdown("# Plot showing error by tool")
73
-
74
  with gr.Row():
75
- sel_tool = gr.Dropdown(label="Select a tool", choices=INC_TOOLS, value=INC_TOOLS[0])
 
 
 
 
76
 
77
  with gr.Row():
78
- plot_tool_error = gr.BarPlot(
79
- title="Error Percentage",
80
- x_title="Week",
81
- y_title="Error Percentage",
82
- show_label=True,
83
- interactive=True,
84
- show_actions_button=True,
85
- tooltip=["request_month_year_week", "error_perc"],
86
- width=800
 
87
  )
88
 
 
 
 
 
 
 
 
 
 
 
89
  with gr.Row():
90
  gr.Markdown("# Plot showing error by week")
91
 
92
  with gr.Row():
93
- choices = error['request_month_year_week'].unique().tolist()
94
  # sort the choices by the latest week to be on the top
95
  choices = sorted(choices)
96
  sel_week = gr.Dropdown(
@@ -100,52 +240,19 @@ with demo:
100
  )
101
 
102
  with gr.Row():
103
- plot_week_error = gr.BarPlot(
104
- title="Error Percentage",
105
- x_title="Tool",
106
- y_title="Error Percentage",
107
- show_label=True,
108
- interactive=True,
109
- show_actions_button=True,
110
- tooltip=["tool", "error_perc"],
111
- width=800
112
- )
113
-
114
-
115
- def update_tool_plot(selected_tool):
116
- filtered_data = error[error['tool'] == selected_tool]
117
- # convert column name to string
118
- filtered_data.columns = filtered_data.columns.astype(str)
119
- # convert error_perc to 4 decimal place
120
- filtered_data['error_perc'] = filtered_data['error_perc'].apply(lambda x: round(x, 4))
121
- update = gr.LinePlot(
122
- title="Error Percentage",
123
- x_title="Week",
124
- y_title="Error Percentage",
125
- x="request_month_year_week",
126
- y="error_perc",
127
- value=filtered_data
128
- )
129
- return update
130
-
131
- def update_week_plot(selected_week):
132
- filtered_data = error[error['request_month_year_week'] == selected_week]
133
- # convert column name to string
134
- filtered_data.columns = filtered_data.columns.astype(str)
135
- # convert error_perc to 4 decimal place
136
- filtered_data['error_perc'] = filtered_data['error_perc'].apply(lambda x: round(x, 4))
137
- update = gr.BarPlot(
138
- title="Error Percentage",
139
- x_title="Tool",
140
- y_title="Error Percentage",
141
- x="tool",
142
- y="error_perc",
143
- value=filtered_data
144
- )
145
- return update
146
-
147
- sel_tool.change(update_tool_plot, inputs=sel_tool, outputs=plot_tool_error)
148
- sel_week.change(update_week_plot, inputs=sel_week, outputs=plot_week_error)
149
 
150
  with gr.Row():
151
  sel_tool
 
1
  import gradio as gr
2
  import pandas as pd
3
+ from tabs.trades import (
4
+ prepare_trades,
5
+ get_overall_trades,
6
+ get_overall_winning_trades,
7
+ plot_trades_by_week,
8
+ plot_winning_trades_by_week,
9
+ plot_trade_details
10
+ )
11
+ from tabs.tool_win import (
12
+ get_tool_winning_rate,
13
+ get_overall_winning_rate,
14
+ plot_winning_trades,
15
+ plot_winning_plot_by_tool
16
+ )
17
+ from tabs.error import (
18
+ get_error_data,
19
+ get_error_data_overall,
20
+ plot_error_data,
21
+ plot_tool_error_data,
22
+ plot_week_error_data
23
+ )
24
 
25
+ tools_df = pd.read_csv("./data/tools.csv")
26
+ trades_df = pd.read_csv("./data/all_trades_profitability.csv")
27
+ trades_df = prepare_trades(trades_df)
28
 
29
  demo = gr.Blocks()
30
 
 
42
  'prediction-request-reasoning-claude'
43
  ]
44
 
45
+
46
+ # TOOLS DATA
47
+ error_df = get_error_data(
48
+ tools_df=tools_df,
49
+ inc_tools=INC_TOOLS
50
+ )
51
+ error_overall_df = get_error_data_overall(
52
+ error_df=error_df
53
+ )
54
+ winning_rate_df = get_tool_winning_rate(
55
+ tools_df=tools_df,
56
+ inc_tools=INC_TOOLS
57
+ )
58
+ winning_rate_all_df = get_overall_winning_rate(
59
+ wins_df=winning_rate_df
60
+ )
61
+ trades_count_df = get_overall_trades(
62
+ trades_df=trades_df
63
+ )
64
+ trades_winning_rate_df = get_overall_winning_trades(
65
+ trades_df=trades_df
66
+ )
 
 
67
 
68
  with demo:
69
  gr.HTML("<h1>Olas Predict Actual Performance</h1>")
70
  gr.Markdown("This app shows the actual performance of Olas Predict tools on the live market.")
71
 
72
  with gr.Tabs():
73
+ with gr.TabItem("🔥Trades Dashboard"):
74
+ with gr.Row():
75
+ gr.Markdown("# Plot of number of trades by week")
76
+ with gr.Row():
77
+ plot_trades_by_week = plot_trades_by_week(
78
+ trades_df=trades_count_df
79
+ )
80
+ with gr.Row():
81
+ gr.Markdown("# Plot of winning trades by week")
82
+ with gr.Row():
83
+ plot_winning_trades_by_week = plot_winning_trades_by_week(
84
+ trades_df=trades_winning_rate_df
85
+ )
86
+ with gr.Row():
87
+ gr.Markdown("# Plot of trade details")
88
+ with gr.Row():
89
+ trade_details_selector = gr.Dropdown(
90
+ label="Select a trade",
91
+ choices=[
92
+ "mech calls",
93
+ "collateral amount",
94
+ "earnings",
95
+ "net earnings",
96
+ "ROI"
97
+ ],
98
+ value="mech calls"
99
+ )
100
+ with gr.Row():
101
+ trade_details_plot = plot_trade_details(
102
+ trade_detail="mech calls",
103
+ trades_df=trades_df
104
+ )
105
+
106
+ def update_trade_details(trade_detail):
107
+ return plot_trade_details(
108
+ trade_detail=trade_detail,
109
+ trades_df=trades_df
110
+ )
111
+
112
+ trade_details_selector.change(
113
+ update_trade_details,
114
+ inputs=trade_details_selector,
115
+ outputs=trade_details_plot
116
+ )
117
+
118
+ with gr.Row():
119
+ trade_details_selector
120
+ with gr.Row():
121
+ trade_details_plot
122
+
123
+ with gr.TabItem("🚀 Tool Winning Dashboard"):
124
+ with gr.Row():
125
+ gr.Markdown("# Plot showing overall winning rate")
126
+
127
+ with gr.Row():
128
+ winning_selector = gr.Dropdown(
129
+ label="Select Metric",
130
+ choices=['losses', 'wins', 'total_request', 'win_perc'],
131
+ value='win_perc',
132
+ )
133
+
134
+ with gr.Row():
135
+ winning_plot = plot_winning_trades(
136
+ wins_df=winning_rate_all_df,
137
+ winning_selector="win_perc"
138
+ )
139
+
140
+ def update_winning_plot(winning_selector):
141
+ return plot_winning_trades(
142
+ wins_df=winning_rate_all_df,
143
+ winning_selector=winning_selector
144
+ )
145
+
146
+ winning_selector.change(
147
+ plot_winning_trades,
148
+ inputs=winning_selector,
149
+ outputs=winning_plot
150
+ )
151
+
152
+ with gr.Row():
153
+ winning_selector
154
+ with gr.Row():
155
+ winning_plot
156
+
157
+ with gr.Row():
158
+ gr.Markdown("# Plot showing winning rate by tool")
159
+
160
+ with gr.Row():
161
+ sel_tool = gr.Dropdown(
162
+ label="Select a tool",
163
+ choices=INC_TOOLS,
164
+ value=INC_TOOLS[0]
165
+ )
166
+
167
+ with gr.Row():
168
+ plot_tool_win_rate = plot_winning_plot_by_tool(
169
+ wins_df=winning_rate_df,
170
+ tool=INC_TOOLS[0]
171
+ )
172
+
173
+ def update_tool_win_plot(tool):
174
+ return plot_winning_plot_by_tool(
175
+ wins_df=winning_rate_df,
176
+ tool=tool
177
+ )
178
+
179
+ sel_tool.change(
180
+ update_tool_win_plot,
181
+ inputs=sel_tool,
182
+ outputs=plot_tool_win_rate
183
+ )
184
+
185
+ with gr.Row():
186
+ sel_tool
187
+ with gr.Row():
188
+ plot_tool_win_rate
189
+
190
+ with gr.TabItem("🏥 Tool Error Dashboard"):
191
  with gr.Row():
192
  gr.Markdown("# Plot showing overall error")
193
  with gr.Row():
194
+ plot_error_data(
195
+ error_all_df=error_overall_df
196
+ )
 
 
 
 
 
 
 
 
 
 
 
 
197
  with gr.Row():
198
  gr.Markdown("# Plot showing error by tool")
 
199
  with gr.Row():
200
+ sel_tool = gr.Dropdown(
201
+ label="Select a tool",
202
+ choices=INC_TOOLS,
203
+ value=INC_TOOLS[0]
204
+ )
205
 
206
  with gr.Row():
207
+ plot_tool_error = plot_tool_error_data(
208
+ error_df=error_df,
209
+ tool=INC_TOOLS[0]
210
+ )
211
+
212
+
213
+ def update_tool_error_plot(tool):
214
+ return plot_tool_error_data(
215
+ error_df=error_df,
216
+ tool=tool
217
  )
218
 
219
+ sel_tool.change(
220
+ update_tool_error_plot,
221
+ inputs=sel_tool,
222
+ outputs=plot_tool_error
223
+ )
224
+ with gr.Row():
225
+ sel_tool
226
+ with gr.Row():
227
+ plot_tool_error
228
+
229
  with gr.Row():
230
  gr.Markdown("# Plot showing error by week")
231
 
232
  with gr.Row():
233
+ choices = error_overall_df['request_month_year_week'].unique().tolist()
234
  # sort the choices by the latest week to be on the top
235
  choices = sorted(choices)
236
  sel_week = gr.Dropdown(
 
240
  )
241
 
242
  with gr.Row():
243
+ plot_week_error = plot_week_error_data(
244
+ error_df=error_df,
245
+ week=choices[-1]
246
+ )
247
+
248
+ def update_week_error_plot(selected_week):
249
+ return plot_week_error_data(
250
+ error_df=error_df,
251
+ week=selected_week
252
+ )
253
+
254
+ sel_tool.change(update_tool_error_plot, inputs=sel_tool, outputs=plot_tool_error)
255
+ sel_week.change(update_week_error_plot, inputs=sel_week, outputs=plot_week_error)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
 
257
  with gr.Row():
258
  sel_tool
data/all_trades_profitability.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:28ee508150a1cba56c9439d0cbfcf4871cb9f32f0792eb1d4dd7bca95af1e903
3
- size 28328169
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:866a83eac6c603f435ee960b0da2570ced109438ee73e13a525b06a3d7baa133
3
+ size 28938394
data/delivers.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0dafbbf73918de11435cbeaee7196ab0f37a18b06656a0c5325b1fa86be98b2c
3
- size 1121772123
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:04f73cf0443fc8e91dd4b2e5188aee00f06ccc89d3977bf8e57063076ca91f51
3
+ size 1270000369
data/fpmmTrades.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3a16a49dac94891d4438ea4eba6a52d6ef00f2985bbcc0e41daeb6f8557f5536
3
- size 62639698
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e4600c2925a707bc882fda67612d03e28903e11947fe56f3e594f575f437d20
3
+ size 64196881
data/fpmms.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d7933c45ab45cf377b55dbdc49f413ede81a7582cd843717c70cdd71f8fa7b74
3
- size 391125
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:721b874d94ebb1a83456f75b911f79fd654971c2150976911968b27790ed7f84
3
+ size 399415
data/requests.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:70d06d62c1fe5dd50fe5c7e3066413e843eb536cc51f08325fd85570b8255007
3
- size 124945839
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:db71f7e4cebe1e68eb280615d4331f3fe6a8732d94c29920b7b485f048631b7a
3
+ size 129156993
data/summary_profitability.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d4769b2c800f4a3c655de8a5673070c5be00ce5733798cc9a745cc5df2f961a6
3
- size 46612
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a999ed3c31ae1ee71da379e0840995584491457db4ca7250ca2e7f9b55c3869
3
+ size 48242
data/tools.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4045250b8b4ec74ca3d37ce94208665c1ea09042b6681106615f0773ce46aee0
3
- size 1211219315
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35f76795539604c1c50f70d161c217c32c0fa04bbbd94ee29f5717b782c6863f
3
+ size 1363028261
nbs/weekly_analysis.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
tabs/__pycache__/error.cpython-310.pyc ADDED
Binary file (2.46 kB). View file
 
tabs/__pycache__/tool_win.cpython-310.pyc ADDED
Binary file (2.03 kB). View file
 
tabs/__pycache__/trades.cpython-310.pyc ADDED
Binary file (2.93 kB). View file
 
tabs/error.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+
4
+ def set_error(row):
5
+ if row.error not in [True, False]:
6
+ if not row.prompt_response:
7
+ return True
8
+ return False
9
+ return row.error
10
+
11
+ def get_error_data(tools_df, inc_tools):
12
+ tools_inc = tools_df[tools_df['tool'].isin(inc_tools)]
13
+ tools_inc['error'] = tools_inc.apply(set_error, axis=1)
14
+ error = tools_inc.groupby(['tool', 'request_month_year_week', 'error']).size().unstack().fillna(0).reset_index()
15
+ error['error_perc'] = (error[True] / (error[False] + error[True])) * 100
16
+ error['total_requests'] = error[False] + error[True]
17
+ return error
18
+
19
+ def get_error_data_overall(error_df):
20
+ error_total = error_df.groupby('request_month_year_week').agg({'total_requests': 'sum', False: 'sum', True: 'sum'}).reset_index()
21
+ error_total['error_perc'] = (error_total[True] / error_total['total_requests']) * 100
22
+ error_total.columns = error_total.columns.astype(str)
23
+ error_total['error_perc'] = error_total['error_perc'].apply(lambda x: round(x, 4))
24
+ return error_total
25
+
26
+ def plot_error_data(error_all_df):
27
+ return gr.BarPlot(
28
+ value=error_all_df,
29
+ x="request_month_year_week",
30
+ y="error_perc",
31
+ title="Error Percentage",
32
+ x_title="Week",
33
+ y_title="Error Percentage",
34
+ height=800,
35
+ show_label=True,
36
+ interactive=True,
37
+ show_actions_button=True,
38
+ tooltip=["request_month_year_week", "error_perc"]
39
+ )
40
+
41
+ def plot_tool_error_data(error_df, tool):
42
+ error_tool = error_df[error_df['tool'] == tool]
43
+ error_tool.columns = error_tool.columns.astype(str)
44
+ error_tool['error_perc'] = error_tool['error_perc'].apply(lambda x: round(x, 4))
45
+
46
+ return gr.BarPlot(
47
+ title="Error Percentage",
48
+ x_title="Week",
49
+ y_title="Error Percentage",
50
+ show_label=True,
51
+ interactive=True,
52
+ show_actions_button=True,
53
+ tooltip=["request_month_year_week", "error_perc"],
54
+ width=800,
55
+ value=error_tool,
56
+ x="request_month_year_week",
57
+ y="error_perc"
58
+ )
59
+
60
+ def plot_week_error_data(error_df, week):
61
+ error_week = error_df[error_df['request_month_year_week'] == week]
62
+ error_week.columns = error_week.columns.astype(str)
63
+ error_week['error_perc'] = error_week['error_perc'].apply(lambda x: round(x, 4))
64
+ return gr.BarPlot(
65
+ value=error_week,
66
+ x="tool",
67
+ y="error_perc",
68
+ title="Error Percentage",
69
+ x_title="Tool",
70
+ y_title="Error Percentage",
71
+ height=800,
72
+ show_label=True,
73
+ interactive=True,
74
+ show_actions_button=True,
75
+ tooltip=["tool", "error_perc"]
76
+ )
77
+
tabs/tool_win.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+
4
+ def set_error(row):
5
+ if row.error not in [True, False]:
6
+ if not row.prompt_response:
7
+ return True
8
+ return False
9
+ return row.error
10
+
11
+
12
+ def get_tool_winning_rate(tools_df, inc_tools):
13
+ tools_inc = tools_df[tools_df['tool'].isin(inc_tools)]
14
+ tools_inc['error'] = tools_inc.apply(set_error, axis=1)
15
+ tools_non_error = tools_inc[tools_inc['error'] != True]
16
+ tools_non_error['currentAnswer'].replace('no', 'No', inplace=True)
17
+ tools_non_error['currentAnswer'].replace('yes', 'Yes', inplace=True)
18
+ tools_non_error = tools_non_error[tools_non_error['currentAnswer'].isin(['Yes', 'No'])]
19
+ tools_non_error = tools_non_error[tools_non_error['vote'].isin(['Yes', 'No'])]
20
+ tools_non_error['win'] = tools_non_error['currentAnswer'] == tools_non_error['vote']
21
+ tools_non_error['win'] = tools_non_error['win'].astype(int)
22
+ tools_non_error.columns = tools_non_error.columns.astype(str)
23
+ wins = tools_non_error.groupby(['tool', 'request_month_year_week', 'win']).size().unstack().fillna(0)
24
+ wins['win_perc'] = (wins[1] / (wins[0] + wins[1]))*100
25
+ wins.reset_index(inplace=True)
26
+ wins['total_request'] = wins[0] + wins[1]
27
+ wins.columns = wins.columns.astype(str)
28
+ return wins
29
+
30
+
31
+ def get_overall_winning_rate(wins_df):
32
+ overall_wins = wins_df.groupby('request_month_year_week').agg({
33
+ "0": 'sum',
34
+ "1": 'sum',
35
+ "win_perc": 'mean',
36
+ "total_request": 'sum'
37
+ }).rename(columns={"0": 'losses', "1": 'wins'}).reset_index()
38
+ return overall_wins
39
+
40
+
41
+ def plot_winning_trades(
42
+ wins_df,
43
+ winning_selector="win_perc"
44
+ ):
45
+ return gr.BarPlot(
46
+ title="Winning Rate",
47
+ x_title="Date",
48
+ y_title=winning_selector,
49
+ show_label=True,
50
+ interactive=True,
51
+ show_actions_button=True,
52
+ tooltip=["request_month_year_week", winning_selector],
53
+ width=800,
54
+ value=wins_df,
55
+ x="request_month_year_week",
56
+ y=winning_selector
57
+ )
58
+
59
+
60
+ def plot_winning_plot_by_tool(wins_df, tool):
61
+ return gr.BarPlot(
62
+ title="Winning Rate",
63
+ x_title="Week",
64
+ y_title="Winning Rate",
65
+ x="request_month_year_week",
66
+ y="win_perc",
67
+ value=wins_df[wins_df['tool'] == tool],
68
+ width=800,
69
+ show_label=True,
70
+ interactive=True,
71
+ show_actions_button=True,
72
+ tooltip=["request_month_year_week", "win_perc"]
73
+ )
tabs/trades.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+
4
+
5
+ def prepare_trades(trades_df):
6
+ trades_df['creation_timestamp'] = pd.to_datetime(trades_df['creation_timestamp'])
7
+ trades_df['month_year'] = trades_df['creation_timestamp'].dt.to_period('M').astype(str)
8
+ trades_df['month_year_week'] = trades_df['creation_timestamp'].dt.to_period('W').astype(str)
9
+ trades_df['winning_trade'] = trades_df['winning_trade'].astype(int)
10
+ return trades_df
11
+
12
+
13
+ def get_overall_trades(trades_df):
14
+ trades_count = trades_df.groupby('month_year_week').size().reset_index()
15
+ trades_count.columns = trades_count.columns.astype(str)
16
+ trades_count.rename(columns={'0': 'trades'}, inplace=True)
17
+ return trades_count
18
+
19
+ def get_overall_winning_trades(trades_df):
20
+ winning_trades = trades_df.groupby(['month_year_week'])['winning_trade'].sum() / trades_df.groupby(['month_year_week'])['winning_trade'].count() * 100
21
+ # winning_trades is a series, give it a dataframe
22
+ winning_trades = winning_trades.reset_index()
23
+ winning_trades.columns = winning_trades.columns.astype(str)
24
+ winning_trades.columns = ['month_year_week', 'winning_trade']
25
+ return winning_trades
26
+
27
+ def plot_trade_details(trade_detail, trades_df):
28
+ if trade_detail == "mech calls":
29
+ # this is to filter out the data before 2023-09-01
30
+ trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
31
+ trades_filtered = trades_filtered.groupby("month_year_week")["num_mech_calls"].quantile([0.25, 0.5, 0.75]).unstack()
32
+ trades_filtered.columns = trades_filtered.columns.astype(str)
33
+ trades_filtered.reset_index(inplace=True)
34
+ trades_filtered.columns = [
35
+ "month_year_week",
36
+ "25th_percentile",
37
+ "50th_percentile",
38
+ "75th_percentile"
39
+ ]
40
+ # reformat the data as percentile, date, value
41
+ trades_filtered = trades_filtered.melt(id_vars=["month_year_week"], var_name="percentile", value_name="mech_calls")
42
+
43
+ return gr.LinePlot(
44
+ value=trades_filtered,
45
+ x="month_year_week",
46
+ y="mech_calls",
47
+ color="percentile",
48
+ show_label=True,
49
+ interactive=True,
50
+ show_actions_button=True,
51
+ tooltip=["month_year_week", "percentile", "mech_calls"]
52
+ )
53
+
54
+ if trade_detail == "collateral amount":
55
+ trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
56
+ trades_filtered = trades_filtered.groupby("month_year_week")["collateral_amount"].quantile([0.25, 0.5, 0.75]).unstack()
57
+ trades_filtered.columns = trades_filtered.columns.astype(str)
58
+ trades_filtered.reset_index(inplace=True)
59
+ trades_filtered.columns = [
60
+ "month_year_week",
61
+ "25th_percentile",
62
+ "50th_percentile",
63
+ "75th_percentile"
64
+ ]
65
+ # reformat the data as percentile, date, value
66
+ trades_filtered = trades_filtered.melt(id_vars=["month_year_week"], var_name="percentile", value_name="collateral_amount")
67
+
68
+ return gr.LinePlot(
69
+ value=trades_filtered,
70
+ x="month_year_week",
71
+ y="collateral_amount",
72
+ color="percentile",
73
+ show_label=True,
74
+ interactive=True,
75
+ show_actions_button=True,
76
+ tooltip=["month_year_week", "percentile", "collateral_amount"]
77
+ )
78
+
79
+ if trade_detail == "earnings":
80
+ trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
81
+ trades_filtered = trades_filtered.groupby("month_year_week")["earnings"].quantile([0.25, 0.5, 0.75]).unstack()
82
+ trades_filtered.columns = trades_filtered.columns.astype(str)
83
+ trades_filtered.reset_index(inplace=True)
84
+ trades_filtered.columns = [
85
+ "month_year_week",
86
+ "25th_percentile",
87
+ "50th_percentile",
88
+ "75th_percentile"
89
+ ]
90
+ # reformat the data as percentile, date, value
91
+ trades_filtered = trades_filtered.melt(id_vars=["month_year_week"], var_name="percentile", value_name="earnings")
92
+
93
+ return gr.LinePlot(
94
+ value=trades_filtered,
95
+ x="month_year_week",
96
+ y="earnings",
97
+ color="percentile",
98
+ show_label=True,
99
+ interactive=True,
100
+ show_actions_button=True,
101
+ tooltip=["month_year_week", "percentile", "earnings"]
102
+ )
103
+
104
+ if trade_detail == "net earnings":
105
+ trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
106
+ trades_filtered = trades_filtered.groupby("month_year_week")["net_earnings"].quantile([0.25, 0.5, 0.75]).unstack()
107
+ trades_filtered.columns = trades_filtered.columns.astype(str)
108
+ trades_filtered.reset_index(inplace=True)
109
+ trades_filtered.columns = [
110
+ "month_year_week",
111
+ "25th_percentile",
112
+ "50th_percentile",
113
+ "75th_percentile"
114
+ ]
115
+ # reformat the data as percentile, date, value
116
+ trades_filtered = trades_filtered.melt(id_vars=["month_year_week"], var_name="percentile", value_name="net_earnings")
117
+
118
+ return gr.LinePlot(
119
+ value=trades_filtered,
120
+ x="month_year_week",
121
+ y="net_earnings",
122
+ color="percentile",
123
+ show_label=True,
124
+ interactive=True,
125
+ show_actions_button=True,
126
+ tooltip=["month_year_week", "percentile", "net_earnings"]
127
+ )
128
+
129
+ if trade_detail == "ROI":
130
+ trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
131
+ trades_filtered = trades_filtered.groupby("month_year_week")["roi"].quantile([0.25, 0.5, 0.75]).unstack()
132
+ trades_filtered.columns = trades_filtered.columns.astype(str)
133
+ trades_filtered.reset_index(inplace=True)
134
+ trades_filtered.columns = [
135
+ "month_year_week",
136
+ "25th_percentile",
137
+ "50th_percentile",
138
+ "75th_percentile"
139
+ ]
140
+ # reformat the data as percentile, date, value
141
+ trades_filtered = trades_filtered.melt(id_vars=["month_year_week"], var_name="percentile", value_name="ROI")
142
+
143
+ return gr.LinePlot(
144
+ value=trades_filtered,
145
+ x="month_year_week",
146
+ y="ROI",
147
+ color="percentile",
148
+ show_label=True,
149
+ interactive=True,
150
+ show_actions_button=True,
151
+ tooltip=["month_year_week", "percentile", "ROI"]
152
+ )
153
+
154
+ def plot_trades_by_week(trades_df):
155
+ return gr.BarPlot(
156
+ value=trades_df,
157
+ x="month_year_week",
158
+ y="trades",
159
+ show_label=True,
160
+ interactive=True,
161
+ show_actions_button=True,
162
+ tooltip=["month_year_week", "trades"]
163
+ )
164
+
165
+ def plot_winning_trades_by_week(trades_df):
166
+ return gr.BarPlot(
167
+ value=trades_df,
168
+ x="month_year_week",
169
+ y="winning_trade",
170
+ show_label=True,
171
+ interactive=True,
172
+ show_actions_button=True,
173
+ tooltip=["month_year_week", "winning_trade"]
174
+ )