Skip to content

Commit

Permalink
calculate sums and create plots
Browse files Browse the repository at this point in the history
  • Loading branch information
yaph committed Sep 15, 2013
1 parent 529d9fd commit d1dd2da
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
63 changes: 56 additions & 7 deletions aggregate.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,70 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from glob import glob
from os.path import abspath, dirname, join
import os

root_dir = dirname(abspath(__file__))
data_dir = join(root_dir, 'data')
import pandas as pd
import matplotlib.pyplot as plt

from collections import defaultdict
from glob import glob


root_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(root_dir, 'data')
reports = glob(data_dir + '/*.json')

stats = {}
metrics = (
'Sum Physical SLOC',
'Sum Logical SLOC',
'Sum files',
'Sum functions',
'Mean Maintainability index',
'Mean parameter count',
#'Mean cyclomatic complexity',
#'Mean Halstead difficulty',
#'Mean Halstead volume',
#'Mean Halstead effort',
#'Mean functions per file',
)

stats = defaultdict(dict)
stats.fromkeys(metrics)


for report in reports:
project = os.path.splitext(os.path.basename(report))[0]
with open(report, 'r') as f:
project_files = json.load(f)
stats['Sum files'][project] = len(project_files)
for project_file in project_files:
stats[project] = stats.get(project, 0) + project_file['aggregate']['complexity']['sloc']['logical']
stats['Sum Logical SLOC'][project] = stats['Sum Logical SLOC'].get(project, 0) + project_file['aggregate']['complexity']['sloc']['logical']
stats['Sum Physical SLOC'][project] = stats['Sum Physical SLOC'].get(project, 0) + project_file['aggregate']['complexity']['sloc']['physical']
stats['Mean Maintainability index'][project] = stats['Mean Maintainability index'].get(project, 0) + project_file['maintainability']
stats['Mean parameter count'][project] = stats['Mean parameter count'].get(project, 0) + project_file['params']
stats['Sum functions'][project] = stats['Sum functions'].get(project, 0) + len(project_file['functions'])


#print [(k, v) for k, v in sorted(stats['Sum files'].items(), key=lambda x: x[1], reverse=True)]
for metric in stats:
values = list(stats[metric].values())
if metric in ['Mean Maintainability index', 'Mean parameter count']:
try:
counts = list(stats['Sum files'].values())
except:
continue
values = [v / counts[i] for i, v in enumerate(values)]
stats[metric] = pd.Series(values, index=list(stats[metric].keys()))

df = pd.DataFrame(stats)

for metric in stats:
df = df.sort(metric, ascending=True)
fig = plt.figure()

axes = plt.Axes(fig, [.2,.1,.7,.8]) # [left, bottom, width, height]
fig.add_axes(axes)

print [(k, v) for k, v in sorted(stats.items(), key=lambda x: x[1], reverse=True)]
#plt.margins = 1000
df[metric].plot(kind='barh', title=metric, alpha=0.7)
plt.savefig('images/' + metric.replace(' ', '-'))
Binary file added images/Mean-Maintainability-index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Mean-parameter-count.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Sum-Logical-SLOC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Sum-Physical-SLOC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Sum-files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Sum-functions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d1dd2da

Please sign in to comment.