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,