arshy commited on
Commit
1b657c1
·
1 Parent(s): f661028

better refresh data

Browse files
app.py CHANGED
@@ -30,10 +30,82 @@ from tabs.error import (
30
  from tabs.about import about_olas_predict
31
 
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  def refresh_data():
34
  try:
35
  global tools_df, trades_df, error_df, error_overall_df, winning_rate_df, winning_rate_overall_df, trades_count_df, trades_winning_rate_df
 
36
  logging.info("Refreshing data...")
 
37
  tools_df = pd.read_csv("./data/tools.csv", low_memory=False)
38
  trades_df = pd.read_csv("./data/all_trades_profitability.csv")
39
  trades_df = prepare_trades(trades_df)
@@ -43,6 +115,7 @@ def refresh_data():
43
  winning_rate_overall_df = get_overall_winning_rate(wins_df=winning_rate_df)
44
  trades_count_df = get_overall_trades(trades_df=trades_df)
45
  trades_winning_rate_df = get_overall_winning_trades(trades_df=trades_df)
 
46
  logging.info("Data refreshed.")
47
  except Exception as e:
48
  logging.error("Failed to refresh data: %s", e)
@@ -53,6 +126,7 @@ def pull_refresh_data():
53
  try:
54
  result = subprocess.run(["python", "./scripts/pull_data.py"], check=True)
55
  logging.info("Script executed successfully: %s", result)
 
56
  except subprocess.CalledProcessError as e:
57
  logging.error("Failed to run script: %s", e)
58
  return # Stop execution if the script fails
@@ -113,13 +187,13 @@ with demo:
113
  with gr.Row():
114
  gr.Markdown("# Plot of number of trades by week")
115
  with gr.Row():
116
- plot_trades_by_week = plot_trades_by_week(
117
  trades_df=trades_count_df
118
  )
119
  with gr.Row():
120
  gr.Markdown("# Plot of winning trades by week")
121
  with gr.Row():
122
- plot_winning_trades_by_week = plot_winning_trades_by_week(
123
  trades_df=trades_winning_rate_df
124
  )
125
  with gr.Row():
@@ -162,17 +236,15 @@ with demo:
162
  with gr.Row():
163
  with gr.Column():
164
  refresh_button = gr.Button("Refresh Data")
165
- with gr.Column():
166
- latest_data_label = gr.Label(
167
- value=f"Last data point: {trades_df['creation_timestamp'].max()}"
168
- )
169
 
170
- def refresh_callback():
171
- refresh_data()
172
- latest_data_label.value = f"Last data point: {trades_df['creation_timestamp'].max()}"
173
- return latest_data_label.value
174
-
175
- refresh_button.click(refresh_callback, outputs=latest_data_label)
 
 
176
 
177
  with gr.TabItem("🚀 Tool Winning Dashboard"):
178
  with gr.Row():
@@ -219,7 +291,7 @@ with demo:
219
  )
220
 
221
  with gr.Row():
222
- plot_tool_win_rate = plot_tool_winnings_by_tool(
223
  wins_df=winning_rate_df,
224
  tool=INC_TOOLS[0]
225
  )
@@ -233,19 +305,30 @@ with demo:
233
  sel_tool.change(
234
  update_tool_winnings_by_tool_plot,
235
  inputs=sel_tool,
236
- outputs=plot_tool_win_rate
237
  )
238
 
239
  with gr.Row():
240
  sel_tool
241
  with gr.Row():
242
- plot_tool_win_rate
 
 
 
 
 
 
 
 
 
 
 
243
 
244
  with gr.TabItem("🏥 Tool Error Dashboard"):
245
  with gr.Row():
246
  gr.Markdown("# Plot showing overall error")
247
  with gr.Row():
248
- plot_error_data(
249
  error_all_df=error_overall_df
250
  )
251
  with gr.Row():
@@ -258,7 +341,7 @@ with demo:
258
  )
259
 
260
  with gr.Row():
261
- plot_tool_error = plot_tool_error_data(
262
  error_df=error_df,
263
  tool=INC_TOOLS[0]
264
  )
@@ -273,12 +356,12 @@ with demo:
273
  sel_tool.change(
274
  update_tool_error_plot,
275
  inputs=sel_tool,
276
- outputs=plot_tool_error
277
  )
278
  with gr.Row():
279
  sel_tool
280
  with gr.Row():
281
- plot_tool_error
282
 
283
  with gr.Row():
284
  gr.Markdown("# Plot showing error by week")
@@ -294,7 +377,7 @@ with demo:
294
  )
295
 
296
  with gr.Row():
297
- plot_week_error = plot_week_error_data(
298
  error_df=error_df,
299
  week=choices[-1]
300
  )
@@ -305,17 +388,29 @@ with demo:
305
  week=selected_week
306
  )
307
 
308
- sel_tool.change(update_tool_error_plot, inputs=sel_tool, outputs=plot_tool_error)
309
- sel_week.change(update_week_error_plot, inputs=sel_week, outputs=plot_week_error)
310
 
311
  with gr.Row():
312
  sel_tool
313
  with gr.Row():
314
- plot_tool_error
315
  with gr.Row():
316
  sel_week
317
  with gr.Row():
318
- plot_week_error
 
 
 
 
 
 
 
 
 
 
 
 
319
 
320
  with gr.TabItem("ℹ️ About"):
321
  with gr.Accordion("About Olas Predict"):
 
30
  from tabs.about import about_olas_predict
31
 
32
 
33
+ def update_trades_plots():
34
+ global tools_df, trades_df, error_df, error_overall_df, winning_rate_df, winning_rate_overall_df, trades_count_df, trades_winning_rate_df
35
+
36
+ refresh_data()
37
+
38
+ updated_trades_by_week_plot = plot_trades_by_week(
39
+ trades_df=trades_count_df
40
+ )
41
+
42
+ updated_winning_trades_by_week_plot = plot_winning_trades_by_week(
43
+ trades_df=trades_winning_rate_df
44
+ )
45
+
46
+ updated_trade_details_plot = plot_trade_details(
47
+ trade_detail="mech calls",
48
+ trades_df=trades_df
49
+ )
50
+
51
+ return (
52
+ updated_trades_by_week_plot,
53
+ updated_winning_trades_by_week_plot,
54
+ updated_trade_details_plot
55
+ )
56
+
57
+
58
+ def update_tool_winnings_plots():
59
+ global tools_df, trades_df, error_df, error_overall_df, winning_rate_df, winning_rate_overall_df, trades_count_df, trades_winning_rate_df
60
+
61
+ refresh_data()
62
+
63
+ updated_winning_plot = plot_tool_winnings_overall(
64
+ wins_df=winning_rate_overall_df,
65
+ winning_selector="win_perc"
66
+ )
67
+
68
+ updated_tool_winnings_by_tool_plot = plot_tool_winnings_by_tool(
69
+ wins_df=winning_rate_df,
70
+ tool=INC_TOOLS[0]
71
+ )
72
+
73
+ return (
74
+ updated_winning_plot,
75
+ updated_tool_winnings_by_tool_plot
76
+ )
77
+
78
+ def update_error_plots():
79
+ global tools_df, trades_df, error_df, error_overall_df, winning_rate_df, winning_rate_overall_df, trades_count_df, trades_winning_rate_df
80
+
81
+ refresh_data()
82
+
83
+ updated_error_overall_plot = plot_error_data(
84
+ error_all_df=error_overall_df
85
+ )
86
+
87
+ updated_tool_error_plot = plot_tool_error_data(
88
+ error_df=error_df,
89
+ tool=INC_TOOLS[0]
90
+ )
91
+
92
+ updated_week_error_plot = plot_week_error_data(
93
+ error_df=error_df,
94
+ week=choices[-1]
95
+ )
96
+
97
+ return (
98
+ updated_error_overall_plot,
99
+ updated_tool_error_plot,
100
+ updated_week_error_plot
101
+ )
102
+
103
  def refresh_data():
104
  try:
105
  global tools_df, trades_df, error_df, error_overall_df, winning_rate_df, winning_rate_overall_df, trades_count_df, trades_winning_rate_df
106
+
107
  logging.info("Refreshing data...")
108
+
109
  tools_df = pd.read_csv("./data/tools.csv", low_memory=False)
110
  trades_df = pd.read_csv("./data/all_trades_profitability.csv")
111
  trades_df = prepare_trades(trades_df)
 
115
  winning_rate_overall_df = get_overall_winning_rate(wins_df=winning_rate_df)
116
  trades_count_df = get_overall_trades(trades_df=trades_df)
117
  trades_winning_rate_df = get_overall_winning_trades(trades_df=trades_df)
118
+
119
  logging.info("Data refreshed.")
120
  except Exception as e:
121
  logging.error("Failed to refresh data: %s", e)
 
126
  try:
127
  result = subprocess.run(["python", "./scripts/pull_data.py"], check=True)
128
  logging.info("Script executed successfully: %s", result)
129
+ refresh_data()
130
  except subprocess.CalledProcessError as e:
131
  logging.error("Failed to run script: %s", e)
132
  return # Stop execution if the script fails
 
187
  with gr.Row():
188
  gr.Markdown("# Plot of number of trades by week")
189
  with gr.Row():
190
+ trades_by_week_plot = plot_trades_by_week(
191
  trades_df=trades_count_df
192
  )
193
  with gr.Row():
194
  gr.Markdown("# Plot of winning trades by week")
195
  with gr.Row():
196
+ winning_trades_by_week_plot = plot_winning_trades_by_week(
197
  trades_df=trades_winning_rate_df
198
  )
199
  with gr.Row():
 
236
  with gr.Row():
237
  with gr.Column():
238
  refresh_button = gr.Button("Refresh Data")
 
 
 
 
239
 
240
+ refresh_button.click(
241
+ update_trades_plots,
242
+ outputs=[
243
+ trades_by_week_plot,
244
+ winning_trades_by_week_plot,
245
+ trade_details_plot,
246
+ ]
247
+ )
248
 
249
  with gr.TabItem("🚀 Tool Winning Dashboard"):
250
  with gr.Row():
 
291
  )
292
 
293
  with gr.Row():
294
+ tool_winnings_by_tool_plot = plot_tool_winnings_by_tool(
295
  wins_df=winning_rate_df,
296
  tool=INC_TOOLS[0]
297
  )
 
305
  sel_tool.change(
306
  update_tool_winnings_by_tool_plot,
307
  inputs=sel_tool,
308
+ outputs=tool_winnings_by_tool_plot
309
  )
310
 
311
  with gr.Row():
312
  sel_tool
313
  with gr.Row():
314
+ tool_winnings_by_tool_plot
315
+ with gr.Row():
316
+ refresh_button = gr.Button("Refresh Data")
317
+
318
+ refresh_button.click(
319
+ update_tool_winnings_plots,
320
+ outputs=[
321
+ winning_plot,
322
+ tool_winnings_by_tool_plot
323
+ ]
324
+ )
325
+
326
 
327
  with gr.TabItem("🏥 Tool Error Dashboard"):
328
  with gr.Row():
329
  gr.Markdown("# Plot showing overall error")
330
  with gr.Row():
331
+ error_overall_plot = plot_error_data(
332
  error_all_df=error_overall_df
333
  )
334
  with gr.Row():
 
341
  )
342
 
343
  with gr.Row():
344
+ tool_error_plot = plot_tool_error_data(
345
  error_df=error_df,
346
  tool=INC_TOOLS[0]
347
  )
 
356
  sel_tool.change(
357
  update_tool_error_plot,
358
  inputs=sel_tool,
359
+ outputs=tool_error_plot
360
  )
361
  with gr.Row():
362
  sel_tool
363
  with gr.Row():
364
+ tool_error_plot
365
 
366
  with gr.Row():
367
  gr.Markdown("# Plot showing error by week")
 
377
  )
378
 
379
  with gr.Row():
380
+ week_error_plot = plot_week_error_data(
381
  error_df=error_df,
382
  week=choices[-1]
383
  )
 
388
  week=selected_week
389
  )
390
 
391
+ sel_tool.change(update_tool_error_plot, inputs=sel_tool, outputs=tool_error_plot)
392
+ sel_week.change(update_week_error_plot, inputs=sel_week, outputs=week_error_plot)
393
 
394
  with gr.Row():
395
  sel_tool
396
  with gr.Row():
397
+ tool_error_plot
398
  with gr.Row():
399
  sel_week
400
  with gr.Row():
401
+ week_error_plot
402
+
403
+ with gr.Row():
404
+ refresh_button = gr.Button("Refresh Data")
405
+
406
+ refresh_button.click(
407
+ update_error_plots,
408
+ outputs=[
409
+ error_overall_plot,
410
+ tool_error_plot,
411
+ week_error_plot
412
+ ]
413
+ )
414
 
415
  with gr.TabItem("ℹ️ About"):
416
  with gr.Accordion("About Olas Predict"):
data/all_trades_profitability.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b72fb0e0fef1fd1dca99a5eb13126b892c7e57007c5f82985e84a4017ed603d9
3
- size 30934774
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ed325e54d1901d69a27fbb18a19e3d7479bd2e89eac8fad22e5cbe01abfd335
3
+ size 32001583
data/delivers.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5ab02c18ce54ffd37dfb2602f2da3db92c2a3a302c797618eb045b51084a4098
3
- size 1807054756
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d7e07db2af936529c721932218be4832d7dbe113dbb50e534bb8bf060d609cc
3
+ size 2014149364
data/fpmmTrades.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:19fd7a791f784004f7f04fd10cec62b7868452925aeaa70157cfa6da0c1afeb7
3
- size 68441241
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e4abd630e8476e2d6cbfe684f14a843d7ae22e750133e4c4ee96e12ffabdb03
3
+ size 69980018
data/fpmms.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:054fb82ef35ad64b3d1835d8708a355a36f75b742eccec74301fc828959aad23
3
- size 423147
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:04cb5e845138d2e7d69e699521fc3fa9adac5bc67438ad5afc0aab0dc9488568
3
+ size 429913
data/requests.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1248612c06090d0d576ea7f438b60990c9043256ce53f6bf3b871b42ed0eab90
3
- size 144528918
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13b123c5b509f37032582888b51a9536c3c855a3954bbf6695e1ff23c1fc7f42
3
+ size 148756035
data/summary_profitability.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2956b3f0d3a21b8c11a770cdb78e0655acab2164f2f680b4fa2addb449fcec62
3
- size 54358
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d2129ca0d2324e5c10fc2220913d0ef28067a788e69d3f84d2a261eed1f57588
3
+ size 56460
data/t_map.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e18c0957b8513a2f91a60ba7f83553752a261bdf150a24cb065cc30d52e0b92f
3
- size 6585190
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ac7f44ec10ae465f40149c039181a427f82ff6e820a88f17207d33b8a7237fc
3
+ size 6781847
data/tools.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3a56b54aba97829458a543662334b4b66d64f69522f86a1427d31a3a6888f0aa
3
- size 1911388629
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6657130c88b5e3f90d53725b5fb1646af030d45e33175cdb3cf6e5a81d5e740d
3
+ size 2121884792
test.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+
4
+
5
+ demo = gr.Blocks()
6
+
7
+ data1 = pd.DataFrame({
8
+ "tool": ["tool1", "tool2", "tool3"],
9
+ "error": [0.1, 0.2, 0.3]
10
+ })
11
+
12
+ data2 = pd.DataFrame({
13
+ "tool": ["tool1", "tool2", "tool3", "tool4"],
14
+ "error": [0.1, 0.2, 0.3, 0.4]
15
+ })
16
+
17
+ data3 = pd.DataFrame({
18
+ "tool": ["tool1", "tool2", "tool3", "tool4", "tool5"],
19
+ "error": [0.1, 0.2, 0.3, 0.4, 0.5]
20
+ })
21
+
22
+
23
+ def update_plot1():
24
+ data = pd.DataFrame({
25
+ "tool": ["tool1", "tool2", "tool3", "tool4"],
26
+ "error": [0.1, 0.2, 0.3, 0.4]
27
+ })
28
+ return gr.BarPlot(
29
+ data,
30
+ x="tool",
31
+ y="error"
32
+ )
33
+
34
+ def update_plot2():
35
+ data = pd.DataFrame({
36
+ "tool": ["tool1", "tool2", "tool3", "tool4", "tool5"],
37
+ "error": [0.1, 0.2, 0.3, 0.4, 0.5]
38
+ })
39
+ return gr.BarPlot(
40
+ data,
41
+ x="tool",
42
+ y="error"
43
+ )
44
+
45
+ def update_plot3():
46
+ data = pd.DataFrame({
47
+ "tool": ["tool1", "tool2", "tool3", "tool4", "tool5", "tool6"],
48
+ "error": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
49
+ })
50
+ return gr.BarPlot(
51
+ data,
52
+ x="tool",
53
+ y="error"
54
+ )
55
+
56
+ def update_plots():
57
+ return update_plot1(), update_plot2(), update_plot3()
58
+
59
+ with demo:
60
+ with gr.Row():
61
+ plot1 = gr.BarPlot(
62
+ data1,
63
+ x="tool",
64
+ y="error"
65
+ )
66
+
67
+ with gr.Row():
68
+ plot2 = gr.BarPlot(
69
+ data2,
70
+ x="tool",
71
+ y="error"
72
+ )
73
+
74
+ with gr.Row():
75
+ plot3 = gr.BarPlot(
76
+ data3,
77
+ x="tool",
78
+ y="error"
79
+ )
80
+
81
+ with gr.Row():
82
+ update_button = gr.Button("Update")
83
+
84
+ update_button.click(
85
+ update_plots,
86
+ inputs=[],
87
+ outputs=[plot1, plot2, plot3]
88
+ )
89
+
90
+ demo.launch(
91
+ debug=True
92
+ )