From ef3e8ef3372216ef57501e4af08e10caebc6cb56 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Tue, 1 Oct 2024 20:57:36 +0200 Subject: [PATCH] Add logarithmic scale --- bnp_pdf_statement_parser.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/bnp_pdf_statement_parser.py b/bnp_pdf_statement_parser.py index d4f0273..edf2d3a 100755 --- a/bnp_pdf_statement_parser.py +++ b/bnp_pdf_statement_parser.py @@ -7,6 +7,7 @@ import subprocess import re import matplotlib.pyplot as plt import matplotlib.ticker as ticker +from datetime import datetime path = f'/home/benjamin/Desktop/bens_folder/bazaar/documents/bnp/bank_statements/' @@ -38,12 +39,16 @@ PRINT_TRANSACTIONS = False totalMonthlyDebits = [] totalMonthlyCredits = [] +firstDatetime = None +lastDatetime = None for folder in sorted(os.listdir()): for file in sorted(os.listdir(folder)): #folder = '2022' #file = '20220321.pdf' filePath = f'{folder}/{file}' print(filePath) + if firstDatetime is None: + firstDatetime = file content = getTextFromPdf(filePath) lines = content.splitlines() started = False @@ -91,17 +96,42 @@ for folder in sorted(os.listdir()): comment += [line] #break #break +lastDatetime = file fig, ax = plt.subplots() plt.title('Monthly debits and credits') plt.xlabel('Date') plt.ylabel('€') ALPHA = 0.5 -xTicks = range(len(totalMonthlyDebits)) + +def getMonthIndex(aDatetimeStr): + aDatetime = datetime.strptime(aDatetimeStr, '%Y%m%d.pdf') + return aDatetime.year * 12 + aDatetime.month + +''' +print(firstDatetime) +print(lastDatetime) +exit(1) +''' +#print(getMonthIndex(firstDatetime)) +#print(getMonthIndex(lastDatetime)) +xTicks = range(getMonthIndex(firstDatetime), getMonthIndex(lastDatetime) + 1) +#print(len(xTicks)) +#print(len(totalMonthlyDebits)) plt.bar(xTicks, totalMonthlyDebits, alpha = ALPHA, label = 'Debit') plt.bar(xTicks, totalMonthlyCredits, alpha = ALPHA, label = 'Credit') plt.legend() +plt.yscale('log') ax.yaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,}')) +def getMonthName(monthIndex): + return datetime((monthIndex - 1) // 12, 1 + (monthIndex - 1) % 12, 1).strftime('%b %Y') + +ticksLabels = [getMonthName(monthIndex) for monthIndex in xTicks] +plt.xticks(xTicks, ticksLabels, rotation = 90) +#plt.tight_layout() +# How to show the horizontal lines for subticks? +plt.grid(axis = 'y') + plt.show() \ No newline at end of file