Vue d'ensemble du processus
graph TB
Start([main]) --> Engine[Connexion DB]
Engine --> Extract[extract_and_export_data]
subgraph "Extraction des données"
E1[Tables sources<br/>step_6_03 & step_3_02]
E2[Filtrage année MAX]
E3[Sélection colonnes]
E4[Renommage business]
E5[Formatage final]
E1 --> E2 --> E3 --> E4 --> E5
end
subgraph "Export Excel"
X1[Promotion_Level_Table.xlsx]
X2[Baseline_Table.xlsx]
end
Extract --> E1
E5 --> X1
E5 --> X2
X1 --> End([Fin])
X2 --> End
style X1 fill:#90EE90
style X2 fill:#90EE90
Flux de données détaillé
flowchart LR
subgraph "Sources"
T1[(step_6_03_final_with_scope_promo_table)]
T2[(step_3_02_model_data_baseline)]
end
subgraph "Traitement"
F1(Détection Parmalat)
F2{is_parmalat?}
F3(Query avec EAN_desc)
F4(Query sans EAN_desc)
F5(Sélection colonnes)
F6(Renommage colonnes)
F7(Arrondi discounts)
end
subgraph "Sorties"
O1("app/outputs/{business_unit}/<br/>Promotion_Level_Table.xlsx")
O2("app/outputs/{business_unit}/<br/>Baseline_Table.xlsx")
end
T1 --> F1
T2 --> F1
F1 --> F2
F2 -->|Non| F3
F2 -->|Oui| F4
F3 --> F5
F4 --> F5
F5 --> F6
F6 --> F7
F7 --> O1
F7 --> O2
Détection du business unit et adaptation
stateDiagram-v2
[*] --> Detection: extract_and_export_data()
Detection --> CheckBU: business_unit.lower()
CheckBU --> Parmalat: == 'italy_parmalat'
CheckBU --> Others: != 'italy_parmalat'
state Parmalat {
[*] --> NoEANDesc: is_parmalat = True
NoEANDesc --> ColumnsWithout: Colonnes sans EAN_desc
ColumnsWithout --> QueryWithout: Query adaptée
}
state Others {
[*] --> WithEANDesc: is_parmalat = False
WithEANDesc --> ColumnsWith: Colonnes avec EAN_desc
ColumnsWith --> QueryWith: Query standard
}
Parmalat --> Processing
Others --> Processing
Processing --> [*]
Requêtes SQL et filtrage année MAX
sequenceDiagram
participant Main as extract_and_export_data()
participant DB as Database
participant DF as DataFrame
Note over Main: Query promotions table
Main->>DB: SELECT * FROM step_6_03_final_with_scope_promo_table<br/>WHERE Year = (SELECT MAX(Year) FROM step_6_03)
DB-->>Main: All columns, max year only
Main->>Main: Sélection colonnes selon BU
alt is_parmalat = True
Main->>Main: 20 colonnes (sans EAN_desc)
else is_parmalat = False
Main->>Main: 21 colonnes (avec EAN_desc)
end
Main->>DF: df_step_6_03[columns_to_select]
Note over Main: Query baseline table
alt is_parmalat = True
Main->>DB: SELECT Retailer_name, EAN, Year,<br/>CAST(Week AS INTEGER) AS Week, Baseline_Volume<br/>WHERE Year = MAX
else is_parmalat = False
Main->>DB: SELECT Retailer_name, EAN, EAN_desc, Year,<br/>CAST(Week AS INTEGER) AS Week, Baseline_Volume<br/>WHERE Year = MAX
end
DB-->>Main: Baseline data
Main->>DF: df_step_3_02
graph TD
subgraph "Colonnes techniques (DB)"
T1[Adj_Promo_Volume]
T2[Promo_margin_at_event_level]
T3[NSV_at_event_level]
T4[In_Scope]
T5[Volume_Uplift_%]
T6[On_invoice_discount]
T7[Category]
T8[Event_Type]
T9[Event_duration_in_weeks]
end
subgraph "Colonnes business (Excel)"
B1[Promo_Volume]
B2[Promo_margin]
B3[Promo_NSV]
B4[Filter]
B5[Volume Uplift]
B6[Sell-in discount]
B7[High-level classification]
B8[Segmentation]
B9[Event duration]
end
T1 --> B1
T2 --> B2
T3 --> B3
T4 --> B4
T5 --> B5
T6 --> B6
T7 --> B7
T8 --> B8
T9 --> B9
style T1 fill:#e3f2fd
style T2 fill:#e3f2fd
style T3 fill:#e3f2fd
style T4 fill:#e3f2fd
style T5 fill:#e3f2fd
style T6 fill:#e3f2fd
style T7 fill:#e3f2fd
style T8 fill:#e3f2fd
style T9 fill:#e3f2fd
style B1 fill:#e8f5e9
style B2 fill:#e8f5e9
style B3 fill:#e8f5e9
style B4 fill:#e8f5e9
style B5 fill:#e8f5e9
style B6 fill:#e8f5e9
style B7 fill:#e8f5e9
style B8 fill:#e8f5e9
style B9 fill:#e8f5e9
Structure des fichiers Excel de sortie
flowchart TB
subgraph "Promotion_Level_Table.xlsx"
direction LR
P1[Retailer_name<br/>STRING]
P2[EAN<br/>STRING]
P3[EAN_desc<br/>STRING<br/>sauf Parmalat]
P4[New_category<br/>STRING]
P5[Promotion_Code<br/>STRING]
P6[Year<br/>INTEGER]
P7[Baseline_Volume<br/>FLOAT]
P8[Promo_Volume<br/>FLOAT]
P9[Promo_margin<br/>FLOAT]
P10[...]
P11[Sell-in discount<br/>FLOAT<br/>1 décimale]
P12[Event duration<br/>INTEGER]
end
subgraph "Baseline_Table.xlsx"
direction LR
B1[Retailer_name<br/>STRING]
B2[EAN<br/>STRING]
B3[EAN_desc<br/>STRING<br/>sauf Parmalat]
B4[Year<br/>INTEGER]
B5[Week<br/>INTEGER]
B6[Baseline_Volume<br/>FLOAT]
end
note1[21 colonnes total<br/>20 pour Parmalat]
note2[6 colonnes total<br/>5 pour Parmalat]
P1 -.-> note1
B1 -.-> note2
Traitement spécifique des données
graph LR
subgraph "Formatage et arrondi"
F1(DataFrame original)
F2(Arrondi Sell-in discount)
F3(DataFrame formaté)
F1 --> F2
F2 --> F3
note1("df['Sell-in discount'].round(1)")
F2 -.-> note1
end
subgraph "Export Excel"
E1(to_excel)
E2(index=False)
E3(Fichier Excel)
F3 --> E1
E1 --> E2
E2 --> E3
end
subgraph "Chemins de sortie"
P1("app/outputs/")
P2("{business_unit}/")
P3("Promotion_Level_Table.xlsx<br/>Baseline_Table.xlsx")
P1 --> P2
P2 --> P3
end
E3 --> P3
Gestion des erreurs et cas limites
stateDiagram-v2
[*] --> TryQuery: Exécution requêtes
TryQuery --> Success: Données récupérées
TryQuery --> SQLError: Erreur SQL
TryQuery --> EmptyData: Pas de données
SQLError --> LogError: Log message erreur
LogError --> RaiseException: Propagation exception
EmptyData --> LogWarning: Log warning
LogWarning --> ContinueEmpty: Continue avec DF vide
Success --> SelectColumns: Sélection colonnes
ContinueEmpty --> SelectColumns
SelectColumns --> KeyError: Colonne manquante
SelectColumns --> RenameOK: Colonnes OK
KeyError --> RaisePandas: pandas.KeyError
RenameOK --> ExportExcel: Export Excel
ExportExcel --> WriteError: Erreur écriture
ExportExcel --> ExportOK: Export réussi
WriteError --> CheckPermission: Vérifier permissions
CheckPermission --> LogFileError: Log erreur fichier
ExportOK --> [*]
RaiseException --> [*]
RaisePandas --> [*]
LogFileError --> [*]
graph TD
subgraph "Optimisations SQL"
S1("Sous-requête MAX(Year)<br/>évite full scan")
S2("SELECT colonnes nécessaires<br/>pas SELECT *")
S3("CAST(Week AS INTEGER)<br/>typage explicite")
end
subgraph "Optimisations Pandas"
P1("Sélection colonnes<br/>avant renommage")
P2("Pas de copie DF<br/>inutile")
P3("Export direct<br/>sans transformations")
end
subgraph "Mémoire"
M1("Une seule lecture<br/>par table")
M2("Libération mémoire<br/>après export")
M3("Pas de stockage<br/>intermédiaire")
end
S1 --> Performance("Performance<br/>optimale")
S2 --> Performance
S3 --> Performance
P1 --> Performance
P2 --> Performance
P3 --> Performance
M1 --> Performance
M2 --> Performance
M3 --> Performance
style Performance fill:#4CAF50,color:#fff
Points clés de maintenance
mindmap
root((Step 08<br/>Simulation<br/>Inputs))
Adaptations BU
Détection Parmalat
is_parmalat flag
Queries différentes
Colonnes adaptées
Nouveaux BU
Ajouter condition
Adapter colonnes
Tester mapping
Synchronisation
Colonnes sources
step_6_03 changes
step_3_02 updates
Renommage
Mapping technique business
Ordre colonnes
Types cohérents
Formats Excel
Structure fixe
21 ou 20 colonnes promo
6 ou 5 colonnes baseline
Formatage
Sell in discount 1 décimale
index False obligatoire
UTF 8 automatique
Chemins sortie
Structure imposée
app outputs business unit
Noms fichiers fixes
Permissions
Écriture requise
Création répertoire