arshy commited on
Commit
5cd4921
·
1 Parent(s): b7308a9
Files changed (1) hide show
  1. app.py +9 -33
app.py CHANGED
@@ -42,50 +42,26 @@ logger = get_logger()
42
 
43
  def get_last_one_month_data():
44
  con = duckdb.connect(':memory:')
45
- # one_month_ago = (datetime.now() - timedelta(days=30)).strftime('%Y-%m-%d')
46
 
47
  # Query to fetch data from all_trades_profitability.parquet
48
  query2 = f"""
49
  SELECT *
50
  FROM read_parquet('./data/all_trades_profitability.parquet')
51
  """
52
-
53
- logger.info("Query 2: " + query2)
54
  df2 = con.execute(query2).fetchdf()
55
- logger.info("here2")
56
 
57
- # Reading tools.parquet in chunks
58
- parquet_file_path = './data/tools.parquet'
59
- chunk_size = 100000 # Adjust chunk size based on your memory capacity
60
- offset = 0
61
- all_filtered_data = []
62
-
63
- while True:
64
- # Read a chunk of data
65
- query1 = f"""
66
- SELECT *
67
- FROM read_parquet('{parquet_file_path}', OFFSET {offset}, ROWS {chunk_size})
68
- """
69
-
70
- logger.info("Query 1: " + query1)
71
- chunk_df = con.execute(query1).fetchdf()
72
-
73
- # Break if the chunk is empty (end of file)
74
- if chunk_df.empty:
75
- break
76
-
77
- # Collect the filtered chunk
78
- all_filtered_data.append(chunk_df)
79
 
80
- # Update offset
81
- offset += chunk_size
82
-
83
- # Concatenate all filtered chunks into a single DataFrame
84
- df1 = pd.concat(all_filtered_data, ignore_index=True)
85
- logger.info("here3")
86
-
87
  con.close()
 
88
  return df1, df2
 
89
 
90
  def prepare_data():
91
  tools_df, trades_df = get_last_one_month_data()
 
42
 
43
  def get_last_one_month_data():
44
  con = duckdb.connect(':memory:')
 
45
 
46
  # Query to fetch data from all_trades_profitability.parquet
47
  query2 = f"""
48
  SELECT *
49
  FROM read_parquet('./data/all_trades_profitability.parquet')
50
  """
 
 
51
  df2 = con.execute(query2).fetchdf()
 
52
 
53
+ one_months_ago = (datetime.now() - timedelta(days=60)).strftime('%Y-%m-%d')
54
+ query1 = f"""
55
+ SELECT *
56
+ FROM read_parquet('./data/tools.parquet')
57
+ WHERE request_time >= '{one_months_ago}'
58
+ """
59
+ df1 = con.execute(query1).fetchdf()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
 
 
 
 
 
 
 
61
  con.close()
62
+
63
  return df1, df2
64
+
65
 
66
  def prepare_data():
67
  tools_df, trades_df = get_last_one_month_data()