From 837f7d4c086f962d7da153859eb6fd4b272a2387 Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Tue, 25 Nov 2025 08:51:27 +0000 Subject: [PATCH] Update detection results to use correct key names for scores Corrects the key names used to retrieve detection results in `compare_models.py` to match the output format of the hybrid detector. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 600ade79-ad9b-4993-b968-e6466b703598 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/RJGlbTt --- .replit | 4 ---- python_ml/compare_models.py | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.replit b/.replit index 8eace38..3dc4618 100644 --- a/.replit +++ b/.replit @@ -18,10 +18,6 @@ externalPort = 80 localPort = 41303 externalPort = 3002 -[[ports]] -localPort = 41797 -externalPort = 3001 - [[ports]] localPort = 43471 externalPort = 3003 diff --git a/python_ml/compare_models.py b/python_ml/compare_models.py index 3429ff5..46f0cf5 100644 --- a/python_ml/compare_models.py +++ b/python_ml/compare_models.py @@ -116,6 +116,13 @@ def reanalyze_with_hybrid(detector, ip_address, old_detection): new_detection = result[0] # Confronto + new_score = new_detection.get('risk_score', 0) + new_type = new_detection.get('anomaly_type', 'unknown') + new_confidence = new_detection.get('confidence_level', 'unknown') + + # Determina se รจ anomalia (score >= 80 = critical threshold) + new_is_anomaly = new_score >= 80 + comparison = { 'ip_address': ip_address, 'logs_count': len(logs), @@ -126,14 +133,14 @@ def reanalyze_with_hybrid(detector, ip_address, old_detection): 'old_blocked': old_detection['blocked'], # Nuovo modello Hybrid (rianalisi) - 'new_score': new_detection.get('anomaly_score', 0), - 'new_anomaly_type': new_detection.get('anomaly_type', 'unknown'), - 'new_confidence': new_detection.get('confidence', 'unknown'), - 'new_is_anomaly': new_detection.get('is_anomaly', False), + 'new_score': new_score, + 'new_anomaly_type': new_type, + 'new_confidence': new_confidence, + 'new_is_anomaly': new_is_anomaly, # Delta - 'score_delta': new_detection.get('anomaly_score', 0) - float(old_detection['risk_score']), - 'type_changed': old_detection['anomaly_type'] != new_detection.get('anomaly_type', 'unknown'), + 'score_delta': new_score - float(old_detection['risk_score']), + 'type_changed': old_detection['anomaly_type'] != new_type, } return comparison