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