Created
February 26, 2013 15:51
-
-
Save clarete/2ab8eb23e84f153ca1f2 to your computer and use it in GitHub Desktop.
Generates charts about the split test data collected by the script collectsplitdata.py
This file contains 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
import json | |
import pygal | |
# Parsing the json file | |
content = json.load(open('split.json')) | |
# App app names | |
app_names = list({x['what'] for x in content['app']}) | |
# All file names | |
file_names = list({x['what'] for x in content['files']}) | |
# Returns how many times a certain file appears in the file or in the | |
# app list | |
get_num_changes = \ | |
lambda k, f: len([x for x in content[k] if x['what'] == f]) | |
def is_invalid(label): | |
return ((label is None) or | |
('split' in label) or | |
('migrations' in label) or | |
('util/switches.py' in label)) | |
# Time to gen some nice charts | |
def changes(kind, labels, opts=None): | |
# Reading parameters | |
opts = opts or {} | |
limit = opts.get('limit', -1) | |
sortfunc = opts.get('sortfunc') | |
reverse = opts.get('reverse', False) | |
# Gathering all data, cause we need to sort it | |
data = [(item, get_num_changes(kind, item)) for item in labels | |
if not is_invalid(item)] | |
data.sort(key=sortfunc, reverse=reverse) | |
# Limitting data according to the caller's request | |
if limit > 0: | |
data = data[:limit] | |
# Translating the data to the format expected by matplotlib | |
chart = pygal.HorizontalBar(truncate_legend=35) | |
for label, num_changes in data: | |
if kind == 'files': | |
label = '/'.join(label.split('/')[-2:]) | |
chart.add(label, float(num_changes)) | |
chart.render_to_file('split-per-{}.svg'.format(kind)) | |
def files_per_change(): | |
# Preparing the data | |
commits = {} | |
for file_ in content['files']: | |
commits[file_['hash']] = commits.get(file_['hash'], -1) + 1 | |
commits = sorted(commits.items(), key=lambda x: x[1], reverse=True) | |
commits = commits[:10] | |
# Creating the chart | |
chart = pygal.HorizontalBar() | |
for commit, num_files in commits: | |
chart.add(commit, num_files) | |
chart.render_to_file('split-per-changes.svg') | |
if __name__ == '__main__': | |
changes('app', app_names, { | |
'sortfunc': lambda x: x[1], | |
'limit': 5, | |
'reverse': True, | |
}) | |
changes('files', file_names, { | |
'sortfunc': lambda x: x[1], | |
'limit': 10, | |
'reverse': True, | |
}) | |
files_per_change() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment