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

Subscribers

People subscribed via source and target branches

to all changes: