def calculate_health(current, voltage, vibration,
baseline_current=5.0,
baseline_voltage=220.0,
baseline_vibration=0.5,
current_trend=0.0,
vibration_trend=0.0):
Calculates health percentage (0-100) based on sensor deviations.
health = 100.0
# 1. Current penalty
current_increase = max(0, current - baseline_current)
health -= current_increase * 3.0
# 2. Voltage deviation penalty
voltage_deviation = abs(voltage - baseline_voltage)
health -= (voltage_deviation / baseline_voltage) * 20.0
# 3. Vibration penalty
vibration_increase = max(0, vibration - baseline_vibration)
health -= vibration_increase * 8.0
# 4. Trend penalties
if current_trend > 0.05: health -= 5.0
if vibration_trend > 0.02: health -= 5.0
# 5. Cross-sensor correlation (Severe State)
current_severe = (current - baseline_current) > (0.2 * baseline_current)
vibration_severe = (vibration - baseline_vibration) > (0.5 * baseline_vibration)
if current_severe and vibration_severe:
health -= 15.0
# 6. Power efficiency check
power = voltage * current
expected_power = baseline_voltage * baseline_current
if power > expected_power * 1.2:
health -= 8.0
return max(0.0, min(100.0, health))