{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Phase 4 — Variant Assignment / Variant Modeling\n", "## Compliments Reference DB Pipeline\n", "\n", "**Version:** 1.0.0\n", "**Date:** 2026-07-30\n", "\n", "**Input:** Phase 3 outputs + Phase 2 output\n", "\n", "**This phase does:**\n", "1. Transforms Phase 3 product groups into structured variant models\n", "2. Assigns deterministic variant_ids to products within each group\n", "3. Creates variant tables and mappings\n", "4. Validates variant consistency rules\n", "\n", "**CRITICAL:** This phase does NOT use nutrition data.\n", "**CRITICAL:** This phase does NOT use any external taxonomy.\n", "**CRITICAL:** This phase is 100% deterministic (no LLM)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-07-30T17:47:27.262371Z", "iopub.status.busy": "2026-07-30T17:47:27.261832Z", "iopub.status.idle": "2026-07-30T17:47:28.134559Z", "shell.execute_reply": "2026-07-30T17:47:28.132783Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python: 3.13.7 (main, Mar 3 2026, 12:19:54) [GCC 15.2.0]\n", "pandas: 3.0.5\n", "numpy: 2.5.1\n", "Timestamp: 2026-07-30T17:47:28.129557+00:00\n" ] } ], "source": [ "import json, hashlib, uuid, sys\n", "from datetime import datetime, timezone\n", "from pathlib import Path\n", "\n", "import pandas as pd\n", "import numpy as np\n", "\n", "print(f\"Python: {sys.version}\")\n", "print(f\"pandas: {pd.__version__}\")\n", "print(f\"numpy: {np.__version__}\")\n", "print(f\"Timestamp: {datetime.now(timezone.utc).isoformat()}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Variant Definition\n", "\n", "A **variant** is a purchasable representation of the same reference product\n", "that differs in attributes such as:\n", "\n", "- **Size**: 500 g, 1 kg, 2 kg\n", "- **Package quantity**: 1 × 500 g, 2 × 500 g\n", "- **Pack configuration**: single, multipack, case\n", "\n", "Variants within the same group share the same identity attributes:\n", "- is_organic, is_gluten_free, is_naturally_simple, etc.\n", "- product_line\n", "- flavour\n", "- formulation\n", "- fat_level\n", "\n", "Variants differ only in size/package attributes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Load Phase 3 Outputs" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-07-30T17:47:28.285611Z", "iopub.status.busy": "2026-07-30T17:47:28.284392Z", "iopub.status.idle": "2026-07-30T17:47:28.445823Z", "shell.execute_reply": "2026-07-30T17:47:28.441829Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Phase 3 mapping: 4440 rows, 14 columns\n", "Columns: ['upc', 'external_id', 'group_id', 'group_name', 'core_title', 'original_title', 'brand', 'size', 'identity_hash', 'product_domain', 'taxonomy', 'product_line', 'source', 'source_url']\n" ] }, { "data": { "text/html": [ "
| \n", " | upc | \n", "external_id | \n", "group_id | \n", "group_name | \n", "core_title | \n", "original_title | \n", "brand | \n", "size | \n", "identity_hash | \n", "product_domain | \n", "taxonomy | \n", "product_line | \n", "source | \n", "source_url | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "5.574252e+10 | \n", "297608EA | \n", "27b951a3-bef1-5ed4-80b7-7ef5cdca910a | \n", "Cold And Sinus Plus | \n", "Cold And Sinus Plus | \n", "Compliments Cold And Sinus Plus 20 Count | \n", "Compliments | \n", "20 per pack | \n", "0|0|0|0|0|0|0|0|0|fat_none|regular|Core|lime| | \n", "unknown | \n", "GENERAL_GROCERY | \n", "Core | \n", "voila | \n", "https://voila.ca/products/compliments-cold-and... | \n", "
| 1 | \n", "5.574234e+10 | \n", "464324EA | \n", "e608ba58-8f93-59f1-9446-edb91aef79bd | \n", "Twister T2 Light Bulbs 23W Soft White | \n", "Twister T2 Light Bulbs 23W Soft White | \n", "Compliments Twister T2 Light Bulbs 23W Soft Wh... | \n", "Compliments | \n", "2 per pack | \n", "0|0|0|0|0|0|0|0|0|fat_none|reduced_fat|Core|lime| | \n", "unknown | \n", "GENERAL_GROCERY | \n", "Core | \n", "voila | \n", "https://voila.ca/products/compliments-twister-... | \n", "
| 2 | \n", "9.900026e+11 | \n", "144288CS | \n", "336c79d8-796d-5682-8195-793883dd97ef | \n", "Zero Calorie Soft Drink | \n", "Zero Calorie Soft Drink | \n", "Compliments Zero Calorie Soft Drink 12 x 355ml | \n", "Compliments | \n", "12 x 29.583ml | \n", "0|0|0|0|0|0|0|0|0|fat_none|regular|Core|lime| | \n", "food | \n", "BEVERAGES | \n", "Core | \n", "voila | \n", "https://voila.ca/products/compliments-zero-cal... | \n", "
| 3 | \n", "5.574257e+10 | \n", "312204EA | \n", "fd1acb22-4231-5b7b-bde4-8709b31cf04c | \n", "Kalamata Whole Olives | \n", "Kalamata Whole Olives | \n", "Compliments Kalamata Whole Olives 375 ml | \n", "Compliments | \n", "375ml | \n", "0|0|0|0|0|0|0|0|0|fat_none|regular|Core|lime|w... | \n", "unknown | \n", "GENERAL_GROCERY | \n", "Core | \n", "voila | \n", "https://voila.ca/products/compliments-kalamata... | \n", "
| 4 | \n", "5.574256e+10 | \n", "259928EA | \n", "4ff536c8-c957-5fe8-8faa-3f539d6048ef | \n", "Sliced Almonds | \n", "Sliced Almonds | \n", "Compliments Sliced Almonds 250 g | \n", "Compliments | \n", "250g | \n", "0|0|0|0|0|0|0|0|0|fat_none|regular|Core|almond... | \n", "unknown | \n", "GENERAL_GROCERY | \n", "Core | \n", "voila | \n", "https://voila.ca/products/compliments-sliced-a... | \n", "