8 ''' Csv parsing and formatting
10 def __init__(self
, a
, b
, aM
=[], bM
=[]):
11 self
.setA
= self
._prep
(a
, *aM
)
12 self
.setB
= self
._prep
(b
, *bM
)
13 if self
.setA
== None or self
.setB
== None:
14 print "Operation failed"
17 def _prep(self
, csv_file
, col
=0, start
=0, end
=sys
.maxint
):
18 ''' Prepare values in selected column from CSV file (f)
20 with
open(csv_file
) as f
:
23 fn
+= [0]*(col
-len(fn
)) #: Pad/ ignore columns (< col)
24 fn
.append('name') #: Mark selected column
25 raw
= list(csv
.DictReader(f
, fieldnames
=fn
))
26 return set(map(lambda e
: e
['name'], raw
[start
:end
]))
28 ''' Make properties use validation & write-once only
31 def setA(self
): return self
._setA
34 def setB(self
): return self
._setB
38 if self
._setA
== None:
43 if self
._setB
== None:
47 def setA(self
): return set(self
._setA
)
50 def setB(self
): return set(self
._setB
)
52 ''' Comparse datasets (/ wrappers for set built-in)
56 def all(self
): return self
.setB
.union(self
.setB
)
59 def clean(self
): return self
.setB
.intersection(self
.setA
)
62 def added(self
): return self
.setB
.difference(self
.setA
)
65 def erased(self
): return self
.setA
.difference(self
.setB
)
69 c
, e
= len(self
.clean
), len(self
.erased
)
71 return 100 * float(e
) / float(c
)