Merge "Add d3 graph presentation to yardstick reporting"
[releng.git] / utils / test / reporting / yardstick / reporting-status.py
1 #!/usr/bin/python
2 #
3 # This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 import datetime
10 import jinja2
11 import os
12
13 import reportingUtils as utils
14 import reportingConf as conf
15 import scenarioResult as sr
16 from scenarios import config as cf
17
18 # Logger
19 logger = utils.getLogger("Yardstick-Status")
20 reportingDate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
21
22 logger.info("*******************************************")
23 logger.info("*   Generating reporting scenario status  *")
24 logger.info("*   Data retention = %s days              *" % conf.PERIOD)
25 logger.info("*                                         *")
26 logger.info("*******************************************")
27
28
29 # For all the versions
30 for version in conf.versions:
31     # For all the installers
32     for installer in conf.installers:
33         # get scenarios results data
34         scenario_results = utils.getScenarioStatus(installer, version)
35         if 'colorado' == version:
36             stable_result = utils.getScenarioStatus(installer,
37                                                     'stable/colorado')
38             for k, v in stable_result.items():
39                 if k not in scenario_results.keys():
40                     scenario_results[k] = []
41                 scenario_results[k] += stable_result[k]
42         scenario_result_criteria = {}
43
44         for s in scenario_results.keys():
45             if installer in cf.keys() and s in cf[installer].keys():
46                 scenario_results.pop(s)
47
48         # From each scenarios get results list
49         for s, s_result in scenario_results.items():
50             logger.info("---------------------------------")
51             logger.info("installer %s, version %s, scenario %s:" % (installer,
52                                                                     version, s))
53
54             ten_criteria = len(s_result)
55             ten_score = 0
56             for v in s_result:
57                 ten_score += v
58
59             four_result = s_result[:conf.LASTEST_TESTS]
60             four_criteria = len(four_result)
61             four_score = 0
62             for v in four_result:
63                 four_score += v
64
65             s_status = str(utils.get_percent(four_result, s_result))
66             s_four_score = str(four_score) + '/' + str(four_criteria)
67             s_ten_score = str(ten_score) + '/' + str(ten_criteria)
68             s_score_percent = utils.get_percent(four_result, s_result)
69
70             if '100' == s_status:
71                 logger.info(">>>>> scenario OK, save the information")
72             else:
73                 logger.info(">>>> scenario not OK, last 4 iterations = %s, \
74                             last 10 days = %s" % (s_four_score, s_ten_score))
75
76             # Save daily results in a file
77             path_validation_file = (conf.REPORTING_PATH +
78                                     "/release/" + version +
79                                     "/scenario_history.txt")
80
81             if not os.path.exists(path_validation_file):
82                 with open(path_validation_file, 'w') as f:
83                     info = 'date,scenario,installer,details,score\n'
84                     f.write(info)
85
86             with open(path_validation_file, "a") as f:
87                 info = (reportingDate + "," + s + "," + installer +
88                         "," + s_ten_score + "," +
89                         str(s_score_percent) + "\n")
90                 f.write(info)
91
92             scenario_result_criteria[s] = sr.ScenarioResult(s_status,
93                                                             s_four_score,
94                                                             s_ten_score,
95                                                             s_score_percent)
96
97             logger.info("--------------------------")
98
99         templateLoader = jinja2.FileSystemLoader(conf.REPORTING_PATH)
100         templateEnv = jinja2.Environment(loader=templateLoader, autoescape=True)
101
102         TEMPLATE_FILE = "/template/index-status-tmpl.html"
103         template = templateEnv.get_template(TEMPLATE_FILE)
104
105         outputText = template.render(scenario_results=scenario_result_criteria,
106                                      installer=installer,
107                                      period=conf.PERIOD,
108                                      version=version,
109                                      date=reportingDate)
110
111         with open(conf.REPORTING_PATH + "/release/" + version +
112                   "/index-status-" + installer + ".html", "wb") as fh:
113             fh.write(outputText)