Promotion simulator data preparation
Run these commands from this project directory with Python 3.11 or later. The data preparation scripts use the standard library, including SQLite. The demo starts from the LSKD campaign brief. The generator creates all product variants, stock, contact, permission, order, campaign and response records.
The scaled history guide runs the 30-month Parquet pipeline and explains the checks and policy evaluation. The commands below run the small fixture.
Quick local check
On macOS, Linux or WSL, use Python 3.11 or later with the IANA time zone database available. From this directory, run the regression checks.
python3 data-prep/test_pipeline.py -v
Then run the reference dataset below and the planner command in the same shell. Open the generated seasonal-plan.json to see the actions, comparison with broad email, and coverage. For the larger history, use the scaled replay and audit commands.
To read the draft project page locally, run these commands from the repository root with Node 24 or later and pnpm 9.15.4. Open /projects/promotion-simulator on the local Working Figure URL printed by Next.js.
pnpm install --frozen-lockfile
pnpm dev:workingfigure
Run the reference dataset
demo_dir=$(mktemp -d)
python3 data-prep/generate_fixture.py "$demo_dir"
python3 data-prep/import_data.py "$demo_dir/canonical-export" "$demo_dir/canonical.sqlite" \
--data-origin synthetic --outcomes-through 2026-05-05T00:00:00Z
python3 data-prep/build_snapshots.py "$demo_dir/canonical.sqlite" "$demo_dir/current.csv" \
--campaign seasonal-range --as-of 2026-05-05T00:00:00Z --training "$demo_dir/training.csv"
The import report includes counts by campaign and channel, assignment probability coverage and campaigns without a wait comparison. The generator's manifest records the seed, table counts and completion date for outcomes. Use --contacts or --seed to generate another fixture. Each campaign includes eligible email, SMS and wait assignments, with an explicit wait record where drawn. The default fixture includes new contacts in the second historical wave, delayed events, failed deliveries and opt-outs. A separate planning campaign has 12 recently released products, colour and size variants, and some early shopping behaviour. Its campaign ID and planning cutoff are in the manifest. Its sends and outcomes are open decisions.
current.csv contains one row per contact visible at the cutoff. It includes email and SMS permission, web-store serviceability, last related product family and size where known, prior orders, recent style views and the latest unresolved range basket with point-in-time stock status. An observed purchase from the featured range clears the prior shopping reminder.
training.csv adds the assigned action, logged eligible channel and message combinations, decision context, label cutoff and a kept-range-order label for each matured decision. The simulated label closes seven days after assignment plus 30 days for returns. Features use the history available when the assignment was made. Labels use the later outcome cutoff. A blank label indicates a known reporting delay affecting the order or return. Wait and failed-delivery assignments are retained so comparisons can use assignment as recorded.
Import a different export layout
python3 data-prep/import_data.py "$demo_dir/alternate-export" "$demo_dir/alternate.sqlite" \
--mapping data-prep/mappings/alternate.json --data-origin synthetic \
--outcomes-through 2026-05-05T00:00:00Z
python3 data-prep/build_snapshots.py "$demo_dir/alternate.sqlite" "$demo_dir/alternate.csv" \
--campaign seasonal-range --as-of 2026-05-05T00:00:00Z --training "$demo_dir/alternate-training.csv"
cmp "$demo_dir/current.csv" "$demo_dir/alternate.csv"
cmp "$demo_dir/training.csv" "$demo_dir/alternate-training.csv"
The alternate export changes file names, headers, column order, channel and permission labels, and timestamp offsets. Both imports should produce identical CSVs. The mapping example defines the CSV file, canonical-to-source column names and optional source-to-canonical value aliases for each table. Read the SQL contract for field definitions and keys. Use stable IDs across tables and explicit timezone offsets. An empty table can be supplied as a header-only CSV. Leave unknown optional values blank, including historical assignment probabilities and order coverage dates. A known observed order is usable even if the source cannot establish a customer's order history since signup. The order and return tables treat a return as the whole recorded item for an order and SKU.
Import builds a new local database snapshot. An invalid row or cross-table link leaves the previous database in place. Identical repeated records are counted once, and conflicting rows with the same ID are reported as errors. For a team's own export, supply its data origin and an outcome completion date from the source before building training labels. The completion date is a statement about what the export covers. The latest recorded order alone cannot establish it.
Run python3 data-prep/test_pipeline.py to check import parity, late events, range membership, returns, SMS decision contexts and the planner's chronological holdout.
Continue with the response baseline to compare audience-specific email and SMS with a broad email at the same send volume.