1 from exc
import IncompatibleUnits
4 return unicode(st
).encode('utf-8')
7 print encode_utf8(' '.join(map(unicode, args
)))
9 class CorrelationChecker
:
10 def __init__(self
, targets
):
11 self
.targets
= targets
14 def checkCandidate(self
, num
, verbose
=False, verbose_limit
=0.1):
15 for tid
, t
in enumerate(self
.targets
):
17 diff
= t
.getDifference(num
)
18 diffsofar
= self
.matchd
.get(tid
, None)
20 if diffsofar
== None or diff
< diffsofar
[0]:
21 self
.matchd
[tid
] = (diff
, num
)
22 if verbose
and diff
< verbose_limit
:
23 self
.printBestMatch(tid
)
24 except IncompatibleUnits
:
26 except ZeroDivisionError:
29 def printBestMatches(self
):
30 tids
= [ t
[0] for t
in sorted(self
.matchd
.items(), key
=lambda t
:t
[1]) ]
32 self
.printBestMatch(tid
)
34 def printBestMatch(self
, tid
):
35 match
= self
.matchd
.get(tid
, None)
41 print "------ %.3f%%; "%(100*(1-diff
),), diff
44 myprint(num
.headStr())