-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResultDiffer.py
113 lines (91 loc) · 2.95 KB
/
ResultDiffer.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import re as rgex
from NumberParser import parseNumber
from StringReader import ReadResult
def basicReconciler(a, p):
if a == p:
return a
elif a == "" and p != "":
return p
elif p == "" and a != "":
return a
return None
def preferAlignReconciler(a, p):
return a
def preferParseReconciler(a, p):
return p
def preferLongerReconciler(a, p):
if len(a) > len(p):
return a
elif len(p) > len(a):
return p
return None
def importRegexMatchReconciler(a, p):
pattern = rgex.compile('(\d{1,3}([,.])?(\d{3})([,.])?\d{1,2})')
aMatches = pattern.match(a)
pMatches = pattern.match(p)
if aMatches and not pMatches:
return a
if pMatches and not aMatches:
return p
if aMatches and pMatches:
if len(a) > 10 and len(p) < 10:
return p
return None
def preferLowerNumberReconciler(a, p):
a = parseNumber(a)
p = parseNumber(p)
if p is not None and a is not None:
if p > a:
return str(a)
elif a < p:
return str(p)
elif a == p:
return str(a)
return None
def listReconciler(a, p, list):
for rec in list:
result = rec(a, p)
if result is not None:
return result
return ""
def importeReconciler(a, p):
return listReconciler(a, p, [basicReconciler, preferAlignReconciler])
def dateReconciler(a, p):
return listReconciler(a, p, [basicReconciler, preferAlignReconciler])
def cardReconciler(a, p):
return listReconciler(a, p, [basicReconciler, preferAlignReconciler])
def loteReconciler(a, p):
return listReconciler(a, p, [basicReconciler, preferLongerReconciler, preferAlignReconciler])
def cuotasReconciler(a, p):
return listReconciler(a, p, [basicReconciler, preferLowerNumberReconciler, preferParseReconciler])
class ResultDiffer:
def __init__(self, align, parse):
self.align = align
self.parse = parse
def reconcile(self, debug = False):
# date, card, importe, lote, cuotas
dateA = self.align.date
dateP = self.parse.date
date = dateReconciler(dateA, dateP)
cardA = self.align.card
cardP = self.parse.card
card = cardReconciler(cardA, cardP)
importA = self.align.importe
importP = self.parse.importe
importe = importeReconciler(importA, importP)
loteA = self.align.lote
loteP = self.parse.lote
lote = loteReconciler(loteA, loteP)
cuotasA = self.align.cuotas
cuotasP = self.parse.cuotas
cuotas = cuotasReconciler(cuotasA, cuotasP)
if debug:
print("Align:")
print(self.align.csv())
print("Parse:")
print(self.parse.csv())
print("Result:")
print(self.align.headers())
print(ReadResult(date, card, lote, cuotas, importe).csv())
print("\n")
return ReadResult(date, card, lote, cuotas, importe)