From 415f74fe3e353a9b6c324772159b8ffccbc502d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Sat, 17 May 2025 18:51:11 -0300 Subject: [PATCH] query patch --- utils/statistics_server_v3.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/utils/statistics_server_v3.py b/utils/statistics_server_v3.py index 065a5df..b83bf5a 100644 --- a/utils/statistics_server_v3.py +++ b/utils/statistics_server_v3.py @@ -84,13 +84,13 @@ def profit_report(): ORDER BY year_month_utc3;""") last_n_months_rows = cursor.fetchall() #Yearly totals - cursor.execute("""SELECT strftime('%Y', timestamp, 'unixepoch', '-3 hours') AS year_utc3, - SUM(amount) AS total_amount - FROM profits_table - WHERE strftime('%s', 'now') - timestamp <= 24 * 365 * 60 * 60 -- 365 days in seconds - GROUP BY year_utc3 - ORDER BY year_utc3;""") - yearly_totals = cursor.fetchall() + # cursor.execute("""SELECT strftime('%Y', timestamp, 'unixepoch', '-3 hours') AS year_utc3, + # SUM(amount) AS total_amount + # FROM profits_table + # WHERE strftime('%s', 'now') - timestamp <= 24 * 365 * 60 * 60 -- 365 days in seconds + # GROUP BY year_utc3 + # ORDER BY year_utc3;""") + # yearly_totals = cursor.fetchall() #Per exchange cursor.execute("""SELECT exchange_name, @@ -213,10 +213,10 @@ def daily_and_monthly_totals(): start_of_day_unix = int(time.mktime(start_of_day.timetuple())) start_of_month_unix = int(time.mktime(start_of_month.timetuple())) - query = f"""SELECT * FROM profits_table - WHERE timestamp >= {start_of_month_unix} + query = """SELECT * FROM profits_table + WHERE timestamp >= ? ORDER BY timestamp DESC;""" - cursor.execute(query) + cursor.execute(query, (start_of_month_unix,)) query_result = cursor.fetchall() connection.close() @@ -283,7 +283,7 @@ def query_monthly_totals(pair=None): for item in query_result: result[item[0]] = item[1] else: - query = f"""SELECT pair, strftime('%Y-%m', datetime(timestamp, 'unixepoch', '-3 hours')) AS month, + query = """SELECT pair, strftime('%Y-%m', datetime(timestamp, 'unixepoch', '-3 hours')) AS month, SUM(amount) AS total_profit FROM profits_table GROUP BY pair, month;""" @@ -302,7 +302,7 @@ def last_n_deals(n): ''' connection = sqlite3.connect(profits_database) cursor = connection.cursor() - cursor.execute(f"SELECT * FROM profits_table ORDER BY timestamp DESC LIMIT ?",(n,)) + cursor.execute("SELECT * FROM profits_table ORDER BY timestamp DESC LIMIT ?",(n,)) result = cursor.fetchall() connection.close()