blob: 28ec06057a32977d1590a577ddee76f49a9cd4a7 [file] [log] [blame]
gstepanov7cc6ba02015-02-03 17:18:42 +02001from urlparse import urlparse
gstepanov725cc302015-02-09 15:08:06 +02002
gstepanove0f26ab2015-02-02 18:09:37 +02003import json
gstepanovec9048c2015-02-16 19:17:09 +02004import math
5from config import TEST_PATH
6from flask import url_for
gstepanove0f26ab2015-02-02 18:09:37 +02007import os
gstepanov71764e92015-02-02 16:33:11 +02008
gstepanov71764e92015-02-02 16:33:11 +02009class 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
gstepanovb10fa5b2015-02-04 15:55:15 +020018 def __str__(self):
19 return self.build + " " + self.build_type + " " + \
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080020 self.md5 + " " + str(self.results)
gstepanovb10fa5b2015-02-04 15:55:15 +020021
gstepanov71764e92015-02-02 16:33:11 +020022
gstepanovec9048c2015-02-16 19:17:09 +020023def 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]
gstepanov7cc6ba02015-02-03 17:18:42 +020029
gstepanovec9048c2015-02-16 19:17:09 +020030
31def mean(l):
32 n = len(l)
33
34 return sum(l) / n
gstepanovbd7c3292015-02-03 15:23:41 +020035
36
gstepanovec9048c2015-02-16 19:17:09 +020037def stdev(l):
38 m = mean(l)
39 return math.sqrt(sum(map(lambda x: (x - m) ** 2, l)))
gstepanove0f26ab2015-02-02 18:09:37 +020040
41
gstepanovec9048c2015-02-16 19:17:09 +020042def load_test(test_name):
43 test_name += '.json'
gstepanove0f26ab2015-02-02 18:09:37 +020044
gstepanovec9048c2015-02-16 19:17:09 +020045 with open(TEST_PATH + "/" + test_name, 'rt') as f:
46 raw = f.read()
gstepanove0f26ab2015-02-02 18:09:37 +020047
gstepanovec9048c2015-02-16 19:17:09 +020048 if raw != "":
49 test = json.loads(raw)
50 else:
51 test = []
52 import time
53 creation_time = os.path.getmtime(TEST_PATH + "/" + test_name)
gstepanove0f26ab2015-02-02 18:09:37 +020054
gstepanovec9048c2015-02-16 19:17:09 +020055 for t in test:
56 t['date'] = time.ctime(creation_time)
gstepanove0f26ab2015-02-02 18:09:37 +020057
gstepanovec9048c2015-02-16 19:17:09 +020058 return test
gstepanov82d2a942015-02-03 15:10:11 +020059
gstepanov2164d822015-02-04 19:49:40 +020060
gstepanovec9048c2015-02-16 19:17:09 +020061def 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
71def 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
90def 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
104def 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
stgleb75c70412015-02-17 02:52:00 +0200114
115
116
117collect_builds()