File size: 1,598 Bytes
4ad3b10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import numpy as np
from datetime import datetime

def evaluate_coldroom_status(anomaly_detected, temp, is_night, is_weekend, is_peak, reconstruction_error, threshold):
    """
    Implements the intensity math from your JavaScript snippet for Coldrooms.
    """
    intense = 0
    if anomaly_detected:
        intense += 2
        if is_night:
            intense += 1
        if is_weekend:
            intense += 1
            
    if not is_peak and temp > 35:
        intense += 2
        
    if reconstruction_error > threshold * 0.8:
        intense += 2
        
    level = "Normal"
    if intense >= 4:
        level = "Critical"
    elif intense >= 2:
        level = "Warning"
        
    return intense, level

def evaluate_tank_status(anomaly_detected, anomalies, is_night):
    """
    Implements the intensity math from your JavaScript snippet for Tanks.
    """
    intense = 0
    if anomaly_detected:
        intense += 2
        
    # Check for specific dangerous types
    has_impossible = any(a.get('type') == 'impossible_value' for a in anomalies)
    has_spike = any(a.get('type') == 'sudden_spike' for a in anomalies)
    has_fault = any(a.get('type') == 'sensor_fault' for a in anomalies)
    
    if has_impossible:
        intense += 2
    if has_spike:
        intense += 1
    if has_fault:
        intense += 1
        
    if anomaly_detected and is_night:
        intense += 1
        
    # Mapping to Level
    level = "Normal"
    if intense >= 4:
        level = "Critical"
    elif intense >= 2:
        level = "Warning"
        
    return intense, level