-
Notifications
You must be signed in to change notification settings - Fork 1
/
lizardmap.py
65 lines (50 loc) · 1.46 KB
/
lizardmap.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import plotly.graph_objects as go
import lizard
import os
import sys
import statistics
from tqdm import *
def plot(nlocs, files, parents, ccns):
fig = go.Figure(go.Treemap(
labels = files,
values = nlocs,
parents = parents,
marker=dict(
colors=ccns,
colorscale='blues',
cmid=statistics.mean(ccns)),
))
fig.show()
def calc_cc(file_name):
tmp = lizard.analyze_file(file_name)
nloc = tmp.nloc
ccs = []
for i in range(len(tmp.function_list)):
ccs.append(tmp.function_list[i].cyclomatic_complexity)
if not ccs:
return nloc, 0
return nloc , statistics.mean(ccs)
def main():
startpath = sys.argv[1]
nlocs = []
files = []
parents = []
ccns = []
exts = ["html","c", "cpp", "cc", "cxx" , "java", "cs", "js", "ejs", "rs", "go", "php", "py"]
for root, dirs, ffiles in os.walk(startpath):
for d in dirs:
nlocs.append(0)
ccns.append(0)
files.append(os.path.join(root,d))
parents.append(root)
for f in tqdm(ffiles, leave=False):
if f.split(".")[-1] in exts:
nloc, ccn = calc_cc(os.path.join(root,f))
nlocs.append(nloc)
ccns.append(ccn)
files.append(os.path.join(root,f))
parents.append(root)
plot(nlocs, files, parents, ccns)
if __name__ == '__main__':
main()