-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloc_viz.py
40 lines (36 loc) · 1.22 KB
/
loc_viz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Uses https://github.com/cgag/loc to find file-wise LOC for code-bases
import subprocess
import shlex
import os
import sys
import matplotlib.pyplot as plt
from common import get_base_dir, get_projects_to_scan
def filewise_loc_for_project(locPath, base, project):
os.chdir(os.path.join(base, project))
#TODO: Use temp file module
f = open(r'metrics.txt','w')
subprocess.check_call([locPath,
'--files', '--include', 'java$', '--exclude' ,'test'], stdout=f)
f.close()
with open('metrics.txt') as f:
lines = f.read().splitlines()
return list(map(lambda x: int(x.split()[-1]) ,lines[6:]))
def main():
base_dir = get_base_dir()
wd = os.getcwd()
os.chdir(base_dir)
try:
projects = get_projects_to_scan(base_dir)
all_project_locs = [filewise_loc_for_project(f"{os.path.join(wd, 'loc')}",
base_dir, x) for x in projects]
_, ax = plt.subplots()
ax.set_title('File-wise LOC distribution across projects')
ax.boxplot(all_project_locs)
ax.set_xticklabels(projects)
plt.show()
except:
_, value, _ = sys.exc_info()
print('Error %s: %s' % (value.filename, value.strerror))
finally:
os.chdir(wd)
main()