示例#1
0
    def to_table(self, with_zeroes=False):
        data = self._get_stats_values()
        sec_count = len(self.sections)

        # init table
        stats_table = text_tables.TRexTextTable('Traffic stats')
        stats_table.set_cols_align(["r"] * (1 + sec_count) + ["l"])
        stats_table.set_cols_width([self._max_desc_name_len] +
                                   [17] * sec_count +
                                   [self._max_desc_name_len])
        stats_table.set_cols_dtype(['t'] * (2 + sec_count))
        header = [''] + self.sections + ['']
        stats_table.header(header)

        for desc in self._desc:
            if desc['real']:
                vals = [data[section][desc['id']] for section in self.sections]
                if not (with_zeroes or desc['zero'] or any(vals)):
                    continue
                if desc['info'] == 'error':
                    vals = [red(v) if v else green(v) for v in vals]
                if desc['units']:
                    vals = [format_num(v, suffix=desc['units']) for v in vals]

                stats_table.add_row([desc['name']] + vals + [desc['help']])
            else:
                stats_table.add_row([desc['name']] + [''] * (1 + sec_count))

        return stats_table
示例#2
0
    def to_table(self,
                 with_zeroes=False,
                 tgid=0,
                 pid_input=DEFAULT_PROFILE_ID,
                 is_sum=False):
        self._get_tg_names(pid_input)
        num_of_tgids = len(self.tg_names_dict[pid_input]['tg_names'])
        title = ""
        data = {}
        if tgid == 0:
            data = self._get_stats_values(pid_input=pid_input, is_sum=is_sum)
            if is_sum:
                title = 'Traffic stats summary.'
            else:
                title = 'Traffic stats of Profile ID : ' + pid_input + '. Number of template groups = ' + str(
                    num_of_tgids)
        else:
            if not 1 <= tgid <= num_of_tgids:
                raise ASTFErrorBadTG('Invalid tgid in to_table')
            else:
                name = self.tg_names_dict[pid_input]['tg_names'][tgid - 1]
                title = 'Profile ID : ' + pid_input + '. Template Group Name: ' + name + '. Number of template groups = ' + str(
                    num_of_tgids)
                data = self.get_traffic_tg_stats(tg_names=name,
                                                 for_table=True,
                                                 pid_input=pid_input)
        sec_count = len(self.sections)

        # init table
        stats_table = text_tables.TRexTextTable(title)
        stats_table.set_cols_align(["r"] * (1 + sec_count) + ["l"])
        stats_table.set_cols_width([self._max_desc_name_len] +
                                   [17] * sec_count +
                                   [self._max_desc_name_len])
        stats_table.set_cols_dtype(['t'] * (2 + sec_count))
        header = [''] + self.sections + ['']
        stats_table.header(header)

        for desc in self._desc:
            if desc['real']:
                vals = [data[section][desc['id']] for section in self.sections]
                if not (with_zeroes or desc['zero'] or any(vals)):
                    continue
                if desc['info'] == 'error':
                    vals = [red(v) if v else green(v) for v in vals]
                if desc['units']:
                    vals = [format_num(v, suffix=desc['units']) for v in vals]

                stats_table.add_row([desc['name']] + vals + [desc['help']])
            else:
                stats_table.add_row([desc['name']] + [''] * (1 + sec_count))

        return stats_table