use duckdb
Browse files- app.py +23 -7
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
from datetime import datetime
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
from tabs.trades import (
|
| 5 |
prepare_trades,
|
| 6 |
get_overall_trades,
|
|
@@ -24,20 +25,35 @@ from tabs.error import (
|
|
| 24 |
)
|
| 25 |
from tabs.about import about_olas_predict
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def prepare_data():
|
| 29 |
-
tools_df =
|
| 30 |
-
trades_df = pd.read_parquet("./data/all_trades_profitability.parquet")
|
| 31 |
|
| 32 |
# get current month
|
| 33 |
current_month = datetime.now().strftime("%Y-%m")
|
| 34 |
|
| 35 |
tools_df['request_time'] = pd.to_datetime(tools_df['request_time'])
|
| 36 |
-
# only keep trades for the current month
|
| 37 |
-
tools_df = tools_df[tools_df['request_time'].dt.strftime('%Y-%m') == current_month]
|
| 38 |
-
|
| 39 |
trades_df['creation_timestamp'] = pd.to_datetime(trades_df['creation_timestamp'])
|
| 40 |
-
trades_df = trades_df[trades_df['creation_timestamp'].dt.strftime('%Y-%m') == current_month]
|
| 41 |
|
| 42 |
trades_df = prepare_trades(trades_df)
|
| 43 |
return tools_df, trades_df
|
|
|
|
| 1 |
+
from datetime import datetime, timedelta
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
+
import duckdb
|
| 5 |
from tabs.trades import (
|
| 6 |
prepare_trades,
|
| 7 |
get_overall_trades,
|
|
|
|
| 25 |
)
|
| 26 |
from tabs.about import about_olas_predict
|
| 27 |
|
| 28 |
+
|
| 29 |
+
def get_last_two_months_data():
|
| 30 |
+
con = duckdb.connect(':memory:')
|
| 31 |
+
two_months_ago = (datetime.now() - timedelta(days=60)).strftime('%Y-%m-%d')
|
| 32 |
+
|
| 33 |
+
query1 = f"""
|
| 34 |
+
SELECT *
|
| 35 |
+
FROM read_parquet('./data/tools.parquet')
|
| 36 |
+
WHERE request_time >= '{two_months_ago}'
|
| 37 |
+
"""
|
| 38 |
+
query2 = f"""
|
| 39 |
+
SELECT *
|
| 40 |
+
FROM read_parquet('./data/all_trades_profitability.parquet')
|
| 41 |
+
WHERE creation_timestamp >= '{two_months_ago}'
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
df1 = con.execute(query1).fetchdf()
|
| 45 |
+
df2 = con.execute(query2).fetchdf()
|
| 46 |
+
con.close()
|
| 47 |
+
return df1, df2
|
| 48 |
|
| 49 |
def prepare_data():
|
| 50 |
+
tools_df, trades_df = get_last_two_months_data()
|
|
|
|
| 51 |
|
| 52 |
# get current month
|
| 53 |
current_month = datetime.now().strftime("%Y-%m")
|
| 54 |
|
| 55 |
tools_df['request_time'] = pd.to_datetime(tools_df['request_time'])
|
|
|
|
|
|
|
|
|
|
| 56 |
trades_df['creation_timestamp'] = pd.to_datetime(trades_df['creation_timestamp'])
|
|
|
|
| 57 |
|
| 58 |
trades_df = prepare_trades(trades_df)
|
| 59 |
return tools_df, trades_df
|
requirements.txt
CHANGED
|
@@ -5,3 +5,4 @@ pyarrow
|
|
| 5 |
requests
|
| 6 |
gradio==4.13.0
|
| 7 |
pytz
|
|
|
|
|
|
| 5 |
requests
|
| 6 |
gradio==4.13.0
|
| 7 |
pytz
|
| 8 |
+
duckdb
|