Ignore:
Timestamp:
Mar 16, 2012, 5:49:17 AM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage
Children:
b2cee30
Parents:
9a30b56
git-author:
Alex Dehnert <adehnert@…> (03/16/12 05:49:17)
git-committer:
Alex Dehnert <adehnert@…> (03/16/12 05:49:17)
Message:

Better summaries of groups/diffs.py operation

  • Nice table of changes in email, instead of printing the dicts directly
  • Display all signatory types, not just those ignored, in the script terminal output
  • Accurate counts of changed signatories listed (was listing number of lines)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/diffs.py

    r9a30b56 r8254020  
    6262            'Expired': collections.defaultdict(lambda: 0),
    6363        }
     64        self.signatory_types_seen = set()
    6465        self.since = since
    6566        self.now = now
    66         self.stats = collections.defaultdict(lambda: 0)
    6767
    6868    def handle_group(self, before, after, before_fields, after_fields, ):
     
    8686            counter = self.signatory_type_counts[change_type]
    8787            counter[signatory.role.slug] += 1
     88            self.signatory_types_seen.add(signatory.role.slug)
    8889            if signatory.role.slug in self.interesting_signatories:
    8990                if signatory.group != prev_group:
     
    100101                prev_group = signatory.group
    101102            else:
    102                 self.stats["role." + signatory.role.slug] += 1
     103                pass
    103104                #print "Ignoring role %s (signatory %s)" % (signatory.role.slug, signatory, )
    104105
     106    def build_change_stats(self, ):
     107        lines = []
     108        care_about = 0
     109
     110        line = "%20s" % ("", )
     111        change_types = self.signatory_type_counts.keys()
     112        for change_type in change_types:
     113            line += "\t%s" % (change_type, )
     114        lines.append(line); line = ""
     115
     116        for sig_type in self.signatory_types_seen:
     117            line += "%20s" % (sig_type, )
     118            for change_type in change_types:
     119                if sig_type in self.signatory_type_counts[change_type]:
     120                    count = self.signatory_type_counts[change_type][sig_type]
     121                else:
     122                    count = 0
     123                if sig_type in self.interesting_signatories:
     124                    care_about += count
     125                out = "\t%4d" % (count, )
     126                line += out
     127            lines.append(line); line = ""
     128
     129        return "\n".join(lines), care_about
     130
    105131    def end_run(self, ):
     132        change_stats, care_about = self.build_change_stats()
    106133        print "\nChange stats for email to %s:" % (self.address, )
    107         for stat_key, stat_val in self.stats.items():
    108             print "%20s:\t%6d" % (stat_key, stat_val, )
    109         print ""
     134        print change_stats
    110135
    111136        message = "\n\n".join(self.updates)
     
    119144            'num_groups': len(self.updates),
    120145            'groups_message': message,
    121             'num_signatory_records': len(self.signatory_updates),
     146            'care_about': care_about,
     147            'change_stats': change_stats,
    122148            'signatory_types': self.interesting_signatories,
    123             'signatory_type_counts': self.signatory_type_counts,
    124149            'signatories_message': signatories_message,
    125150        })
Note: See TracChangeset for help on using the changeset viewer.