#!/usr/bin/env python3
# HARA ASIL determination per ISO 26262 Part 3 Table 4
ASIL_TABLE = {
# (S, E, C): ASIL
(1,1,1): "QM", (1,1,2): "QM", (1,1,3): "QM",
(1,2,1): "QM", (1,2,2): "QM", (1,2,3): "QM",
(1,3,1): "QM", (1,3,2): "QM", (1,3,3): "A",
(1,4,1): "QM", (1,4,2): "QM", (1,4,3): "A",
(2,1,1): "QM", (2,1,2): "QM", (2,1,3): "QM",
(2,2,1): "QM", (2,2,2): "QM", (2,2,3): "A",
(2,3,1): "QM", (2,3,2): "A", (2,3,3): "B",
(2,4,1): "QM", (2,4,2): "A", (2,4,3): "B",
(3,1,1): "QM", (3,1,2): "QM", (3,1,3): "A",
(3,2,1): "QM", (3,2,2): "A", (3,2,3): "B",
(3,3,1): "A", (3,3,2): "B", (3,3,3): "C",
(3,4,1): "B", (3,4,2): "C", (3,4,3): "D",
}
def determine_asil(severity, exposure, controllability, hazard_name=""):
key = (severity, exposure, controllability)
asil = ASIL_TABLE.get(key, "Invalid")
print(f" {hazard_name or 'Hazard'}: S{severity}, E{exposure}, C{controllability} → ASIL {asil}")
return asil
# EPS HARA example
print("HARA Results — Electronic Power Steering:")
determine_asil(3, 3, 2, "Unintended torque > 3Nm at highway speed") # → ASIL C
determine_asil(3, 3, 1, "Loss of steering assist at low speed") # → ASIL B
determine_asil(2, 2, 2, "Torque oscillation < 1Nm at parking speed") # → QM