VirtualBox

Ignore:
Timestamp:
Oct 24, 2022 7:55:06 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154259
Message:

ValKit/analysis: Kicked out old code.

Location:
trunk/src/VBox/ValidationKit/analysis
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/analysis/__init__.py

    r96407 r97271  
    3838"""
    3939__version__ = "$Revision$"
    40 __all__     = ["reader", "diff", "reporting"]
    4140
  • trunk/src/VBox/ValidationKit/analysis/reporting.py

    r97266 r97271  
    5959if sys.version_info[0] >= 3:
    6060    long = int;     # pylint: disable=redefined-builtin,invalid-name
    61 
    62 
    63 
    64 ##################################################################################################################################
    65 #   Old Carp                                                                                                                     #
    66 ##################################################################################################################################
    67 
    68 def tryAddThousandSeparators(sPotentialInterger):
    69     """ Apparently, python 3.0(/3.1) has(/will have) support for this..."""
    70     # Try convert the string/value to a long.
    71     try:
    72         lVal = long(sPotentialInterger);
    73         lVal = long(sPotentialInterger);
    74     except:
    75         return sPotentialInterger;
    76 
    77     # Convert it back to a string (paranoia) and build up the new string.
    78     sOld      = str(lVal);
    79     chSign    = '';
    80     if sOld[0] == '-':
    81         chSign = '-';
    82         sOld = sOld[1:];
    83     elif sPotentialInterger[0] == '+':
    84         chSign = '+';
    85     cchDigits = len(sOld);
    86     iDigit    = 0
    87     sNewVal   = '';
    88     while iDigit < cchDigits:
    89         if (iDigit % 3) == 0 and iDigit > 0:
    90             sNewVal = ' ' + sNewVal;
    91         sNewVal = sOld[cchDigits - iDigit - 1] + sNewVal;
    92         iDigit += 1;
    93     return chSign + sNewVal;
    94 
    95 
    96 class OldTable(object):
    97     """
    98     A table has a header as well as data rows, thus this class.
    99     """
    100     def __init__(self, oTest, fSplitDiff):
    101         self.aasRows  = [];
    102         self.asHeader = ['Test',];
    103         self.asUnits  = ['',];
    104         for oValue in oTest.aoValues:
    105             self.asHeader.append(oValue.sName);
    106             self.asUnits.append(oValue.sUnit);
    107         self.addRow(oTest, fSplitDiff);
    108 
    109     def addRow(self, oTest, fSplitDiff):
    110         """Adds a row."""
    111         asRow = [oTest.getFullName(),];
    112         for oValue in oTest.aoValues:
    113             asRow.append(oValue.sValue);
    114         if not fSplitDiff:
    115             self.aasRows.append(asRow);
    116         else:
    117             # Split cells into multiple rows on '|'. Omit the first column.
    118             iRow = 0;
    119             asThisRow = [asRow[0], ];
    120             fMoreTodo = True;
    121             while fMoreTodo:
    122                 for i in range(1, len(asRow)):
    123                     asSplit = asRow[i].split('|');
    124                     asThisRow.append(asSplit[0]);
    125                     asRow[i] = '|'.join(asSplit[1:])
    126                 self.aasRows.append(asThisRow);
    127 
    128                 # Done?
    129                 fMoreTodo = False;
    130                 for i in range(1, len(asRow)):
    131                     if len(asRow[i]):
    132                         fMoreTodo = True;
    133                 asThisRow = ['', ];
    134                 iRow += 1;
    135 
    136             # Readability hack: Add an extra row if there are diffs.
    137             if iRow > 1:
    138                 asRow[0] = '';
    139                 self.aasRows.append(asRow);
    140 
    141         return True;
    142 
    143     def hasTheSameHeadingAsTest(self, oTest):
    144         """ Checks if the test values has the same heading."""
    145         i = 1;
    146         for oValue in oTest.aoValues:
    147             if self.asHeader[i] != oValue.sName:
    148                 return False;
    149             if self.asUnits[i]  != oValue.sUnit:
    150                 return False;
    151             i += 1;
    152         return True;
    153 
    154     def hasTheSameHeadingAsTable(self, oTable):
    155         """ Checks if the other table has the same heading."""
    156         if len(oTable.asHeader) != len(self.asHeader):
    157             return False;
    158         for i, sHdr in enumerate(self.asHeader):
    159             if sHdr != oTable.asHeader[i]:
    160                 return False;
    161             if self.asUnits[i]  != oTable.asUnits[i]:
    162                 return False;
    163         return True;
    164 
    165     def appendTable(self, oTable):
    166         """ Append the rows in oTable.  oTable has the same heading as us. """
    167         self.aasRows.extend(oTable.aasRows);
    168         return True;
    169 
    170     # manipulation and stuff
    171 
    172     def optimizeUnits(self):
    173         """ Turns bytes into KB, MB or GB. """
    174         ## @todo
    175         return None;
    176 
    177     def addThousandSeparators(self):
    178         """ Adds thousand separators to make numbers more readable. """
    179         for asRow in self.aasRows:
    180             for iColumn in range(1, len(asRow)):
    181                 asValues = asRow[iColumn].split('|');
    182                 for i, sValue in enumerate(asValues):
    183                     asValues[i] = tryAddThousandSeparators(sValue);
    184                 asRow[iColumn] = '|'.join(asValues);
    185         return True;
    186 
    187     def getRowWidths(self):
    188         """Figure out the column withs."""
    189         # Header is first.
    190         acchColumns = [];
    191         for i, sHdr in enumerate(self.asHeader):
    192             cch = 1;
    193             if not isinstance(sHdr, str): print("dbg: %s" % (sHdr,));
    194             asWords = sHdr.split();
    195             for s in asWords:
    196                 if len(s) > cch:
    197                     cch = len(s);
    198             if i > 0 and len(self.asUnits[i]) > cch:
    199                 cch = len(self.asUnits[i]);
    200             acchColumns.append(cch);
    201 
    202         # Check out all cells.
    203         for asColumns in self.aasRows:
    204             for i, sCol in enumerate(asColumns):
    205                 if len(sCol) > acchColumns[i]:
    206                     acchColumns[i] = len(sCol);
    207         return acchColumns;
    208 
    209 def tabelizeTestResults(oTest, fSplitDiff):
    210     """
    211     Break the test results down into a list of tables containing the values.
    212 
    213     TODO: Handle passed / failed stuff too. Not important for benchmarks.
    214     """
    215     # Pass 1
    216     aoTables = [];
    217     aoStack  = [];
    218     aoStack.append((oTest, 0));
    219     while len(aoStack) > 0:
    220         oCurTest, iChild =  aoStack.pop();
    221 
    222         # depth first
    223         if iChild < len(oCurTest.aoChildren):
    224             aoStack.append((oCurTest, iChild + 1));
    225             aoStack.append((oCurTest.aoChildren[iChild], 0));
    226             continue;
    227 
    228         # values -> row
    229         if len(oCurTest.aoValues) > 0:
    230             if len(aoTables) > 0 and aoTables[len(aoTables) - 1].hasTheSameHeadingAsTest(oCurTest):
    231                 aoTables[len(aoTables) - 1].addRow(oCurTest, fSplitDiff);
    232             else:
    233                 aoTables.append(OldTable(oCurTest, fSplitDiff));
    234 
    235     # Pass 2 - Combine tables with the same heading.
    236     aoTables2 = [];
    237     for oTable in aoTables:
    238         for oTable2 in aoTables2:
    239             if oTable2.hasTheSameHeadingAsTable(oTable):
    240                 oTable2.appendTable(oTable);
    241                 oTable = None;
    242                 break;
    243         if oTable is not None:
    244             aoTables2.append(oTable);
    245 
    246     return aoTables2;
    247 
    248 
    249 def produceHtmlReport(oTest):
    250     """
    251     Produce an HTML report on stdout (via print).
    252     """
    253     print('not implemented: %s' % (oTest));
    254     return False;
    255 
    256 
    257 def produceReStructuredTextReport(oTest):
    258     """
    259     Produce a ReStructured text report on stdout (via print).
    260     """
    261     print('not implemented: %s' % (oTest));
    262     return False;
    263 
    264 
    265 def produceTextReport(oTest):
    266     """
    267     Produce a text report on stdout (via print).
    268     """
    269 
    270     #
    271     # Report header.
    272     #
    273     ## @todo later
    274 
    275     #
    276     # Tabelize the results and display the tables.
    277     #
    278     aoTables = tabelizeTestResults(oTest, True)
    279     for oTable in aoTables:
    280         ## @todo do max/min on the columns where we can do [GMK]B(/s).
    281         oTable.addThousandSeparators();
    282         acchColumns = oTable.getRowWidths();
    283 
    284         # The header.
    285         # This is a bit tedious and the solution isn't entirely elegant due
    286         # to the pick-it-up-as-you-go-along python skills.
    287         aasHeader = [];
    288         aasHeader.append([]);
    289         for i in range(len(oTable.asHeader)):
    290             aasHeader[0].append('');
    291 
    292         for iColumn, _ in enumerate(oTable.asHeader):
    293             asWords = oTable.asHeader[iColumn].split();
    294             iLine   = 0;
    295             for s in asWords:
    296                 if len(aasHeader[iLine][iColumn]) <= 0:
    297                     aasHeader[iLine][iColumn] = s;
    298                 elif len(s) + 1 + len(aasHeader[iLine][iColumn]) <= acchColumns[iColumn]:
    299                     aasHeader[iLine][iColumn] += ' ' + s;
    300                 else:
    301                     iLine += 1;
    302                     if iLine >= len(aasHeader):  # There must be a better way to do this...
    303                         aasHeader.append([]);
    304                         for i in range(len(oTable.asHeader)):
    305                             aasHeader[iLine].append('');
    306                     aasHeader[iLine][iColumn] = s;
    307 
    308         for asLine in aasHeader:
    309             sLine = '';
    310             for i,_ in enumerate(asLine):
    311                 if i > 0: sLine += '  ';
    312                 sLine += asLine[i].center(acchColumns[i]);
    313             print(sLine);
    314 
    315         # Units.
    316         sLine = '';
    317         for i,_ in enumerate(oTable.asUnits):
    318             if i > 0: sLine += '  ';
    319             sLine += oTable.asUnits[i].center(acchColumns[i]);
    320         print(sLine);
    321 
    322         # Separator line.
    323         sLine = '';
    324         for i in range(len(oTable.asHeader)):
    325             if i > 0: sLine += '  '
    326             sLine += '=' * acchColumns[i];
    327         print(sLine);
    328 
    329         # The rows.
    330         for asColumns in oTable.aasRows:
    331             sText = asColumns[0].ljust(acchColumns[0]);
    332             for i in range(1, len(asColumns)):
    333                 sText += '  ' + asColumns[i].rjust(acchColumns[i]);
    334             print(sText);
    335 
    336     return None;
    337 
    33861
    33962
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette