Project

General

Profile

« Previous | Next » 

Revision 1616

exc.py: ExPercentTracker: Track iter_nums of Exceptions as well, to distinguish how many distinct iters had errors

View differences:

lib/exc.py
75 75
        ExTracker.__init__(self)
76 76
        self.iter_text = iter_text
77 77
        self.iter_ct = None
78
        self.err_iter_ct = None
79
        self.last_iter_num = None
78 80
    
79 81
    def add_iters(self, iter_ct):
80 82
        if self.iter_ct == None: self.iter_ct = 0
81 83
        self.iter_ct += iter_ct
82 84
    
85
    def track(self, e, iter_num=None, **format):
86
        if iter_num != None:
87
            if iter_num != self.last_iter_num: # a new iter produced an error
88
                if self.err_iter_ct == None: self.err_iter_ct = 0
89
                self.err_iter_ct += 1
90
                self.last_iter_num = iter_num
91
        ExTracker.track(self, e, **format)
92
    
83 93
    def msg(self):
84 94
        msg = ExTracker.msg(self)
85
        if self.iter_ct != None: msg += ('/'+format.int2str(self.iter_ct)+' '
86
            +self.iter_text+'(s) = '
87
            +format.to_percent(float(self.e_ct)/self.iter_ct))
95
        iter_text_plural = self.iter_text+'(s)'
96
        numerator = self.e_ct
97
        if self.err_iter_ct != None:
98
            msg += ' in '+format.int2str(self.err_iter_ct)+' '+iter_text_plural
99
            numerator = self.err_iter_ct
100
        if self.iter_ct != None:
101
            msg += ('/'+format.int2str(self.iter_ct)+' '+iter_text_plural+' = '
102
            +format.to_percent(float(numerator)/self.iter_ct))
88 103
        return msg

Also available in: Unified diff