How fabiolabowlesdiaz/dym-wsr-generator works
1. Repository purpose
This repo is a Python-based batch system that pulls sales data from a PostgreSQL DWH, computes WSR metrics, optionally enriches analysis with LLM-generated commentary, and emits a final HTML Weekly Sales Report for DYM.
2. Main execution paths
The primary entry point is wsr_generator_main.py, with generate_report.py as an alternate runner. These scripts orchestrate the full pipeline: connect to the database, fetch source data, process metrics, generate charts/tables, and write the report to ./output/.
3. Data access boundary
core/database.py centralizes database connectivity and query execution against the DWH. The README indicates credentials and runtime configuration come from .env, and the system is intended to use read-only access to PostgreSQL.
4. Core report processing
core/data_processor.py is the main transformation layer for WSR-specific business logic: filtering, exclusions, aggregation by brand/city/channel, and calculation of executive-summary metrics. This is where raw database rows become report-ready datasets.
5. Report rendering
core/html_generator.py and utils/html_tables.py build the final HTML document and its tables. core/trend_chart_generator.py generates trend visualizations, so the final report combines structured tables with embedded charts in a single HTML artifact.
6. AI-assisted narrative layer
utils/llm_processor.py is the shared LLM integration used to analyze manager comments and produce narrative text. The README shows OpenRouter/Claude configuration, so external model calls are part of the report-generation path when commentary analysis is enabled.
7. Secondary projection subsystem
The proyeccion_objetiva/ package is a distinct analytics domain for objective projections/nowcasting. It has its own config, data fetcher, statistical engine, driver-based operational engine, narrative generation, and visualization modules, suggesting a parallel pipeline for projection analysis rather than the core WSR report itself.
8. Projection internal structure
Inside proyeccion_objetiva/, pilar2_estadistica/ handles statistical/event-calendar logic, while pilar3_operativa/ handles operational driver analysis and driver narratives. nowcast_engine.py and projection_processor.py appear to coordinate these pieces into projection outputs.
9. Testing and validation
There are both package tests under proyeccion_objetiva/tests/ and repository-level validation scripts such as test_*.py, verify_calculation.py, and scripts/validate_drivers.py. This suggests the codebase mixes unit tests with data/query validation checks against real business logic.
10. Operational runtime and outputs
The system is designed for scheduled batch execution via cron or Windows Task Scheduler, not a long-running service. Its observable outputs are HTML reports in ./output/ and execution logs in wsr_generator.log, which form the main operational artifacts.
11. Documentation and governance
The .planning/ tree contains architecture, roadmap, milestone, and phase documents, while manuales/ holds usage, installation, and maintenance guides. These do not affect runtime flow, but they indicate the repository is managed as a documented operational system with phased delivery and maintenance procedures.
12. Key architectural boundary to draw
The clearest diagram boundary is: source data and external services in, core processing and optional AI narrative in the middle, HTML report and charts out. The projection package should be shown as a related but separable analytics subsystem that can be reused or extended independently of the main WSR generation flow.
Main entry points: data_processor.py Data processor · projection_processor.py Projection flow · html_generator.py HTML report · statistical_engine.py Statistical engine
Components 21
WSR Generator
Primary weekly sales report pipeline and outputs.
- Main runner · Primary batch entry point for WSR generation.
wsr_generator_main.py - Alt runner · Alternative report execution script.
generate_report.py - DB access · Centralized database connectivity and query execution.
core/database.py - Data processor · Filters, aggregates, and computes report metrics.
core/data_processor.py - Trend charts · Generates trend visualizations for the report.
core/trend_chart_generator.py - HTML report · Assembles the final HTML report document.
core/html_generator.py - HTML tables · Builds reusable HTML table fragments.
utils/html_tables.py - LLM narrative · Generates narrative from manager comments and analysis.
utils/llm_processor.py - Output report · Generated HTML reports written to disk.
Projection Analytics
Secondary nowcasting and projection subsystem.
- Projection config · Configuration for the projection subsystem.
proyeccion_objetiva/config.py - Projection data · Fetches source data for projection analysis.
proyeccion_objetiva/data_fetcher.py - Statistical engine · Handles statistical and event-calendar projection logic.
proyeccion_objetiva/pilar2_estadistica/statistical_engine.py - Event calendar · Calendar-aware statistical support for projections.
proyeccion_objetiva/pilar2_estadistica/event_calendar.py - Drivers engine · Analyzes operational drivers for projection outputs.
proyeccion_objetiva/pilar3_operativa/drivers_engine.py - Drivers narrative · Produces explanatory text for driver-based analysis.
proyeccion_objetiva/pilar3_operativa/drivers_narrative.py - Projection flow · Coordinates projection processing across statistical and operational pillars.
proyeccion_objetiva/projection_processor.py - Nowcast engine · Coordinates nowcast-style projection execution.
proyeccion_objetiva/nowcast_engine.py - Projection charts · Generates projection visualizations.
proyeccion_objetiva/visualizacion/projection_chart_generator.py - Projection HTML · Renders projection reports as HTML.
proyeccion_objetiva/visualizacion/projection_html_generator.py
Support & Docs
Validation, scripts, manuals, and planning artifacts.
- Validation · Repository-level and package-level validation scripts and tests.
- Docs & planning · Operational manuals and planning artifacts.
Connections 24
- Main runner → DB access: read data · Loads source sales data from PostgreSQL.
- Alt runner → DB access: read data · Alternative runner also pulls from the DWH.
- DB access → Data processor: raw rows · Provides queried data for WSR business logic.
- Data processor → Trend charts: metrics · Feeds processed trends into chart generation.
- Data processor → HTML tables: table data · Supplies structured datasets for HTML tables.
- Data processor → LLM narrative: comments · Optional narrative enrichment based on manager comments.
- Trend charts → HTML report: charts · Embeds charts into the final report.
- HTML tables → HTML report: tables · Renders tabular sections into the report.
- LLM narrative → HTML report: narrative · Adds AI-generated commentary to the HTML output.
- HTML report → Output report: write html · Writes the final report artifact to disk.
- Projection config → Projection data: settings · Provides runtime configuration for projection data access.
- Projection data → Statistical engine: projection inputs · Feeds fetched data into statistical analysis.
- Event calendar → Statistical engine: calendar logic · Supplies event-aware statistical context.
- Statistical engine → Projection flow: stats output · Contributes statistical projection signals.
- Drivers engine → Projection flow: driver output · Provides operational driver analysis.
- Projection flow → Drivers narrative: analysis · Generates explanatory narrative from projection results.
- Projection flow → Projection charts: series · Feeds data into projection visualization.
- Projection charts → Projection HTML: charts · Embeds projection charts into HTML.
- Drivers narrative → Projection HTML: narrative · Adds driver-based narrative to the projection report.
- Projection HTML → Output report: write html · Projection subsystem also emits HTML artifacts.
- Validation → Data processor: validate · Checks core business logic and calculations.
- Validation → Statistical engine: validate · Exercises projection statistics behavior.
- Docs & planning → Main runner: guide · Documents runtime usage and maintenance.
- Docs & planning → Projection flow: guide · Documents the projection subsystem design and flow.