示例#1
0
    def write(self, max_in_distrib=None):
        'It writes some basic stats of the values'
        if self.count != 0:
            labels = self.labels
            # now we write some basic stats
            format_num = lambda x: '{:,d}'.format(x) if isinstance(
                x, int) else '%.2f' % x
            text = '{}: {}\n'.format(labels['minimum'], format_num(self.min))
            text += '{}: {}\n'.format(labels['maximum'], format_num(self.max))
            text += '{}: {}\n'.format(labels['average'],
                                      format_num(self.average))

            if labels['variance'] is not None:
                text += '{}: {}\n'.format(labels['variance'],
                                          format_num(self.variance))
            if labels['sum'] is not None:
                text += '{}: {}\n'.format(labels['sum'], format_num(self.sum))
            if labels['items'] is not None:
                text += '{}: {}\n'.format(labels['items'], self.count)
            text += '\n'
            distrib = self.calculate_distribution(max_=max_in_distrib,
                                                  bins=self._bins)
            text += draw_histogram_ascii(distrib['bin_limits'],
                                         distrib['counts'])
            return text
        return ''
示例#2
0
    def write(self, max_in_distrib=None):
        'It writes some basic stats of the values'
        if self.count != 0:
            labels = self.labels
            # now we write some basic stats
            format_num = lambda x: '{:,d}'.format(x) if isinstance(x, int) else '%.2f' % x
            text = '{}: {}\n'.format(labels['minimum'], format_num(self.min))
            text += '{}: {}\n'.format(labels['maximum'], format_num(self.max))
            text += '{}: {}\n'.format(labels['average'],
                                      format_num(self.average))

            if labels['variance'] is not None:
                text += '{}: {}\n'.format(labels['variance'],
                                          format_num(self.variance))
            if labels['sum'] is not None:
                text += '{}: {}\n'.format(labels['sum'],
                                          format_num(self.sum))
            if labels['items'] is not None:
                text += '{}: {}\n'.format(labels['items'], self.count)
            text += '\n'
            distrib = self.calculate_distribution(max_=max_in_distrib,
                                                  bins=self._bins)
            text += draw_histogram_ascii(distrib['bin_limits'], distrib['counts'])
            return text
        return ''
示例#3
0
 def test_ascii_histogram(self):
     'It plots an ASCII histogram'
     hist = draw_histogram_ascii(bin_limits=[-2, -1, 0, 1, 2],
                                 counts=[9, 20, 30, 40])
     assert '[-2 , -1[ ( 9): ****************' in hist
示例#4
0
 def test_ascii_histogram(self):
     'It plots an ASCII histogram'
     hist = draw_histogram_ascii(bin_limits=[-2, -1, 0, 1, 2],
                                 counts=[9, 20, 30, 40])
     assert '[-2 , -1[ ( 9): ****************' in hist