From 0afa789e6ce1b971e5a299a2762f0d6650f52866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Tue, 31 Dec 2024 21:25:07 -0300 Subject: [PATCH] yearly details --- profits/profit_report.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/profits/profit_report.py b/profits/profit_report.py index 630237e..b0e7b87 100644 --- a/profits/profit_report.py +++ b/profits/profit_report.py @@ -46,6 +46,15 @@ cursor.execute("""SELECT strftime('%Y-%m', timestamp, 'unixepoch', '-3 hours') A ORDER BY year_month_utc3;""") last_n_months_rows = cursor.fetchall() +#Last n months query +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 <= 60 * 30 * 24 * 60 * 60 -- 48 months in seconds + GROUP BY year_utc3 + ORDER BY year_utc3;""") +last_n_years_rows = cursor.fetchall() + #Yearly totals cursor.execute("""SELECT strftime('%Y', timestamp, 'unixepoch', '-3 hours') AS year_utc3, SUM(amount) AS total_amount @@ -66,6 +75,12 @@ print("-"*line_width) for row in last_n_months_rows[1:]: print(f"{row[0]}: {round(row[1],2)}") print("-"*line_width) +print("Last 5 years:") +print("-"*line_width) +for row in last_n_years_rows: + print(f"{row[0]}: {round(row[1],2)}") +print("-"*line_width) + print(f"Last 30 days average: {round(last_30_days[0][1]/30,2)}") print(f"Last 7 days average: {round(last_7_days[0][1]/7,2)}") cursor.execute("""SELECT strftime('%Y-%m-%d', timestamp, 'unixepoch', '-3 hours') AS day_utc3,