WIP about to plot with transaction precision
This commit is contained in:
parent
7d7ced9b81
commit
69d6442966
@ -5,6 +5,7 @@ import matplotlib.pyplot as plt
|
|||||||
import matplotlib.ticker as ticker
|
import matplotlib.ticker as ticker
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from utils import getDatetimeFromFileName, getMonthIndexSinceEpoch, getMonthNameFromMonthIndex, readPdfBankStatement
|
from utils import getDatetimeFromFileName, getMonthIndexSinceEpoch, getMonthNameFromMonthIndex, readPdfBankStatement
|
||||||
|
import operator
|
||||||
|
|
||||||
PATH = f'/home/benjamin/Desktop/bens_folder/bazaar/documents/bnp/bank_statements/'
|
PATH = f'/home/benjamin/Desktop/bens_folder/bazaar/documents/bnp/bank_statements/'
|
||||||
|
|
||||||
@ -16,30 +17,24 @@ MAIN_BANK_ACCOUNT = 'compte_de_cheques'
|
|||||||
|
|
||||||
debits = []
|
debits = []
|
||||||
credits_ = []
|
credits_ = []
|
||||||
# Precise bank account
|
|
||||||
allTransactions = []
|
allTransactions = []
|
||||||
|
monthlyTransactions = {}
|
||||||
'''
|
|
||||||
def appendTransactions(x):
|
|
||||||
global allTransactions
|
|
||||||
allTransactions += [x]
|
|
||||||
'''
|
|
||||||
|
|
||||||
def appendTransactions(transactions, bankAccount):
|
def appendTransactions(transactions, bankAccount):
|
||||||
global allTransactions
|
global allTransactions
|
||||||
#print('Before')
|
|
||||||
#pprint(allTransactions)
|
|
||||||
for transaction in transactions:
|
for transaction in transactions:
|
||||||
transaction['bank account'] = bankAccount
|
transaction['bank account'] = bankAccount
|
||||||
allTransactions += [transaction]
|
allTransactions += [transaction]
|
||||||
#print('After')
|
date = transaction['date'].replace(day = 1)
|
||||||
#pprint(allTransactions)
|
monthlyTransactions[date] = monthlyTransactions.get(date, []) + [transaction]
|
||||||
|
|
||||||
for folder in os.listdir():
|
for folder in os.listdir():
|
||||||
if folder != MAIN_BANK_ACCOUNT:
|
if folder != MAIN_BANK_ACCOUNT:
|
||||||
for file in os.listdir(folder):
|
for file in os.listdir(folder):
|
||||||
filePath = f'{folder}/{file}'
|
filePath = f'{folder}/{file}'
|
||||||
print(filePath)
|
print(filePath)
|
||||||
|
print(readPdfBankStatement(filePath))
|
||||||
|
exit(0)
|
||||||
transactions = readPdfBankStatement(filePath)[3]
|
transactions = readPdfBankStatement(filePath)[3]
|
||||||
appendTransactions(transactions, folder)
|
appendTransactions(transactions, folder)
|
||||||
|
|
||||||
@ -59,13 +54,21 @@ for folder in sorted(os.listdir()):
|
|||||||
#break
|
#break
|
||||||
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
#pprint(transactions)
|
|
||||||
import operator
|
|
||||||
allTransactions.sort(key = operator.itemgetter('date'))
|
allTransactions.sort(key = operator.itemgetter('date'))
|
||||||
print(len(allTransactions))
|
print(len(allTransactions))
|
||||||
pprint(allTransactions)
|
pprint(allTransactions)
|
||||||
|
|
||||||
exit(0)
|
sortedMonths = sorted(monthlyTransactions.keys())
|
||||||
|
#pprint(sortedMonths)
|
||||||
|
# debit or credit?
|
||||||
|
totalMonthlyCredits = []
|
||||||
|
totalMonthlyDebits = []
|
||||||
|
totalMonthlyDifferences = []
|
||||||
|
#totalMonthlyDebits = [[ for transaction in monthlyTransactions[month]] for month in sortedMonths]
|
||||||
|
for month in sortedMonths:
|
||||||
|
#for transaction in monthlyTransactions[month]:
|
||||||
|
currentMonthlyTransactions = monthlyTransactions[month]
|
||||||
|
monthlyCredits = []
|
||||||
|
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
plt.title('Monthly debits and credits')
|
plt.title('Monthly debits and credits')
|
||||||
@ -73,12 +76,12 @@ plt.xlabel('Date')
|
|||||||
plt.ylabel('€')
|
plt.ylabel('€')
|
||||||
ALPHA = 0.5
|
ALPHA = 0.5
|
||||||
|
|
||||||
xTicks = range(getMonthIndexSinceEpoch(firstDatetime), getMonthIndexSinceEpoch(lastDatetime) + 1)
|
xTicks = range(getMonthIndexSinceEpoch(sortedMonths[0]), getMonthIndexSinceEpoch(sortedMonths[-1]) + 1)
|
||||||
totalMonthlyAmountAndLabel = (
|
totalMonthlyAmountAndLabel = (
|
||||||
#(totalMonthlyDebits, 'Debit'),
|
#(totalMonthlyDebits, 'Debit'),
|
||||||
#(totalMonthlyCredits, 'Credit'),
|
#(totalMonthlyCredits, 'Credit'),
|
||||||
(totalMonthlyDifferences, 'Difference'),
|
(totalMonthlyDifferences, 'Difference'),
|
||||||
(totals, 'Total'),
|
#(totals, 'Total'),
|
||||||
)
|
)
|
||||||
for totalMonthlyAmount, totalMonthlyLabel in totalMonthlyAmountAndLabel:
|
for totalMonthlyAmount, totalMonthlyLabel in totalMonthlyAmountAndLabel:
|
||||||
plt.bar(xTicks, totalMonthlyAmount, alpha = ALPHA, label = totalMonthlyLabel)
|
plt.bar(xTicks, totalMonthlyAmount, alpha = ALPHA, label = totalMonthlyLabel)
|
||||||
|
1
utils.py
1
utils.py
@ -78,6 +78,7 @@ def readPdfBankStatement(filePath):
|
|||||||
break
|
break
|
||||||
firstLineOfPaymentRegexMatch = FIRST_LINE_OF_PAYMENT_REGEX.match(line)
|
firstLineOfPaymentRegexMatch = FIRST_LINE_OF_PAYMENT_REGEX.match(line)
|
||||||
if firstLineOfPaymentRegexMatch is not None:
|
if firstLineOfPaymentRegexMatch is not None:
|
||||||
|
print(line)
|
||||||
if date is not None:
|
if date is not None:
|
||||||
transactions += [{
|
transactions += [{
|
||||||
'date': getDateFollowing(date, initialDate),
|
'date': getDateFollowing(date, initialDate),
|
||||||
|
Loading…
Reference in New Issue
Block a user