-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathFindingCsv.sh
executable file
·148 lines (116 loc) · 7.32 KB
/
PathFindingCsv.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
# Uses path finding algorithms from the Graph Data Science Library of Neo4j and creates CSV reports.
# It requires an already running Neo4j graph database with already scanned and analyzed artifacts.
# The reports (csv files) will be written into the sub directory reports/path-finding-csv.
# Note that "scripts/prepareAnalysis.sh" is required to run prior to this script.
# Requires executeQueryFunctions.sh, projectionFunctions.sh, cleanupAfterReportGeneration.sh
# Overrideable Constants (defaults also defined in sub scripts)
REPORTS_DIRECTORY=${REPORTS_DIRECTORY:-"reports"}
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
set -o errexit -o pipefail
## Get this "scripts/reports" directory if not already set
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
# This way non-standard tools like readlink aren't needed.
REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
echo "pathFindingCsv: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR}"
# Get the "scripts" directory by taking the path of this script and going one directory up.
SCRIPTS_DIR=${SCRIPTS_DIR:-"${REPORTS_SCRIPT_DIR}/.."} # Repository directory containing the shell scripts
echo "pathFindingCsv: SCRIPTS_DIR=${SCRIPTS_DIR}"
# Get the "cypher" directory by taking the path of this script and going two directory up and then to "cypher".
CYPHER_DIR=${CYPHER_DIR:-"${REPORTS_SCRIPT_DIR}/../../cypher"}
echo "pathFindingCsv: CYPHER_DIR=$CYPHER_DIR"
# Define functions to execute a cypher query from within the given file (first and only argument)
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
# Define functions to create and delete Graph Projections like "createDirectedDependencyProjection"
source "${SCRIPTS_DIR}/projectionFunctions.sh"
# Create report directory
REPORT_NAME="path-finding-csv"
FULL_REPORT_DIRECTORY="${REPORTS_DIRECTORY}/${REPORT_NAME}"
mkdir -p "${FULL_REPORT_DIRECTORY}"
# Run the path finding algorithm "All Pairs Shortest Path".
#
# Required Parameters:
# - dependencies_projection=...
# Name prefix for the in-memory projection name for dependencies. Example: "type-path-finding"
# - dependencies_projection_node=...
# Label of the nodes that will be used for the projection. Example: "Type"
# - dependencies_projection_weight_property=...
# Name of the node property that contains the dependency weight. Example: "weight"
allPairsShortestPath() {
local PATH_FINDING_CYPHER_DIR="${CYPHER_DIR}/Path_Finding"
local nodeLabel; nodeLabel=$( extractQueryParameter "dependencies_projection_node" "${@}" )
# Run the algorithm using "stream" and write the results into a CSV file
execute_cypher "${PATH_FINDING_CYPHER_DIR}/Path_Finding_5_All_pairs_shortest_path_distribution_per_project.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${nodeLabel}_all_pairs_shortest_paths_distribution_per_project.csv"
}
# Run the path finding algorithm "Longest Path" (for directed acyclic graphs (DAG)).
#
# Required Parameters:
# - dependencies_projection=...
# Name prefix for the in-memory projection name for dependencies. Example: "type-path-finding"
# - dependencies_projection_node=...
# Label of the nodes that will be used for the projection. Example: "Type"
# - dependencies_projection_weight_property=...
# Name of the node property that contains the dependency weight. Example: "weight"
longestPath() {
local PATH_FINDING_CYPHER_DIR="${CYPHER_DIR}/Path_Finding"
local nodeLabel; nodeLabel=$( extractQueryParameter "dependencies_projection_node" "${@}" )
# Run the algorithm using "stream" and write the results into a CSV file
execute_cypher "${PATH_FINDING_CYPHER_DIR}/Path_Finding_6_Longest_paths_distribution_per_project.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${nodeLabel}_longest_paths_distribution.csv"
}
# Run all contained path finding algorithms.
#
# Required Parameters:
# - dependencies_projection=...
# Name prefix for the in-memory projection name for dependencies. Example: "artifact-path-finding"
# - dependencies_projection_node=...
# Label of the nodes that will be used for the projection. Example: "Artifact"
# - dependencies_projection_weight_property=...
# Name of the node property that contains the dependency weight. Example: "weight"
runPathFindingAlgorithms() {
time allPairsShortestPath "${@}"
time longestPath "${@}"
}
# -- Java Artifact Path Finding ------------------------------------
ARTIFACT_PROJECTION="dependencies_projection=artifact-path-finding"
ARTIFACT_NODE="dependencies_projection_node=Artifact"
ARTIFACT_WEIGHT="dependencies_projection_weight_property=weight"
if createDirectedDependencyProjection "${ARTIFACT_PROJECTION}" "${ARTIFACT_NODE}" "${ARTIFACT_WEIGHT}"; then
runPathFindingAlgorithms "${ARTIFACT_PROJECTION}" "${ARTIFACT_NODE}" "${ARTIFACT_WEIGHT}"
fi
# -- Java Package Path Finding -------------------------------------
PACKAGE_PROJECTION="dependencies_projection=package-path-finding"
PACKAGE_NODE="dependencies_projection_node=Package"
PACKAGE_WEIGHT="dependencies_projection_weight_property=weight25PercentInterfaces"
if createDirectedDependencyProjection "${PACKAGE_PROJECTION}" "${PACKAGE_NODE}" "${PACKAGE_WEIGHT}"; then
runPathFindingAlgorithms "${PACKAGE_PROJECTION}" "${PACKAGE_NODE}" "${PACKAGE_WEIGHT}"
fi
# -- Java Type Path Finding ----------------------------------------
# Note: This is deactivated for now. It might be too granular to be valuable and require too many resources,
#TYPE_PROJECTION="dependencies_projection=type-path-finding"
#TYPE_NODE="dependencies_projection_node=Type"
#TYPE_WEIGHT="dependencies_projection_weight_property=weight"
#
#if createDirectedJavaTypeDependencyProjection "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"; then
# runPathFindingAlgorithms "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"
#fi
# -- Java Method Path Finding --------------------------------------
# Note: This is deactivated for now. It might be too granular to be valuable and require too many resources,
#METHOD_PROJECTION="dependencies_projection=method-path-finding"
#METHOD_NODE="dependencies_projection_node=Method"
#METHOD_WEIGHT="dependencies_projection_weight_property="
#if createDirectedJavaMethodDependencyProjection "${METHOD_PROJECTION}"; then
# runPathFindingAlgorithms "${METHOD_PROJECTION}" "${METHOD_NODE}" "${METHOD_WEIGHT}"
#fi
# -- Typescript Modules Path Finding -------------------------------
MODULE_LANGUAGE="dependencies_projection_language=Typescript"
MODULE_PROJECTION="dependencies_projection=typescript-module-path-finding"
MODULE_NODE="dependencies_projection_node=Module"
MODULE_WEIGHT="dependencies_projection_weight_property=lowCouplingElement25PercentWeight"
if createDirectedDependencyProjection "${MODULE_LANGUAGE}" "${MODULE_PROJECTION}" "${MODULE_NODE}" "${MODULE_WEIGHT}"; then
runPathFindingAlgorithms "${MODULE_PROJECTION}" "${MODULE_NODE}" "${MODULE_WEIGHT}"
fi
# ---------------------------------------------------------------
# Clean-up after report generation. Empty reports will be deleted.
source "${SCRIPTS_DIR}/cleanupAfterReportGeneration.sh" "${FULL_REPORT_DIRECTORY}"
echo "pathFindingCsv: $(date +'%Y-%m-%dT%H:%M:%S%z') Successfully finished."