blob: 2905bbe019eede5bf483f69044286fcd240d86c0 [file] [log] [blame]
gstepanov501151a2015-03-06 17:22:28 +02001# class displays measurement. Moved from storage_api_v_1
2# to avoid circular imports.
3import math
4
5
6class Measurement(object):
7 def __init__(self):
8 self.build = ""
9 self.build_type = 0 # GA/Master/Other
10 self.md5 = ""
11 self.name = ""
12 self.date = None
13 self.results = {
14 "": (float, float)
15 }
16
17 def __str__(self):
18 return self.build + " " + self.build_type + " " + \
19 self.md5 + " " + str(self.results)
20
21
22def mean(l):
23 n = len(l)
24
25 return sum(l) / n
26
27
28def stdev(l):
29 m = mean(l)
30 return math.sqrt(sum(map(lambda x: (x - m) ** 2, l)))
31
32
33def process_build_data(build):
34 """ Function computes mean of all the data from particular build"""
35 for item in build.items():
36 if type(item[1]) is list:
37 m = mean(item[1])
38 s = stdev(item[1])
39 build[item[0]] = [m, s]
40
41
42def create_measurement(data):
43 """ Function creates measurement from data was extracted from database."""
44
45 build_data = data[0]
46
47 m = Measurement()
48 m.build = build_data.build_id
49 m.build_type = build_data.type
50 m.name = build_data.name
51 m.results = {}
52
53 for i in range(1, len(data), 2):
54 result = data[i]
55 param_combination = data[i + 1]
56
57 if not str(param_combination) in m.results:
58 m.results[str(param_combination)] = [result.bandwith]
59 else:
60 m.results[str(param_combination)] += [result.bandwith]
61
62 for k in m.results.keys():
63 m.results[k] = [mean(m.results[k]), stdev(m.results[k])]
64
65 return m