prioriter fair
This commit is contained in:
@ -2,8 +2,96 @@
|
||||
from typing import Dict, Any, List
|
||||
from engine.logger import log_debug, log_info
|
||||
|
||||
|
||||
def load_tp_config_for_con(cur, con_id: int):
|
||||
"""
|
||||
Charge automatiquement toute la configuration TP (det_type = 1)
|
||||
pour un con_id, sans coder les groupes/celfs en dur.
|
||||
|
||||
def load_tp_config_for_con(cur, con_id: int) -> Dict[int, Dict[str, Dict[str, List[Dict[str, Any]]]]]:
|
||||
Structure produite (identique à ton ancienne fonction) :
|
||||
{
|
||||
tp_id: {
|
||||
"tp_name": "...",
|
||||
"config": {
|
||||
<det_groupe>: {
|
||||
<det_clef>: [
|
||||
{
|
||||
det_id,
|
||||
value1, value2, value3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
# 1) Récupérer tous les TP liés au con_id
|
||||
cur.execute("""
|
||||
SELECT tp_id, tp_name
|
||||
FROM reader_config_timingpoint
|
||||
WHERE con_id = %s
|
||||
""", (con_id,))
|
||||
tps = cur.fetchall()
|
||||
|
||||
tp_config = {}
|
||||
|
||||
for tp in tps:
|
||||
tp_id = tp["tp_id"]
|
||||
tp_config[tp_id] = {
|
||||
"tp_name": tp["tp_name"],
|
||||
"config": {}
|
||||
}
|
||||
|
||||
if not tps:
|
||||
log_info(f"[CONFIG] Aucun TP trouvé pour con_id={con_id}")
|
||||
return {}
|
||||
|
||||
# 2) Récupérer toutes les configs det_type = 1 liées aux TP
|
||||
cur.execute("""
|
||||
SELECT
|
||||
d.det_id,
|
||||
d.det_ref1_id AS tp_id,
|
||||
d.det_groupe,
|
||||
d.det_clef,
|
||||
d.det_value1,
|
||||
d.det_value2,
|
||||
d.det_value3
|
||||
FROM reader_config_detail d
|
||||
JOIN reader_config_timingpoint tp ON tp.tp_id = d.det_ref1_id
|
||||
WHERE tp.con_id = %s
|
||||
AND d.det_type = 1
|
||||
ORDER BY d.det_ref1_id, d.det_groupe, d.det_clef, d.det_id
|
||||
""", (con_id,))
|
||||
|
||||
rows = cur.fetchall()
|
||||
|
||||
# 3) Construction automatique
|
||||
for row in rows:
|
||||
tp_id = row["tp_id"]
|
||||
|
||||
group = row["det_groupe"] or "default"
|
||||
clef = row["det_clef"]
|
||||
|
||||
# Créer les niveaux si nécessaires
|
||||
if group not in tp_config[tp_id]["config"]:
|
||||
tp_config[tp_id]["config"][group] = {}
|
||||
|
||||
if clef not in tp_config[tp_id]["config"][group]:
|
||||
tp_config[tp_id]["config"][group][clef] = []
|
||||
|
||||
# Ajouter l’item
|
||||
tp_config[tp_id]["config"][group][clef].append({
|
||||
"det_id": row["det_id"],
|
||||
"value1": row["det_value1"],
|
||||
"value2": row["det_value2"],
|
||||
"value3": row["det_value3"],
|
||||
})
|
||||
|
||||
return tp_config
|
||||
|
||||
|
||||
def load_tp_config_for_conbad(cur, con_id: int) -> Dict[int, Dict[str, Dict[str, List[Dict[str, Any]]]]]:
|
||||
"""
|
||||
Charge TOUTE la configuration TP (det_type = 1) pour un con_id.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user