Spaces:
Runtime error
Runtime error
Create Anomaly_score.py
Browse files- Anomaly_score.py +36 -0
Anomaly_score.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# anomaly_score.py
|
2 |
+
|
3 |
+
import datetime
|
4 |
+
|
5 |
+
class AnomalyScorer:
|
6 |
+
def __init__(self):
|
7 |
+
self.history = []
|
8 |
+
|
9 |
+
def score_event(self, event_type: str, data: dict) -> dict:
|
10 |
+
base_score = {
|
11 |
+
"unauthorized_access": 80,
|
12 |
+
"unexpected_output": 50,
|
13 |
+
"module_instability": 60,
|
14 |
+
"unknown_connection": 90,
|
15 |
+
"philosophical_dissonance": 40,
|
16 |
+
}.get(event_type, 10)
|
17 |
+
|
18 |
+
# Increase score if suspicious data is present
|
19 |
+
if data.get("confidence") and data["confidence"] < 0.4:
|
20 |
+
base_score += 20
|
21 |
+
|
22 |
+
if "kill" in data.get("content", "").lower():
|
23 |
+
base_score += 50
|
24 |
+
|
25 |
+
result = {
|
26 |
+
"timestamp": datetime.datetime.utcnow().isoformat(),
|
27 |
+
"event": event_type,
|
28 |
+
"score": min(base_score, 100),
|
29 |
+
"notes": f"Scored anomaly: {event_type}"
|
30 |
+
}
|
31 |
+
|
32 |
+
self.history.append(result)
|
33 |
+
return result
|
34 |
+
|
35 |
+
def get_history(self):
|
36 |
+
return self.history
|