public
Last active

  • Download Gist
amo-stats-analyze.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
#!/usr/bin/env python
 
import csv
import re
import sys
 
################################################################################
 
# Good reference: http://www.get-firefox.eu/default_025.html
app_ids={
'{136c295a-4a5a-41cf-bf24-5cee526720d5}': 'Nvu',
'{9b0e-13a3a9e97384}': 'Firefox', # Somebody's buggy submission
#'{b58db1ce-a21c-4fcd-abef-68f559f273d7}': '',
'{ec8030f7-c20a-464f-9b0e-13a3a9e96384}': 'Firefox', # Somebody's buggy submission
'{ec8030f7-c20a-4>4f-9b0e-13a3a9e97384}': 'Firefox', # Somebody's buggy submission
'ec8030f7-g20a-464f-9b0e-13a3a9e97384': 'Firefox', # Somebody's buggy submission
'{ee53ece0-255c-4cc6-8a7e-81a8b6e5ba2c}': 'Spicebird',
'songbird@songbirdnest.com': 'Songbird',
'prism@developer.mozilla.org': 'Prism',
'{a23983c0-fd0e-11dc-95ff-0800200c9a66}': 'Fennec',
'{3db10fab-e461-4c80-8b97-957ad5f8ea47}': 'Netscape',
'{718e30fb-e89b-41dd-9da7-e25a45638b28}': 'Sunbird',
'{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}': 'SeaMonkey',
'{3550f703-e582-4d05-9a08-453d09bdfdc6}': 'Thunderbird',
'{a463f10c-3994-11da-9945-000d60ca027b}': 'Flock',
'{ec8030f7-c20a-464f-9b0e-13a3a9e97384}': 'Firefox',
}
 
################################################################################
 
# Read from stdin.
statReader=csv.reader(sys.stdin)
 
# Find the column names.
while True:
cols=statReader.next()
if cols[0][0:8]=='# Fields':
# Extract just the column names from this line.
cols=cols[0][11:-1]
# And split!
cols=cols.split(';')
 
# Stop reading headers.
break
 
# Group the columns into buckets.
buckets=['x', 'x']
for col in cols[2:]:
try:
(app, version)=col.split('/', 2)
except ValueError:
(app, version)=('Unknown', '0')
# If we know what app this is, get its name instead of ID.
if app in app_ids:
app=app_ids[app]
else:
app='Unknown'
version='0'
 
# Trim the version
vnum=re.search('^(\d)(\.\d)?', version)
if vnum and vnum.group(1) and vnum.group(2):
version=vnum.group(1)+vnum.group(2)
else:
version='0'
 
# Super-bucket-ize.
if 'Firefox'==app:
if float(version)<1.0:
version='<1.0'
elif float(version)<2.0:
version='1.5'
elif float(version)<3.0:
version='2.0'
elif float(version)<3.5:
version='3.0'
else:
version='>3.5'
# elif 'Thunderbird'==app:
# if float(version)>=3.0:
# version='3.0'
# elif app in ['Flock', 'SeaMonkey', 'Songbird', 'Spicebird', 'Sunbird']:
# version='All'
elif 'Unknown'!=app:
# Super-super-bucket-ize.
app='Other'
 
bucket=app+'/'+version
if app in ['Other', 'Unknown']: bucket=app
 
buckets.append(bucket)
 
# Figure out the ordered set of headers to produce.
headers=list(set(buckets[3:]))
headers.sort()
headers=['date']+headers
 
# Print out these header names.
statWriter=csv.writer(sys.stdout)
statWriter.writerow(headers)
# Start a csvwriter to hold these columns.
statWriter=csv.DictWriter(sys.stdout, headers, restval='0')
 
for row in statReader:
data={'date':row[0]}
 
for i in range(3, len(row)):
data.setdefault(buckets[i], 0)
data[buckets[i]]+=int(row[i])
 
statWriter.writerow(data)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.