1 # For licensing info see the included LICENSE file
3 # Josef Moudrik, <J dot Moudrik at standard google mail ending>, 2012
5 from exc
import IncompatibleUnits
8 return unicode(st
).encode('utf-8')
11 print encode_utf8(' '.join(map(unicode, args
)))
13 class CorrelationChecker
:
14 def __init__(self
, targets
):
15 self
.targets
= targets
18 def checkCandidate(self
, num
, verbose
=False, verbose_limit
=0.1):
19 for tid
, t
in enumerate(self
.targets
):
21 diff
= t
.getDifference(num
)
22 diffsofar
= self
.matchd
.get(tid
, None)
24 if diffsofar
== None or diff
< diffsofar
[0]:
25 self
.matchd
[tid
] = (diff
, num
)
26 if verbose
and diff
< verbose_limit
:
27 self
.printBestMatch(tid
)
28 except IncompatibleUnits
:
30 except ZeroDivisionError:
33 def printBestMatches(self
):
34 tids
= [ t
[0] for t
in sorted(self
.matchd
.items(), key
=lambda t
:t
[1]) ]
36 self
.printBestMatch(tid
)
38 def printBestMatch(self
, tid
):
39 match
= self
.matchd
.get(tid
, None)
45 print "------ %.3f%%; "%(100*(1-diff
),), diff
48 myprint(num
.headStr())