]> git.donarmstrong.com Git - neurodebian.git/blob - tools/nd_apachelogs2subscriptionstats
Also for stats report which repo and which job number use our setup
[neurodebian.git] / tools / nd_apachelogs2subscriptionstats
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 "Trusty Tahr" (trusty)',
33 }
34
35
36 if __name__ == '__main__':
37     data = {}
38     # get the IP, date and target release
39     # the date is truncated to a month/year combo
40     listget = re.compile(r'^([0-9.:]*) .*\[([^:]*).*GET /lists/([a-z]*)')
41     for line in fileinput.FileInput(openhook=fileinput.hook_compressed):
42         match = listget.match(line)
43         if not match:
44             continue
45         addr, date, release = match.groups()
46         if not release in releases:
47             # ignore fantasy names
48             continue
49         date = datetime.strptime(date, '%d/%b/%Y')
50         # truncate to a week
51         try:
52             date = datetime(date.year, date.month, date.day / 7 * 7 + 1)
53         except ValueError:
54             # only on Feb28...
55             date = datetime(date.year, date.month, date.day / 7 * 7)
56         # microseconds since epoch
57         date = int(time.mktime(date.timetuple()) * 1000)
58         rstats = data.setdefault(releases[release], {})
59         rtime = rstats.setdefault(date, 0)
60         rtime += 1
61         rstats[date] = rtime
62         data[releases[release]] = rstats
63     # determine the union of all timestamps
64     timestamps = set()
65     for codename, stats in data.iteritems():
66         timestamps.update(stats.keys())
67     export = [{'key': release,
68                'values': [[ts, float(data[release].setdefault(ts, 0)) / 7]
69                         for ts in sorted(timestamps)]}
70                                     for release in sorted(data)]
71     print json.dumps(export)