gstepanov | e0f26ab | 2015-02-02 18:09:37 +0200 | [diff] [blame] | 1 | import json |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 2 | import math |
| 3 | from config import TEST_PATH |
| 4 | from flask import url_for |
gstepanov | e0f26ab | 2015-02-02 18:09:37 +0200 | [diff] [blame] | 5 | import os |
gstepanov | 71764e9 | 2015-02-02 16:33:11 +0200 | [diff] [blame] | 6 | |
koder aka kdanilov | dda86d3 | 2015-03-16 11:20:04 +0200 | [diff] [blame] | 7 | |
gstepanov | 71764e9 | 2015-02-02 16:33:11 +0200 | [diff] [blame] | 8 | class Measurement(object): |
| 9 | def __init__(self): |
| 10 | self.build = "" |
| 11 | self.build_type = 0 # GA/Master/Other |
| 12 | self.md5 = "" |
| 13 | self.results = { |
| 14 | "": (float, float) |
| 15 | } |
| 16 | |
gstepanov | b10fa5b | 2015-02-04 15:55:15 +0200 | [diff] [blame] | 17 | def __str__(self): |
| 18 | return self.build + " " + self.build_type + " " + \ |
koder aka kdanilov | 7acd6bd | 2015-02-12 14:28:30 -0800 | [diff] [blame] | 19 | self.md5 + " " + str(self.results) |
gstepanov | b10fa5b | 2015-02-04 15:55:15 +0200 | [diff] [blame] | 20 | |
gstepanov | 71764e9 | 2015-02-02 16:33:11 +0200 | [diff] [blame] | 21 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 22 | def prepare_build_data(build): |
| 23 | for item in build.items(): |
| 24 | if type(item[1]) is list: |
| 25 | m = mean(item[1]) |
| 26 | s = stdev(item[1]) |
| 27 | build[item[0]] = [m, s] |
gstepanov | 7cc6ba0 | 2015-02-03 17:18:42 +0200 | [diff] [blame] | 28 | |
koder aka kdanilov | dda86d3 | 2015-03-16 11:20:04 +0200 | [diff] [blame] | 29 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 30 | def mean(l): |
| 31 | n = len(l) |
| 32 | |
| 33 | return sum(l) / n |
gstepanov | bd7c329 | 2015-02-03 15:23:41 +0200 | [diff] [blame] | 34 | |
| 35 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 36 | def stdev(l): |
| 37 | m = mean(l) |
| 38 | return math.sqrt(sum(map(lambda x: (x - m) ** 2, l))) |
gstepanov | e0f26ab | 2015-02-02 18:09:37 +0200 | [diff] [blame] | 39 | |
| 40 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 41 | def load_test(test_name): |
| 42 | test_name += '.json' |
gstepanov | e0f26ab | 2015-02-02 18:09:37 +0200 | [diff] [blame] | 43 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 44 | with open(TEST_PATH + "/" + test_name, 'rt') as f: |
| 45 | raw = f.read() |
gstepanov | e0f26ab | 2015-02-02 18:09:37 +0200 | [diff] [blame] | 46 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 47 | if raw != "": |
| 48 | test = json.loads(raw) |
| 49 | else: |
| 50 | test = [] |
| 51 | import time |
| 52 | creation_time = os.path.getmtime(TEST_PATH + "/" + test_name) |
gstepanov | e0f26ab | 2015-02-02 18:09:37 +0200 | [diff] [blame] | 53 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 54 | for t in test: |
| 55 | t['date'] = time.ctime(creation_time) |
gstepanov | e0f26ab | 2015-02-02 18:09:37 +0200 | [diff] [blame] | 56 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 57 | return test |
gstepanov | 82d2a94 | 2015-02-03 15:10:11 +0200 | [diff] [blame] | 58 | |
gstepanov | 2164d82 | 2015-02-04 19:49:40 +0200 | [diff] [blame] | 59 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 60 | def collect_tests(): |
| 61 | result = [] |
| 62 | |
| 63 | for file in os.listdir(TEST_PATH): |
| 64 | if file.endswith(".json"): |
| 65 | result.append(file.split('.')[0]) |
| 66 | |
| 67 | return result |
| 68 | |
| 69 | |
| 70 | def collect_builds(): |
| 71 | builds = [] |
| 72 | build_set = set() |
| 73 | tests = collect_tests() |
| 74 | |
| 75 | for t in tests: |
| 76 | test = load_test(t) |
| 77 | |
| 78 | for build in test: |
| 79 | if build["type"] not in build_set: |
| 80 | build_set.add(build["type"]) |
| 81 | builds.append(build) |
| 82 | |
| 83 | for build in builds: |
| 84 | prepare_build_data(build) |
| 85 | |
| 86 | return builds |
| 87 | |
| 88 | |
| 89 | def builds_list(): |
| 90 | data = [] |
| 91 | |
| 92 | for build in collect_builds(): |
| 93 | d = {} |
| 94 | d["type"] = build['type'] |
| 95 | d["url"] = url_for("render_test", test_name=build['name']) |
| 96 | d["date"] = build['date'] |
| 97 | d["name"] = build['name'] |
| 98 | data.append(d) |
| 99 | |
| 100 | return data |
| 101 | |
| 102 | |
| 103 | def create_measurement(build): |
| 104 | m = Measurement() |
| 105 | m.build = build.pop("build_id") |
| 106 | m.build_type = build.pop("type") |
| 107 | m.md5 = build.pop("iso_md5") |
| 108 | m.date = build.pop("date") |
| 109 | m.date = build.pop("name") |
| 110 | m.results = {k: v for k, v in build.items()} |
| 111 | |
| 112 | return m |
stgleb | 75c7041 | 2015-02-17 02:52:00 +0200 | [diff] [blame] | 113 | |
| 114 | |
| 115 | |
| 116 | collect_builds() |