]> git.donarmstrong.com Git - neurodebian.git/blob - tools/nd_popcon2stats
Also for stats report which repo and which job number use our setup
[neurodebian.git] / tools / nd_popcon2stats
1 #!/usr/bin/python
2 # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3 # vi: set ft=python sts=4 ts=4 sw=4 et:
4 #
5 import fileinput
6 import sys
7 import time
8 from datetime import datetime
9 import re
10 import json
11 import operator
12
13
14 releases = {
15     'etch': 'Debian GNU/Linux 4.0 (etch)',
16     'lenny': 'Debian GNU/Linux 5.0 (lenny)',
17     'squeeze': 'Debian GNU/Linux 6.0 (squeeze)',
18     'wheezy': 'Debian GNU/Linux 7.0 (wheezy)',
19     'jessie': 'Debian testing (jessie)',
20     'sid': 'Debian unstable (sid)',
21     'hardy': 'Ubuntu 08.04 LTS "Hardy Heron" (hardy)',
22     'jaunty': 'Ubuntu 09.04 "Jaunty Jackalope" (jaunty)',
23     'karmic': 'Ubuntu 09.10 "Karmic Koala" (karmic)',
24     'lucid': 'Ubuntu 10.04 LTS "Lucid Lynx" (lucid)',
25     'maverick': 'Ubuntu 10.10 "Maverick Meerkat" (maverick)',
26     'natty': 'Ubuntu 11.04 "Natty Narwhal" (natty)',
27     'oneiric': 'Ubuntu 11.10 "Oneiric Ocelot" (oneiric)',
28     'precise': 'Ubuntu 12.04 LTS "Precise Pangolin" (precise)',
29     'quantal': 'Ubuntu 12.10 "Quantal Quetzal" (quantal)',
30     'raring': 'Ubuntu 13.04 "Raring Ringtail" (raring)',
31     'saucy': 'Ubuntu 13.10 "Saucy Salamander" (saucy)',
32     'trusty': 'Ubuntu 14.04 LTS "Trusty Tahr" (trusty)',
33 }
34
35 def error(msg):
36     sys.stderr.write('E: %s\n' % msg)
37
38 def info(msg):
39     # print nothing ATM
40     # sys.stderr.write("I: %s\n" % msg)
41     pass
42
43 file_regex = re.compile('.*popcon-(\d{4}-\d{1,2}-\d{1,2})(|.gz)')
44
45 def read_popcon_stats(filename, read_packages=True):
46     info("Reading %s" % filename)
47     entry = dict(submissions = None,
48                  package = {},
49                  release = {},
50                  architecture = {},
51                  vendor = {})
52
53     for line in fileinput.FileInput(filename, openhook=fileinput.hook_compressed):
54         key, values = [x.strip().lower() for x in line.split(':', 1)]
55         if key == 'package':          # most probable
56             if not read_packages:
57                 break
58             try:
59                 pkg, vote, old, recent, nofiles = values.split()
60             except ValueError:
61                 raise ValueError("Failed to split %s" % values)
62             entry[key][pkg] = tuple(int(x) for x in (vote, old, recent, nofiles))
63         elif key in ('release', 'architecture', 'vendor'):
64             kvalue, value = values.split()
65             entry[key][kvalue] = int(value)
66         elif key == 'submissions':
67             entry[key] = int(values)
68         else:
69             raise ValueError("Do not know how to handle line %r" % line)
70     return entry
71
72 if __name__ == '__main__':
73     data = {}
74
75     popcon_versions = {}
76     timestamps = set()
77
78     for f in sys.argv[1:]:
79         file_reg = file_regex.match(f)
80         if not file_reg:
81             error("Failed to recognize filename %s" % f)
82             continue
83
84         date = time.strptime(file_reg.groups()[0], '%Y-%m-%d')
85         entry = read_popcon_stats(f, read_packages=False)
86
87         date_int = int(time.mktime(date)*1000)
88         # Let's coarsen a bit -- to a week which makes sense anyways
89         # since popcon submissions are spread over a week for balanced
90         # load
91         coarsen_days = 7
92         coarsen = coarsen_days*24*3600*1000
93         # coarsen and place marker at the end of the duration
94         # but not later than today
95         date_int = min((date_int//coarsen + 1)*coarsen,
96                        time.time()*1000)
97         for version, count in entry['release'].iteritems():
98             if not version in popcon_versions:
99                 popcon_versions[version] = {}
100             popcon_ = popcon_versions[version]
101             popcon_[date_int] = count + popcon_.get(date_int, 0)
102             timestamps.add(date_int)
103
104     versions = sorted([x for x in popcon_versions.keys() if not 'ubuntu' in x]) + \
105                sorted([x for x in popcon_versions.keys() if     'ubuntu' in x])
106
107     # we need to make sure that for every date we have an entry for
108     # every version, otherwise d3 pukes because of ... d3.v2.js:expand
109     export = [{'key': k,
110                'values': [[date, popcon_versions[k].get(date, 0)/coarsen_days]
111                           for date in sorted(list(timestamps))]}
112               for k in versions]
113     print json.dumps(export)
114