blob: d02d0cd80f16006b1eed9d0e4d5c436d6cea9ef3 [file] [log] [blame]
gstepanove0f26ab2015-02-02 18:09:37 +02001import json
gstepanovec9048c2015-02-16 19:17:09 +02002import math
3from config import TEST_PATH
4from flask import url_for
gstepanove0f26ab2015-02-02 18:09:37 +02005import os
gstepanov71764e92015-02-02 16:33:11 +02006
koder aka kdanilovdda86d32015-03-16 11:20:04 +02007
gstepanov71764e92015-02-02 16:33:11 +02008class 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
gstepanovb10fa5b2015-02-04 15:55:15 +020017 def __str__(self):
18 return self.build + " " + self.build_type + " " + \
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080019 self.md5 + " " + str(self.results)
gstepanovb10fa5b2015-02-04 15:55:15 +020020
gstepanov71764e92015-02-02 16:33:11 +020021
gstepanovec9048c2015-02-16 19:17:09 +020022def 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]
gstepanov7cc6ba02015-02-03 17:18:42 +020028
koder aka kdanilovdda86d32015-03-16 11:20:04 +020029
gstepanovec9048c2015-02-16 19:17:09 +020030def mean(l):
31 n = len(l)
32
33 return sum(l) / n
gstepanovbd7c3292015-02-03 15:23:41 +020034
35
gstepanovec9048c2015-02-16 19:17:09 +020036def stdev(l):
37 m = mean(l)
38 return math.sqrt(sum(map(lambda x: (x - m) ** 2, l)))
gstepanove0f26ab2015-02-02 18:09:37 +020039
40
gstepanovec9048c2015-02-16 19:17:09 +020041def load_test(test_name):
42 test_name += '.json'
gstepanove0f26ab2015-02-02 18:09:37 +020043
gstepanovec9048c2015-02-16 19:17:09 +020044 with open(TEST_PATH + "/" + test_name, 'rt') as f:
45 raw = f.read()
gstepanove0f26ab2015-02-02 18:09:37 +020046
gstepanovec9048c2015-02-16 19:17:09 +020047 if raw != "":
48 test = json.loads(raw)
49 else:
50 test = []
51 import time
52 creation_time = os.path.getmtime(TEST_PATH + "/" + test_name)
gstepanove0f26ab2015-02-02 18:09:37 +020053
gstepanovec9048c2015-02-16 19:17:09 +020054 for t in test:
55 t['date'] = time.ctime(creation_time)
gstepanove0f26ab2015-02-02 18:09:37 +020056
gstepanovec9048c2015-02-16 19:17:09 +020057 return test
gstepanov82d2a942015-02-03 15:10:11 +020058
gstepanov2164d822015-02-04 19:49:40 +020059
gstepanovec9048c2015-02-16 19:17:09 +020060def 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
70def 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
89def 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
103def 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
stgleb75c70412015-02-17 02:52:00 +0200113
114
115
116collect_builds()