File size: 993 Bytes
fc0c33d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# anomaly_score.py

import datetime

class AnomalyScorer:
    def __init__(self):
        self.history = []

    def score_event(self, event_type: str, data: dict) -> dict:
        base_score = {
            "unauthorized_access": 80,
            "unexpected_output": 50,
            "module_instability": 60,
            "unknown_connection": 90,
            "philosophical_dissonance": 40,
        }.get(event_type, 10)

        # Increase score if suspicious data is present
        if data.get("confidence") and data["confidence"] < 0.4:
            base_score += 20

        if "kill" in data.get("content", "").lower():
            base_score += 50

        result = {
            "timestamp": datetime.datetime.utcnow().isoformat(),
            "event": event_type,
            "score": min(base_score, 100),
            "notes": f"Scored anomaly: {event_type}"
        }

        self.history.append(result)
        return result

    def get_history(self):
        return self.history