|
| 1 | +#! /usr/bin/env python2.3 |
| 2 | + |
| 3 | +# This script generates a simple report outlining the activity in one |
| 4 | +# tracker for the most recent week. |
| 5 | + |
| 6 | +# This script is free software, you may redistribute it |
| 7 | +# and/or modify under the same terms as Python. |
| 8 | + |
| 9 | +import sys, math |
| 10 | +from roundup import instance, date |
| 11 | + |
| 12 | +# open the instance |
| 13 | +if len(sys.argv) != 2: |
| 14 | + print 'You need to specify an instance home dir' |
| 15 | +instance_home = sys.argv[1] |
| 16 | +instance = instance.open(instance_home) |
| 17 | +db = instance.open('admin') |
| 18 | + |
| 19 | +old = date.Date('-1w') |
| 20 | + |
| 21 | +created = [] |
| 22 | +summary = {} |
| 23 | +messages = [] |
| 24 | + |
| 25 | +# loop through all the recently-active issues |
| 26 | +for issue_id in db.issue.filter(None, {'activity': '-1w;'}): |
| 27 | + num = 0 |
| 28 | + for x,ts,userid,action,data in db.issue.history(issue_id): |
| 29 | + if ts < old: continue |
| 30 | + if action == 'create': |
| 31 | + created.append(issue_id) |
| 32 | + elif action == 'set' and data.has_key('messages'): |
| 33 | + num += 1 |
| 34 | + summary.setdefault(db.issue.get(issue_id, 'status'), []).append(issue_id) |
| 35 | + messages.append((num, issue_id)) |
| 36 | + |
| 37 | +#print 'STATUS SUMMARY:' |
| 38 | +#for k,v in summary.items(): |
| 39 | +# print k, len(v) |
| 40 | + |
| 41 | +print '\nCREATED:' |
| 42 | +print '\n'.join(['%s: %s'%(id, db.issue.get(id, 'title')) |
| 43 | + for id in created]) |
| 44 | + |
| 45 | +print '\nRESOLVED:' |
| 46 | +resolved_id = db.status.lookup('resolved') |
| 47 | +print '\n'.join(['%s: %s'%(id, db.issue.get(id, 'title')) |
| 48 | + for id in summary.get(resolved_id, [])]) |
| 49 | + |
| 50 | +print '\nTOP TEN MOST DISCUSSED:' |
| 51 | +messages.sort() |
| 52 | +messages.reverse() |
| 53 | +nmax = messages[0][0] |
| 54 | +fmt = '%%%dd - %%s: %%s'%(int(math.log(nmax, 10)) + 1) |
| 55 | +print '\n'.join([fmt%(num, id, db.issue.get(id, 'title')) |
| 56 | + for num, id in messages[:10]]) |
| 57 | + |
| 58 | +# vim: set filetype=python ts=4 sw=4 et si |
0 commit comments