-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtarjetas.py
More file actions
34 lines (28 loc) · 1.05 KB
/
tarjetas.py
File metadata and controls
34 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
import json
with open(sys.argv[1]) as f:
data = json.load(f)
agregados_tarjeta = {}
agregados_tipo = {}
for tarjeta, transacciones in data.items():
tipos = {}
try:
for transaccion in transacciones:
tipo = transaccion["tipo"]
importe = float(transaccion["importe"].split("$", 2)[1].strip())
if tipo not in tipos:
tipos[tipo] = {"importe": 0.0, "cantidad": 0}
tipos[tipo]["importe"] += importe
tipos[tipo]["cantidad"] += 1
except TypeError:
pass
for tipo in tipos:
tipos[tipo]["promedio"] = tipos[tipo]["importe"] / tipos[tipo]["cantidad"]
if tipo not in agregados_tipo:
agregados_tipo[tipo] = {"importe": 0.0, "cantidad": 0}
agregados_tipo[tipo]["importe"] += importe
agregados_tipo[tipo]["cantidad"] += 1
agregados_tarjeta[tarjeta] = tipos
for tipo in agregados_tipo:
agregados_tipo[tipo]["promedio"] = agregados_tipo[tipo]["importe"] / agregados_tipo[tipo]["cantidad"]
print agregados_tipo