-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerfUtil.py
49 lines (41 loc) · 1.3 KB
/
PerfUtil.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
'''
Created on Apr 18, 2017
@author: dquigley
'''
class PerfUtil(object):
@staticmethod
def normalize(score, weight = 1):
"""
normalizes the score to {-weight0,weight}
This is so a comparison on something like clat with
15 fields doesn't get additional weight. By default weight is 1
"""
if score == 0:
return 0
elif score > 0:
return weight
else:
return -weight
@staticmethod
def compare(first = None, second = None, margin=.20):
"""
First: Base value to compare
Second: object being compared to
margin: decimal percentage to use for variance
will return a value in the set {-1,0,1} for
which item is greater {first, equal, second}
"""
if first is None and second is not None:
return 1
elif second is None and first is not None:
return -1
elif first is None and second is None:
return 0
variance = int(first * margin)
distance = (first - second)
if abs(distance) <= variance:
return 0
elif distance < 0:
return 1
else:
return -1