Skip to content

Instantly share code, notes, and snippets.

Created August 5, 2011 19:46
What would you like to do?
Format Mozilla's "Application" stats into usable columns.
"""Format Mozilla's "Application" stats into usable columns."""
import csv
import re
import sys
reader = csv.reader(open(sys.argv[1]))
writer = csv.writer(sys.stdout)
keys_in =[2:]
key_map = []
for key in keys_in:
key_orig = key
key = re.sub(r'({.*}|unknown)/?', '', key)
if re.match(r'\d\.\d(\.|a|b|pre|$)', key):
key = re.sub(r'^(\d\.\d).*', r'\1', key)
key = 'junk'
writer.writerow(['date'] + sorted(list(set(key_map))))
for record in reader:
tots = {}
for i, value in enumerate(record[2:]):
key = key_map[i]
tots.setdefault(key, 0)
tots[key] += int(value)
writer.writerow([record[0]] + [v for (k, v) in sorted(tots.items())])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment