Skip to content

Instantly share code, notes, and snippets.

@matthew-brett
Created May 10, 2014 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthew-brett/c58e752bee7deea6ce56 to your computer and use it in GitHub Desktop.
Save matthew-brett/c58e752bee7deea6ce56 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
""" Detect Windows versions in crash reports
Runs on *pub-crashdata.csv.gz files from:
https://crash-analysis.mozilla.com/crash_analysis
"""
from __future__ import division, print_function
import sys
import gzip
import csv
import collections
# Simplified from:
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
NT_VERSIONS = {
'6.3': '8',
'6.2': '8',
'6.1': '7',
'6.0': 'Vista',
'5.2': 'XP',
'5.1': 'XP',
'5.0': '2000'}
ORDERED_VERSIONS = ['8',
'7',
'Vista',
'XP',
'2000']
def read_file(fname):
with gzip.open(fname, 'rt') as fobj:
reader = csv.DictReader(fobj, dialect=csv.excel_tab)
rows = list(reader)
return rows
def windows_version(row):
if not row['os_name'] == 'Windows NT':
return None
maj_min = '.'.join(row['os_version'].split('.', 2)[:2])
return NT_VERSIONS.get(maj_min)
def version_percents(rows):
versions = [windows_version(row) for row in rows]
good_versions = [v for v in versions if not v is None]
scalar = 100. / len(good_versions)
counts = collections.Counter(good_versions)
return dict((key, value * scalar) for key, value in counts.items())
def main():
for fname in sys.argv[1:]:
rows = read_file(fname)
pcts = version_percents(rows)
print(fname, ':')
for ver in ORDERED_VERSIONS:
print(' {0:<6}: {1:8.2f}'.format(ver, pcts.get(ver, 0)))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment