Example #1
0
 def _generate_formatted_output(self):
     def output_percent(obj):
         f = None
         if type(obj) is withdelta:
             f = obj.delta
         if f is None:
             return self.delta_colw * ' '
         elif f != f:
             return (self.delta_colw - 3) * ' ' + 'n/a'
         elif f == 0.0:
             return (self.delta_colw - 1) * ' ' + '='
         else:
             as_string = '{:+0.1%}'.format(f)
             padding = ' ' * (self.delta_colw - len(as_string))
             if f > 0.05:
                 return padding + SimpleConsoleFormatter.FAIL + as_string + SimpleConsoleFormatter.ENDC
             elif f > 0.0:
                 return padding + SimpleConsoleFormatter.WARNING + as_string + SimpleConsoleFormatter.ENDC
             else:
                 return padding + SimpleConsoleFormatter.OKGREEN + as_string + SimpleConsoleFormatter.ENDC
     self._formatted_output = []
     for k in self.runs_group:
         self._formatted_output.append([SimpleConsoleFormatter.OKBLUE + k + SimpleConsoleFormatter.ENDC + ' ' * (self.key_colw - len(k))])
         if type(self.runs_group[k]) is list:
             self._formatted_output[-1].append(str(val_of(self.runs_group[k][0])))
             for val in self.runs_group[k][1:]:
                 self._formatted_output[-1] += [str(val_of(val)), output_percent(val)]
         else:
             self._formatted_output[-1].append(str(val_of(self.runs_group[k])))
Example #2
0
 def compute_value_len(self):
     """
     Stores the maximum length of the string representation of each value into
     `value_colw`. Retuns it.
     """
     for k in self.runs_group:
         if type(self.runs_group[k]) is list:
             new_max = max([len(str(val_of(obj))) for obj in self.runs_group[k]])
         else:
             new_max = len(str(val_of(self.runs_group[k])))
         if new_max > self.value_colw:
             self.value_colw = new_max
     return self.value_colw
Example #3
0
        def process_groups(groups, group_offset = 0):
            for n_group in xrange(0, len(groups)):
                runs_in_group = self._num_of_runs_in_group[n_group + group_offset]
                append(self.begin_group(loc.update(
                    n_group=n_group,
                    num_of_runs_in_group=runs_in_group
                )))
                for n_run in xrange(0, runs_in_group):
                    append(self.begin_row(loc.update(n_run=n_run)))
                    for n_col in xrange(0, len(self.header)):
                        # account for missing columns
                        col_name = self.header[n_col]
                        runs_in_cell = -1
                        value = None
                        delta = None
                        if col_name in groups[n_group]:
                            runs_in_cell = self._num_of_runs_in_cell[n_group][col_name]
                            if runs_in_cell > 0:
                                value = groups[n_group][col_name][n_run]
                            else:
                                value = groups[n_group][col_name]
                            delta = value.delta if isinstance(value, withdelta) else None
                            value = val_of(value)

                        append(self.begin_col(loc.update(
                            value=value,
                            delta=delta,
                            num_of_runs_in_cell=runs_in_cell,
                            col_has_delta=self.column_has_delta(col_name),
                            n_col=n_col,
                            col_name=col_name
                        )))
                        append(self.begin_value(loc.update(loc_in_cell=loc.LOC_IN_CELL_VALUE)))
                        append(self.process_value(loc))
                        append(self.end_value(loc))
                        append(self.begin_delta(loc.update(loc_in_cell=loc.LOC_IN_CELL_DELTA)))
                        append(self.process_delta(loc))
                        append(self.end_delta(loc))
                        append(self.end_col(loc.update(loc_in_cell=None)))

                    append(self.end_row(loc.update(
                        value=None,
                        delta=None,
                        num_of_runs_in_cell=-1,
                        col_has_delta=None,
                        n_col=-1,
                        col_name=None
                    )))
                append(self.end_group(loc.update(n_run=-1)))