gstepanov | 501151a | 2015-03-06 17:22:28 +0200 | [diff] [blame] | 1 | # class displays measurement. Moved from storage_api_v_1 |
| 2 | # to avoid circular imports. |
| 3 | import math |
| 4 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 5 | # fix and update all this. Take statistic code from scripts/data2.py |
| 6 | |
gstepanov | 501151a | 2015-03-06 17:22:28 +0200 | [diff] [blame] | 7 | |
| 8 | class 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 | |
| 24 | def mean(l): |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 25 | return sum(l) / len(l) |
gstepanov | 501151a | 2015-03-06 17:22:28 +0200 | [diff] [blame] | 26 | |
| 27 | |
| 28 | def stdev(l): |
| 29 | m = mean(l) |
| 30 | return math.sqrt(sum(map(lambda x: (x - m) ** 2, l))) |
| 31 | |
| 32 | |
| 33 | def 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 | |
| 42 | def 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 kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 65 | return m |