Exemple #1
0
    def generateReportBody(self):
        fInteractive = not self._fSubReport

        # Quick mockup.
        self._sTitle = 'Graph Wizzard'

        sHtml = ''
        sHtml += '<h2>Incomplete code - no complaints yet, thank you!!</h2>\n'

        #
        # Create a form for altering the data we're working with.
        #
        if fInteractive:
            (sTopOfForm, sEndOfForm) = self._generateInteractiveForm()
            sHtml += sTopOfForm
            del sTopOfForm

        #
        # Emit the graphs.  At least one per sample source.
        #
        sHtml += ' <div id="graphwiz-graphs">\n'
        iGraph = 0
        aoCollections = self._oModel.fetchGraphData()
        for iCollection, oCollection in enumerate(aoCollections):
            # Name the graph and add a checkbox for removing it.
            sSampleName = self._calcSampleName(oCollection)
            sHtml += '  <div class="graphwiz-collection" id="graphwiz-source-%u">\n' % (
                iCollection, )
            if fInteractive:
                sHtml += '   <div class="graphwiz-src-select">\n' \
                         '    <input type="checkbox" name="%s" id="%s" value="%s:%s%s" checked class="graphwiz-src-input">\n' \
                         '    <label for="%s">%s</label>\n' \
                         '   </div>\n' \
                       % ( WuiMain.ksParamReportSubjectIds, WuiMain.ksParamReportSubjectIds, oCollection.sType,
                           ':'.join([str(idStr) for idStr in oCollection.aidStrTests]),
                           ':%u' % oCollection.idStrValue if oCollection.idStrValue else '',
                           WuiMain.ksParamReportSubjectIds, sSampleName )

            if len(oCollection.aoSeries) > 0:
                #
                # Split the series into sub-graphs as needed and produce SVGs.
                #
                aaoSeries = self._splitSeries(oCollection.aoSeries)
                for aoSeries in aaoSeries:
                    # Gather the data for this graph. (Most big stuff is passed by
                    # reference, so there shouldn't be any large memory penalty for
                    # repacking the data here.)
                    sYUnit = None
                    if aoSeries[0].iUnit < len(constants.valueunit.g_asNames
                                               ) and aoSeries[0].iUnit > 0:
                        sYUnit = constants.valueunit.g_asNames[
                            aoSeries[0].iUnit]
                    oData = WuiHlpGraphDataTableEx(sXUnit='Build revision',
                                                   sYUnit=sYUnit)

                    fSeriesName = self._figureSeriesNameBits(aoSeries)
                    for oSeries in aoSeries:
                        sSeriesName = self._getSeriesNameFromBits(
                            oSeries, fSeriesName)
                        asHtmlTooltips = None
                        if len(oSeries.aoRevInfo) == len(oSeries.aiRevisions):
                            asHtmlTooltips = []
                            for i in range(len(oSeries.aoRevInfo)):
                                sPlusMinus = ''
                                if oSeries.acSamples[i] > 1:
                                    sPlusMinus = ' (+%s/-%s; %u samples)' \
                                               % ( utils.formatNumber(oSeries.aiErrorBarAbove[i]),
                                                   utils.formatNumber(oSeries.aiErrorBarBelow[i]),
                                                   oSeries.acSamples[i])
                                sTooltip = '<table class=\'graphwiz-tt\'><tr><td>%s:</td><td>%s %s %s</td></tr>'\
                                           '<tr><td>Rev:</td><td>r%s</td></tr>' \
                                         % ( sSeriesName,
                                             utils.formatNumber(oSeries.aiValues[i]),
                                             sYUnit, sPlusMinus,
                                             oSeries.aiRevisions[i],
                                             )
                                oRevInfo = oSeries.aoRevInfo[i]
                                if oRevInfo.sAuthor is not None:
                                    sMsg = oRevInfo.sMessage[:80].strip()
                                    #if sMsg.find('\n') >= 0:
                                    #    sMsg = sMsg[:sMsg.find('\n')].strip();
                                    sTooltip += '<tr><td>Author:</td><td>%s</td></tr>' \
                                                '<tr><td>Date:</td><td>%s</td><tr>' \
                                                '<tr><td>Message:</td><td>%s%s</td></tr>' \
                                              % ( oRevInfo.sAuthor,
                                                  self.formatTsShort(oRevInfo.tsCreated),
                                                  sMsg, '...' if len(oRevInfo.sMessage) > len(sMsg) else '')
                                sTooltip += '</table>'
                                asHtmlTooltips.append(sTooltip)
                        oData.addDataSeries(sSeriesName, oSeries.aiRevisions,
                                            oSeries.aiValues, asHtmlTooltips,
                                            oSeries.aiErrorBarBelow,
                                            oSeries.aiErrorBarAbove)
                    # Render the data into a graph.
                    oGraph = self.oGraphClass('tmgraph-%u' % (iGraph, ), oData,
                                              self._oDisp)
                    self._configureGraph(oGraph)

                    oGraph.setTitle(
                        self._calcGraphName(aoSeries[0], fSeriesName,
                                            sSampleName))
                    sHtml += '   <div class="graphwiz-graph" id="graphwiz-graph-%u">\n' % (
                        iGraph, )
                    sHtml += oGraph.renderGraph()
                    sHtml += '\n   </div>\n'
                    iGraph += 1

                #
                # Emit raw tabular data if requested.
                #
                if self._dParams[WuiMain.ksParamGraphWizTabular]:
                    sHtml += '   <div class="graphwiz-tab-div" id="graphwiz-tab-%u">\n' \
                             '    <table class="tmtable graphwiz-tab">\n' \
                           % (iCollection, )
                    for aoSeries in aaoSeries:
                        if aoSeries[0].iUnit < len(
                                constants.valueunit.g_asNames
                        ) and aoSeries[0].iUnit > 0:
                            sUnit = constants.valueunit.g_asNames[
                                aoSeries[0].iUnit]
                        else:
                            sUnit = str(aoSeries[0].iUnit)

                        for iSeries, oSeries in enumerate(aoSeries):
                            sColor = self.oGraphClass.calcSeriesColor(iSeries)

                            sHtml += '<thead class="tmheader">\n' \
                                     ' <tr class="graphwiz-tab graphwiz-tab-new-series-row">\n' \
                                     '  <th colspan="5"><span style="background-color:%s;">&nbsp;&nbsp;</span> %s</th>\n' \
                                     ' </tr>\n' \
                                     ' <tr class="graphwiz-tab graphwiz-tab-col-hdr-row">\n' \
                                     '  <th>Revision</th><th>Value (%s)</th><th>&Delta;max</th><th>&Delta;min</th>' \
                                     '<th>Samples</th>\n' \
                                     ' </tr>\n' \
                                     '</thead>\n' \
                                   % ( sColor,
                                       self._getSeriesNameFromBits(oSeries, self.kfSeriesName_All & ~self.kfSeriesName_OsArchs),
                                       sUnit )

                            for i in range(len(oSeries.aiRevisions)):
                                sHtml += '     <tr class="%s"><td>r%s</td><td>%s</td><td>+%s</td><td>-%s</td><td>%s</td></tr>\n' \
                                       % ( 'tmodd' if i & 1 else 'tmeven',
                                           oSeries.aiRevisions[i], oSeries.aiValues[i],
                                           oSeries.aiErrorBarAbove[i], oSeries.aiErrorBarBelow[i],
                                           oSeries.acSamples[i])
                    sHtml += '    </table>\n' \
                             '   </div>\n'
            else:
                sHtml += '<i>No results.</i>\n'
            sHtml += '  </div>\n'
        sHtml += ' </div>\n'

        #
        # Finish the form.
        #
        if fInteractive:
            sHtml += sEndOfForm

        return sHtml
    def generateReportBody(self):
        fInteractive = not self._fSubReport;

        # Quick mockup.
        self._sTitle = 'Graph Wizzard';

        sHtml = '';
        sHtml += '<h2>Incomplete code - no complaints yet, thank you!!</h2>\n';

        #
        # Create a form for altering the data we're working with.
        #
        if fInteractive:
            (sTopOfForm, sEndOfForm) = self._generateInteractiveForm();
            sHtml += sTopOfForm;
            del sTopOfForm;

        #
        # Emit the graphs.  At least one per sample source.
        #
        sHtml += ' <div id="graphwiz-graphs">\n';
        iGraph = 0;
        aoCollections = self._oModel.fetchGraphData();
        for iCollection, oCollection in enumerate(aoCollections):
            # Name the graph and add a checkbox for removing it.
            sSampleName = self._calcSampleName(oCollection);
            sHtml += '  <div class="graphwiz-collection" id="graphwiz-source-%u">\n' % (iCollection,);
            if fInteractive:
                sHtml += '   <div class="graphwiz-src-select">\n' \
                         '    <input type="checkbox" name="%s" id="%s" value="%s:%s%s" checked class="graphwiz-src-input">\n' \
                         '    <label for="%s">%s</label>\n' \
                         '   </div>\n' \
                       % ( WuiMain.ksParamReportSubjectIds, WuiMain.ksParamReportSubjectIds, oCollection.sType,
                           ':'.join([str(idStr) for idStr in oCollection.aidStrTests]),
                           ':%u' % oCollection.idStrValue if oCollection.idStrValue else '',
                           WuiMain.ksParamReportSubjectIds, sSampleName );

            if len(oCollection.aoSeries) > 0:
                #
                # Split the series into sub-graphs as needed and produce SVGs.
                #
                aaoSeries = self._splitSeries(oCollection.aoSeries);
                for aoSeries in aaoSeries:
                    # Gather the data for this graph. (Most big stuff is passed by
                    # reference, so there shouldn't be any large memory penalty for
                    # repacking the data here.)
                    sYUnit = None;
                    if aoSeries[0].iUnit < len(constants.valueunit.g_asNames) and aoSeries[0].iUnit > 0:
                        sYUnit = constants.valueunit.g_asNames[aoSeries[0].iUnit];
                    oData = WuiHlpGraphDataTableEx(sXUnit = 'Build revision', sYUnit = sYUnit);

                    fSeriesName = self._figureSeriesNameBits(aoSeries);
                    for oSeries in aoSeries:
                        sSeriesName = self._getSeriesNameFromBits(oSeries, fSeriesName);
                        asHtmlTooltips = None;
                        if len(oSeries.aoRevInfo) == len(oSeries.aiRevisions):
                            asHtmlTooltips = [];
                            for i in range(len(oSeries.aoRevInfo)):
                                sPlusMinus = '';
                                if oSeries.acSamples[i] > 1:
                                    sPlusMinus = ' (+%s/-%s; %u samples)' \
                                               % ( utils.formatNumber(oSeries.aiErrorBarAbove[i]),
                                                   utils.formatNumber(oSeries.aiErrorBarBelow[i]),
                                                   oSeries.acSamples[i])
                                sTooltip = '<table class=\'graphwiz-tt\'><tr><td>%s:</td><td>%s %s %s</td></tr>'\
                                           '<tr><td>Rev:</td><td>r%s</td></tr>' \
                                         % ( sSeriesName,
                                             utils.formatNumber(oSeries.aiValues[i]),
                                             sYUnit, sPlusMinus,
                                             oSeries.aiRevisions[i],
                                             );
                                oRevInfo = oSeries.aoRevInfo[i];
                                if oRevInfo.sAuthor is not None:
                                    sMsg = oRevInfo.sMessage[:80].strip();
                                    #if sMsg.find('\n') >= 0:
                                    #    sMsg = sMsg[:sMsg.find('\n')].strip();
                                    sTooltip += '<tr><td>Author:</td><td>%s</td></tr>' \
                                                '<tr><td>Date:</td><td>%s</td><tr>' \
                                                '<tr><td>Message:</td><td>%s%s</td></tr>' \
                                              % ( oRevInfo.sAuthor,
                                                  self.formatTsShort(oRevInfo.tsCreated),
                                                  sMsg, '...' if len(oRevInfo.sMessage) > len(sMsg) else '');
                                sTooltip += '</table>';
                                asHtmlTooltips.append(sTooltip);
                        oData.addDataSeries(sSeriesName, oSeries.aiRevisions, oSeries.aiValues, asHtmlTooltips,
                                            oSeries.aiErrorBarBelow, oSeries.aiErrorBarAbove);
                    # Render the data into a graph.
                    oGraph = self.oGraphClass('tmgraph-%u' % (iGraph,), oData, self._oDisp);
                    self._configureGraph(oGraph);

                    oGraph.setTitle(self._calcGraphName(aoSeries[0], fSeriesName, sSampleName));
                    sHtml += '   <div class="graphwiz-graph" id="graphwiz-graph-%u">\n' % (iGraph,);
                    sHtml += oGraph.renderGraph();
                    sHtml += '\n   </div>\n';
                    iGraph += 1;

                #
                # Emit raw tabular data if requested.
                #
                if self._dParams[WuiMain.ksParamGraphWizTabular]:
                    sHtml += '   <div class="graphwiz-tab-div" id="graphwiz-tab-%u">\n' \
                             '    <table class="tmtable graphwiz-tab">\n' \
                           % (iCollection, );
                    for aoSeries in aaoSeries:
                        if aoSeries[0].iUnit < len(constants.valueunit.g_asNames) and aoSeries[0].iUnit > 0:
                            sUnit = constants.valueunit.g_asNames[aoSeries[0].iUnit];
                        else:
                            sUnit = str(aoSeries[0].iUnit);

                        for iSeries, oSeries in enumerate(aoSeries):
                            sColor = self.oGraphClass.calcSeriesColor(iSeries);

                            sHtml += '<thead class="tmheader">\n' \
                                     ' <tr class="graphwiz-tab graphwiz-tab-new-series-row">\n' \
                                     '  <th colspan="5"><span style="background-color:%s;">&nbsp;&nbsp;</span> %s</th>\n' \
                                     ' </tr>\n' \
                                     ' <tr class="graphwiz-tab graphwiz-tab-col-hdr-row">\n' \
                                     '  <th>Revision</th><th>Value (%s)</th><th>&Delta;max</th><th>&Delta;min</th>' \
                                     '<th>Samples</th>\n' \
                                     ' </tr>\n' \
                                     '</thead>\n' \
                                   % ( sColor,
                                       self._getSeriesNameFromBits(oSeries, self.kfSeriesName_All & ~self.kfSeriesName_OsArchs),
                                       sUnit );

                            for i in range(len(oSeries.aiRevisions)):
                                sHtml += '     <tr class="%s"><td>r%s</td><td>%s</td><td>+%s</td><td>-%s</td><td>%s</td></tr>\n' \
                                       % ( 'tmodd' if i & 1 else 'tmeven',
                                           oSeries.aiRevisions[i], oSeries.aiValues[i],
                                           oSeries.aiErrorBarAbove[i], oSeries.aiErrorBarBelow[i],
                                           oSeries.acSamples[i]);
                    sHtml += '    </table>\n' \
                             '   </div>\n';
            else:
                sHtml += '<i>No results.</i>\n';
            sHtml += '  </div>\n'
        sHtml += ' </div>\n';

        #
        # Finish the form.
        #
        if fInteractive:
            sHtml += sEndOfForm;

        return sHtml;