1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: wuireport.py 56295 2015-06-09 14:29:55Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | Test Manager WUI - Reports.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2012-2015 Oracle Corporation
|
---|
11 |
|
---|
12 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | available from http://www.virtualbox.org. This file is free software;
|
---|
14 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | General Public License (GPL) as published by the Free Software
|
---|
16 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 |
|
---|
20 | The contents of this file may alternatively be used under the terms
|
---|
21 | of the Common Development and Distribution License Version 1.0
|
---|
22 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
23 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
24 | CDDL are applicable instead of those of the GPL.
|
---|
25 |
|
---|
26 | You may elect to license modified versions of this file under the
|
---|
27 | terms and conditions of either the GPL or the CDDL or both.
|
---|
28 | """
|
---|
29 | __version__ = "$Revision: 56295 $"
|
---|
30 |
|
---|
31 |
|
---|
32 | # Validation Kit imports.
|
---|
33 | from testmanager.webui.wuicontentbase import WuiContentBase;
|
---|
34 | from testmanager.webui.wuihlpgraph import WuiHlpGraphDataTable, WuiHlpBarGraph;
|
---|
35 | from testmanager.core.report import ReportModelBase;
|
---|
36 |
|
---|
37 |
|
---|
38 | class WuiReportBase(WuiContentBase):
|
---|
39 | """
|
---|
40 | Base class for the reports.
|
---|
41 | """
|
---|
42 |
|
---|
43 | def __init__(self, oModel, dParams, fSubReport = False, fnDPrint = None, oDisp = None):
|
---|
44 | WuiContentBase.__init__(self, fnDPrint = fnDPrint, oDisp = oDisp);
|
---|
45 | self._oModel = oModel;
|
---|
46 | self._dParams = dParams;
|
---|
47 | self._fSubReport = fSubReport;
|
---|
48 | self._sTitle = None;
|
---|
49 |
|
---|
50 | def generateNavigator(self, sWhere):
|
---|
51 | """
|
---|
52 | Generates the navigator (manipulate _dParams).
|
---|
53 | Returns HTML.
|
---|
54 | """
|
---|
55 | assert sWhere == 'top' or sWhere == 'bottom';
|
---|
56 |
|
---|
57 | return '';
|
---|
58 |
|
---|
59 | def generateReportBody(self):
|
---|
60 | """
|
---|
61 | This is overridden by the child class to generate the report.
|
---|
62 | Returns HTML.
|
---|
63 | """
|
---|
64 | return '<h3>Must override generateReportBody!</h3>';
|
---|
65 |
|
---|
66 | def show(self):
|
---|
67 | """
|
---|
68 | Generate the report.
|
---|
69 | Returns (sTitle, HTML).
|
---|
70 | """
|
---|
71 |
|
---|
72 | sTitle = self._sTitle if self._sTitle is not None else type(self).__name__;
|
---|
73 | sReport = self.generateReportBody();
|
---|
74 | if not self._fSubReport:
|
---|
75 | sReport = self.generateNavigator('top') + sReport + self.generateNavigator('bottom');
|
---|
76 | sTitle = self._oModel.sSubject + ' - ' + sTitle; ## @todo add subject to title in a proper way!
|
---|
77 |
|
---|
78 | return (sTitle, sReport);
|
---|
79 |
|
---|
80 |
|
---|
81 | class WuiReportSuccessRate(WuiReportBase):
|
---|
82 | """
|
---|
83 | Generates a report displaying the success rate over time.
|
---|
84 | """
|
---|
85 |
|
---|
86 | def generateReportBody(self):
|
---|
87 | self._sTitle = 'Success rate';
|
---|
88 |
|
---|
89 | adPeriods = self._oModel.getSuccessRates();
|
---|
90 |
|
---|
91 | sReport = '';
|
---|
92 |
|
---|
93 | oTable = WuiHlpGraphDataTable('Period', [ 'Succeeded', 'Skipped', 'Failed' ]);
|
---|
94 |
|
---|
95 | #for i in range(len(adPeriods) - 1, -1, -1):
|
---|
96 | for i in range(len(adPeriods)):
|
---|
97 | dStatuses = adPeriods[i];
|
---|
98 | cSuccess = dStatuses[ReportModelBase.ksTestStatus_Success] + dStatuses[ReportModelBase.ksTestStatus_Skipped];
|
---|
99 | cTotal = cSuccess + dStatuses[ReportModelBase.ksTestStatus_Failure];
|
---|
100 | sPeriod = self._oModel.getPeriodDesc(i);
|
---|
101 | if cTotal > 0:
|
---|
102 | iPctSuccess = dStatuses[ReportModelBase.ksTestStatus_Success] * 100 / cTotal;
|
---|
103 | iPctSkipped = dStatuses[ReportModelBase.ksTestStatus_Skipped] * 100 / cTotal;
|
---|
104 | iPctFailure = dStatuses[ReportModelBase.ksTestStatus_Failure] * 100 / cTotal;
|
---|
105 | oTable.addRow(sPeriod, [ iPctSuccess, iPctSkipped, iPctFailure ],
|
---|
106 | [ '%s%% (%d)' % (iPctSuccess, dStatuses[ReportModelBase.ksTestStatus_Success]),
|
---|
107 | '%s%% (%d)' % (iPctSkipped, dStatuses[ReportModelBase.ksTestStatus_Skipped]),
|
---|
108 | '%s%% (%d)' % (iPctFailure, dStatuses[ReportModelBase.ksTestStatus_Failure]), ]);
|
---|
109 | else:
|
---|
110 | oTable.addRow(sPeriod, [ 0, 0, 0 ], [ '0%', '0%', '0%' ]);
|
---|
111 |
|
---|
112 | cTotalNow = adPeriods[0][ReportModelBase.ksTestStatus_Success];
|
---|
113 | cTotalNow += adPeriods[0][ReportModelBase.ksTestStatus_Skipped];
|
---|
114 | cSuccessNow = cTotalNow;
|
---|
115 | cTotalNow += adPeriods[0][ReportModelBase.ksTestStatus_Failure];
|
---|
116 | sReport += '<p>Current success rate: ';
|
---|
117 | if cTotalNow > 0:
|
---|
118 | sReport += '%s%% (thereof %s%% skipped)</p>\n' \
|
---|
119 | % ( cSuccessNow * 100 / cTotalNow, adPeriods[0][ReportModelBase.ksTestStatus_Skipped] * 100 / cTotalNow);
|
---|
120 | else:
|
---|
121 | sReport += 'N/A</p>\n'
|
---|
122 |
|
---|
123 | oGraph = WuiHlpBarGraph('success-rate', oTable, self._oDisp);
|
---|
124 | oGraph.setRangeMax(100);
|
---|
125 | sReport += oGraph.renderGraph();
|
---|
126 |
|
---|
127 | return sReport;
|
---|
128 |
|
---|
129 |
|
---|
130 | class WuiReportFailureReasons(WuiReportBase):
|
---|
131 | """
|
---|
132 | Generates a report displaying the failure reasons over time.
|
---|
133 | """
|
---|
134 |
|
---|
135 | def generateReportBody(self):
|
---|
136 | # Mockup.
|
---|
137 | self._sTitle = 'Success rate';
|
---|
138 | return '<p>Graph showing COUNT(idFailureReason) grouped by time period.</p>' \
|
---|
139 | '<p>New reasons per period, tracked down to build revision.</p>' \
|
---|
140 | '<p>Show graph content in table form.</p>';
|
---|
141 |
|
---|
142 |
|
---|
143 | class WuiReportSummary(WuiReportBase):
|
---|
144 | """
|
---|
145 | Summary report.
|
---|
146 | """
|
---|
147 |
|
---|
148 | def generateReportBody(self):
|
---|
149 | self._sTitle = 'Summary';
|
---|
150 | sHtml = '<p>This will display several reports and listings useful to get an overview of %s (id=%s).</p>' \
|
---|
151 | % (self._oModel.sSubject, self._oModel.aidSubjects,);
|
---|
152 |
|
---|
153 | oSuccessRate = WuiReportSuccessRate(self._oModel, self._dParams, fSubReport = True,
|
---|
154 | fnDPrint = self._fnDPrint, oDisp = self._oDisp);
|
---|
155 | sHtml += oSuccessRate.show()[1];
|
---|
156 |
|
---|
157 | return sHtml;
|
---|
158 |
|
---|