-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate.py
47 lines (34 loc) · 1.09 KB
/
calculate.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
import numpy as np
from statistics import mean, stdev
import math
class Calculate():
def error(base, e, method='auto'):
v = [base, e]
if method == 'auto':
method = 'perc'
if method == 'diff':
return max(v) - min(v)
if method == 'perc':
return "{0:.4f} %".format(100 * (1 - (min(v) / max(v))))
if method == 'log2':
return int(np.log2(1 - (min(v) / max(v))))
return Calculate.error(base, e)
def score(base, e, method='auto'):
v = [base, e]
if method == 'auto':
method = 'log2'
if method == 'perc':
return "{0:.4f} %".format(100 * (min(v) / max(v)))
if method == 'log2':
if min(v) == max(v):
return 32
return -int(np.log2(1 - (min(v) / max(v))))
return Calculate.score(base, e)
def stats(data):
s = {}
s['min'] = min(data)
s['max'] = max(data)
s['avg'] = mean(data)
s['dev'] = 0 if len(data) == 1 else stdev(data)
s['data'] = data
return s