Feat: multiaccount is working
This commit is contained in:
parent
53476b7beb
commit
56787e631a
@ -14,7 +14,7 @@ class Account(object):
|
||||
self._account = account
|
||||
|
||||
def tribut(self, seuil = 0):
|
||||
"""Tels who owns what to who (recursive algorithm
|
||||
"""Tells who owns what to who (recursive algorithm
|
||||
|
||||
:param seuil: seuil à partir duquel on ne doit plus rien.
|
||||
:return: liste des valeurs associées aux débits des comptes après le remboursement
|
||||
|
33
pralo.py
33
pralo.py
@ -15,6 +15,7 @@
|
||||
import csv
|
||||
import os
|
||||
import optparse
|
||||
from pathlib import Path
|
||||
|
||||
from account import Account
|
||||
|
||||
@ -101,6 +102,18 @@ def affiche_final(donRec, output = print):
|
||||
for g in donRec:
|
||||
output("{don} donne {montant} à {rec}".format(don = g[0], rec = g[1], montant = round(g[2],2)))
|
||||
|
||||
def join_comptes(compte1, compte2):
|
||||
"""
|
||||
>>> c1 = [['pop', 3], ['bab', -2]]
|
||||
>>> c2 = [['pop', 1], ['nin', -3]]
|
||||
>>> join_comptes(c1, c2)
|
||||
[('nin', -3), ('pop', 4), ('bab', -2)]
|
||||
"""
|
||||
c_dict1 = {k: v for k, v in compte1}
|
||||
c_dict2 = {k: v for k, v in compte2}
|
||||
|
||||
joined = {k: c_dict1.get(k, 0) + c_dict2.get(k, 0) for k in set(c_dict1) | set(c_dict2)}
|
||||
return [(k, v) for k,v in joined.items()]
|
||||
|
||||
# ------------------------------
|
||||
# Bloc principal
|
||||
@ -111,6 +124,7 @@ if __name__ == '__main__':
|
||||
parser = optparse.OptionParser()
|
||||
# options proposée
|
||||
parser.add_option("-f","--file",action="store", type = "string", dest="file_name", help="Analyse les comptes à partir du fichier donné en argument")
|
||||
parser.add_option("-p","--path",action="store", type = "string", dest="pathname", help="Analyse les comptes à partir de tous les fichiers csv du repertoir (multicompte)")
|
||||
parser.add_option("-e","--seuil",action="store", type = "int", dest="seuil",default=0, help="Seuil à partir duquel on concidère qu'il n'est plus nécessaire de payer.")
|
||||
# Digestion
|
||||
(options, args) = parser.parse_args()
|
||||
@ -124,6 +138,25 @@ if __name__ == '__main__':
|
||||
final = account.tribut(options.seuil)
|
||||
affiche_final(final)
|
||||
|
||||
if options.pathname:
|
||||
path = Path(options.pathname)
|
||||
assert path.exists()
|
||||
god = []
|
||||
for f in path.glob('*.csv'):
|
||||
print(f"Compte: {f.name}")
|
||||
compte = extrait_from_file(f)
|
||||
compte_normalise = forfait(compte)
|
||||
print(compte_normalise)
|
||||
god = join_comptes(god, compte_normalise)
|
||||
|
||||
|
||||
print("")
|
||||
print(god)
|
||||
account = Account(god)
|
||||
final = account.tribut(options.seuil)
|
||||
affiche_final(final)
|
||||
|
||||
|
||||
# ------------------------------
|
||||
# Fin du programme
|
||||
# ------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user