arshy commited on
Commit
5b5bfee
1 Parent(s): 120d6b7

third commit

Browse files
app.py CHANGED
@@ -9,10 +9,10 @@ from tabs.trades import (
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,
@@ -55,7 +55,7 @@ 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(
@@ -132,19 +132,19 @@ with demo:
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
  )
@@ -165,19 +165,19 @@ with demo:
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
  )
 
9
  plot_trade_details
10
  )
11
  from tabs.tool_win import (
12
+ get_tool_winning_rate,
13
  get_overall_winning_rate,
14
+ plot_tool_winnings_overall,
15
+ plot_tool_winnings_by_tool
16
  )
17
  from tabs.error import (
18
  get_error_data,
 
55
  tools_df=tools_df,
56
  inc_tools=INC_TOOLS
57
  )
58
+ winning_rate_overall_df = get_overall_winning_rate(
59
  wins_df=winning_rate_df
60
  )
61
  trades_count_df = get_overall_trades(
 
132
  )
133
 
134
  with gr.Row():
135
+ winning_plot = plot_tool_winnings_overall(
136
+ wins_df=winning_rate_overall_df,
137
  winning_selector="win_perc"
138
  )
139
 
140
+ def update_tool_winnings_overall_plot(winning_selector):
141
+ return plot_tool_winnings_overall(
142
+ wins_df=winning_rate_overall_df,
143
  winning_selector=winning_selector
144
  )
145
 
146
  winning_selector.change(
147
+ update_tool_winnings_overall_plot,
148
  inputs=winning_selector,
149
  outputs=winning_plot
150
  )
 
165
  )
166
 
167
  with gr.Row():
168
+ plot_tool_win_rate = plot_tool_winnings_by_tool(
169
  wins_df=winning_rate_df,
170
  tool=INC_TOOLS[0]
171
  )
172
 
173
+ def update_tool_winnings_by_tool_plot(tool):
174
+ return plot_tool_winnings_by_tool(
175
  wins_df=winning_rate_df,
176
  tool=tool
177
  )
178
 
179
  sel_tool.change(
180
+ update_tool_winnings_by_tool_plot,
181
  inputs=sel_tool,
182
  outputs=plot_tool_win_rate
183
  )
tabs/__pycache__/error.cpython-310.pyc CHANGED
Binary files a/tabs/__pycache__/error.cpython-310.pyc and b/tabs/__pycache__/error.cpython-310.pyc differ
 
tabs/__pycache__/tool_win.cpython-310.pyc CHANGED
Binary files a/tabs/__pycache__/tool_win.cpython-310.pyc and b/tabs/__pycache__/tool_win.cpython-310.pyc differ
 
tabs/__pycache__/trades.cpython-310.pyc CHANGED
Binary files a/tabs/__pycache__/trades.cpython-310.pyc and b/tabs/__pycache__/trades.cpython-310.pyc differ
 
tabs/error.py CHANGED
@@ -1,6 +1,10 @@
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:
@@ -31,11 +35,12 @@ def plot_error_data(error_all_df):
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):
@@ -51,10 +56,11 @@ def plot_tool_error_data(error_df, tool):
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):
@@ -68,10 +74,11 @@ def plot_week_error_data(error_df, week):
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
 
 
1
  import pandas as pd
2
  import gradio as gr
3
 
4
+
5
+ HEIGHT=600
6
+ WIDTH=1000
7
+
8
  def set_error(row):
9
  if row.error not in [True, False]:
10
  if not row.prompt_response:
 
35
  title="Error Percentage",
36
  x_title="Week",
37
  y_title="Error Percentage",
 
38
  show_label=True,
39
  interactive=True,
40
  show_actions_button=True,
41
+ tooltip=["request_month_year_week", "error_perc"],
42
+ height=HEIGHT,
43
+ width=WIDTH
44
  )
45
 
46
  def plot_tool_error_data(error_df, tool):
 
56
  interactive=True,
57
  show_actions_button=True,
58
  tooltip=["request_month_year_week", "error_perc"],
 
59
  value=error_tool,
60
  x="request_month_year_week",
61
+ y="error_perc",
62
+ height=HEIGHT,
63
+ width=WIDTH
64
  )
65
 
66
  def plot_week_error_data(error_df, week):
 
74
  title="Error Percentage",
75
  x_title="Tool",
76
  y_title="Error Percentage",
 
77
  show_label=True,
78
  interactive=True,
79
  show_actions_button=True,
80
+ tooltip=["tool", "error_perc"],
81
+ height=HEIGHT,
82
+ width=WIDTH
83
  )
84
 
tabs/tool_win.py CHANGED
@@ -1,6 +1,11 @@
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:
@@ -10,21 +15,21 @@ def set_error(row):
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
 
@@ -38,7 +43,7 @@ def get_overall_winning_rate(wins_df):
38
  return overall_wins
39
 
40
 
41
- def plot_winning_trades(
42
  wins_df,
43
  winning_selector="win_perc"
44
  ):
@@ -50,14 +55,15 @@ def plot_winning_trades(
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",
@@ -65,9 +71,10 @@ def plot_winning_plot_by_tool(wins_df, tool):
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
  )
 
1
  import pandas as pd
2
  import gradio as gr
3
 
4
+
5
+ HEIGHT=600
6
+ WIDTH=1000
7
+
8
+
9
  def set_error(row):
10
  if row.error not in [True, False]:
11
  if not row.prompt_response:
 
15
 
16
 
17
  def get_tool_winning_rate(tools_df, inc_tools):
18
+ tools_inc = tools_df[tools_df['tool'].isin(inc_tools)].copy()
19
  tools_inc['error'] = tools_inc.apply(set_error, axis=1)
20
  tools_non_error = tools_inc[tools_inc['error'] != True]
21
+ tools_non_error.loc[:, 'currentAnswer'] = tools_non_error['currentAnswer'].replace({'no': 'No', 'yes': 'Yes'})
 
22
  tools_non_error = tools_non_error[tools_non_error['currentAnswer'].isin(['Yes', 'No'])]
23
  tools_non_error = tools_non_error[tools_non_error['vote'].isin(['Yes', 'No'])]
24
+ tools_non_error['win'] = (tools_non_error['currentAnswer'] == tools_non_error['vote']).astype(int)
 
25
  tools_non_error.columns = tools_non_error.columns.astype(str)
26
  wins = tools_non_error.groupby(['tool', 'request_month_year_week', 'win']).size().unstack().fillna(0)
27
+ wins['win_perc'] = (wins[1] / (wins[0] + wins[1])) * 100
28
  wins.reset_index(inplace=True)
29
  wins['total_request'] = wins[0] + wins[1]
30
  wins.columns = wins.columns.astype(str)
31
+ # Convert request_month_year_week to string and explicitly set type for Altair
32
+ wins['request_month_year_week'] = wins['request_month_year_week'].astype(str)
33
  return wins
34
 
35
 
 
43
  return overall_wins
44
 
45
 
46
+ def plot_tool_winnings_overall(
47
  wins_df,
48
  winning_selector="win_perc"
49
  ):
 
55
  interactive=True,
56
  show_actions_button=True,
57
  tooltip=["request_month_year_week", winning_selector],
 
58
  value=wins_df,
59
  x="request_month_year_week",
60
+ y=winning_selector,
61
+ height=HEIGHT,
62
+ width=WIDTH
63
  )
64
 
65
 
66
+ def plot_tool_winnings_by_tool(wins_df, tool):
67
  return gr.BarPlot(
68
  title="Winning Rate",
69
  x_title="Week",
 
71
  x="request_month_year_week",
72
  y="win_perc",
73
  value=wins_df[wins_df['tool'] == tool],
 
74
  show_label=True,
75
  interactive=True,
76
  show_actions_button=True,
77
+ tooltip=["request_month_year_week", "win_perc"],
78
+ height=HEIGHT,
79
+ width=WIDTH
80
  )
tabs/trades.py CHANGED
@@ -2,6 +2,9 @@ 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)
@@ -48,7 +51,9 @@ def plot_trade_details(trade_detail, trades_df):
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":
@@ -73,7 +78,9 @@ def plot_trade_details(trade_detail, trades_df):
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":
@@ -98,7 +105,9 @@ def plot_trade_details(trade_detail, trades_df):
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":
@@ -123,7 +132,9 @@ def plot_trade_details(trade_detail, trades_df):
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":
@@ -148,7 +159,9 @@ def plot_trade_details(trade_detail, trades_df):
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):
@@ -159,7 +172,9 @@ def plot_trades_by_week(trades_df):
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):
@@ -170,5 +185,7 @@ def plot_winning_trades_by_week(trades_df):
170
  show_label=True,
171
  interactive=True,
172
  show_actions_button=True,
173
- tooltip=["month_year_week", "winning_trade"]
 
 
174
  )
 
2
  import pandas as pd
3
 
4
 
5
+ HEIGHT=600
6
+ WIDTH=1000
7
+
8
  def prepare_trades(trades_df):
9
  trades_df['creation_timestamp'] = pd.to_datetime(trades_df['creation_timestamp'])
10
  trades_df['month_year'] = trades_df['creation_timestamp'].dt.to_period('M').astype(str)
 
51
  show_label=True,
52
  interactive=True,
53
  show_actions_button=True,
54
+ tooltip=["month_year_week", "percentile", "mech_calls"],
55
+ height=HEIGHT,
56
+ width=WIDTH
57
  )
58
 
59
  if trade_detail == "collateral amount":
 
78
  show_label=True,
79
  interactive=True,
80
  show_actions_button=True,
81
+ tooltip=["month_year_week", "percentile", "collateral_amount"],
82
+ height=HEIGHT,
83
+ width=WIDTH
84
  )
85
 
86
  if trade_detail == "earnings":
 
105
  show_label=True,
106
  interactive=True,
107
  show_actions_button=True,
108
+ tooltip=["month_year_week", "percentile", "earnings"],
109
+ height=HEIGHT,
110
+ width=WIDTH
111
  )
112
 
113
  if trade_detail == "net earnings":
 
132
  show_label=True,
133
  interactive=True,
134
  show_actions_button=True,
135
+ tooltip=["month_year_week", "percentile", "net_earnings"],
136
+ height=HEIGHT,
137
+ width=WIDTH
138
  )
139
 
140
  if trade_detail == "ROI":
 
159
  show_label=True,
160
  interactive=True,
161
  show_actions_button=True,
162
+ tooltip=["month_year_week", "percentile", "ROI"],
163
+ height=HEIGHT,
164
+ width=WIDTH
165
  )
166
 
167
  def plot_trades_by_week(trades_df):
 
172
  show_label=True,
173
  interactive=True,
174
  show_actions_button=True,
175
+ tooltip=["month_year_week", "trades"],
176
+ height=HEIGHT,
177
+ width=WIDTH
178
  )
179
 
180
  def plot_winning_trades_by_week(trades_df):
 
185
  show_label=True,
186
  interactive=True,
187
  show_actions_button=True,
188
+ tooltip=["month_year_week", "winning_trade"],
189
+ height=HEIGHT,
190
+ width=WIDTH
191
  )