Skip to content

Commit 6a3f2ae

Browse files
authored
Merge pull request #539 from JohT/feature/analyze-npm-package-dependencies
Analyze npm package dependencies
2 parents 42ef1ec + d32fbe6 commit 6a3f2ae

24 files changed

Lines changed: 230 additions & 31 deletions

cypher/GitLog/Add_CHANGED_TOGETHER_WITH_relationships_to_code_files.cypher

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ MATCH (firstGitFile:Git&File&!Repository)-[gitChange:CHANGED_TOGETHER_WITH]-(sec
44
WHERE elementId(firstGitFile) < elementId(secondGitFile)
55
MATCH (firstGitFile)-[:RESOLVES_TO]->(firstCodeFile:File&!Git&!Repository)
66
MATCH (secondGitFile)-[:RESOLVES_TO]->(secondCodeFile:File&!Git&!Repository)
7+
WHERE firstGitFile <> secondGitFile
78
CALL (firstCodeFile, secondCodeFile, gitChange) {
89
MERGE (firstCodeFile)-[pairwiseChange:CHANGED_TOGETHER_WITH]-(secondCodeFile)
910
SET pairwiseChange = properties(gitChange)
10-
} IN TRANSACTIONS
11+
} IN TRANSACTIONS OF 750 ROWS
1112
RETURN count(*) AS pairCount

cypher/GitLog/Add_CHANGED_TOGETHER_WITH_relationships_to_git_files.cypher

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ WHERE updateCommitCount > 2
3939
WITH *
4040
,fileCombination[0] AS firstFile
4141
,fileCombination[1] AS secondFile
42+
WHERE firstFile <> secondFile
4243
WITH *
4344
// Get the lowest number of git update commits of both files (file pair)
4445
,CASE WHEN firstFile.updateCommitCount < secondFile.updateCommitCount

cypher/GitLog/Add_RESOLVES_TO_relationships_to_git_files_for_Java.cypher

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ WHERE gitFileName ENDS WITH codeFileName
2020
CALL { WITH git_file, code_file
2121
MERGE (git_file)-[:RESOLVES_TO]->(code_file)
2222
ON CREATE SET git_file.resolved = true
23-
} IN TRANSACTIONS
23+
} IN TRANSACTIONS OF 1000 ROWS
2424
RETURN count(DISTINCT codeFileName) AS numberOfCodeFiles
2525
,collect(DISTINCT codeFileName + ' <-> ' + gitFileName + '\n')[0..4] AS examples
2626
// RETURN codeFileName, gitFileName

cypher/GitLog/Add_RESOLVES_TO_relationships_to_git_files_for_Typescript.cypher

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ WHERE codeFileName ENDS WITH gitFileName
2222
CALL { WITH git_file, code_file
2323
MERGE (git_file)-[:RESOLVES_TO]->(code_file)
2424
ON CREATE SET git_file.resolved = true
25-
} IN TRANSACTIONS
25+
} IN TRANSACTIONS OF 1000 ROWS
2626
RETURN count(DISTINCT codeFileName) AS numberOfCodeFiles
2727
,collect(DISTINCT codeFileName + ' <-> ' + gitFileName + '\n')[0..4] AS examples
2828
// RETURN codeFileName, gitFileName
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// List of all NPM packages and their dependencies with build levels for GraphViz Visualization
2+
3+
MATCH (sourceForStatistics:NPM:Package)-[dependencyForStatistics:DEPENDS_ON]->(targetForStatistics:NPM:Package)
4+
WHERE sourceForStatistics.maxDistanceFromSource IS NOT NULL
5+
AND targetForStatistics.maxDistanceFromSource IS NOT NULL
6+
WITH min(dependencyForStatistics.weightByDependencyType) AS minWeight
7+
,max(dependencyForStatistics.weightByDependencyType) AS maxWeight
8+
,max(targetForStatistics.maxDistanceFromSource) AS maxLevel
9+
MATCH (source:NPM:Package)-[dependency:DEPENDS_ON]->(target:NPM:Package)
10+
WHERE source.maxDistanceFromSource IS NOT NULL
11+
AND target.maxDistanceFromSource IS NOT NULL
12+
WITH *, CASE
13+
WHEN maxWeight = minWeight THEN 0.0
14+
ELSE toFloat(dependency.weightByDependencyType - minWeight) / toFloat(maxWeight - minWeight)
15+
END AS normalizedWeight
16+
WITH *, round((normalizedWeight * 5) + 1, 2) AS penWidth
17+
WITH *, "\\n(level " + coalesce(source.maxDistanceFromSource + "/" + maxLevel, "?") + ")" AS sourceLevelInfo
18+
WITH *, "\\n(level " + coalesce(target.maxDistanceFromSource + "/" + maxLevel, "?") + ")" AS targetLevelInfo
19+
WITH *, source.name + sourceLevelInfo AS fullSourceName
20+
WITH *, target.name + targetLevelInfo AS fullTargetName
21+
WITH *, "\" -> \"" + fullTargetName
22+
+ "\" [label = " + dependency.weightByDependencyType + ";"
23+
+ " penwidth = " + penWidth + ";"
24+
+ " ];" AS graphVizDotNotationEdge
25+
WITH *, "\"" + fullSourceName + coalesce(graphVizDotNotationEdge, "\" [];") AS graphVizDotNotationLine
26+
ORDER BY dependency.weightByDependencyType DESC, target.maxDistanceFromSource DESC
27+
RETURN graphVizDotNotationLine
28+
//Debugging
29+
//,source.name AS sourceName
30+
//,target.name AS targetName
31+
//,penWidth
32+
//,normalizedWeight
33+
//,dependency.weightByDependencyType AS weight
34+
//,minWeight
35+
//,maxWeight
36+
LIMIT 440

cypher/Internal_Dependencies/Typescript_Module_build_levels_for_graphviz.cypher

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
WITH min(dependencyForStatistics.weight) AS minWeight
77
,max(dependencyForStatistics.weight) AS maxWeight
88
,max(targetForStatistics.maxDistanceFromSource) AS maxLevel
9-
MATCH (source:TS:Module)-[dependency:DEPENDS_ON]->(target:TS:Module)
9+
MATCH (source:TS:Module)-[dependency:DEPENDS_ON]->(target:TS:Module)
1010
WHERE source.maxDistanceFromSource IS NOT NULL
1111
AND target.maxDistanceFromSource IS NOT NULL
1212
WITH *, toFloat(dependency.cardinality - minWeight) / toFloat(maxWeight - minWeight) AS normalizedWeight
1313
WITH *, round((normalizedWeight * 5) + 1, 2) AS penWidth
14-
WITH *, source.rootProjectName + "\\n" + source.name + "\\n(level " + coalesce(source.maxDistanceFromSource + "/" + maxLevel, "?") + ")" AS fullSourceName
15-
WITH *, target.rootProjectName + "\\n" + target.name + "\\n(level " + coalesce(target.maxDistanceFromSource + "/" + maxLevel, "?") + ")" AS fullTargetName
14+
WITH *, "\\n(level " + coalesce(source.maxDistanceFromSource + "/" + maxLevel, "?") + ")" AS sourceLevelInfo
15+
WITH *, "\\n(level " + coalesce(target.maxDistanceFromSource + "/" + maxLevel, "?") + ")" AS targetLevelInfo
16+
WITH *, source.rootProjectName + "\\n" + source.name + sourceLevelInfo AS fullSourceName
17+
WITH *, target.rootProjectName + "\\n" + target.name + targetLevelInfo AS fullTargetName
1618
WITH *, "\" -> \"" + fullTargetName
1719
+ "\" [label = " + dependency.cardinality + ";"
1820
+ " penwidth = " + penWidth + ";"

cypher/Path_Finding/Path_Finding_6_Longest_paths_contributors_for_graphviz.cypher

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Path Finding - Longest path - Stream - List all dependencies for nodes contributing to longest paths and highlight those paths in the Visualization with GraphViz.
1+
// Path Finding - Longest path - Stream - List all dependencies for nodes contributing to longest paths and highlight those paths in the Visualization with GraphViz. Recommended prerequisite: Topological_Sort_Write.cypher
22

33
// Gather global statistics about dependency weights and levels for normalization and node details
44
MATCH (sourceNodeForStatistics)-[dependencyForStatistics:DEPENDS_ON]->(targetNodeForStatistics)
@@ -55,8 +55,12 @@
5555
WITH *, dependency[$dependencies_projection_weight_property] AS weight
5656
WITH *, toFloat(weight - minWeight) * weightNormalizationFactor AS normalizedWeight
5757
WITH *, round((normalizedWeight * 5) + 1, 2) AS penWidth
58-
WITH *, source.name + "\\n(level " + source.maxDistanceFromSource + "/" + maxLevel + ")" AS startNodeTitle
59-
WITH *, target.name + "\\n(level " + target.maxDistanceFromSource + "/" + maxLevel + ")" AS endNodeTitle
58+
WITH *, coalesce("\\n(level " + source.maxDistanceFromSource + "/" + maxLevel + ")", "") AS startNodeLevelInfo
59+
WITH *, coalesce("\\n" + source.rootProjectName, "") AS startNodeProjectInfo
60+
WITH *, coalesce("\\n(level " + target.maxDistanceFromSource + "/" + maxLevel + ")", "") AS endNodeLevelInfo
61+
WITH *, coalesce("\\n" + target.rootProjectName, "") AS endNodeProjectInfo
62+
WITH *, source.name + startNodeProjectInfo + startNodeLevelInfo AS startNodeTitle
63+
WITH *, target.name + endNodeProjectInfo + endNodeLevelInfo AS endNodeTitle
6064
// The longest path will be highlighted in red.
6165
WITH *, CASE WHEN isPartOfLongestPath THEN "; color=\"red\""
6266
// Dependencies contributing to the longest path will be highlighted in dark orange.

cypher/Path_Finding/Path_Finding_6_Longest_paths_for_graphviz.cypher

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Path Finding - Longest path - Stream - Find the top 100 dependencies contributing to the longest paths for Visualization with GraphViz
1+
// Path Finding - Longest path - Stream - Find the top 100 dependencies contributing to the longest paths for Visualization with GraphViz. Recommended prerequisite: Topological_Sort_Write.cypher
22

33
MATCH (sourceNodeForStatistics)-[dependencyForStatistics:DEPENDS_ON]->(targetNodeForStatistics)
44
WHERE $dependencies_projection_node IN LABELS(sourceNodeForStatistics)
@@ -19,8 +19,12 @@
1919
WITH *, dependency[$dependencies_projection_weight_property] AS weight
2020
WITH *, toFloat(weight - minWeight) * weightNormalizationFactor AS normalizedWeight
2121
WITH *, round((normalizedWeight * 5) + 1, 2) AS penWidth
22-
WITH *, startNode.name + "\\n(level " + startNode.maxDistanceFromSource + "/" + maxLevel + ")" AS startNodeTitle
23-
WITH *, endNode.name + "\\n(level " + endNode.maxDistanceFromSource + "/" + maxLevel + ")" AS endNodeTitle
22+
WITH *, coalesce("\\n(level " + startNode.maxDistanceFromSource + "/" + maxLevel + ")", "") AS startNodeLevelInfo
23+
WITH *, coalesce("\\n" + startNode.rootProjectName, "") AS startNodeProjectInfo
24+
WITH *, coalesce("\\n(level " + endNode.maxDistanceFromSource + "/" + maxLevel + ")", "") AS endNodeLevelInfo
25+
WITH *, coalesce("\\n" + endNode.rootProjectName, "") AS endNodeProjectInfo
26+
WITH *, startNode.name + startNodeProjectInfo + startNodeLevelInfo AS startNodeTitle
27+
WITH *, endNode.name + endNodeProjectInfo + endNodeLevelInfo AS endNodeTitle
2428
WITH *, "[label=" + weight + "; penwidth=" + penWidth + "; ];" AS graphVizEdgeAttributes
2529
WITH *, "\"" + startNodeTitle + "\" -> \"" + endNodeTitle + "\" " + graphVizEdgeAttributes AS graphVizDotNotationLine
2630
RETURN graphVizDotNotationLine
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Example on how to set the parameters for path finding in this case for NPM Packages
2+
3+
:params {
4+
"dependencies_projection_language":"NPM",
5+
"dependencies_projection": "npm-package-path-finding",
6+
"dependencies_projection_node": "Package",
7+
"dependencies_projection_weight_property": "weightByDependencyType",
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Example on how to set the parameters for path finding in this case for TypeScript modules
2+
3+
:params {
4+
"dependencies_projection_language":"Typescript",
5+
"dependencies_projection": "typescript-module-path-finding",
6+
"dependencies_projection_node": "Module",
7+
"dependencies_projection_weight_property": "lowCouplingElement25PercentWeight",
8+
}

0 commit comments

Comments
 (0)