Created
September 5, 2009 21:30
-
-
Save arantius/181519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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', | |
'[email protected]': 'Songbird', | |
'[email protected]': '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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment