The Fini warehouse exposes two SQL views that sit on top of the star schema and serve as the primary interface for all downstream analytics. Rather than repeating join logic across every script, the views centralise it once and present a flat, denormalised result set that Python code can query directly withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/andresshm/fini-marketing-intelligence/llms.txt
Use this file to discover all available pages before exploring further.
pd.read_sql. Both views are defined in sql/views.sql and are created with CREATE OR REPLACE VIEW so they can be safely re-applied without dropping dependent queries.
vw_sales_enriched
vw_sales_enriched is the general-purpose analytics view. It joins all three tables in the star schema — fact_sales, dim_products, and dim_customers — into a single wide result set, giving every transaction its full product and customer context. This is the view the insights engine (insights/generate_insights.py) and the RFM segmentation model (insights/generate_rfm.py) read from.
DDL
Output Columns
| Column | Source | Description |
|---|---|---|
sale_id | fact_sales | Transaction primary key |
sale_date | fact_sales | Date of the transaction |
units | fact_sales | Units sold in this transaction |
discount | fact_sales | Fractional discount applied (0.00–0.30) |
revenue | fact_sales | Net revenue after discount |
margin | fact_sales | Gross margin (revenue − cost) |
product_name | dim_products | Human-readable product name |
category | dim_products | Product family (Gummies, Belts, etc.) |
season | dim_products | Seasonal positioning of the product |
launch_date | dim_products | Date the product was first available |
region | dim_customers | Geographic region of the customer |
purchase_frequency | dim_customers | Behavioural frequency segment (Low / Medium / High) |
preferred_channel | dim_customers | Customer’s primary sales channel |
age_group | dim_customers | Customer age bracket |
How It’s Used
insights/generate_insights.py reads the entire view in a single pd.read_sql call and then slices the resulting DataFrame for each business insight — revenue by purchase_frequency, average units and margin across discount groups, and revenue by region. The flat structure means no Python-side joins are required.
Example Query
Revenue breakdown by product category and sales channel, ordered by total revenue descending:vw_product_launches
vw_product_launches is a specialised view focused on post-launch performance. It joins fact_sales with dim_products and adds a computed column — days_since_launch — that measures how far each transaction occurred from the product’s release date. A WHERE clause filters out any sales that pre-date the launch (which cannot occur in the synthetic data, but the guard makes the view safe against future real-world data imports).
DDL
Output Columns
| Column | Source | Description |
|---|---|---|
sale_id | fact_sales | Transaction primary key |
sale_date | fact_sales | Date of the transaction |
product_id | dim_products | Product surrogate key |
product_name | dim_products | Human-readable product name |
category | dim_products | Product family |
launch_date | dim_products | Date the product was first available |
units | fact_sales | Units sold in this transaction |
revenue | fact_sales | Net revenue after discount |
margin | fact_sales | Gross margin for this transaction |
days_since_launch | Computed | sale_date − launch_date as an integer number of days |
The days_since_launch Column
days_since_launch is a derived integer computed directly in the SELECT list as a PostgreSQL date subtraction. A value of 0 means the product was sold on its launch day; a value of 90 means 90 days after launch. The insights engine uses this to define a first-90-days launch window and rank products by revenue velocity.
The WHERE Clause
WHERE f.sale_date >= p.launch_date ensures only valid post-launch transactions are included. This makes days_since_launch always non-negative and prevents edge-case negative values from distorting launch-window aggregations.
How It’s Used
insights/generate_insights.py filters the view to the first 90 days after launch and aggregates revenue by product_name to identify the best-performing new product:
Example Query
Cumulative revenue by product at 30, 60, and 90 days post-launch:Neither view selects
cost from fact_sales. The vw_product_launches view omits cost because launch-velocity analysis focuses on revenue and margin; cost can always be reconstructed as revenue - margin from the available columns if needed.