Aller au contenu

Diagrammes Step 04 - Building Model Database

Vue d'ensemble du processus

graph TB
    Start([main]) --> Scoping[main_scoping]
    Scoping --> Modelling[main_modelling]

    subgraph "Phase 1: Scoping"
        S1[Lecture données step_2_03_*]
        S2[Ajustement volumes<br/>low-volume retailers]
        S3[Calcul marge brute ajustée]
        S4[Enrichissement catégories]
        S5[Agrégation sans Promotion_Code]

        S1 --> S2 --> S3 --> S4 --> S5
    end

    subgraph "Phase 2: Modelling"
        M1[Classification intensité promo]
        M2[Méthodologie baseline<br/>Standard/Statistical]
        M3[Calcul baseline volumes]
        M4[Ajustements et In&Out rules]

        M1 --> M2 --> M3 --> M4
    end

    Scoping --> S1
    S5 --> Modelling
    Modelling --> M1
    M4 --> End([Fin])

Flux détaillé du Scoping

flowchart LR
    subgraph "Ajustement volumes low-volume retailers"
        A1[Calcul volume annuel<br/>par retailer]
        A2[Tri croissant]
        A3[Share cumulé ≤ 25%]
        A4[Seuil par catégorie]
        A5[Arrondi multiple de 5]
        A6[Volume < seuil → 0]

        A1 --> A2 --> A3 --> A4 --> A5 --> A6
    end

    subgraph "Calcul marge brute ajustée"
        M1[Average costs<br/>Product+Other]
        M2[Average costs<br/>Level Two]
        M3[Années incomplètes?]
        M4[Utiliser année N-1]
        M5[Formule GM ajustée]

        M1 --> M5
        M2 --> M3
        M3 -->|<52 sem| M4
        M3 -->|52 sem| M5
        M4 --> M5
    end

Classification intensité promotionnelle

graph TD
    subgraph "Métriques annuelles"
        PW[Promo_weight = Volume promo / Volume total]
        PI[Promo_intensity = Nb semaines promo / Nb semaines ventes > 0]
    end

    subgraph "Classification"
        C1{Promo_intensity}
        C1 -->|≤ 0.60| Low[Low → Standard]
        C1 -->|0.60 - 0.75| Mid[Mid → Standard]
        C1 -->|> 0.75| High[High → Statistical]
    end

    PW --> C1
    PI --> C1

Méthodologie Standard

sequenceDiagram
    participant DF as DataFrame
    participant FLAGS as Flags Calculator
    participant BL as Baseline Calculator

    DF->>FLAGS: Flag outliers (percentiles 5%-95%)
    FLAGS->>DF: Flag_Outliers

    Note over FLAGS: Galbani: pas de pre-promo<br/>Parmalat: fenêtre dynamique

    FLAGS->>DF: Flag_Buying_period_post_promo

    DF->>FLAGS: Identifier semaines qualifiées
    Note over FLAGS: Pas outlier<br/>Pas promo<br/>Pas post-promo
    FLAGS->>DF: Flag_qualified_week

    DF->>BL: Pour chaque semaine
    loop N dernières semaines qualifiées
        BL->>BL: Chercher semaines qualifiées
        BL->>BL: Moyenne des volumes
    end
    BL->>DF: Baseline_Volume

Méthodologie Statistical

flowchart TD
    subgraph "Segmentation Galbani"
        G1[3 segments par année]
        G2[Q1: sem 1-17]
        G3[Q2Q3: sem 18-39]
        G4[Q4: sem 40-52]

        G1 --> G2
        G1 --> G3
        G1 --> G4
    end

    subgraph "Segmentation Parmalat"
        P1[2 saisons par catégorie]
        P2[H: High season]
        P3[L: Low season]
        P4[52 colonnes config]

        P1 --> P2
        P1 --> P3
        P4 --> P2
        P4 --> P3
    end

    subgraph "Calcul Baseline"
        B1[Exclusion outliers]
        B2[Avg volume promo]
        B3[Std dev promo]
        B4[VC = Std/Avg]
        B5{VC value}

        B1 --> B2 --> B3 --> B4 --> B5

        B5 -->|< 0.40| F1[Avg - 2×Std<br/>ou Avg - 1.5×Std]
        B5 -->|0.40-1.00| F2[Avg - Std]
        B5 -->|> 1.00| F3[Avg - 0.5×Std]
    end

Redistribution volumes Parmalat

stateDiagram-v2
    [*] --> Analyse: Pour chaque Retailer×EAN×Year

    Analyse --> Pattern: Chercher pattern

    state Pattern {
        [*] --> Consecutive: Semaines consécutives > 0
        Consecutive --> Zeros: Suivies de 5 zéros
        Zeros --> Check: Vérifier conditions
    }

    Check --> CalcAvg: Calculer moyennes

    state CalcAvg {
        ConsecAvg: Moyenne consécutives
        SeasonAvg: Moyenne saisonnière
    }

    CalcAvg --> Compare: ConsecAvg ≥ SeasonAvg?

    Compare --> Redistribute: OUI
    Compare --> Skip: NON

    Redistribute --> NewValue: Sum / (consec + 5 zéros)
    Skip --> Keep: Garder volumes originaux

    NewValue --> [*]
    Keep --> [*]

Ajustements baseline

graph LR
    subgraph "Ajustements Standard → Statistical"
        A1[Baseline null/≤0<br/>+ Standard]
        A2[Recalculer avec<br/>Statistical]
        A3[Merger résultats]
        A4[Update methodology]

        A1 --> A2 --> A3 --> A4
    end

    subgraph "Normalisation Statistical"
        N1[Baseline < 0<br/>ou null]
        N2[25e percentile<br/>volumes > 0]
        N3[Moyenne ≤ P25]
        N4[Baseline normalisé]

        N1 --> N2 --> N3 --> N4
    end

Rules In&Out

flowchart TB
    subgraph "Identification In&Out"
        I1[Selling weeks < 35%<br/>ou ≤ 41%]
        I2[Promo weight > 90%]
        I3[In&Out condition]

        I1 --> I3
        I2 --> I3
    end

    subgraph "Galbani Rules"
        G1[Check substitute EAN]
        G2{Substitute<br/>exists?}
        G3[Baseline = 0]
        G4[Format ratio]
        G5[Corrective factor]
        G6[Substitute baseline<br/>/ factor]

        I3 --> G1 --> G2
        G2 -->|Non| G3
        G2 -->|Oui| G4 --> G5 --> G6
    end

    subgraph "Parmalat Rules"
        P1{Package type}
        P2[BRICK]
        P3[VALIGETTA]
        P4[Baseline = 0]
        P5{Substitute<br/>In&Out?}
        P6[Use substitute]

        I3 --> P1
        P1 --> P2 --> P4
        P1 --> P3 --> P5
        P5 -->|Oui| P4
        P5 -->|Non| P6
    end

Points de contrôle qualité

graph TD
    subgraph "Vérifications Parmalat"
        V1[Row count avant/après]
        V2[Redistribution appliquée?]
        V3[Baseline calculé avec<br/>volumes redistributés]
        V4[Volumes originaux restaurés]
    end

    subgraph "Contrôles généraux"
        C1[Semaines manquantes ajoutées]
        C2[52 semaines par combinaison]
        C3[Baseline methodology cohérente]
        C4[In&Out status tracé]
    end

    V1 --> LOG[Logs détaillés]
    V2 --> LOG
    V3 --> LOG
    V4 --> LOG
    C1 --> LOG
    C2 --> LOG
    C3 --> LOG
    C4 --> LOG

Flux de données final

graph TB
    subgraph "Tables entrée"
        T1[(step_2_03_sell_in_base)]
        T2[(Sub_Category_Mapping)]
        T3[(Retailer_Group)]
        T4[(In_Out_Comparable)]
        T5[(Statistical_params)]
    end

    subgraph "Tables sortie"
        O1[(step_3_00_sell_in<br/>Détail avec ajustements)]
        O2[(step_3_01_after_scoping<br/>Agrégé sans promo code)]
        O3[(step_3_02_model_data_baseline<br/>Avec baseline calculé)]
    end

    T1 --> Process[Processing]
    T2 --> Process
    T3 --> Process
    T4 --> Process
    T5 --> Process

    Process --> O1
    Process --> O2
    Process --> O3

    style O3 fill:#90EE90

Spécificités par business unit

mindmap
  root((Step 04<br/>Model<br/>Database))
    Galbani
      Agrégation
        Retailer_name
        EAN + EAN_desc
        Year
      Baseline Standard
        Pas de flag pre-promo
        Post-promo configurable
        Unique_Week_ID
      In&Out
        Seuil 35% selling
        Format ratio
        Corrective factor
    Parmalat
      Agrégation
        Retailer_classification
        EAN seul
        Year
      Volume redistribution
        Pattern consecutif + zéros
        Comparaison saisonnière
        Baseline uniquement
      Baseline
        Fenêtres FB dynamiques
        Critères saison + récence
        2 saisons H/L
      In&Out
        Seuil 41% selling
        BRICK vs VALIGETTA
        Substitute status