Merge lp:~dholbach/ubuntu-review-overview/stats into lp:ubuntu-review-overview

Proposed by Daniel Holbach
Status: Merged
Merged at revision: 26
Proposed branch: lp:~dholbach/ubuntu-review-overview/stats
Merge into: lp:ubuntu-review-overview
Diff against target: 77 lines (+73/-0)
1 file modified
stats.py (+73/-0)
To merge this branch: bzr merge lp:~dholbach/ubuntu-review-overview/stats
Reviewer Review Type Date Requested Status
Nigel Babu (community) Approve
Review via email: mp+27233@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nigel Babu (nigelbabu) wrote :

Ack

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'stats.py'
2--- stats.py 1970-01-01 00:00:00 +0000
3+++ stats.py 2010-06-10 08:52:25 +0000
4@@ -0,0 +1,73 @@
5+#!/usr/bin/python
6+
7+import data
8+
9+import subprocess
10+import csv
11+import sys
12+import os
13+
14+def difference(a, b):
15+ if a>b:
16+ return "+"+str(a-b)
17+ else:
18+ return str(a-b)
19+
20+def assemble_report(stats, descriptions):
21+ report = ""
22+ for i in range(0, len(descriptions)-1):
23+ if len(stats) > 1:
24+ report += "%s: %s (%s)\n" % (descriptions[i], stats[-1][i], \
25+ difference(stats[-1][i], stats[-2][i]))
26+ else:
27+ report += "%s: %s\n" % (descriptions[i], stats[-1][i])
28+ if i == 1:
29+ report += "---\n"
30+ date = subprocess.Popen(["date", "-R"], stdout=subprocess.PIPE)
31+ report += """---
32+Last updated: %s
33+""" % date.communicate()[0].strip()
34+ return report
35+
36+def get_data(stats):
37+ launchpad = data.lp_login()
38+ ubuntu = launchpad.distributions['ubuntu']
39+ total_patches = data.get_count(ubuntu.searchTasks(has_patch=True, status=data.open_status))
40+ already_reviewed_patches = data.get_count(ubuntu.searchTasks(has_patch=True,
41+ status=data.open_status,
42+ tags=data.reviewed_tags,
43+ tags_combinator='Any'))
44+ numbers = [total_patches, already_reviewed_patches]
45+ descriptions = ["Total bugs with patches", "Reviewed patches"]
46+ for tag in data.reviewed_tags:
47+ numbers += [data.get_count(ubuntu.searchTasks(tags=tag))]
48+ descriptions += ["Bugs with '%s'" % tag]
49+ stats += [numbers]
50+ return (stats, descriptions)
51+
52+def main():
53+ stats = []
54+ stats_file = os.path.join(data.data_dir(), "stats.csv")
55+ if os.path.exists(stats_file):
56+ f = open(stats_file, "r")
57+ csv_reader = csv.reader(f)
58+ stats = [map(lambda a: int(a), row) for row in csv_reader]
59+ f.close()
60+ (stats, descriptions) = get_data(stats)
61+ if os.path.exists(stats_file):
62+ os.remove(stats_file)
63+ f = open(stats_file, "w")
64+ csv_writer = csv.writer(f)
65+ csv_writer.writerows(stats)
66+ f.close()
67+
68+ report = assemble_report(stats, descriptions)
69+ report_file = os.path.join(data.data_dir(), "report")
70+ if os.path.exists(report_file):
71+ os.remove(report_file)
72+ f = open(report_file, "w")
73+ f.write(report)
74+ f.close()
75+
76+if __name__ == "__main__":
77+ sys.exit(main())

Subscribers

People subscribed via source and target branches

to all changes: