Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eabb2777d | |||
| af1706aa88 | |||
| e52a0d0b71 | |||
| 6605456b94 |
4
.env
4
.env
@ -1,5 +1,5 @@
|
|||||||
ENV_CODE = "dev"
|
ENV_CODE = "public"
|
||||||
PORT=8502
|
PORT=8501
|
||||||
DOT_FILE = "schema.txt"
|
DOT_FILE = "schema.txt"
|
||||||
GITEA_URL = "https://fabnum-git.peccini.fr/api/v1"
|
GITEA_URL = "https://fabnum-git.peccini.fr/api/v1"
|
||||||
ORGANISATION = "fabnum"
|
ORGANISATION = "fabnum"
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,6 +26,7 @@ venv/
|
|||||||
Local/
|
Local/
|
||||||
HTML/
|
HTML/
|
||||||
Corpus/
|
Corpus/
|
||||||
|
pgpt/
|
||||||
|
|
||||||
# Ignorer données Fiches (adapté à ton projet)
|
# Ignorer données Fiches (adapté à ton projet)
|
||||||
Fiches/
|
Fiches/
|
||||||
|
|||||||
31
batch_ia/batch-fabnum.service
Normal file
31
batch_ia/batch-fabnum.service
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Service batch IA pour utilisateur fabnum
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=fabnum
|
||||||
|
WorkingDirectory=/home/fabnum/fabnum-public/batch_ia
|
||||||
|
Environment=PYTHONPATH=/home/fabnum/fabnum-public
|
||||||
|
ExecStart=/home/fabnum/fabnum-public/venv/bin/python /home/fabnum/fabnum-public/batch_ia/batch_runner.py
|
||||||
|
Restart=always
|
||||||
|
Nice=10
|
||||||
|
CPUSchedulingPolicy=batch
|
||||||
|
|
||||||
|
# Limites de ressources
|
||||||
|
CPUQuota=87.5% # ~14 cores sur 16
|
||||||
|
MemoryMax=12G # RAM maximale autorisée
|
||||||
|
TasksMax=1 # maximum 1 subprocess/thread simultané
|
||||||
|
|
||||||
|
# Sécurité renforcée
|
||||||
|
ProtectSystem=full
|
||||||
|
ReadWritePaths=/home/fabnum/fabnum-public/batch_ia
|
||||||
|
|
||||||
|
# Journal propre
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
# semanage fcontext -a -t svirt_sandbox_file_t "/home/fabnum/fabnum-dev/batch_ia(/.*)?"
|
||||||
@ -3,6 +3,14 @@ import time
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from networkx.drawing.nx_agraph import write_dot
|
from networkx.drawing.nx_agraph import write_dot
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
current_file = os.path.realpath(__file__)
|
||||||
|
parent_dir = os.path.abspath(os.path.join(os.path.dirname(current_file), '..'))
|
||||||
|
if parent_dir not in sys.path:
|
||||||
|
sys.path.insert(0, parent_dir)
|
||||||
|
|
||||||
from utils.translations import _
|
from utils.translations import _
|
||||||
|
|
||||||
BATCH_DIR = Path(__file__).resolve().parent
|
BATCH_DIR = Path(__file__).resolve().parent
|
||||||
|
|||||||
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
@ -3,6 +3,8 @@ import pandas as pd
|
|||||||
import logging
|
import logging
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
import json
|
import json
|
||||||
|
import yaml
|
||||||
|
import pathlib
|
||||||
from networkx.drawing.nx_agraph import read_dot
|
from networkx.drawing.nx_agraph import read_dot
|
||||||
|
|
||||||
# Configuration Gitea
|
# Configuration Gitea
|
||||||
@ -129,35 +131,102 @@ def recuperer_donnees_2(graph, noeuds_2):
|
|||||||
return donnees
|
return donnees
|
||||||
|
|
||||||
|
|
||||||
def couleur_noeud(n, niveaux, G):
|
def load_seuils_config(path: str = "assets/config.yaml") -> dict:
|
||||||
|
"""
|
||||||
|
Charge les seuils depuis le fichier de configuration YAML.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
path (str): Chemin vers le fichier de configuration.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Dictionnaire contenant les seuils pour chaque indice.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
data = yaml.safe_load(pathlib.Path(path).read_text(encoding="utf-8"))
|
||||||
|
return data.get("seuils", {})
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning(f"Erreur lors du chargement des seuils depuis {path}: {e}")
|
||||||
|
# Valeurs par défaut en cas d'erreur
|
||||||
|
return {
|
||||||
|
"ISG": {"vert": {"max": 40}, "orange": {"min": 40, "max": 70}, "rouge": {"min": 70}},
|
||||||
|
"IHH": {"vert": {"max": 15}, "orange": {"min": 15, "max": 25}, "rouge": {"min": 25}},
|
||||||
|
"IVC": {"vert": {"max": 15}, "orange": {"min": 15, "max": 60}, "rouge": {"min": 60}}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def determiner_couleur_par_seuil(valeur: int, seuils_indice: dict) -> str:
|
||||||
|
"""
|
||||||
|
Détermine la couleur en fonction de la valeur et des seuils configurés.
|
||||||
|
Logique alignée avec determine_threshold_color du projet.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
valeur (int): Valeur de l'indice à évaluer.
|
||||||
|
seuils_indice (dict): Seuils pour cet indice depuis la configuration.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Couleur correspondante ("darkgreen", "orange", "darkred", "gray").
|
||||||
|
"""
|
||||||
|
if valeur < 0:
|
||||||
|
return "gray"
|
||||||
|
|
||||||
|
# Vérifier d'abord le seuil rouge (priorité la plus haute)
|
||||||
|
if "rouge" in seuils_indice and "min" in seuils_indice["rouge"]:
|
||||||
|
if valeur >= seuils_indice["rouge"]["min"]:
|
||||||
|
return "darkred"
|
||||||
|
|
||||||
|
# Ensuite le seuil orange
|
||||||
|
if "orange" in seuils_indice and "min" in seuils_indice["orange"] and "max" in seuils_indice["orange"]:
|
||||||
|
if valeur >= seuils_indice["orange"]["min"] and valeur < seuils_indice["orange"]["max"]:
|
||||||
|
return "orange"
|
||||||
|
|
||||||
|
# Seuil vert (valeurs inférieures au seuil orange)
|
||||||
|
if "vert" in seuils_indice and "max" in seuils_indice["vert"]:
|
||||||
|
if valeur < seuils_indice["vert"]["max"]:
|
||||||
|
return "darkgreen"
|
||||||
|
|
||||||
|
# Par défaut orange si on ne trouve pas de correspondance exacte
|
||||||
|
return "orange"
|
||||||
|
|
||||||
|
|
||||||
|
def couleur_noeud(n: str, niveaux: dict, G: nx.DiGraph) -> str:
|
||||||
|
"""
|
||||||
|
Détermine la couleur d'un nœud en fonction de son niveau et de ses attributs.
|
||||||
|
Utilise les seuils définis dans le fichier de configuration.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
n (str): Nom du nœud.
|
||||||
|
niveaux (dict): Dictionnaire associant chaque nœud à son niveau.
|
||||||
|
G (nx.DiGraph): Graphe NetworkX contenant les données.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Couleur du nœud.
|
||||||
|
"""
|
||||||
niveau = niveaux.get(n, 99)
|
niveau = niveaux.get(n, 99)
|
||||||
attrs = G.nodes[n]
|
attrs = G.nodes[n]
|
||||||
|
seuils = load_seuils_config()
|
||||||
|
|
||||||
# Niveau 99 : pays géographique avec isg
|
# Niveau 99 : pays géographique avec isg
|
||||||
if niveau == 99:
|
if niveau == 99:
|
||||||
isg = int(attrs.get("isg", -1))
|
isg = int(attrs.get("isg", -1))
|
||||||
return (
|
if isg >= 0 and "ISG" in seuils:
|
||||||
"darkred" if isg >= 60 else
|
return determiner_couleur_par_seuil(isg, seuils["ISG"])
|
||||||
"orange" if isg >= 31 else
|
return "gray"
|
||||||
"darkgreen" if isg >= 0 else
|
|
||||||
"gray"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Niveau 11 ou 12 connecté à un pays géographique
|
# Niveau 11 ou 12 connecté à un pays géographique
|
||||||
if niveau in (11, 12, 1011, 1012):
|
if niveau in (11, 12, 1011, 1012):
|
||||||
for succ in G.successors(n):
|
for succ in G.successors(n):
|
||||||
if niveaux.get(succ) == 99:
|
if niveaux.get(succ) == 99:
|
||||||
isg = int(G.nodes[succ].get("isg", -1))
|
isg = int(G.nodes[succ].get("isg", -1))
|
||||||
return (
|
if isg >= 0 and "ISG" in seuils:
|
||||||
"darkred" if isg >= 60 else
|
return determiner_couleur_par_seuil(isg, seuils["ISG"])
|
||||||
"orange" if isg >= 31 else
|
return "gray"
|
||||||
"darkgreen" if isg >= 0 else
|
|
||||||
"gray"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Logique existante pour IHH / IVC
|
# Logique existante pour IHH / IVC
|
||||||
if niveau in (10, 1010) and attrs.get("ihh_pays"):
|
if niveau in (10, 1010) and attrs.get("ihh_pays"):
|
||||||
ihh = int(attrs["ihh_pays"])
|
ihh = int(attrs["ihh_pays"])
|
||||||
|
if "IHH" in seuils:
|
||||||
|
return determiner_couleur_par_seuil(ihh, seuils["IHH"])
|
||||||
|
# Fallback vers les anciennes valeurs
|
||||||
return (
|
return (
|
||||||
"darkgreen" if ihh <= 15 else
|
"darkgreen" if ihh <= 15 else
|
||||||
"orange" if ihh <= 25 else
|
"orange" if ihh <= 25 else
|
||||||
@ -165,6 +234,9 @@ def couleur_noeud(n, niveaux, G):
|
|||||||
)
|
)
|
||||||
elif niveau == 2 and attrs.get("ivc"):
|
elif niveau == 2 and attrs.get("ivc"):
|
||||||
ivc = int(attrs["ivc"])
|
ivc = int(attrs["ivc"])
|
||||||
|
if "IVC" in seuils:
|
||||||
|
return determiner_couleur_par_seuil(ivc, seuils["IVC"])
|
||||||
|
# Fallback vers les anciennes valeurs
|
||||||
return (
|
return (
|
||||||
"darkgreen" if ivc <= 15 else
|
"darkgreen" if ivc <= 15 else
|
||||||
"orange" if ivc <= 30 else
|
"orange" if ivc <= 30 else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user