arshy commited on
Commit
dd5a703
·
1 Parent(s): d5eb594

refresh data button

Browse files
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import subprocess
2
  import logging
 
3
  import gradio as gr
4
  import pandas as pd
5
  from apscheduler.schedulers.background import BackgroundScheduler
@@ -30,15 +31,6 @@ from tabs.about import about_olas_predict
30
 
31
 
32
  def refresh_data():
33
- # Run the pull_data.py script and wait for it to finish
34
- try:
35
- result = subprocess.run(["python", "./scripts/pull_data.py"], check=True)
36
- logging.info("Script executed successfully: %s", result)
37
- except subprocess.CalledProcessError as e:
38
- logging.error("Failed to run script: %s", e)
39
- return # Stop execution if the script fails
40
-
41
- # Reload dataframes
42
  try:
43
  global tools_df, trades_df, error_df, error_overall_df, winning_rate_df, winning_rate_overall_df, trades_count_df, trades_winning_rate_df
44
  logging.info("Refreshing data...")
@@ -55,12 +47,27 @@ def refresh_data():
55
  except Exception as e:
56
  logging.error("Failed to refresh data: %s", e)
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  tools_df = pd.read_csv("./data/tools.csv", low_memory=False)
59
  trades_df = pd.read_csv("./data/all_trades_profitability.csv")
60
  trades_df = prepare_trades(trades_df)
61
 
 
62
  demo = gr.Blocks()
63
 
 
64
  INC_TOOLS = [
65
  'prediction-online',
66
  'prediction-offline',
@@ -76,7 +83,6 @@ INC_TOOLS = [
76
  ]
77
 
78
 
79
- # TOOLS DATA
80
  error_df = get_error_data(
81
  tools_df=tools_df,
82
  inc_tools=INC_TOOLS
@@ -153,6 +159,21 @@ with demo:
153
  with gr.Row():
154
  trade_details_plot
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  with gr.TabItem("🚀 Tool Winning Dashboard"):
157
  with gr.Row():
158
  gr.Markdown("# Plot showing overall winning rate")
@@ -302,10 +323,8 @@ with demo:
302
 
303
  # Create the scheduler
304
  scheduler = BackgroundScheduler(timezone=utc)
305
- scheduler.add_job(refresh_data, CronTrigger(hour=0, minute=0)) # Runs daily at 12 AM UTC
306
  scheduler.start()
307
- # scheduler = BackgroundScheduler(timezone=utc)
308
- # scheduler.add_job(refresh_data, CronTrigger(hour='*')) # Runs every hour
309
- # scheduler.start()
310
 
311
  demo.queue(default_concurrency_limit=40).launch()
 
1
  import subprocess
2
  import logging
3
+ from datetime import datetime
4
  import gradio as gr
5
  import pandas as pd
6
  from apscheduler.schedulers.background import BackgroundScheduler
 
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...")
 
47
  except Exception as e:
48
  logging.error("Failed to refresh data: %s", e)
49
 
50
+
51
+ def pull_refresh_data():
52
+ # Run the pull_data.py script and wait for it to finish
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
59
+
60
+ refresh_data()
61
+
62
+
63
  tools_df = pd.read_csv("./data/tools.csv", low_memory=False)
64
  trades_df = pd.read_csv("./data/all_trades_profitability.csv")
65
  trades_df = prepare_trades(trades_df)
66
 
67
+
68
  demo = gr.Blocks()
69
 
70
+
71
  INC_TOOLS = [
72
  'prediction-online',
73
  'prediction-offline',
 
83
  ]
84
 
85
 
 
86
  error_df = get_error_data(
87
  tools_df=tools_df,
88
  inc_tools=INC_TOOLS
 
159
  with gr.Row():
160
  trade_details_plot
161
 
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 Datepoint: {trades_df['creation_timestamp'].max()}"
168
+ )
169
+
170
+ def refresh_callback():
171
+ refresh_data()
172
+ latest_data_label.value = f"Last Datepoint: {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():
179
  gr.Markdown("# Plot showing overall winning rate")
 
323
 
324
  # Create the scheduler
325
  scheduler = BackgroundScheduler(timezone=utc)
326
+ scheduler.add_job(pull_refresh_data, CronTrigger(hour=0, minute=0)) # Runs daily at 12 AM UTC
327
  scheduler.start()
328
+
 
 
329
 
330
  demo.queue(default_concurrency_limit=40).launch()
data/all_trades_profitability.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a44c5981d5f7d3f9628867f8e19da232d27a11209faf350f1296fdc9d83dee10
3
- size 30485816
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b72fb0e0fef1fd1dca99a5eb13126b892c7e57007c5f82985e84a4017ed603d9
3
+ size 30934774
data/delivers.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:469e09441d868dcd1099c68fef477efa3db4cf29e9d0d1108304271b42446701
3
- size 1614690489
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ab02c18ce54ffd37dfb2602f2da3db92c2a3a302c797618eb045b51084a4098
3
+ size 1807054756
data/fpmmTrades.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ed1d99c15ca5224ec4f21b51e991b16182767b661e0daad0428486753e9d1d39
3
- size 65739046
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:19fd7a791f784004f7f04fd10cec62b7868452925aeaa70157cfa6da0c1afeb7
3
+ size 68441241
data/fpmms.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8970d361261cfe4511029d4ff298811d1925564ff9d20bde0d7916ddcb3994b4
3
- size 412839
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:054fb82ef35ad64b3d1835d8708a355a36f75b742eccec74301fc828959aad23
3
+ size 423147
data/requests.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fc4eeaef48b0221fafb6bd8fd2f87748a53a0567f2ba0a4b950018b6be888fef
3
- size 138062209
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1248612c06090d0d576ea7f438b60990c9043256ce53f6bf3b871b42ed0eab90
3
+ size 144528918
data/summary_profitability.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:18cb23fddd471ec17c3052f9b49faeb34aeb2180429e39c60ee2026007112d50
3
- size 49852
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2956b3f0d3a21b8c11a770cdb78e0655acab2164f2f680b4fa2addb449fcec62
3
+ size 54358
data/t_map.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5b771c7cdf05f51715fc109ec707cf95d239d49db50316f1f0ea5c53516574c9
3
- size 6307493
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e18c0957b8513a2f91a60ba7f83553752a261bdf150a24cb065cc30d52e0b92f
3
+ size 6585190
data/tools.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:189a8b51d1b6535a565ad0e231a69ea07b6e2e12f955ac0298f3449bb809477f
3
- size 1714417440
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a56b54aba97829458a543662334b4b66d64f69522f86a1427d31a3a6888f0aa
3
+ size 1911388629