blob: 1dbf30c63d668587090299649ff6084f3791167c [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
koder aka kdanilovdda86d32015-03-16 11:20:04 +02009
gstepanov71764e92015-02-02 16:33:11 +020010class Measurement(object):
11 def __init__(self):
12 self.build = ""
13 self.build_type = 0 # GA/Master/Other
14 self.md5 = ""
15 self.results = {
16 "": (float, float)
17 }
18
gstepanovb10fa5b2015-02-04 15:55:15 +020019 def __str__(self):
20 return self.build + " " + self.build_type + " " + \
koder aka kdanilov7acd6bd2015-02-12 14:28:30 -080021 self.md5 + " " + str(self.results)
gstepanovb10fa5b2015-02-04 15:55:15 +020022
gstepanov71764e92015-02-02 16:33:11 +020023
gstepanovec9048c2015-02-16 19:17:09 +020024def prepare_build_data(build):
25 for item in build.items():
26 if type(item[1]) is list:
27 m = mean(item[1])
28 s = stdev(item[1])
29 build[item[0]] = [m, s]
gstepanov7cc6ba02015-02-03 17:18:42 +020030
koder aka kdanilovdda86d32015-03-16 11:20:04 +020031
gstepanovec9048c2015-02-16 19:17:09 +020032def mean(l):
33 n = len(l)
34
35 return sum(l) / n
gstepanovbd7c3292015-02-03 15:23:41 +020036
37
gstepanovec9048c2015-02-16 19:17:09 +020038def stdev(l):
39 m = mean(l)
40 return math.sqrt(sum(map(lambda x: (x - m) ** 2, l)))
gstepanove0f26ab2015-02-02 18:09:37 +020041
42
gstepanovec9048c2015-02-16 19:17:09 +020043def load_test(test_name):
44 test_name += '.json'
gstepanove0f26ab2015-02-02 18:09:37 +020045
gstepanovec9048c2015-02-16 19:17:09 +020046 with open(TEST_PATH + "/" + test_name, 'rt') as f:
47 raw = f.read()
gstepanove0f26ab2015-02-02 18:09:37 +020048
gstepanovec9048c2015-02-16 19:17:09 +020049 if raw != "":
50 test = json.loads(raw)
51 else:
52 test = []
53 import time
54 creation_time = os.path.getmtime(TEST_PATH + "/" + test_name)
gstepanove0f26ab2015-02-02 18:09:37 +020055
gstepanovec9048c2015-02-16 19:17:09 +020056 for t in test:
57 t['date'] = time.ctime(creation_time)
gstepanove0f26ab2015-02-02 18:09:37 +020058
gstepanovec9048c2015-02-16 19:17:09 +020059 return test
gstepanov82d2a942015-02-03 15:10:11 +020060
gstepanov2164d822015-02-04 19:49:40 +020061
gstepanovec9048c2015-02-16 19:17:09 +020062def collect_tests():
63 result = []
64
65 for file in os.listdir(TEST_PATH):
66 if file.endswith(".json"):
67 result.append(file.split('.')[0])
68
69 return result
70
71
72def collect_builds():
73 builds = []
74 build_set = set()
75 tests = collect_tests()
76
77 for t in tests:
78 test = load_test(t)
79
80 for build in test:
81 if build["type"] not in build_set:
82 build_set.add(build["type"])
83 builds.append(build)
84
85 for build in builds:
86 prepare_build_data(build)
87
88 return builds
89
90
91def builds_list():
92 data = []
93
94 for build in collect_builds():
95 d = {}
96 d["type"] = build['type']
97 d["url"] = url_for("render_test", test_name=build['name'])
98 d["date"] = build['date']
99 d["name"] = build['name']
100 data.append(d)
101
102 return data
103
104
105def create_measurement(build):
106 m = Measurement()
107 m.build = build.pop("build_id")
108 m.build_type = build.pop("type")
109 m.md5 = build.pop("iso_md5")
110 m.date = build.pop("date")
111 m.date = build.pop("name")
112 m.results = {k: v for k, v in build.items()}
113
114 return m
stgleb75c70412015-02-17 02:52:00 +0200115
116
117
118collect_builds()