# Scoring accounts from product usage: what breaks on the way to the CRM

When a software company scores accounts from product usage and pushes the score into its CRM, what breaks between the warehouse
model and the field a salesperson reads, and what does each break do to the holdout read of the score's added expansion? This
study runs a dbt model on a synthetic product-led company through a simulated CRM sync, with planted faults declared before any
check ran, and a randomized holdout on who Sales calls. The page is `index.html`, and it reads the 100-company run (`results/r1b/`).

The data is synthetic. No customer or company record is used, and nothing here describes an employer.

## Reproduce

Python 3.12 with numpy and duckdb for the study; dbt-core and dbt-duckdb only to rebuild the compiled SQL.

```
python3 -B tests/test_study.py
python3 -B tools/run_r1b.py results/r1b/runs <seed>    # the 100-company run, seeds 1 to 100, one file each
python3 -B tools/summarize_r1b.py results/r1b/runs
python3 -B tools/derive_r1b.py                          # the read per call reached and the other per-call figures, from the stored rows
python3 -B tools/run_study.py results/runs <seed>       # seeds 1 to 40 under the design's original calculation
python3 -B tools/summarize.py results/runs
python3 -B tools/trace.py
python3 -I -B site/render.py
python3 -I -B tools/check_numbers.py
```

To rebuild from dbt: set `USAGE_SCORE_DB` to a new folder, run `python3 -B tools/dbt_seed1.py <path to dbt>`, then
`dbt compile` and `python3 -B tools/compile_sql.py <dbt target dir>`.

Every run reproduces exactly for a given seed. The stored rows replay with no model and no key: `results/runs/` into
`results/summary.json`, 40 companies under the design's original calculation, and `results/r1b/runs/` into `results/r1b/summary.json`, the
100 companies the page reads.

## Files

- `DESIGN-r1.md`, `protocol-r1.json`, `predictions-r1.json`, `faults-r1.json`: committed before any fault or check ran on a scored
  company. `CHANGES-r1.md`: the declared changes after that.
- `DESIGN-r1b.md`, `predictions-r1b.json`, `layers-r1b.json`: the rules set after the results (calls count inside the reading window and for expansions they changed), committed before the code and run that use them.
- `results/r1b/derived.json`, `tools/derive_r1b.py`: reporting only, decided after the results (declared in `CHANGES-r1.md`): the read per call reached, the keep rule on the read's footing, and the check that read minus the caused-expansion gap is
  the groups' baseline gap. The per-call figures are blank where a fault moves calls into the held-out group; the plain ratio is kept under its own name.
- `faults-blind-r1.json`: the eight faults from an independent author who never saw the checks, in the author's words.
- `dbt/`: the project. The score is `dbt/models/marts/fct_account_week_score.sql`, one row per account and week.
- `tools/generate.py`: the synthetic company. `tools/world.py`: what a call does, in three assumed worlds.
- `tools/warehouse.py`: runs the SQL dbt compiled.
- `tools/pipeline.py`: the weekly sync, the rep's list and the two reads. `tools/faults.py`, `tools/faults_blind.py`: the faults.
- `tools/corrected.py`, `tools/run_r1b.py`, `tools/summarize_r1b.py`: the calculation with the rules above, its runner and its summary. `tools/pipeline.py`, `tools/run_study.py` and `tools/summarize.py` hold the original calculation.
- `tools/checks.py`: the checks. `tools/sizing.py`: the holdout sizing rule from the retargeting-holdout study, unchanged.
- `site/render.py`, `site/page.css`: the page. Every number on it comes from `results/` or `assumptions.json`, and the claims the
  text makes are asserted in `render.py`.
- `vendor/viz-design-system/`: the chart kit (version 2.3.0) with its licences.

Some files are packed in product-usage-account-scoring-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
