Skip to content

Commit 9e95b6b

Browse files
committed
Add file distance to DEPENDS_ON relationships
1 parent 688d25d commit 9e95b6b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Set file distance for dependencies as the shortest path of CONTAINS relationships (intuitively the fewest number of change directory commands needed)
2+
3+
MATCH (source:File)-[dependency:DEPENDS_ON]->(target:File)
4+
MATCH changeDirectoryPath = shortestPath((source)-[:CONTAINS*1..15]-(target))
5+
WHERE ALL ( file IN nodes(changeDirectoryPath) WHERE "File" IN labels(file) )
6+
OPTIONAL MATCH (source)<-[:CONTAINS]-(commonDirectory:Directory)-[:CONTAINS]->(target)
7+
WITH CASE commonDirectory
8+
WHEN IS NOT NULL THEN 0
9+
ELSE length(changeDirectoryPath)
10+
END AS fileDistanceAsFewestChangeDirectoryCommands
11+
,dependency
12+
,source
13+
,target
14+
SET dependency.fileDistanceAsFewestChangeDirectoryCommands
15+
=fileDistanceAsFewestChangeDirectoryCommands
16+
RETURN fileDistanceAsFewestChangeDirectoryCommands
17+
,count(*) AS numberOfDependencies
18+
,count(DISTINCT source) AS numberOfDependencyUsers
19+
,count(DISTINCT target) AS numberOfDependencyProviders
20+
,collect(source.fileName + ' uses ' + target.fileName)[0..4] AS examples
21+
ORDER BY fileDistanceAsFewestChangeDirectoryCommands
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Find shortest path regarding file location (contains relationships) between dependent modules (highest incoming dependencies first)
2+
3+
MATCH (sourceModule:TS:Module)<-[dependency:DEPENDS_ON]-(targetModule:TS:Module)
4+
WHERE sourceModule <> targetModule
5+
WITH sourceModule
6+
,count(DISTINCT targetModule) AS incomingDependencies
7+
,sum(dependency.cardinality) AS incomingDependencyCardinality
8+
,avg(dependency.declarationCount) AS incomingDependencyAverageDeclarationUsageCount
9+
,collect(DISTINCT targetModule) AS targetModules
10+
UNWIND targetModules AS targetModule
11+
MATCH (sourceModule)<-[dependency:DEPENDS_ON]-(targetModule)
12+
MATCH changeDirectoryPath = shortestPath((sourceModule)-[:CONTAINS*1..15]-(targetModule))
13+
WHERE ALL ( n IN nodes(changeDirectoryPath) WHERE "File" IN labels(n) )
14+
OPTIONAL MATCH (sourceModule)<-[:CONTAINS]-(commonDirectory:Directory)-[:CONTAINS]->(targetModule)
15+
WHERE commonDirectory IS NULL // remove line to also include modules in the same directory
16+
RETURN sourceModule.fileName AS sourceModuleName
17+
,labels(sourceModule)[0..4]
18+
,incomingDependencies
19+
,incomingDependencyCardinality
20+
,incomingDependencyAverageDeclarationUsageCount
21+
,targetModule.fileName AS targetModuleName
22+
,dependency.cardinality AS dependencyCardinality
23+
,dependency.declarationCount AS usedDeclarations
24+
,CASE commonDirectory
25+
WHEN IS NOT NULL THEN 0
26+
ELSE length(changeDirectoryPath)
27+
END AS shortestChangeDirectoryDistance
28+
//,nodes(changeDirectoryPath) AS shortestChangeDirectoryPath
29+
//,sourceModule, targetModule, changeDirectoryPath
30+
ORDER BY shortestChangeDirectoryDistance DESC, sourceModule.incomingDependencies ASC
31+
LIMIT 40

0 commit comments

Comments
 (0)