Spaces:
Sleeping
Sleeping
Update executives/nexus_qualification.py
Browse files
executives/nexus_qualification.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
# executives/nexus_qualification.py
|
| 2 |
import joblib
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
MODEL_UNIFIED_PATH = "../pickle_result/nexus_modele_final_V35.pkl"
|
| 6 |
|
| 7 |
# =====================================================================
|
| 8 |
# MATRICE LÉGALE DE L'ÉTAT FRANÇAIS (SGDSN / DISPOSITIF ORSEC)
|
| 9 |
-
# Cloisonnement strict des cibles par domaine d'intervention
|
| 10 |
# =====================================================================
|
| 11 |
MATRICE_CIBLES_ISOLEES = {
|
| 12 |
"MÉDICAL": {"CITOYEN": 1, "VIP_LOCAL": 2, "PRESIDENT": 5},
|
|
@@ -40,37 +40,80 @@ class QualificationEngine:
|
|
| 40 |
elif cible_id == 4: return "PRESIDENT"
|
| 41 |
return "CITOYEN"
|
| 42 |
|
| 43 |
-
def calculer_priorite_sgdsn(self, domaine, severite, impact, profil_cible):
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return 20.0
|
| 48 |
-
elif domaine in ["CYBERSÉCURITÉ", "ÉNERGIE & INFRASTRUCTURES", "TRANSPORT & MOBILITÉ"]
|
| 49 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
if (severite == 4 and domaine in ["MÉDICAL", "POMPIER", "POLICE", "RISQUES ENVIRONNEMENTAUX", "CYBERSÉCURITÉ"]) or \
|
| 53 |
-
(severite >= 3 and profil_cible == "VIP_LOCAL" and domaine in ["CYBERSÉCURITÉ", "ÉNERGIE & INFRASTRUCTURES", "MÉDICAL"])
|
|
|
|
| 54 |
|
| 55 |
base_vitale = 10.0
|
| 56 |
-
|
| 57 |
delta_masse = 0.0
|
|
|
|
| 58 |
if impact == 2: delta_masse = 1.5
|
| 59 |
elif impact == 3: delta_masse = 3.0
|
| 60 |
elif impact == 4: delta_masse = 4.5
|
| 61 |
|
|
|
|
|
|
|
|
|
|
| 62 |
delta_infra = 0.0
|
| 63 |
-
if profil_cible == "VIP_LOCAL"
|
|
|
|
| 64 |
|
| 65 |
score_final = base_vitale + delta_masse + delta_infra
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
#
|
| 69 |
poids_cible = MATRICE_CIBLES_ISOLEES.get(domaine, {}).get(profil_cible, 1)
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
return min(round(score_normalise, 1),
|
| 74 |
|
| 75 |
def evaluer_ticket(self, texte):
|
| 76 |
if self.mode == "ML":
|
|
@@ -80,11 +123,10 @@ class QualificationEngine:
|
|
| 80 |
severite = int(float(prediction[1]))
|
| 81 |
impact = int(float(prediction[2]))
|
| 82 |
cible_id = int(float(prediction[3]))
|
| 83 |
-
|
| 84 |
friction = str(prediction[4]).upper()
|
| 85 |
|
| 86 |
profil_cible = self.traduire_cible_ml(cible_id)
|
| 87 |
-
score = self.calculer_priorite_sgdsn(domaine, severite, impact, profil_cible)
|
| 88 |
|
| 89 |
return domaine, score, friction
|
| 90 |
else:
|
|
|
|
| 1 |
# executives/nexus_qualification.py
|
| 2 |
import joblib
|
| 3 |
import os
|
| 4 |
+
import re
|
| 5 |
|
| 6 |
MODEL_UNIFIED_PATH = "../pickle_result/nexus_modele_final_V35.pkl"
|
| 7 |
|
| 8 |
# =====================================================================
|
| 9 |
# MATRICE LÉGALE DE L'ÉTAT FRANÇAIS (SGDSN / DISPOSITIF ORSEC)
|
|
|
|
| 10 |
# =====================================================================
|
| 11 |
MATRICE_CIBLES_ISOLEES = {
|
| 12 |
"MÉDICAL": {"CITOYEN": 1, "VIP_LOCAL": 2, "PRESIDENT": 5},
|
|
|
|
| 40 |
elif cible_id == 4: return "PRESIDENT"
|
| 41 |
return "CITOYEN"
|
| 42 |
|
| 43 |
+
def calculer_priorite_sgdsn(self, domaine, severite, impact, profil_cible, texte_brut=""):
|
| 44 |
+
t_lower = str(texte_brut).lower()
|
| 45 |
+
|
| 46 |
+
# 1. COUPE-CIRCUIT ABSOLU (PROTOCOLE JUPITER : 18.0 - 20.0)
|
| 47 |
+
# CORRECTION : Une centrale nucléaire ou un site souverain est traité au même niveau que le Chef de l'État
|
| 48 |
+
is_souverain = (profil_cible == "PRESIDENT") or bool(re.search(r'\b(centrale|nucléaire|nucleaire)\b', t_lower))
|
| 49 |
+
|
| 50 |
+
if is_souverain:
|
| 51 |
+
if domaine in ["MÉDICAL", "POLICE", "POMPIER", "RISQUES ENVIRONNEMENTAUX"] and severite >= 3:
|
| 52 |
return 20.0
|
| 53 |
+
elif domaine in ["CYBERSÉCURITÉ", "ÉNERGIE & INFRASTRUCTURES", "TRANSPORT & MOBILITÉ"]:
|
| 54 |
+
return 20.0
|
| 55 |
+
|
| 56 |
+
# 2. PLAFONDS DE VERRE (Niveau 1 : Domaines Bridés)
|
| 57 |
+
if domaine in ["NON_URGENT", "EN_ATTENTE"]:
|
| 58 |
+
return 0.2
|
| 59 |
+
if domaine == "DIGITAL SUPPORT":
|
| 60 |
+
return min((0.5 + severite * 0.5 + impact * 0.2), 2.9) if profil_cible == "CITOYEN" else 4.9
|
| 61 |
+
if domaine == "ANIMALIER":
|
| 62 |
+
return min((0.5 + severite * 1.0 + impact * 0.5), 2.9)
|
| 63 |
+
if domaine in ["SERVICES URBAINS", "ASSISTANCE SOCIALE"]:
|
| 64 |
+
return min((0.5 + severite * 1.0 + impact * 1.0), 4.9)
|
| 65 |
|
| 66 |
+
# SCANNER DE MASSE (PLAN NOVI)
|
| 67 |
+
has_groupe = re.search(r'\b(groupe|foule|plusieurs|masse|nombreux|personnes|gens|équipe|classe|centaine|cinquantaine)\b', t_lower)
|
| 68 |
+
has_transport = re.search(r'\b(bus|cars|car|train|métro|metro|tram|avion|navire)\b', t_lower)
|
| 69 |
+
|
| 70 |
+
# 3. DOCTRINE DE GUERRE / MASSE (PLAN NOVI / CIBLES STRATÉGIQUES : 10.1 - 15.0)
|
| 71 |
if (severite == 4 and domaine in ["MÉDICAL", "POMPIER", "POLICE", "RISQUES ENVIRONNEMENTAUX", "CYBERSÉCURITÉ"]) or \
|
| 72 |
+
(severite >= 3 and profil_cible == "VIP_LOCAL" and domaine in ["CYBERSÉCURITÉ", "ÉNERGIE & INFRASTRUCTURES", "MÉDICAL", "TRANSPORT & MOBILITÉ"]) or \
|
| 73 |
+
(has_groupe and (domaine in ["POMPIER", "MÉDICAL", "POLICE"])):
|
| 74 |
|
| 75 |
base_vitale = 10.0
|
|
|
|
| 76 |
delta_masse = 0.0
|
| 77 |
+
|
| 78 |
if impact == 2: delta_masse = 1.5
|
| 79 |
elif impact == 3: delta_masse = 3.0
|
| 80 |
elif impact == 4: delta_masse = 4.5
|
| 81 |
|
| 82 |
+
if has_groupe: delta_masse = max(delta_masse, 3.5)
|
| 83 |
+
if has_transport: delta_masse = max(delta_masse, 4.0)
|
| 84 |
+
|
| 85 |
delta_infra = 0.0
|
| 86 |
+
if profil_cible == "VIP_LOCAL" or re.search(r'\b(hôpital|hopital|clinique|école|ecole|gare|aéroport)\b', t_lower):
|
| 87 |
+
delta_infra = 4.0
|
| 88 |
|
| 89 |
score_final = base_vitale + delta_masse + delta_infra
|
| 90 |
+
|
| 91 |
+
if domaine in ["CYBERSÉCURITÉ", "ÉNERGIE & INFRASTRUCTURES"]:
|
| 92 |
+
return min(round(score_final, 1), 15.0)
|
| 93 |
+
|
| 94 |
+
return min(round(score_final, 1), 19.9)
|
| 95 |
|
| 96 |
+
# 4. ÉCHELLE CIVILE DYNAMIQUE (Urgence Vitale Individuelle : 5.0 - 10.0)
|
| 97 |
poids_cible = MATRICE_CIBLES_ISOLEES.get(domaine, {}).get(profil_cible, 1)
|
| 98 |
+
score_base = 0.5 + (severite * 1.5) + (impact * 1.0) + (poids_cible * 0.5)
|
| 99 |
+
|
| 100 |
+
bonus_gravite = 0.0
|
| 101 |
+
|
| 102 |
+
mots_stress = ['très', 'tres', 'ultra', 'grave', 'gravement', 'fort', 'forte', 'énorme', 'enorme', 'extrême', 'extreme', 'pire', 'vite', 'urgence']
|
| 103 |
+
if any(mot in t_lower for mot in mots_stress):
|
| 104 |
+
bonus_gravite += 1.2
|
| 105 |
+
|
| 106 |
+
mots_cliniques = ['sang', 'saigne', 'douleur', 'pression', 'brûlure', 'brule', 'coupé', 'coupe', 'cassé', 'casse', 'tomber', 'tombé']
|
| 107 |
+
if any(mot in t_lower for mot in mots_cliniques):
|
| 108 |
+
bonus_gravite += 1.8
|
| 109 |
+
|
| 110 |
+
mots_liste = t_lower.split()
|
| 111 |
+
if len(mots_liste) <= 4 and bonus_gravite > 0:
|
| 112 |
+
bonus_gravite += 0.8
|
| 113 |
+
|
| 114 |
+
score_normalise = score_base + bonus_gravite
|
| 115 |
|
| 116 |
+
return min(round(score_normalise, 1), 10.0)
|
| 117 |
|
| 118 |
def evaluer_ticket(self, texte):
|
| 119 |
if self.mode == "ML":
|
|
|
|
| 123 |
severite = int(float(prediction[1]))
|
| 124 |
impact = int(float(prediction[2]))
|
| 125 |
cible_id = int(float(prediction[3]))
|
|
|
|
| 126 |
friction = str(prediction[4]).upper()
|
| 127 |
|
| 128 |
profil_cible = self.traduire_cible_ml(cible_id)
|
| 129 |
+
score = self.calculer_priorite_sgdsn(domaine, severite, impact, profil_cible, str(texte))
|
| 130 |
|
| 131 |
return domaine, score, friction
|
| 132 |
else:
|