Skip to content

Commit 18a01e7

Browse files
committed
Add csv query reports to anomaly detection
1 parent cff7aaa commit 18a01e7

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

domains/anomaly-detection/anomalyDetectionPython.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,23 @@ anomaly_detection_labels() {
162162

163163
local language
164164
language=$( extractQueryParameter "projection_language" "${@}" )
165-
165+
166166
echo "anomalyDetectionPython: $(date +'%Y-%m-%dT%H:%M:%S%z') Labelling ${language} ${nodeLabel} anomalies..."
167+
168+
# Within the absolute (full) report directory for anomaly detection, create a sub directory for every detailed type (Java_Package, Java_Type,...)
169+
local detail_report_directory="${FULL_REPORT_DIRECTORY}/${language}_${nodeLabel}"
170+
mkdir -p "${detail_report_directory}"
171+
167172
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeRemoveLabels.cypher" "${@}"
168-
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeAuthority.cypher" "${@}"
169-
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBottleneck.cypher" "${@}"
170-
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeHub.cypher" "${@}"
171-
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBridge.cypher" "${@}"
172-
execute_cypher_summarized "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}"
173+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeAuthority.cypher" "${@}" > "${detail_report_directory}/AnomalyArchetypeTopAuthority.csv"
174+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBottleneck.cypher" "${@}" > "${detail_report_directory}/AnomalyArchetypeTopBottleneck.csv"
175+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeHub.cypher" "${@}" > "${detail_report_directory}/AnomalyArchetypeTopHub.csv"
176+
# The following two label types require Python scripts to run first.
177+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeBridge.cypher" "${@}" > "${detail_report_directory}/AnomalyArchetypeTopBridge.csv"
178+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionArchetypeOutlier.cypher" "${@}" > "${detail_report_directory}/AnomalyArchetypeTopOutlier.csv"
179+
# Output the top anomalies and their archetype + rank
180+
execute_cypher "${ANOMALY_DETECTION_LABEL_CYPHER_DIR}/AnomalyDetectionTopAnomalies.cypher" "${@}" > "${detail_report_directory}/TopAnomalies.csv"
181+
173182
}
174183

175184
# Run the anomaly detection pipeline.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// List top anomalies
2+
3+
MATCH (codeUnit)
4+
WHERE $projection_node_label IN labels(codeUnit)
5+
AND codeUnit.anomalyScore > 0
6+
AND codeUnit.anomalyLabel = 1
7+
ORDER BY codeUnit.anomalyScore DESC
8+
LIMIT 50
9+
OPTIONAL MATCH (artifact:Java:Artifact)-[:CONTAINS]->(codeUnit)
10+
WITH *, artifact.name AS artifactName
11+
OPTIONAL MATCH (projectRoot:Directory)<-[:HAS_ROOT]-(proj:TS:Project)-[:CONTAINS]->(codeUnit)
12+
WITH *, last(split(projectRoot.absoluteFileName, '/')) AS projectName
13+
WITH *, coalesce(artifactName, projectName) AS projectName
14+
RETURN projectName
15+
,codeUnit.name AS shortCodeUnitName
16+
,coalesce(codeUnit.fqn, codeUnit.globalFqn, codeUnit.fileName, codeUnit.signature, codeUnit.name) AS codeUnitName
17+
,codeUnit.anomalyScore AS anomalyScore
18+
,coalesce(codeUnit.anomalyAuthorityRank, 0) AS authorityRank
19+
,coalesce(codeUnit.anomalyBottleneckRank, 0) AS bottleneckRank
20+
,coalesce(codeUnit.anomalyBridgeRank, 0) AS bridgeRank
21+
,coalesce(codeUnit.anomalyHubRank, 0) AS hubRank
22+
,coalesce(codeUnit.anomalyOutlierRank, 0) AS outlierRank
23+
,codeUnit.anomalyTopFeature1 AS topFeature1
24+
,codeUnit.anomalyTopFeature2 AS topFeature2
25+
,codeUnit.anomalyTopFeature3 AS topFeature3
26+
,codeUnit.anomalyTopFeatureSHAPValue1 AS topFeature1Score
27+
,codeUnit.anomalyTopFeatureSHAPValue2 AS topFeature2Score
28+
,codeUnit.anomalyTopFeatureSHAPValue3 AS topFeature3Score

0 commit comments

Comments
 (0)