Add Rally summary and Doctor for visualization
[releng.git] / utils / test / result_collection_api / dashboard / doctor2Dashboard.py
1  #!/usr/bin/python
2 #
3 # Copyright (c) 2015 Orange
4 # morgan.richomme@orange.com
5 #
6 # This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # This script is used to build dashboard ready json results
13 # It may be used for all the test case of the Doctor project
14 # a new method format_<Test_case>_for_dashboard(results)
15 #
16 import re
17 import datetime
18
19
20 def get_doctor_cases():
21     """
22     get the list of the supported test cases
23     TODO: update the list when adding a new test case for the dashboard
24     """
25     return ["doctor-notification","doctor-mark-down"]
26
27
28 def format_doctor_for_dashboard(case, results):
29     """
30     generic method calling the method corresponding to the test case
31     check that the testcase is properly declared first
32     then build the call to the specific method
33     """
34     
35     if check_doctor_case_exist(case):
36         # note we add _case because testcase and project had the same name
37         # TODO refactoring...looks fine at the beginning wit only 1 project
38         # not very ugly now and clearly not optimized...
39         cmd = "format_" + case.replace('-','_') + "_case_for_dashboard(results)"
40         res = eval(cmd)
41     else:
42         res = []
43     return res
44
45
46 def check_doctor_case_exist(case):
47     """
48     check if the testcase exists
49     if the test case is not defined or not declared in the list
50     return False
51     """
52     doctor_cases = get_doctor_cases()
53
54     if (case is None or case not in doctor_cases):
55         return False
56     else:
57         return True
58
59
60 def format_doctor_mark_down_case_for_dashboard(results):
61     """
62     Post processing for the doctor test case
63     """
64     test_data = [{'description': 'doctor-mark-down results for Dashboard'}]
65     return test_data
66
67
68 def format_doctor_notification_case_for_dashboard(results):
69     """
70     Post processing for the doctor-notification test case
71     """
72     test_data = [{'description': 'doctor results for Dashboard'}]
73     # Graph 1: (duration)=f(time)
74     # ***************************************
75     new_element = []
76
77     # default duration 0:00:08.999904
78     # consider only seconds => 09
79     for data in results:
80         t = data['details']['duration']
81         new_element.append({'x': data['creation_date'],
82                             'y': t})
83
84     test_data.append({'name': "doctor-notification duration ",
85                       'info': {'type': "graph",
86                                'xlabel': 'time (s)',
87                                'ylabel': 'duration (s)'},
88                       'data_set': new_element})
89
90     # Graph 2: bar
91     # ************
92     nbTest = 0
93     nbTestOk = 0
94
95     for data in results:
96         nbTest += 1
97         if data['details']['status'] == "OK":
98             nbTestOk += 1
99
100     test_data.append({'name': "doctor-notification status",
101                       'info': {"type": "bar"},
102                       'data_set': [{'Nb tests': nbTest,
103                                     'Nb Success': nbTestOk}]})
104
105     return test_data