Skip to content

Commit dba3f46

Browse files
committed
feat: add sum of coupling
1 parent 111d02a commit dba3f46

8 files changed

Lines changed: 33 additions & 5 deletions

File tree

apps/backend/src/services/change-coupling.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('change coupling service', () => {
5454
[0, 0, 0],
5555
]);
5656

57+
expect(result.sumOfCoupling).toEqual([4, 3, 3]);
5758
expect(result.fileCount).toEqual([3, 2, 2]);
5859
});
5960
});

apps/backend/src/services/change-coupling.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type ChangeCouplingResult = {
99
matrix: number[][];
1010
dimensions: string[];
1111
groups: string[];
12+
sumOfCoupling: number[];
1213

1314
fileCount: number[];
1415
cohesion: number[];
@@ -26,6 +27,7 @@ export async function calcChangeCoupling(
2627
const matrix = getEmptyMatrix(modules.length);
2728

2829
const commitsPerModule: number[] = new Array(matrix.length).fill(0);
30+
const sumOfCoupling: number[] = new Array(matrix.length).fill(0);
2931

3032
const parseOptions: ParseOptions = {
3133
limits,
@@ -43,19 +45,34 @@ export async function calcChangeCoupling(
4345
}
4446
}
4547
}
48+
49+
updateSumOfCoupling(touchedModules, sumOfCoupling);
4650
addToMatrix(touchedModules, matrix);
4751
}, parseOptions);
4852

4953
return {
5054
matrix,
5155
dimensions: displayModules,
5256
groups: config.groups,
53-
57+
sumOfCoupling,
5458
fileCount: commitsPerModule,
5559
cohesion: new Array(matrix.length).fill(-1),
5660
};
5761
}
5862

63+
function updateSumOfCoupling(
64+
touchedModules: Set<number>,
65+
sumOfCoupling: number[]
66+
) {
67+
const count = touchedModules.size;
68+
if (count > 1) {
69+
const otherModules = count - 1;
70+
for (const module of touchedModules) {
71+
sumOfCoupling[module] += otherModules;
72+
}
73+
}
74+
}
75+
5976
function addToMatrix(touchedModules: Set<number>, matrix: number[][]) {
6077
const touchedArray = Array.from(touchedModules);
6178
for (const module1 of touchedArray) {

apps/backend/src/services/hotspot.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jest.mock('../infrastructure/log', () => ({
4141
"Jane Doe <jane.doe@acme.com>,${now.toISOString()}"
4242
10\t0\t/booking/feature-manage/my.component.ts
4343
0\t1\t/checkin/feature-checkin/my.component.ts
44+
0\t1\t/shared/feature-checkin/my.component.md
4445
4546
"John Doe <john.doe@acme.com>,${now.toISOString()}"
4647
10\t0\t/booking/feature-manage/my.component.ts

apps/backend/src/services/hotspot.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Limits } from '../model/limits';
99

1010
import { calcCyclomaticComplexity } from '../utils/complexity';
1111
import { countLinesInFile } from '../utils/count-lines';
12-
import { Config } from '../model/config';
1312

1413
export type ComplexityMetric = 'McCabe' | 'Length';
1514

@@ -126,6 +125,10 @@ async function analyzeLogs(
126125
continue;
127126
}
128127

128+
if (!change.path.endsWith('.ts')) {
129+
continue;
130+
}
131+
129132
if (!hotspots[change.path]) {
130133
const complexity = calcComplexity(options, change, criteria);
131134

apps/frontend/src/app/features/coupling/coupling.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export class CouplingComponent {
9696
toGraph(result: CouplingResult): Graph {
9797
result.matrix = this.clearSelfLinks(result.matrix);
9898

99+
console.log('result', result);
100+
99101
const groupNodes: CouplingNodeDefinition[] = this.groupByFolder()
100102
? createGroups(result.dimensions)
101103
: [];

apps/frontend/src/app/features/coupling/graph.adapter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export function createNodes(
7171
for (let i = 0; i < result.dimensions.length; i++) {
7272
const label = result.dimensions[i];
7373

74+
const soc = result.sumOfCoupling ? result.sumOfCoupling[i] : -1;
75+
const relSoc = soc !== null ? soc / result.fileCount[i] : -1;
76+
7477
const node: CouplingNodeDefinition = {
7578
data: {
7679
id: '' + i,
@@ -85,8 +88,8 @@ export function createNodes(
8588
`
8689
: `${label}
8790
<br><br>${result.fileCount[i]} commits
88-
<br>Outgoing Deps: ${sumRow(result.matrix, i)}
89-
<br>Incoming Deps: ${sumCol(result.matrix, i)}
91+
<br>Sum of Coupling (SoC): ${soc}
92+
<br>SoC per Commit: ${Math.round(relSoc * 100)}%
9093
`,
9194
dimension: label,
9295
},

apps/frontend/src/app/model/coupling-result.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface CouplingResult {
44
cohesion: number[];
55
matrix: number[][];
66
groups: string[];
7+
sumOfCoupling: [];
78
}
89

910
export const initCouplingResult: CouplingResult = {
@@ -12,4 +13,5 @@ export const initCouplingResult: CouplingResult = {
1213
cohesion: [],
1314
matrix: [[]],
1415
groups: [],
16+
sumOfCoupling: [],
1517
};

apps/frontend/src/app/ui/graph/graph.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
Component,
3-
effect,
43
ElementRef,
54
input,
65
OnChanges,

0 commit comments

Comments
 (0)