Skip to content

@arantius /format-app.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Format Mozilla's "Application" stats into usable columns.
#!/usr/bin/env/python
"""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 = reader.next()[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)
else:
key = 'junk'
key_map.append(key)
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
Something went wrong with that request. Please try again.