Spaces:
Sleeping
Sleeping
File size: 2,499 Bytes
f95ba65 | 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | from __future__ import annotations
from typing import Any, Dict
import math
def _f(x: Any, default: float = 0.0) -> float:
try:
return float(x)
except (TypeError, ValueError):
return float(default)
def _i(x: Any, default: int = 0) -> int:
try:
return int(x)
except (TypeError, ValueError):
return int(default)
def compute_engineered(values: Dict[str, Any]) -> Dict[str, Any]:
"""
Reproduit à l'identique Transform.feature_engineering(df) mais sur un dict.
IMPORTANT
- Nécessite 4 champs de satisfaction (comme dans l'ETL):
satisfaction_employee_environnement
satisfaction_employee_nature_travail
satisfaction_employee_equipe
satisfaction_employee_equilibre_pro_perso
- Le dashboard peut cacher ces champs dans l'UI si tu veux,
mais ils doivent exister pour un calcul strictement identique.
"""
d = dict(values)
sat_env = _f(d.get("satisfaction_employee_environnement"))
sat_nat = _f(d.get("satisfaction_employee_nature_travail"))
sat_eqp = _f(d.get("satisfaction_employee_equipe"))
sat_wlb = _f(d.get("satisfaction_employee_equilibre_pro_perso"))
d["satisfaction_moyenne"] = (sat_env + sat_nat + sat_eqp + sat_wlb) / 4.0
pee = _f(d.get("nombre_participation_pee"))
anc = _f(d.get("annees_dans_l_entreprise"))
d["nonlineaire_participation_pee"] = pee / (pee + anc + 1.0)
hs = _f(d.get("heures_supplementaires"))
salaire = _f(d.get("revenu_mensuel"))
d["ratio_heures_sup_salaire"] = hs / (salaire + 1.0)
dist = _f(d.get("distance_domicile_travail"))
# d/(d+10)/(d+10) = d / (d+10)^2
denom = (dist + 10.0)
d["nonlinaire_charge_contrainte"] = hs * dist / (denom * denom)
d["nonlinaire_surmenage_insatisfaction"] = hs * (1.0 - _f(d["satisfaction_moyenne"]))
age = _i(d.get("age"))
d["jeune_surcharge"] = int((age < 30) and (hs == 1.0))
# (annees_dans_l_entreprise - annees_depuis_la_derniere_promotion)/(annees_dans_l_entreprise + 1)
adlp = _f(d.get("annees_depuis_la_derniere_promotion"))
d["anciennete_sans_promotion"] = (anc - adlp) / (anc + 1.0)
nb_exp = _f(d.get("nombre_experiences_precedentes"))
tot_exp = _f(d.get("annee_experience_totale"))
d["mobilite_carriere"] = nb_exp / (tot_exp + 1.0)
d["risque_global"] = (
_f(d["ratio_heures_sup_salaire"])
* _f(d["anciennete_sans_promotion"])
* (1.0 - _f(d["satisfaction_moyenne"]))
)
return d
|