-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.py
321 lines (252 loc) · 9.7 KB
/
report.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import json
from collections import defaultdict, namedtuple
from datetime import datetime
import matplotlib.pyplot as plt
import seaborn as sn
import pandas as pd
from config import DOMAIN, DOTFILE_PATH, DENYLIST
Measure = namedtuple("Measure", ["label", "color"])
MEASURES = {
"noc": Measure("NOC", "limegreen"),
"ca": Measure("Ca", "purple"),
"ce": Measure("Ce", "teal"),
"instability": Measure("Instability", "deeppink"),
"dcm_lcom3": Measure("DCM (LCOM3)", "black"),
"dcm_sim": Measure("DCM (SIM)", "darkorange"),
"dcm_cc": Measure("DCM (CC)", "blue"),
"p-depdegree": Measure("P-DepDegree", "red"),
"dlm": Measure("DLM", "gold"),
}
DEPGRAPH = json.load(open("./data/depgraph.json"))
DATA = {m: json.load(open(f"./data/{m}.json")) for m in MEASURES}
def plot_measurement_values(m: str):
"""
Plots the sorted measurement values for measure m
and stores the graph under ./graphs/<m>.png
"""
data = DATA[m]
label, color = MEASURES[m]
xvalues = [i for i in range(len(data))]
# Plot graphs
plt.plot(
xvalues,
[y for _, y in sorted(data.items(), key=lambda i: i[1])],
"o",
label=label,
color=color,
markersize=1,
)
plt.legend()
plt.ylabel("measurement values")
plt.xlabel("packages")
# plt.show()
plt.savefig(f"./graphs/{m}.png")
plt.close()
def plot_comparison(m1: str, m2: str):
"""
Plots the sorted measurement values for measure m1
and the corresponding measurement values for m2
and stores the graph under ./graphs/<m1>_and_<m2>.png
"""
data_m1 = DATA[m1]
label_m1, color_m1 = MEASURES[m1]
data_m2 = DATA[m2]
label_m2, color_m2 = MEASURES[m2]
xvalues = [i for i in range(len(data_m1))]
# Plot graphs
plt.plot(
xvalues,
[y for _, y in sorted(data_m1.items(), key=lambda i: i[1])],
"o",
label=label_m1,
color=color_m1,
markersize=1,
)
plt.plot(
xvalues,
[data_m2[p] for p, _ in sorted(data_m1.items(), key=lambda i: i[1])],
"o",
label=label_m2,
color=color_m2,
markersize=1,
)
plt.legend()
plt.ylabel("measurement values")
plt.xlabel("packages")
# plt.show()
plt.savefig(f"./graphs/{m1}_and_{m2}.png")
plt.close()
def table(head: tuple, body: list):
table = []
header = f"| Rank | {'|'.join(head)} |"
table.append(header)
separator = len(head) * "| ----" + "|"
table.append(separator)
for i, d in enumerate(body):
row = f"| {i + 1} | {'|'.join([f'{e}' for e in d])} |"
table.append(row)
return table
def generate():
# lambdas
write = (
lambda x: report.write(x + "\n")
if isinstance(x, str)
else report.writelines([l + "\n" for l in x])
)
only_pkg = lambda x: x[len(DOMAIN) + 1 :] if x.startswith(DOMAIN) else x
# group classes by packages
packages = defaultdict(list)
for c in DEPGRAPH:
p = c.rpartition(".")[0]
packages[p].append(c)
# create graphs
for m in MEASURES:
plot_measurement_values(m)
plot_comparison("noc", "ce")
plot_comparison("dcm_cc", "noc")
plot_comparison("dcm_cc", "ce")
plot_comparison("dcm_cc", "dcm_lcom3")
plot_comparison("noc", "dcm_lcom3")
# create correlation matrix
corr_data = {}
for m in sorted(MEASURES.keys()):
corr_data[MEASURES[m].label] = [DATA[m][p] for p in sorted(packages.keys())]
df = pd.DataFrame(corr_data, columns=[MEASURES[m].label for m in sorted(MEASURES.keys())])
corrMatrix = df.corr(method="pearson")
sn.heatmap(corrMatrix, annot=True)
plt.xticks(rotation=45)
plt.savefig("./graphs/corr_matrix.png", bbox_inches="tight")
# generate report
date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
report = open(f"./reports/{DOMAIN} - {date}.md", "w")
write("# Report")
write(
f"This report for the software system with domain {DOMAIN} was created at {date} based on dot file *{DOTFILE_PATH}*."
)
write("## Graphs & Data")
write("- Data sets for all measures can be found in the folder *./data*")
write("- Graphs for all measures can be found in the folder *./graphs*")
write("- Correlation matrix for all measures can be found in the folder *./graphs*")
# general information
write("## General Information")
write(f"- Number of packages: {len(packages)}")
write(f"- Number of classes: {len(DEPGRAPH)}")
nested_classes = [c for c in DEPGRAPH if "$" in c]
write(f"- Number of nested classes: {len(nested_classes)}")
deps = [(c, d) for c, deps in DEPGRAPH.items() for d in deps]
write(f"- Number of dependencies: {len(deps)}")
# deny list
write("## Deny List")
write("Elements of the deny list:")
for d in DENYLIST:
write(f"- {d}")
# measures
write("## Measures")
# statistics regarding noc
write("### Number of Classes (NOC)")
noc_avg = round(sum(DATA["noc"].values()) / len(DATA["noc"]), 0)
write(f"- Average NOC: {len(DEPGRAPH)} / {len(packages)} = {noc_avg}")
noc_below_avg = [p for p, v in DATA["noc"].items() if v < noc_avg]
write(f"- Number of packages with NOC value below average: {len(noc_below_avg)}")
noc_below_3 = [p for p, v in DATA["noc"].items() if v < 3]
write(f"- Number of packages with NOC less than 3: {len(noc_below_3)}")
write("- The 5 packages with highest NOC:")
noc_top5 = [
(only_pkg(p), v)
for p, v in list(reversed(sorted(DATA["noc"].items(), key=lambda i: i[1])))[:5]
]
write(table(("Packages", "NOC"), noc_top5))
# statistics regarding ca
write("### Afferent Coupling (Ca)")
ca_zero = [p for p, v in DATA["ca"].items() if v == 0]
write(f"- Number of packages with Ca == 0: {len(ca_zero)}")
write("- The 5 packages with highest Ca (+ corresponding Ce and I values):")
ca_top5 = [
(only_pkg(p), v, DATA["ce"][p], round(DATA["instability"][p], 3))
for p, v in list(reversed(sorted(DATA["ca"].items(), key=lambda i: i[1])))[:5]
]
write(table(("Packages", "Ca", "Ce", "I"), ca_top5))
# statistics regarding ce
write("### Efferent Coupling (Ce)")
ce_zero = [p for p, v in DATA["ce"].items() if v == 0]
write(f"- Number of packages with Ce == 0: {len(ce_zero)}")
write("- The 5 packages with highest Ce (+ corresponding Ca and I values):")
ce_top5 = [
(only_pkg(p), v, DATA["ca"][p], round(DATA["instability"][p], 3))
for p, v in list(reversed(sorted(DATA["ce"].items(), key=lambda i: i[1])))[:5]
]
write(table(("Packages", "Ce", "Ca", "I"), ca_top5))
# statistics regarding instability
write("### Instability (I)")
i_zero = [p for p, v in DATA["instability"].items() if v == 0]
write(f"- Number of packages with I == 0: {len(i_zero)}")
i_one = [p for p, v in DATA["instability"].items() if v == 1]
write(f"- Number of packages with I == 1: {len(i_one)}")
write("- The 5 packages with highest I:")
i_top5 = [
(only_pkg(p), round(v, 3))
for p, v in list(
reversed(sorted(DATA["instability"].items(), key=lambda i: i[1]))
)[:5]
]
write(table(("Packages", "I"), i_top5))
# statistics regarding dcm_lcom3
write("### Dependency Cohesion Measures (DCM)")
write("#### DCM based on LCOM3 (DCM<sub>LCOM3</sub>)")
dcm_lcom3_avg = round(sum(DATA["dcm_lcom3"].values()) / len(DATA["dcm_lcom3"]), 0)
write(f"- Average DCM<sub>LCOM3</sub>: {dcm_lcom3_avg}")
write("- The 5 packages with highest DCM<sub>LCOM3</sub>:")
dcm_lcom3_top5 = [
(only_pkg(p), v)
for p, v in list(
reversed(sorted(DATA["dcm_lcom3"].items(), key=lambda i: i[1]))
)[:5]
]
write(table(("Packages", "DCM<sub>LCOM3</sub>"), dcm_lcom3_top5))
# statistics regarding dcm_sim
write("#### DCM based on similarity measure (DCM<sub>SIM</sub>")
write(
"- The 5 packages with highest DCM<sub>SIM</sub> (+ corresponding DCM<sub>CC</sub> value):"
)
dcm_sim_top5 = [
(only_pkg(p), round(v, 3), round(DATA["dcm_cc"][p], 3))
for p, v in list(reversed(sorted(DATA["dcm_sim"].items(), key=lambda i: i[1])))[
:5
]
]
write(table(("Packages", "DCM<sub>SIM</sub>", "DCM<sub>CC</sub>"), dcm_sim_top5))
# statistics regarding dcm_cc
write("#### DCM based on cohesion count (DCM<sub>CC</sub>")
write(
"- The 5 packages with highest DCM<sub>CC</sub> (+ corresponding DCM<sub>SIM</sub> value):"
)
dcm_cc_top5 = [
(only_pkg(p), round(v, 3), round(DATA["dcm_sim"][p], 3))
for p, v in list(reversed(sorted(DATA["dcm_cc"].items(), key=lambda i: i[1])))[
:5
]
]
write(table(("Packages", "DCM<sub>CC</sub>", "DCM<sub>SIM</sub>"), dcm_cc_top5))
# statistics regarding p-depdegree
write("### Package DepDegree (P-DepDegree)")
write("5 packages with highest P-DepDegree:")
pdd_top5 = [
(only_pkg(p), round(v, 3))
for p, v in list(
reversed(sorted(DATA["p-depdegree"].items(), key=lambda i: i[1]))
)[:5]
]
write(table(("Packages", "P-DepDegree"), pdd_top5))
# statistics regardging dlm
write("### Dependency Locality Measure (DLM)")
dlm_zero = [p for p, v in DATA["dlm"].items() if v == 0]
write(f"- Number of packages with DLM == 0: {len(dlm_zero)}")
write("- The 5 packages with highest DLM (+ corresponding NOC and Ce values):")
dlm_top5 = [
(only_pkg(p), v, DATA["noc"][p], DATA["ce"][p])
for p, v in list(reversed(sorted(DATA["dlm"].items(), key=lambda i: i[1])))[:5]
]
write(table(("Packages", "DLM", "NOC", "Ce"), dlm_top5))
report.close()
if __name__ == "__main__":
generate()