blob: 430664f4830049652867ae3880d211b65090968b [file] [log] [blame]
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02001import argparse
2from collections import OrderedDict
3import sys
4
5import charts
6import storage_api
7
8
Yulia Portnova919f3be2015-02-06 12:49:22 +02009def ssize_to_kb(ssize):
10 try:
11 smap = dict(k=1, K=1, M=1024, m=1024, G=1024**2, g=1024**2)
12 for ext, coef in smap.items():
13 if ssize.endswith(ext):
14 return int(ssize[:-1]) * coef
15
16 if int(ssize) % 1024 != 0:
17 raise ValueError()
18
19 return int(ssize) / 1024
20
21 except (ValueError, TypeError, AttributeError):
22 tmpl = "Unknow size format {0!r} (or size not multiples 1024)"
23 raise ValueError(tmpl.format(ssize))
24
25
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020026def parse_args(argv):
27 parser = argparse.ArgumentParser()
28 parser.add_argument('-s', '--storage', help='storage location', dest="url")
29 parser.add_argument('-e', '--email', help='user email',
30 default="aaa@gmail.com")
31 parser.add_argument('-p', '--password', help='user password',
32 default="1234")
33 return parser.parse_args(argv)
34
35
Yulia Portnova919f3be2015-02-06 12:49:22 +020036def build_vertical_bar(results):
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020037 data = {}
Yulia Portnova919f3be2015-02-06 12:49:22 +020038 charts_url = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020039
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020040 for build, results in results.items():
Yulia Portnova919f3be2015-02-06 12:49:22 +020041 for key, value in results.results.items():
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020042 keys = key.split(' ')
43 if not data.get(keys[2]):
44 data[keys[2]] = {}
45 if not data[keys[2]].get(build):
46 data[keys[2]][build] = {}
47 data[keys[2]][build][' '.join([keys[0], keys[1]])] = value
48
Yulia Portnovae4408022015-02-10 15:39:25 +020049 scale_x_a = ['randwrite a', 'randread a', 'write a', 'read a']
50 scale_x_s = ['randwrite s', 'randread s', 'write s', 'read s']
51
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020052 for name, value in data.items():
53 title = name
54 legend = []
Yulia Portnovae4408022015-02-10 15:39:25 +020055 dataset_s = []
56 dataset_a = []
57
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020058 for build_id, build_results in value.items():
59 legend.append(build_id)
Yulia Portnovae4408022015-02-10 15:39:25 +020060 # import pdb;pdb.set_trace()
61 ordered_build_results_s = OrderedDict(
62 sorted([(k, v) for k, v in build_results.items()
63 if k in scale_x_s], key=lambda t: scale_x_s.index(t[0])))
64 ordered_build_results_a = OrderedDict(
65 sorted([(k, v) for k, v in build_results.items()
66 if k in scale_x_a], key=lambda t: scale_x_a.index(t[0])))
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020067
Yulia Portnovae4408022015-02-10 15:39:25 +020068 dataset_s.append(ordered_build_results_s.values())
69 dataset_a.append(ordered_build_results_a.values())
70
71 bar_s = charts.render_vertical_bar(title, legend, dataset_s,
72 scale_x=scale_x_s)
73 bar_a = charts.render_vertical_bar(title, legend, dataset_a,
74 scale_x=scale_x_a)
75 charts_url.extend([str(bar_s), str(bar_a)])
Yulia Portnova919f3be2015-02-06 12:49:22 +020076 return charts_url
77
78
79def build_lines_chart(results):
80 data = {}
81 charts_url = []
82
83 for build, results in results.items():
84 for key, value in results.results.items():
85 keys = key.split(' ')
86 if not data.get(' '.join([keys[0], keys[1]])):
87 data[' '.join([keys[0], keys[1]])] = {}
88 if not data[' '.join([keys[0], keys[1]])].get(build):
89 data[' '.join([keys[0], keys[1]])][build] = {}
90 data[' '.join([keys[0], keys[1]])][build][keys[2]] = value
91
92 for name, value in data.items():
93 title = name
94 legend = []
95 dataset = []
96 scale_x = []
97 for build_id, build_results in value.items():
98 legend.append(build_id)
99 ordered_build_results = OrderedDict(sorted(build_results.items(),
100 key=lambda t: ssize_to_kb(t[0])))
101 if not scale_x:
102 scale_x = ordered_build_results.keys()
103 dataset.append(zip(*ordered_build_results.values())[0])
104
105 chart = charts.render_lines(title, legend, dataset, scale_x)
106 charts_url.append(str(chart))
107
108 return charts_url
109
110
111def render_html(charts_urls):
112 templ = open("report.html", 'r').read()
113 body = "<div><ol>%s</ol></div>"
114 li = "<li><img src='%s'></li>"
115 ol = []
116 for chart in charts_urls:
117 ol.append(li % chart)
118 html = templ % {'body': body % '\n'.join(ol)}
119 open('results.html', 'w').write(html)
120
121
122def report(url, email=None, password=None):
123 storage = storage_api.create_storage(url, email, password)
124 results = storage.recent_builds()
125 bars = build_vertical_bar(results)
126 lines = build_lines_chart(results)
127
128 render_html(bars + lines)
Yulia Portnova6d72d7f2015-02-04 16:48:50 +0200129
130
131def main(argv):
132 opts = parse_args(argv)
133 report(opts.url)
134 return 0
135
136
137if __name__ == '__main__':
138 exit(main(sys.argv[1:]))