blob: b15c579886e6edd6970e18a46b593be5dda82144 [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
koder aka kdanilove06762a2015-03-22 23:32:09 +02005# fix and update all this. Take statistic code from scripts/data2.py
6
gstepanov501151a2015-03-06 17:22:28 +02007
8class Measurement(object):
9 def __init__(self):
10 self.build = ""
11 self.build_type = 0 # GA/Master/Other
12 self.md5 = ""
13 self.name = ""
14 self.date = None
15 self.results = {
16 "": (float, float)
17 }
18
19 def __str__(self):
20 return self.build + " " + self.build_type + " " + \
21 self.md5 + " " + str(self.results)
22
23
24def mean(l):
koder aka kdanilove06762a2015-03-22 23:32:09 +020025 return sum(l) / len(l)
gstepanov501151a2015-03-06 17:22:28 +020026
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
koder aka kdanilovda45e882015-04-06 02:24:42 +030065 return m