Skip to content

Commit 5f579ca

Browse files
committed
Fix missing declarationCount property on DEPENDS_ON relationships
1 parent fc35197 commit 5f579ca

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

cypher/DependsOn_Relationship_Weights/Add_fine_grained_weights_for_Typescript_external_module_dependencies.cypher

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// Get the top level dependency between a Typescript module and the external modules it uses
44
MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:ExternalModule)
5-
WHERE NOT EXISTS {(target)-[:RESOLVES_TO]->(source)}
5+
// Exclude all targets where an ExternalModule was found that resolves to them
6+
// because those are covered in the fine grained weights for "ExternalModule"s.
7+
WHERE NOT EXISTS { (target)-[:RESOLVES_TO]->(source) }
68
OPTIONAL MATCH (source)-[resolvedModuleDependency:DEPENDS_ON]->(resolvedTarget:TS:Module)<-[:RESOLVES_TO]-(target)
79
WITH source
810
,target
@@ -43,15 +45,17 @@ OPTIONAL MATCH (source)-[ra:DEPENDS_ON]->(declaration)-[:RESOLVES_TO]->(abstract
4345
// - "lowCouplingElement25PercentWeight" subtracts 75% of the weights for abstract types like Interfaces and Type aliases
4446
// to compensate for their low coupling influence. Not included "high coupling" elements like Functions and Classes
4547
// remain in the weight as they were. The same applies for "lowCouplingElement10PercentWeight" but with in a stronger manner.
46-
SET moduleDependency.declarationCount = declarationCount
47-
,moduleDependency.abstractTypeCount = abstractTypeCount
48-
,moduleDependency.abstractTypeCardinality = abstractTypeCardinality
49-
,moduleDependency.lowCouplingElement25PercentWeight = toInteger(moduleDependency.cardinality - round(abstractTypeCardinality * 0.75))
50-
,moduleDependency.lowCouplingElement10PercentWeight = toInteger(moduleDependency.cardinality - round(abstractTypeCardinality * 0.90))
48+
SET moduleDependency.declarationCount = coalesce(declarationCount, 0)
49+
,moduleDependency.abstractTypeCount = coalesce(abstractTypeCount, 0)
50+
,moduleDependency.abstractTypeCardinality = coalesce(abstractTypeCardinality, 0)
51+
,moduleDependency.lowCouplingElement25PercentWeight =
52+
toInteger(moduleDependency.cardinality - round(abstractTypeCardinality * 0.75))
53+
,moduleDependency.lowCouplingElement10PercentWeight =
54+
toInteger(moduleDependency.cardinality - round(abstractTypeCardinality * 0.90))
5155
// Set all new properties also to a resolved (direct) dependency relationship if it exists.
52-
,resolvedModuleDependency.declarationCount = declarationCount
53-
,resolvedModuleDependency.abstractTypeCount = abstractTypeCount
54-
,resolvedModuleDependency.abstractTypeCardinality = abstractTypeCardinality
56+
,resolvedModuleDependency.declarationCount = coalesce(declarationCount, 0)
57+
,resolvedModuleDependency.abstractTypeCount = coalesce(abstractTypeCount, 0)
58+
,resolvedModuleDependency.abstractTypeCardinality = coalesce(abstractTypeCardinality, 0)
5559
,resolvedModuleDependency.lowCouplingElement25PercentWeight = toInteger(resolvedModuleDependency.cardinality - round(abstractTypeCardinality * 0.75))
5660
,resolvedModuleDependency.lowCouplingElement10PercentWeight = toInteger(resolvedModuleDependency.cardinality - round(abstractTypeCardinality * 0.90))
5761
RETURN source.globalFqn AS sourceName

cypher/DependsOn_Relationship_Weights/Add_fine_grained_weights_for_Typescript_internal_module_dependencies.cypher

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@
88
WITH source
99
,target
1010
,moduleDependency
11+
,moduleDependency.cardinality AS targetModuleCardinality
12+
13+
// Get optional external (e.g. type) declarations that the external module (target) provides and the source module uses
1114
OPTIONAL MATCH (source)-[elementDependency:DEPENDS_ON]->(elementType:TS)<-[:EXPORTS]-(target)
1215
WITH source
1316
,target
1417
,moduleDependency
18+
,targetModuleCardinality
1519
,count(DISTINCT elementType.globalFqn) AS elementTypeCount
1620
,sum(elementDependency.cardinality) AS elementTypeCardinality
1721
,collect(DISTINCT elementType.globalFqn)[0..4] AS elementTypeExamples
22+
,collect(elementType) AS elementTypes
23+
// Get optional low coupling elements (TypeAlias, Interface) that the source module contains and defines (low level) that depend on the external module (target)
24+
UNWIND elementTypes AS abstractType
1825
OPTIONAL MATCH (source)-[abstractDependency:DEPENDS_ON]->(abstractType:TypeAlias|Interface)<-[:EXPORTS]-(target)
1926
WITH source
2027
,target
2128
,moduleDependency
29+
,targetModuleCardinality
2230
,elementTypeCount
2331
,elementTypeCardinality
2432
,elementTypeExamples
@@ -34,21 +42,22 @@ OPTIONAL MATCH (source)-[abstractDependency:DEPENDS_ON]->(abstractType:TypeAlias
3442
// - "lowCouplingElement25PercentWeight" subtracts 75% of the weights for abstract types like Interfaces and Type aliases
3543
// to compensate for their low coupling influence. Not included "high coupling" elements like Functions and Classes
3644
// remain in the weight as they were. The same applies for "lowCouplingElement10PercentWeight" but with in a stronger manner.
37-
SET moduleDependency.abstractTypeCount = abstractTypeCount
45+
SET moduleDependency.declarationCount = coalesce(elementTypeCount, 0)
46+
,moduleDependency.abstractTypeCount = coalesce(abstractTypeCount, 0)
3847
,moduleDependency.abstractTypeCardinality = abstractTypeCardinality
3948
,moduleDependency.lowCouplingElement25PercentWeight =
4049
toInteger(elementTypeCardinality - round(abstractTypeCardinality * 0.75))
4150
,moduleDependency.lowCouplingElement10PercentWeight =
4251
toInteger(elementTypeCardinality - round(abstractTypeCardinality * 0.90))
4352
RETURN source.globalFqn AS sourceName
4453
,target.globalFqn AS targetName
45-
,abstractTypeCount
4654
,elementTypeCount
47-
,moduleDependency.cardinality AS externalModuleCardinality
48-
,abstractTypeCardinality
55+
,abstractTypeCount
56+
,targetModuleCardinality
4957
,elementTypeCardinality
58+
,abstractTypeCardinality
5059
,moduleDependency.lowCouplingElement25PercentWeight
5160
,moduleDependency.lowCouplingElement10PercentWeight
52-
,abstractTypeExamples
5361
,elementTypeExamples
62+
,abstractTypeExamples
5463
ORDER BY sourceName ASC

0 commit comments

Comments
 (0)