]>
gitweb.pimeys.fr Git - scripts-20-100.git/blob - bde/combiennegs.py
2 # -*- encoding: utf-8 -*-
4 """ Pour savoir combien de fois les gens sont passés en négatif """
10 cur
= con
.cursor(cursor_factory
= psycopg2
.extras
.DictCursor
)
11 cur
.execute("SELECT * FROM transactions ORDER BY date ASC;")
12 transactions
= cur
.fetchall()
15 def combienneg(alltrans
):
16 nums
= list(set([t
["emetteur"] for t
in alltrans
] + [t
["destinataire"] for t
in alltrans
]))
17 soldes
= dict([(n
, 0) for n
in nums
])
18 negs
= dict([(n
, []) for n
in nums
])
19 for trans
in [t
for t
in alltrans
if t
["valide"]]:
20 for (num
, signe
) in [(trans
["emetteur"], -1), (trans
["destinataire"], 1)]:
21 newsolde
= soldes
[num
] + trans
["montant"] * trans
["quantite"] * signe
22 if soldes
[num
] >= 0 and newsolde
< 0:
23 negs
[num
].append(t
["date"])
24 soldes
[num
] = newsolde
27 if __name__
== "__main__":
28 con
= psycopg2
.connect(database
="bde")
29 transactions
= get_data(con
)
30 (negs
, soldes
) = combienneg(transactions
)