Skip to content

Commit 024b71d

Browse files
committed
Add anomaly archetype labels and reports
1 parent d8a331c commit 024b71d

9 files changed

+615
-4
lines changed

domains/anomaly-detection/anomalyDetectionCsv.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ SCRIPTS_DIR=${SCRIPTS_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/../../scripts"} # Re
2525
# Get the "cypher" query directory for gathering features.
2626
ANOMALY_DETECTION_FEATURE_CYPHER_DIR=${ANOMALY_DETECTION_FEATURE_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/features"}
2727
ANOMALY_DETECTION_QUERY_CYPHER_DIR=${ANOMALY_DETECTION_QUERY_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/queries"}
28+
ANOMALY_DETECTION_LABEL_CYPHER_DIR=${ANOMALY_DETECTION_LABEL_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/labels"}
2829

29-
# Define functions to execute a cypher query from within a given file (first and only argument) like "execute_cypher"
30+
# Define functions to execute a cypher query from within a given file (first and only argument) like "execute_cypher" and "execute_cypher_summarized"
3031
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
3132

3233
# Define functions to create and delete Graph Projections like "createUndirectedDependencyProjection"
@@ -60,6 +61,7 @@ anomaly_detection_features() {
6061
execute_cypher_queries_until_results "${ANOMALY_DETECTION_FEATURE_CYPHER_DIR}/AnomalyDetectionFeature-ArticleRank-Exists.cypher" \
6162
"${ANOMALY_DETECTION_FEATURE_CYPHER_DIR}/AnomalyDetectionFeature-ArticleRank-Write.cypher" "${@}"
6263
}
64+
6365
# Run queries to find anomalies in the graph.
6466
#
6567
# Required Parameters:
@@ -85,6 +87,28 @@ anomaly_detection_queries() {
8587
execute_cypher "${ANOMALY_DETECTION_QUERY_CYPHER_DIR}/AnomalyDetectionUnexpectedCentralNodes.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}_AnomalyDetection_UnexpectedCentralNodes.csv"
8688
}
8789

90+
# Label code units with top anomalies by archetype.
91+
#
92+
# Required Parameters:
93+
# - projection_node_label=...
94+
# Label of the nodes that will be used for the projection. Example: "Package"
95+
anomaly_detection_labels() {
96+
local nodeLabel
97+
nodeLabel=$( extractQueryParameter "projection_node_label" "${@}" )
98+
99+
local language
100+
language=$( extractQueryParameter "projection_language" "${@}" )
101+
102+
echo "anomalyDetectionCsv: $(date +'%Y-%m-%dT%H:%M:%S%z') Labelling ${language} ${nodeLabel} anomalies..."
103+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeRemoveLabels.cypher" "${@}"
104+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeAuthority.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}_AnomalyArchetypeTopAuthority.csv"
105+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBottleneck.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}_AnomalyArchetypeTopBottleneck.csv"
106+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeHub.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}_AnomalyArchetypeTopHub.csv"
107+
# The following two label types require Python scripts to run first and are skipped here intentionally:
108+
# execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBridge.cypher" "${@}"
109+
# execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}"
110+
}
111+
88112
# Run the anomaly detection pipeline.
89113
#
90114
# Required Parameters:
@@ -97,6 +121,7 @@ anomaly_detection_queries() {
97121
anomaly_detection_csv_reports() {
98122
time anomaly_detection_features "${@}"
99123
time anomaly_detection_queries "${@}"
124+
time anomaly_detection_labels "${@}"
100125
}
101126

102127
# Create report directory

domains/anomaly-detection/anomalyDetectionPython.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SCRIPTS_DIR=${SCRIPTS_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/../../scripts"} # Re
2525
# Get the "cypher" query directory for gathering features.
2626
ANOMALY_DETECTION_FEATURE_CYPHER_DIR=${ANOMALY_DETECTION_FEATURE_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/features"}
2727
ANOMALY_DETECTION_QUERY_CYPHER_DIR=${ANOMALY_DETECTION_QUERY_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/queries"}
28+
ANOMALY_DETECTION_LABEL_CYPHER_DIR=${ANOMALY_DETECTION_LABEL_CYPHER_DIR:-"${ANOMALY_DETECTION_SCRIPT_DIR}/labels"}
2829

2930
# Function to display script usage
3031
usage() {
@@ -138,6 +139,27 @@ anomaly_detection_using_python() {
138139
execute_cypher "${ANOMALY_DETECTION_FEATURE_CYPHER_DIR}/AnomalyDetectionFeatures.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}AnomalyDetection_Features.csv"
139140
}
140141

142+
# Label code units with top anomalies by archetype.
143+
#
144+
# Required Parameters:
145+
# - projection_node_label=...
146+
# Label of the nodes that will be used for the projection. Example: "Package"
147+
anomaly_detection_labels() {
148+
local nodeLabel
149+
nodeLabel=$( extractQueryParameter "projection_node_label" "${@}" )
150+
151+
local language
152+
language=$( extractQueryParameter "projection_language" "${@}" )
153+
154+
echo "anomalyDetectionPython: $(date +'%Y-%m-%dT%H:%M:%S%z') Labelling ${language} ${nodeLabel} anomalies..."
155+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeRemoveLabels.cypher" "${@}"
156+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeAuthority.cypher" "${@}"
157+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBottleneck.cypher" "${@}"
158+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeHub.cypher" "${@}"
159+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBridge.cypher" "${@}"
160+
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}"
161+
}
162+
141163
# Run the anomaly detection pipeline.
142164
#
143165
# Required Parameters:
@@ -150,6 +172,7 @@ anomaly_detection_using_python() {
150172
anomaly_detection_python_reports() {
151173
time anomaly_detection_features "${@}"
152174
anomaly_detection_using_python "${@}"
175+
time anomaly_detection_labels "${@}"
153176
}
154177

155178
# Create report directory

0 commit comments

Comments
 (0)