Skip to content

Commit

Permalink
Minor optimiztions
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Mar 24, 2021
1 parent 9e34b64 commit 52d1ad5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions enlighten/_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,15 @@ def _get_subcounters(self, elapsed, fields, bar_fields=True, force_float=False):
"""

subcounters = []
sub_count = 0

if not self._subcounters:
return subcounters

for num, subcounter in enumerate(self._subcounters, 1):

sub_count += subcounter.count

fields['count_%d' % num] = Float(subcounter.count) if force_float else subcounter.count

if self.total and bar_fields:
Expand Down Expand Up @@ -523,14 +529,12 @@ def _get_subcounters(self, elapsed, fields, bar_fields=True, force_float=False):
fields['eta_%d' % num] = u'?'

# Parent fields
if subcounters:
subcount = sum(sub[0].count for sub in subcounters)
fields['count_00'] = Float(subcount) if force_float else subcount
fields['count_0'] = fields['count'] - subcount
fields['count_00'] = Float(sub_count) if force_float else sub_count
fields['count_0'] = fields['count'] - sub_count

if bar_fields:
fields['percentage_00'] = percentage_00 = sum(sub[1] for sub in subcounters) * 100
fields['percentage_0'] = fields['percentage'] - percentage_00
if bar_fields:
fields['percentage_00'] = percentage_00 = sum(sub[1] for sub in subcounters) * 100
fields['percentage_0'] = fields['percentage'] - percentage_00

return subcounters

Expand Down

0 comments on commit 52d1ad5

Please sign in to comment.