mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-19 13:08:11 +02:00
- /api/produits/search (POST démarre un job, GET suit l'avancement) : Qlik d'abord, repli catalogue FF (source: "db"), cache mémoire 10 min des seuls résultats Qlik exploitables, une recherche Qlik à la fois. - /api/produits/opportunites : produits de la même famille, local vs réseau. - Page produit-fiche (?codein= ou ?cc=) : getProduitFiche / getProduitFicheByCodeCentrale, report du stock de fin de mois. - normalizeMargePct (compare-reseau) et types JSON identiques au client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG2LLJuswrrTTPKJmunEVf
43 lines
1.5 KiB
Rust
43 lines
1.5 KiB
Rust
//! CollectFlow — Comparatif local vs réseau pour un produit — partie serveur de
|
|
//! `src/features/produits/lib/compare-reseau.ts`.
|
|
//!
|
|
//! Le calcul du comparatif lui-même (`computeComparatif`, `indiceVerdict`) reste
|
|
//! côté interface : seul `normalizeMargePct` sert au serveur (recherche produit).
|
|
|
|
/// Le taux de marge Qlik est un ratio brut (0.32 = 32 %) mais certaines
|
|
/// configurations renvoient déjà des points de pourcentage. Même normalisation
|
|
/// que la colonne « Marge % / Réseau » de la Grille.
|
|
pub fn normalize_marge_pct(raw: Option<f64>) -> Option<f64> {
|
|
let v = raw?;
|
|
if !v.is_finite() || v == 0.0 {
|
|
return None;
|
|
}
|
|
Some(if v.abs() <= 1.0 { v * 100.0 } else { v })
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn ratio_brut_converti_en_points() {
|
|
assert_eq!(normalize_marge_pct(Some(0.32)), Some(32.0));
|
|
assert_eq!(normalize_marge_pct(Some(-0.5)), Some(-50.0));
|
|
assert_eq!(normalize_marge_pct(Some(1.0)), Some(100.0));
|
|
}
|
|
|
|
#[test]
|
|
fn points_de_pourcentage_conserves() {
|
|
assert_eq!(normalize_marge_pct(Some(32.5)), Some(32.5));
|
|
assert_eq!(normalize_marge_pct(Some(-12.0)), Some(-12.0));
|
|
}
|
|
|
|
#[test]
|
|
fn absent_nul_ou_non_fini() {
|
|
assert_eq!(normalize_marge_pct(None), None);
|
|
assert_eq!(normalize_marge_pct(Some(0.0)), None);
|
|
assert_eq!(normalize_marge_pct(Some(f64::NAN)), None);
|
|
assert_eq!(normalize_marge_pct(Some(f64::INFINITY)), None);
|
|
}
|
|
}
|