Skip to content

Commit 31b3783

Browse files
committed
Add Treemap visualization to anomaly detection
1 parent f19656b commit 31b3783

File tree

4 files changed

+1519
-7
lines changed

4 files changed

+1519
-7
lines changed

domains/anomaly-detection/anomalyDetectionPython.sh

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ REPORTS_DIRECTORY=${REPORTS_DIRECTORY:-"reports"}
2020
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
2121
# This way non-standard tools like readlink aren't needed.
2222
ANOMALY_DETECTION_SCRIPT_DIR=${ANOMALY_DETECTION_SCRIPT_DIR:-$(CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)}
23-
echo "anomalyDetectionPipeline: ANOMALY_DETECTION_SCRIPT_DIR=${ANOMALY_DETECTION_SCRIPT_DIR}"
23+
echo "anomalyDetectionPython: ANOMALY_DETECTION_SCRIPT_DIR=${ANOMALY_DETECTION_SCRIPT_DIR}"
2424
# Get the "scripts" directory by taking the path of this script and going one directory up.
2525
SCRIPTS_DIR=${SCRIPTS_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/../../scripts"} # Repository directory containing the shell scripts
2626
# Get the "cypher" query directory for gathering features.
@@ -49,7 +49,7 @@ while [[ $# -gt 0 ]]; do
4949
verboseMode="--verbose"
5050
;;
5151
*)
52-
echo -e "${COLOR_ERROR}anomalyDetectionPipeline: Error: Unknown option: ${key}${COLOR_DEFAULT}" >&2
52+
echo -e "${COLOR_ERROR}anomalyDetectionPython: Error: Unknown option: ${key}${COLOR_DEFAULT}" >&2
5353
usage
5454
;;
5555
esac
@@ -72,10 +72,10 @@ is_sufficient_data_available() {
7272
query_result=$( execute_cypher "${ANOMALY_DETECTION_QUERY_CYPHER_DIR}/AnomalyDetectionNodeCount.cypher" "${@}" )
7373
node_count=$(get_csv_column_value "${query_result}" "node_count")
7474
if [ "${node_count}" -lt 15 ]; then
75-
echo "anomalyDetectionPipeline: Warning: Skipping anomaly detection. Only ${node_count} ${language} ${nodeLabel} nodes. At least 15 required."
75+
echo "anomalyDetectionPython: Warning: Skipping anomaly detection. Only ${node_count} ${language} ${nodeLabel} nodes. At least 15 required."
7676
false
7777
else
78-
echo "anomalyDetectionPipeline: Info: Running anomaly detection with ${node_count} ${language} ${nodeLabel} nodes."
78+
echo "anomalyDetectionPython: Info: Running anomaly detection with ${node_count} ${language} ${nodeLabel} nodes."
7979
true
8080
fi
8181
}
@@ -92,7 +92,7 @@ is_sufficient_data_available() {
9292
anomaly_detection_features() {
9393
local nodeLabel
9494
nodeLabel=$( extractQueryParameter "projection_node_label" "${@}" )
95-
echo "anomalyDetectionPipeline: $(date +'%Y-%m-%dT%H:%M:%S%z') Collecting features for ${nodeLabel} nodes..."
95+
echo "anomalyDetectionPython: $(date +'%Y-%m-%dT%H:%M:%S%z') Collecting features for ${nodeLabel} nodes..."
9696

9797
# Determine the Betweenness centrality (with the directed graph projection) if not already done
9898
execute_cypher_queries_until_results "${ANOMALY_DETECTION_FEATURE_CYPHER_DIR}/AnomalyDetectionFeature-Betweenness-Exists.cypher" \
@@ -127,7 +127,7 @@ anomaly_detection_using_python() {
127127
local language
128128
language=$( extractQueryParameter "projection_language" "${@}" )
129129

130-
echo "anomalyDetectionPipeline: $(date +'%Y-%m-%dT%H:%M:%S%z') Executing Python scripts for ${language} ${nodeLabel} nodes..."
130+
echo "anomalyDetectionPython: $(date +'%Y-%m-%dT%H:%M:%S%z') Executing Python scripts for ${language} ${nodeLabel} nodes..."
131131

132132
# Within the absolute (full) report directory for anomaly detection, create a sub directory for every detailed type (Java_Package, Java_Type,...)
133133
local detail_report_directory="${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}"
@@ -152,6 +152,8 @@ anomaly_detection_using_python() {
152152
# Required Parameters:
153153
# - projection_node_label=...
154154
# Label of the nodes that will be used for the projection. Example: "Package"
155+
# - projection_language=...
156+
# Name of the associated programming language. Examples: "Java", "Typescript"
155157
anomaly_detection_labels() {
156158
local nodeLabel
157159
nodeLabel=$( extractQueryParameter "projection_node_label" "${@}" )
@@ -168,6 +170,19 @@ anomaly_detection_labels() {
168170
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}"
169171
}
170172

173+
# Visualize results with treemap charts.
174+
#
175+
# Required Parameters:
176+
# - projection_language=...
177+
# Name of the associated programming language. Examples: "Java", "Typescript"
178+
anomaly_detection_treemap_visualization() {
179+
local language
180+
language=$( extractQueryParameter "projection_language" "${@}" )
181+
182+
echo "anomalyDetectionPython: $(date +'%Y-%m-%dT%H:%M:%S%z') Visualizing ${language} results..."
183+
time "${ANOMALY_DETECTION_SCRIPT_DIR}/treemapVisualizations.py" "${@}" "--report_directory" "${FULL_REPORT_DIRECTORY}" ${verboseMode}
184+
}
185+
171186
# Run the anomaly detection pipeline.
172187
#
173188
# Required Parameters:
@@ -177,6 +192,8 @@ anomaly_detection_labels() {
177192
# Label of the nodes that will be used for the projection. Example: "Package"
178193
# - projection_weight_property=...
179194
# Name of the node property that contains the dependency weight. Example: "weight"
195+
# - projection_language=...
196+
# Name of the associated programming language. Examples: "Java", "Typescript"
180197
anomaly_detection_python_reports() {
181198
time anomaly_detection_features "${@}"
182199
anomaly_detection_using_python "${@}"
@@ -229,6 +246,7 @@ if is_sufficient_data_available "${ALGORITHM_NODE}=Type" "${ALGORITHM_WEIGHT}=we
229246
if createUndirectedJavaTypeDependencyProjection "${PROJECTION_NAME}=type-anomaly-detection"; then
230247
createDirectedJavaTypeDependencyProjection "${PROJECTION_NAME}=type-anomaly-detection-directed"
231248
anomaly_detection_python_reports "${ALGORITHM_PROJECTION}=type-anomaly-detection" "${ALGORITHM_NODE}=Type" "${ALGORITHM_WEIGHT}=weight" "${ALGORITHM_LANGUAGE}=Java" "${COMMUNITY_PROPERTY}" "${EMBEDDING_PROPERTY}"
249+
anomaly_detection_treemap_visualization "${ALGORITHM_LANGUAGE}=Java"
232250
fi
233251
fi
234252

@@ -238,6 +256,7 @@ if is_sufficient_data_available "${ALGORITHM_NODE}=Module" "${ALGORITHM_WEIGHT}=
238256
if createUndirectedDependencyProjection "${PROJECTION_NAME}=typescript-module-embedding" "${PROJECTION_NODE}=Module" "${PROJECTION_WEIGHT}=lowCouplingElement25PercentWeight" "${PROJECTION_LANGUAGE}=Typescript"; then
239257
createDirectedDependencyProjection "${PROJECTION_NAME}=typescript-module-embedding-directed" "${PROJECTION_NODE}=Module" "${PROJECTION_WEIGHT}=lowCouplingElement25PercentWeight" "${PROJECTION_LANGUAGE}=Typescript"
240258
anomaly_detection_python_reports "${ALGORITHM_PROJECTION}=typescript-module-embedding" "${ALGORITHM_NODE}=Module" "${ALGORITHM_WEIGHT}=lowCouplingElement25PercentWeight" "${ALGORITHM_LANGUAGE}=Typescript" "${COMMUNITY_PROPERTY}" "${EMBEDDING_PROPERTY}"
259+
anomaly_detection_treemap_visualization "${ALGORITHM_LANGUAGE}=Module"
241260
fi
242261
fi
243262

@@ -246,4 +265,4 @@ fi
246265
# Clean-up after report generation. Empty reports will be deleted.
247266
source "${SCRIPTS_DIR}/cleanupAfterReportGeneration.sh" "${FULL_REPORT_DIRECTORY}"
248267

249-
echo "anomalyDetectionPipeline: $(date +'%Y-%m-%dT%H:%M:%S%z') Successfully finished."
268+
echo "anomalyDetectionPython: $(date +'%Y-%m-%dT%H:%M:%S%z') Successfully finished."

0 commit comments

Comments
 (0)