Ajout script mise a jour de tracker
[auf_roundup.git] / scripts / weekly-report
CommitLineData
c638d827
CR
1#! /usr/bin/env python
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
9import sys, math
10from roundup import instance, date
11
12# open the instance
13if len(sys.argv) != 2:
14 print 'You need to specify an instance home dir'
15instance_home = sys.argv[1]
16instance = instance.open(instance_home)
17db = instance.open('admin')
18
19old = date.Date('-1w')
20
21created = []
22summary = {}
23messages = []
24
25# loop through all the recently-active issues
26for 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
41print '\nCREATED:'
42print '\n'.join(['%s: %s'%(id, db.issue.get(id, 'title'))
43 for id in created])
44
45print '\nRESOLVED:'
46resolved_id = db.status.lookup('resolved')
47print '\n'.join(['%s: %s'%(id, db.issue.get(id, 'title'))
48 for id in summary.get(resolved_id, [])])
49
50print '\nTOP TEN MOST DISCUSSED:'
51messages.sort()
52messages.reverse()
53nmax = messages[0][0]
54fmt = '%%%dd - %%s: %%s'%(int(math.log(nmax, 10)) + 1)
55print '\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