Sync: code local unifié

Synchronisation du code source local (fait foi).

Signed-off-by: lions dev Team
This commit is contained in:
dahoud
2026-03-15 16:25:40 +00:00
parent e82dc356f3
commit 75a19988b0
730 changed files with 53599 additions and 13145 deletions

View File

@@ -1,6 +1,6 @@
package dev.lions.unionflow.server.service;
import dev.lions.unionflow.server.api.dto.analytics.KPITrendDTO;
import dev.lions.unionflow.server.api.dto.analytics.KPITrendResponse;
import dev.lions.unionflow.server.api.enums.analytics.PeriodeAnalyse;
import dev.lions.unionflow.server.api.enums.analytics.TypeMetrique;
import jakarta.enterprise.context.ApplicationScoped;
@@ -32,6 +32,8 @@ public class TrendAnalysisService {
@Inject KPICalculatorService kpiCalculatorService;
@Inject dev.lions.unionflow.server.repository.OrganisationRepository organisationRepository;
/**
* Calcule la tendance d'un KPI sur une période donnée
*
@@ -40,7 +42,7 @@ public class TrendAnalysisService {
* @param organisationId L'ID de l'organisation (optionnel)
* @return Les données de tendance du KPI
*/
public KPITrendDTO calculerTendance(
public KPITrendResponse calculerTendance(
TypeMetrique typeMetrique, PeriodeAnalyse periodeAnalyse, UUID organisationId) {
log.info(
"Calcul de la tendance pour {} sur la période {} et l'organisation {}",
@@ -52,7 +54,7 @@ public class TrendAnalysisService {
LocalDateTime dateFin = periodeAnalyse.getDateFin();
// Génération des points de données historiques
List<KPITrendDTO.PointDonneeDTO> pointsDonnees =
List<KPITrendResponse.PointDonneeDTO> pointsDonnees =
genererPointsDonnees(typeMetrique, dateDebut, dateFin, organisationId);
// Calculs statistiques
@@ -67,7 +69,7 @@ public class TrendAnalysisService {
// Détection d'anomalies
detecterAnomalies(pointsDonnees, stats);
return KPITrendDTO.builder()
return KPITrendResponse.builder()
.typeMetrique(typeMetrique)
.periodeAnalyse(periodeAnalyse)
.organisationId(organisationId)
@@ -97,12 +99,12 @@ public class TrendAnalysisService {
}
/** Génère les points de données historiques pour la période */
private List<KPITrendDTO.PointDonneeDTO> genererPointsDonnees(
private List<KPITrendResponse.PointDonneeDTO> genererPointsDonnees(
TypeMetrique typeMetrique,
LocalDateTime dateDebut,
LocalDateTime dateFin,
UUID organisationId) {
List<KPITrendDTO.PointDonneeDTO> points = new ArrayList<>();
List<KPITrendResponse.PointDonneeDTO> points = new ArrayList<>();
// Déterminer l'intervalle entre les points
ChronoUnit unite = determinerUniteIntervalle(dateDebut, dateFin);
@@ -122,8 +124,8 @@ public class TrendAnalysisService {
calculerValeurPourIntervalle(
typeMetrique, dateCourante, dateFinIntervalle, organisationId);
KPITrendDTO.PointDonneeDTO point =
KPITrendDTO.PointDonneeDTO.builder()
KPITrendResponse.PointDonneeDTO point =
KPITrendResponse.PointDonneeDTO.builder()
.date(dateCourante)
.valeur(valeur)
.libelle(formaterLibellePoint(dateCourante, unite))
@@ -141,12 +143,12 @@ public class TrendAnalysisService {
}
/** Calcule les statistiques descriptives des points de données */
private StatistiquesDTO calculerStatistiques(List<KPITrendDTO.PointDonneeDTO> points) {
private StatistiquesDTO calculerStatistiques(List<KPITrendResponse.PointDonneeDTO> points) {
if (points.isEmpty()) {
return new StatistiquesDTO();
}
List<BigDecimal> valeurs = points.stream().map(KPITrendDTO.PointDonneeDTO::getValeur).toList();
List<BigDecimal> valeurs = points.stream().map(KPITrendResponse.PointDonneeDTO::getValeur).toList();
BigDecimal valeurActuelle = points.get(points.size() - 1).getValeur();
BigDecimal valeurMinimale = valeurs.stream().min(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
@@ -178,7 +180,7 @@ public class TrendAnalysisService {
}
/** Calcule la tendance linéaire (régression linéaire simple) */
private TendanceDTO calculerTendanceLineaire(List<KPITrendDTO.PointDonneeDTO> points) {
private TendanceDTO calculerTendanceLineaire(List<KPITrendResponse.PointDonneeDTO> points) {
if (points.size() < 2) {
return new TendanceDTO(BigDecimal.ZERO, BigDecimal.ZERO);
}
@@ -233,7 +235,7 @@ public class TrendAnalysisService {
/** Calcule une prédiction pour la prochaine période */
private BigDecimal calculerPrediction(
List<KPITrendDTO.PointDonneeDTO> points, TendanceDTO tendance) {
List<KPITrendResponse.PointDonneeDTO> points, TendanceDTO tendance) {
if (points.isEmpty()) return BigDecimal.ZERO;
BigDecimal derniereValeur = points.get(points.size() - 1).getValeur();
@@ -244,10 +246,10 @@ public class TrendAnalysisService {
}
/** Détecte les anomalies dans les points de données */
private void detecterAnomalies(List<KPITrendDTO.PointDonneeDTO> points, StatistiquesDTO stats) {
private void detecterAnomalies(List<KPITrendResponse.PointDonneeDTO> points, StatistiquesDTO stats) {
BigDecimal seuilAnomalie = stats.ecartType.multiply(new BigDecimal("2")); // 2 écarts-types
for (KPITrendDTO.PointDonneeDTO point : points) {
for (KPITrendResponse.PointDonneeDTO point : points) {
BigDecimal ecartMoyenne = point.getValeur().subtract(stats.valeurMoyenne).abs();
if (ecartMoyenne.compareTo(seuilAnomalie) > 0) {
point.setAnomalie(true);
@@ -314,7 +316,7 @@ public class TrendAnalysisService {
};
}
private BigDecimal calculerEvolutionGlobale(List<KPITrendDTO.PointDonneeDTO> points) {
private BigDecimal calculerEvolutionGlobale(List<KPITrendResponse.PointDonneeDTO> points) {
if (points.size() < 2) return BigDecimal.ZERO;
BigDecimal premiereValeur = points.get(0).getValeur();
@@ -360,8 +362,10 @@ public class TrendAnalysisService {
}
private String obtenirNomOrganisation(UUID organisationId) {
// À implémenter avec le repository
return null;
if (organisationId == null) return null;
return organisationRepository.findByIdOptional(organisationId)
.map(org -> org.getNom())
.orElse(null);
}
// === CLASSES INTERNES ===