Skip to content

Commit e87e5ff

Browse files
authored
Merge pull request #470 from JohT/fix/path-finding-should-detect-empty-projections
Detect empty projection for path finding
2 parents b71c4c2 + 52c9435 commit e87e5ff

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

jupyter/PathFindingJava.ipynb

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
"id": "ec6baa64",
3030
"metadata": {},
3131
"source": [
32-
"## What GPT-4 has to say about it\n",
33-
"\n",
3432
"### All pairs shortest path\n",
3533
"\n",
3634
"Interpreting the results of the \"all pairs shortest path\" algorithm on a graph of statically analyzed code modules and their dependencies involves understanding the structure and implications of the paths between nodes (modules) in the graph. Here are some specific steps and insights to consider:\n",
@@ -95,7 +93,9 @@
9593
"\n",
9694
"8. **Documentation & Knowledge Transfer**: If certain modules consistently appear in the longest paths, they may require better documentation. Ensuring that their roles and the reasons for their lengthy dependencies are well understood can facilitate knowledge transfer among team members.\n",
9795
"\n",
98-
"By focusing on the longest paths in your dependency graph, you can uncover areas requiring attention for optimization, maintenance, and improved system architecture."
96+
"By focusing on the longest paths in your dependency graph, you can uncover areas requiring attention for optimization, maintenance, and improved system architecture.\n",
97+
"\n",
98+
"(Text adapted from ChatGPT 4)"
9999
]
100100
},
101101
{
@@ -568,6 +568,18 @@
568568
" plot.show()"
569569
]
570570
},
571+
{
572+
"cell_type": "code",
573+
"execution_count": null,
574+
"id": "04a4a930",
575+
"metadata": {},
576+
"outputs": [],
577+
"source": [
578+
"# Small function to convert nan to zero in general\n",
579+
"def nan_to_zero(value: float) -> float:\n",
580+
" return 0 if np.isnan(value) else value"
581+
]
582+
},
571583
{
572584
"cell_type": "markdown",
573585
"id": "0b42163d",
@@ -618,7 +630,10 @@
618630
"outputs": [],
619631
"source": [
620632
"# Create the directed and unweighted projection with the parameters defined directly above\n",
621-
"is_package_data_available=create_directed_unweighted_projection(package_path_finding_parameters)"
633+
"is_package_data_available=create_directed_unweighted_projection(package_path_finding_parameters)\n",
634+
"\n",
635+
"if not is_package_data_available:\n",
636+
" print(\"No projected data for path finding available for Package nodes.\")"
622637
]
623638
},
624639
{
@@ -677,7 +692,7 @@
677692
"metadata": {},
678693
"outputs": [],
679694
"source": [
680-
"package_dependencies_graph_diameter=all_pairs_shortest_paths_distribution_per_artifact['distance'].max()\n",
695+
"package_dependencies_graph_diameter=nan_to_zero(all_pairs_shortest_paths_distribution_per_artifact['distance'].max())\n",
681696
"print('The diameter (longest shortest path) of the projected package dependencies Graph is:', package_dependencies_graph_diameter)"
682697
]
683698
},
@@ -942,7 +957,7 @@
942957
"metadata": {},
943958
"outputs": [],
944959
"source": [
945-
"package_dependencies_max_longest_path=longest_paths_distribution_per_artifact['distance'].max()\n",
960+
"package_dependencies_max_longest_path=nan_to_zero(longest_paths_distribution_per_artifact['distance'].max())\n",
946961
"print('The max. longest path of the projected package dependencies is:', package_dependencies_max_longest_path)"
947962
]
948963
},
@@ -1210,7 +1225,10 @@
12101225
"outputs": [],
12111226
"source": [
12121227
"# Create the directed and unweighted projection with the parameters defined directly above\n",
1213-
"is_artifact_data_available=create_directed_unweighted_projection(artifact_path_finding_parameters)"
1228+
"is_artifact_data_available=create_directed_unweighted_projection(artifact_path_finding_parameters)\n",
1229+
"\n",
1230+
"if not is_artifact_data_available:\n",
1231+
" print(\"No projected data for path finding available for Artifact nodes.\")"
12141232
]
12151233
},
12161234
{
@@ -1228,6 +1246,7 @@
12281246
"metadata": {},
12291247
"outputs": [],
12301248
"source": [
1249+
"print(\"Projection data available: \" + str(is_artifact_data_available))\n",
12311250
"artifact_projection_statistics=query_cypher_to_data_frame(\"../cypher/Dependencies_Projection/Dependencies_12_Get_Projection_Statistics.cypher\", artifact_path_finding_parameters)\n",
12321251
"artifact_projection_statistics"
12331252
]
@@ -1280,7 +1299,7 @@
12801299
"metadata": {},
12811300
"outputs": [],
12821301
"source": [
1283-
"artifact_dependencies_graph_diameter=all_pairs_shortest_paths_distribution_for_artifacts['distance'].max()\n",
1302+
"artifact_dependencies_graph_diameter=nan_to_zero(all_pairs_shortest_paths_distribution_for_artifacts['distance'].max())\n",
12841303
"print('The diameter (longest shortest path) of the projected artifact dependencies Graph is:', artifact_dependencies_graph_diameter)"
12851304
]
12861305
},
@@ -1358,7 +1377,7 @@
13581377
"outputs": [],
13591378
"source": [
13601379
"# Execute algorithm \"longest path (for directed acyclic graphs)\" and query overall and artifact specific results\n",
1361-
"longest_artifact_paths_distribution=query_if_data_available(is_package_data_available, \"../cypher/Path_Finding/Path_Finding_6_Longest_paths_distribution_per_project.cypher\", artifact_path_finding_parameters)"
1380+
"longest_artifact_paths_distribution=query_if_data_available(is_artifact_data_available, \"../cypher/Path_Finding/Path_Finding_6_Longest_paths_distribution_per_project.cypher\", artifact_path_finding_parameters)"
13621381
]
13631382
},
13641383
{
@@ -1376,7 +1395,7 @@
13761395
"metadata": {},
13771396
"outputs": [],
13781397
"source": [
1379-
"artifact_dependencies_max_longest_path=longest_artifact_paths_distribution['distance'].max()\n",
1398+
"artifact_dependencies_max_longest_path=nan_to_zero(longest_artifact_paths_distribution['distance'].max())\n",
13801399
"print('The max. longest path of the projected artifact dependencies is:', artifact_dependencies_max_longest_path)"
13811400
]
13821401
},

jupyter/PathFindingTypescript.ipynb

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
"id": "ec6baa64",
3030
"metadata": {},
3131
"source": [
32-
"## What GPT-4 has to say about it\n",
33-
"\n",
3432
"### All pairs shortest path\n",
3533
"\n",
3634
"Interpreting the results of the \"all pairs shortest path\" algorithm on a graph of statically analyzed code modules and their dependencies involves understanding the structure and implications of the paths between nodes (modules) in the graph. Here are some specific steps and insights to consider:\n",
@@ -95,7 +93,9 @@
9593
"\n",
9694
"8. **Documentation & Knowledge Transfer**: If certain modules consistently appear in the longest paths, they may require better documentation. Ensuring that their roles and the reasons for their lengthy dependencies are well understood can facilitate knowledge transfer among team members.\n",
9795
"\n",
98-
"By focusing on the longest paths in your dependency graph, you can uncover areas requiring attention for optimization, maintenance, and improved system architecture."
96+
"By focusing on the longest paths in your dependency graph, you can uncover areas requiring attention for optimization, maintenance, and improved system architecture. \n",
97+
"\n",
98+
"(Text adapted from ChatGPT 4)"
9999
]
100100
},
101101
{
@@ -651,6 +651,18 @@
651651
" return result_data_frame.sort_values(ascending=False);"
652652
]
653653
},
654+
{
655+
"cell_type": "code",
656+
"execution_count": null,
657+
"id": "ab378355",
658+
"metadata": {},
659+
"outputs": [],
660+
"source": [
661+
"# Small function to convert nan to zero in general\n",
662+
"def nan_to_zero(value: float) -> float:\n",
663+
" return 0 if np.isnan(value) else value"
664+
]
665+
},
654666
{
655667
"cell_type": "markdown",
656668
"id": "0b42163d",
@@ -701,7 +713,10 @@
701713
"outputs": [],
702714
"source": [
703715
"# Create the directed and unweighted projection with the parameters defined directly above\n",
704-
"is_module_data_available=create_directed_unweighted_projection(module_path_finding_parameters)"
716+
"is_module_data_available=create_directed_unweighted_projection(module_path_finding_parameters)\n",
717+
"\n",
718+
"if not is_module_data_available:\n",
719+
" print(\"No projected data for path finding available for Module nodes.\")"
705720
]
706721
},
707722
{
@@ -719,6 +734,7 @@
719734
"metadata": {},
720735
"outputs": [],
721736
"source": [
737+
"print(\"Projection data available: \" + str(is_module_data_available))\n",
722738
"module_projection_statistics=query_cypher_to_data_frame(\"../cypher/Dependencies_Projection/Dependencies_12_Get_Projection_Statistics.cypher\", module_path_finding_parameters)\n",
723739
"module_projection_statistics"
724740
]
@@ -759,7 +775,7 @@
759775
"metadata": {},
760776
"outputs": [],
761777
"source": [
762-
"module_dependencies_graph_diameter=all_pairs_shortest_paths_distribution_per_project_and_root_project['distance'].max()\n",
778+
"module_dependencies_graph_diameter=nan_to_zero(all_pairs_shortest_paths_distribution_per_project_and_root_project['distance'].max())\n",
763779
"print('The diameter (longest shortest path) of the projected module dependencies Graph is:', module_dependencies_graph_diameter)"
764780
]
765781
},
@@ -996,12 +1012,14 @@
9961012
"metadata": {},
9971013
"outputs": [],
9981014
"source": [
999-
"all_pairs_shortest_paths_distribution_per_root_project_isolated=all_pairs_shortest_paths_distribution_per_project_and_root_project.query('isDifferentTargetRootProject == False')\n",
1000-
"\n",
1001-
"all_pairs_shortest_paths_distribution_per_root_project_isolated.\\\n",
1002-
" groupby([\"sourceRootProject\", \"distance\"], as_index=False)\\\n",
1003-
" [[\"pairCount\", \"sourceNodeCount\",\"targetNodeCount\"]].\\\n",
1004-
" apply(max).head(20)"
1015+
"all_pairs_shortest_paths_distribution_per_root_project_isolated = all_pairs_shortest_paths_distribution_per_project_and_root_project.query('isDifferentTargetRootProject == False')\n",
1016+
"if all_pairs_shortest_paths_distribution_per_root_project_isolated.empty:\n",
1017+
" print(\"No data for all pairs shortest paths per root project available.\")\n",
1018+
"else:\n",
1019+
" display(all_pairs_shortest_paths_distribution_per_root_project_isolated.\n",
1020+
" groupby([\"sourceRootProject\", \"distance\"], as_index=False)\n",
1021+
" [[\"pairCount\", \"sourceNodeCount\", \"targetNodeCount\"]].\n",
1022+
" apply(max).head(20))"
10051023
]
10061024
},
10071025
{
@@ -1159,7 +1177,7 @@
11591177
"metadata": {},
11601178
"outputs": [],
11611179
"source": [
1162-
"module_dependencies_max_longest_path=longest_paths_distribution_per_project['distance'].max()\n",
1180+
"module_dependencies_max_longest_path=nan_to_zero(longest_paths_distribution_per_project['distance'].max())\n",
11631181
"print('The max. longest path of the projected module dependencies is:', module_dependencies_max_longest_path)"
11641182
]
11651183
},

0 commit comments

Comments
 (0)