@datama/studio-skill-instructions 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTRUCTIONS.md +22 -23
- package/README.md +1 -1
- package/package.json +1 -1
- package/references/chart.md +55 -0
- package/references/market-equation.md +56 -72
- package/references/solutions/compare.md +77 -100
- package/references/solutions/detect.md +25 -23
- package/references/solutions/explore.md +55 -72
- package/references/solutions/pivot.md +16 -25
- package/references/theming.md +16 -6
- package/references/plotter/annotations.md +0 -54
- package/references/plotter/embedded.md +0 -37
- package/references/plotter/standalone.md +0 -142
- package/references/studio-instantiation.md +0 -117
- package/references/studio-stories.md +0 -241
package/INSTRUCTIONS.md
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
# Datama Studio
|
|
2
2
|
|
|
3
|
-
Delivers a standalone HTML page rendering Datama Studio **stories** (one question each, holding one or more analyses)
|
|
3
|
+
Delivers a standalone HTML page rendering Datama Studio **stories** (one question each, holding one or more analyses). The dataset is inlined in the page; Datama computes in the browser.
|
|
4
4
|
|
|
5
5
|
Linked `references/…` files are read the same way as this one: `python3 scripts/datama.py instructions references/<file>.md`. Read one only when the request needs it.
|
|
6
6
|
|
|
7
7
|
## Steps
|
|
8
8
|
|
|
9
|
-
1. **Pick the solution.** Two sides ("2024 vs 2025", "before/after", "why did X drop") → `compare`. A breakdown or a chart across dimensions → `explore`. Unusual points over time → `detect` (needs a date column). Where a KPI is the most uneven, no comparison → `pivot`.
|
|
10
|
-
2. **Save the dataset to a file once, as you received it**: a JSON array, a connector result holding a `rows` array, JSON Lines or CSV. Over ~20 000 rows, aggregate along the dimensions that matter first.
|
|
9
|
+
1. **Pick the solution.** Two sides ("2024 vs 2025", "before/after", "why did X drop") → `compare`. A breakdown or a chart across dimensions → `explore`. Unusual points over time → `detect` (needs a date column). Where a KPI is the most uneven, no comparison → `pivot`. Comparison and breakdown together, or unclear → `compare`.
|
|
10
|
+
2. **Save the dataset to a file once, as you received it**: a JSON array, a connector result holding a `rows` array, JSON Lines or CSV. One flat row per segment, the same columns on every row. Metrics are plain numbers (`null` when missing, never `"1 200 €"`); dates use one format per column, ISO `YYYY-MM-DD` preferred. Give raw counts, not precomputed ratios: the market equation computes them. Over ~20 000 rows, aggregate along the dimensions that matter first.
|
|
11
11
|
3. **Write the configuration** (below), then **build**:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
python3 scripts/datama.py build --data rows.json --config '<json>' --out page.html
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
It prints `true`, a summary line and `Warning:` lines (then, for a licensed page, `Datama comment:` and the comments the page shows), or `Validation failed:` with one fix per line: apply them and run it again. Warnings do not block: fix those that touch the request.
|
|
17
|
+
It prints `true`, a summary line and `Warning:` lines (then, for a licensed page, `Datama comment:` and the comments the page shows), or `Validation failed:` with one fix per line: apply them and run it again. Warnings do not block: fix those that touch the request. Never fill `assets/studio-output-template.html` by hand.
|
|
18
18
|
4. **Deliver** the page: an HTML Artifact with `capabilities: {downloads: true}` on Claude, a full-height iframe Frame on Dust (if the Frame blocks the CDN, the `.html` file to open in a browser), Canvas or the file on ChatGPT, the file in the workspace on Cursor and Claude Code.
|
|
19
19
|
5. **Summarize.** When the build printed `Datama comment:`, sum up those comments in the user's words: they are the analysis the page shows. Otherwise say in a few lines what each story analyses. Never produce a breakdown of your own from the rows.
|
|
20
20
|
|
|
21
|
+
A request to compare or analyse data needs nothing more than this file: build with the defaults, then offer the changes below.
|
|
22
|
+
|
|
21
23
|
## Configuration
|
|
22
24
|
|
|
23
25
|
Write only the choices that need judgement, as one flat JSON object. The build derives the rest (dimensions, story, pins, module, steps, formula).
|
|
24
26
|
|
|
25
27
|
```json
|
|
26
|
-
{"solution": "compare", "metrics": ["Sessions", "Orders", "Revenue"], "context": "
|
|
28
|
+
{"solution": "compare", "metrics": ["Sessions", "Orders", "Revenue"], "context": "Quarter",
|
|
27
29
|
"start": ["Q1"], "end": ["Q2"], "totalStepName": "Revenue", "totalStepUnit": "€",
|
|
28
30
|
"title": "Pourquoi le CA a baissé au T2", "language": "fr-FR"}
|
|
29
31
|
```
|
|
@@ -37,39 +39,36 @@ Column names are exact tokens from the data: never translate, pluralize, rename
|
|
|
37
39
|
- Order: the business flow. Web: sessions → product views → add to cart → checkout → orders → revenue. Acquisition: cost → impressions → clicks → sessions → conversions → revenue. Subscription: expirations → renewals → revenue. Otherwise: column order.
|
|
38
40
|
- Custom equation, only when the meaning requires it: `steps` (each `{"numerator", "denominator"}`, named `"<numerator> per <denominator>"`) and `formula` over step indices `[1]`…`[N]`. Cost per unit: `[1]+[2]+[3]` over `Cost_x / Units` steps. NPS: `([1]-[2])*100` over `Promoters / Answers`, `Detractors / Answers`. Details: [market-equation.md](references/market-equation.md).
|
|
39
41
|
- `totalStepName`: the KPI computed, in business words (`Revenue`, `ROAS`, `NPS`), never a step name like `Revenue per Orders`. `totalStepUnit`: `"€"` for money, `"%"` for a percentage, otherwise `""`.
|
|
40
|
-
- `dimensions` defaults to every other column; set it
|
|
42
|
+
- `dimensions` defaults to every other column; set it to leave columns out, or to keep a numeric label (year, store id, zip code) out of the metrics.
|
|
43
|
+
|
|
44
|
+
**Comparison** (Compare; optional in the other solutions). `context` is the dimension holding the two sides. `start` is the reference side (before, A), `end` the side explained (after, B): values as written in the data (`["2024"]`, several merged on one side: `["Desktop", "Tablet"]`), or `[first, last]` each on a date column. Without `context`: the older half of the first date column against the newer half. Rolling periods: `"relative": true`, indices from the most recent date, `"start": [13, 7], "end": [6, 0]`. Two metric columns (budget vs actual), a second comparison, a what-if simulation: [compare.md](references/solutions/compare.md#advanced).
|
|
41
45
|
|
|
42
|
-
**
|
|
46
|
+
**Filters**, only when asked: `"filters": [{"column": "Country", "operator": "in", "value": ["France"]}]`, every clause kept (AND). Operators: `in` / `not` a list of values, `like` a text, `gte` / `lte` / `after` / `before` a bound, `between` `[low, high]` (inclusive).
|
|
43
47
|
|
|
44
|
-
**
|
|
48
|
+
**Several analyses.** `"modules": [{"solution": "compare"}, {"solution": "explore", "primary": "Country", "secondary": "Comparison Dimension"}]` stacks analyses in one story, sharing its comparison, filters and equation (`"displayMode": "slide"`: one per slide). `"stories": [{…}, {…}]` adds one tab per question; each story takes the top-level keys and overrides them. A module input every module of the story must share (drill-down hierarchy, detection method, analysis method) goes in `"shared": {…}` instead of the module. Story look: `"appearance"` ([theming.md](references/theming.md#story-canvas-appearance)).
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
## Changing a setting
|
|
51
|
+
|
|
52
|
+
Every other key of the configuration is a module input. Write only what the request asks. The frequent ones:
|
|
47
53
|
- Compare: `view` (`waterfall-default` · `tree-default`), `analysisMethod` (`auto` · `steps` · `dimensions`), `waterfallMeasure`, `stylePreset`, `chartTitle` — [compare.md](references/solutions/compare.md).
|
|
48
54
|
- Explore: `primary` (axis dimension), `secondary` (series dimension, or `"Comparison Dimension"` for Start vs End), `metric1` / `metric2` / `metric3` (a metric, a step name, or with a comparison `"<measure> Δ"` / `"<measure> % Change"`), `chart.category` (`bar` · `line` · `area` · `combo` · `mekko` · `scatter`), `chart.layout` (`clustered` · `stacked` · `percent` · `overlay`) — [explore.md](references/solutions/explore.md).
|
|
49
55
|
- Detect: `detectionMethod`, `lastPointsOnlyEnabled` with `lastPointsCount`, `confidence` — [detect.md](references/solutions/detect.md).
|
|
50
56
|
- Pivot: `view`, `hierarchyExplorationMethod` (`hierarchy` · `top`), `hierarchyTopLeaves` — [pivot.md](references/solutions/pivot.md).
|
|
51
|
-
-
|
|
52
|
-
|
|
53
|
-
`python3 scripts/datama.py settings compare|explore|detect|pivot [word]` lists every input with its default. An input listed neither there nor in the solution file does not exist: say "configurable in the Datama app, not exposed to this skill", never "Datama cannot do it".
|
|
54
|
-
|
|
55
|
-
**Several analyses.** `"modules": [{"solution": "compare"}, {"solution": "explore", "primary": "Country", "secondary": "Comparison Dimension"}]` stacks analyses in one story, sharing its comparison, filters and equation (`"displayMode": "slide"`: one per slide). `"stories": [{…}, {…}]` adds one tab per question; each story takes the top-level keys and overrides them.
|
|
56
|
-
|
|
57
|
-
**Look** (palette, brand colors, background) goes in `--theme '{"colors": {"palette": "modern"}}'`, not in the configuration: [theming.md](references/theming.md); `datama.py settings theme` lists palettes, style presets and colors.
|
|
58
|
-
|
|
59
|
-
## Plotter
|
|
57
|
+
- Chart details the inputs do not cover (axis, legend, labels, average lines): the `plotter` key — [chart.md](references/chart.md).
|
|
58
|
+
- Look (palette, brand colors, background): `--theme '{"colors": {"palette": "modern"}}'`, not the configuration — [theming.md](references/theming.md).
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
Anything else: look it up in the **settings registry** of the Studio release the page loads:
|
|
62
61
|
|
|
63
62
|
```bash
|
|
64
|
-
python3 scripts/datama.py
|
|
65
|
-
|
|
63
|
+
python3 scripts/datama.py settings compare|explore|detect|pivot [word] # module inputs and their defaults
|
|
64
|
+
python3 scripts/datama.py settings modules|pins|plotter|theme [word] # modules, story pins, chart keys, palettes and presets
|
|
66
65
|
```
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
A setting absent from the registry does not exist: say "configurable in the Datama app, not exposed to this skill", never "Datama cannot do it". Only when the registry lists a setting without making its effect clear, search the Studio source as a last resort: `python3 scripts/datama.py source '<regex>' [--context 5]` (the readable build of `@datama/studio`). Use it to understand a value, never to invent a key.
|
|
69
68
|
|
|
70
69
|
## Editing a page
|
|
71
70
|
|
|
72
|
-
Rebuild from the page, passing only the keys that change: `--from page.html --config '{"view": "tree-default"}'`, `--config '{"solution": "explore", "primary": "Country"}'`, or `--from page.html --theme '{"colors": {"palette": "ocean"}}'`. On a page with several stories, a top-level key changes every story; `"stories": [{}, {"view": "tree-default"}]` changes the second only.
|
|
71
|
+
Rebuild from the page, passing only the keys that change: `--from page.html --config '{"view": "tree-default"}'`, `--config '{"solution": "explore", "primary": "Country"}'`, or `--from page.html --theme '{"colors": {"palette": "ocean"}}'`. On a page with several stories, a top-level key changes every story; `"stories": [{}, {"view": "tree-default"}]` changes the second only.
|
|
73
72
|
|
|
74
73
|
## Rules
|
|
75
74
|
|
package/README.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
Workflow of the `datama-studio` agent skill. The installed skill prints it with `python3 scripts/datama.py instructions`, and one reference with `python3 scripts/datama.py instructions references/<file>.md`.
|
|
4
4
|
|
|
5
|
-
Published from the `studio-skill` repository on each release tag.
|
|
5
|
+
Published from the `studio-skill` repository on each release tag. The settings registry is not here: it ships with `@datama/studio` (`contract/settings-registry.json`) and is read with `python3 scripts/datama.py settings`.
|
package/package.json
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Tuning the chart of a module (`plotter`)
|
|
2
|
+
|
|
3
|
+
Every Studio module draws with Plotter. The `plotter` key of the configuration (saved on the module slot as `configuration.plotter`) is a **partial** chart configuration deep-merged over the defaults. Use it for precise chart requests the module inputs do not cover: axis, legend, labels, padding, average lines.
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{"solution": "compare", "metrics": ["Orders", "Revenue"], "context": "Year", "start": ["2024"], "end": ["2025"],
|
|
7
|
+
"plotter": {"reverse": true, "legends": {"display": true}}}
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Rules
|
|
11
|
+
|
|
12
|
+
- Write only the keys that change. Every valid key, its type and its default: `python3 scripts/datama.py settings plotter [word]`. A key not listed there does not exist and is rejected.
|
|
13
|
+
- Prefer module inputs first: Compare `stylePreset`, `chartTitle`, `waterfallValueLabels`, `view`; Explore `chart.*`. They are tested together with the solution layout.
|
|
14
|
+
- Explore: any non-empty `plotter` is read as a saved chart and skips Explore's default look (preset, value labels on bars). Add one only when needed.
|
|
15
|
+
- Keys owned by the solution layout (`layout`, `views`, `traces`, `customViews`) are rebuilt by the module; leave them out.
|
|
16
|
+
- Never store pixel positions or computed values.
|
|
17
|
+
|
|
18
|
+
## Frequent requests
|
|
19
|
+
|
|
20
|
+
| Request | `plotter` |
|
|
21
|
+
| ------------------------------------- | --------------------------------------------------------------------------- |
|
|
22
|
+
| Horizontal bars / swap axes | `{"reverse": true}` |
|
|
23
|
+
| Show the legend at the bottom | `{"legends": {"display": true, "position": "bottom"}}` |
|
|
24
|
+
| Hide the measure axis | `{"axis": {"y": {"hidden": true}}}` |
|
|
25
|
+
| Compact numbers on axis ticks (K / M) | `{"axis": {"ticks": {"texts": {"format": {"compact": true}}}}}` |
|
|
26
|
+
| Two decimals on axis ticks | `{"axis": {"ticks": {"texts": {"format": {"decimals": 2}}}}}` |
|
|
27
|
+
| Bigger chart margins | `{"plot": {"padding": {"top": 30, "right": 20, "bottom": 30, "left": 20}}}` |
|
|
28
|
+
| No bar gradient | `{"bars": {"gradient": {"display": false}}}` |
|
|
29
|
+
| Bar value labels | `{"bars": {"labels": {"display": true}}}` |
|
|
30
|
+
| Hide the waterfall connectors | `{"waterfall": {"links": {"display": false}}}` |
|
|
31
|
+
| Bigger header title | `{"header": {"title": {"size": 22}}}` |
|
|
32
|
+
| No animations | `{"behaviors": {"transitionDuration": 0}}` |
|
|
33
|
+
|
|
34
|
+
## Average and value lines (Explore)
|
|
35
|
+
|
|
36
|
+
A dotted reference line at an average, or at one element value, labelled past the end of the plot. Add one only when the user asks ("add the average line"). On Compare, gaps between bars use the module input `waterfallDifferenceArrows` ([compare.md](solutions/compare.md#advanced)).
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{"plotter": {"annotations": {"valueLines": [
|
|
40
|
+
{"id": "average-sessions", "trace": "Sessions", "kind": "average"},
|
|
41
|
+
{"id": "average-tablet", "trace": "Sessions", "kind": "average", "series": "Tablet"}
|
|
42
|
+
]}}}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
| Key | Value | Meaning |
|
|
46
|
+
| -------- | ----------------------- | ------------------------------------------------------------------------------------- |
|
|
47
|
+
| `id` | string | Unique id |
|
|
48
|
+
| `trace` | string | The measure name |
|
|
49
|
+
| `kind` | `"average"` · `"value"` | Mean of the plotted elements (stack totals when stacked), or the value of one element |
|
|
50
|
+
| `series` | string | `average` of one series only (one value of the `secondary` dimension) |
|
|
51
|
+
| `key` | string | `value` lines: stable id of the anchor element |
|
|
52
|
+
|
|
53
|
+
## Table view
|
|
54
|
+
|
|
55
|
+
Every chart also offers a table view (`table.enabled`, default on). Its columns, pagination and styling live under `plotter.table`; leave them to the solution unless the user asks for a table change.
|
|
@@ -1,109 +1,93 @@
|
|
|
1
1
|
# Market equation: metrics, steps, formula, main KPI
|
|
2
2
|
|
|
3
|
-
The market equation explains a main KPI as a chain of steps (volumes and ratios). Compare decomposes a change along it, Explore and Detect
|
|
4
|
-
|
|
5
|
-
## Where it lives
|
|
6
|
-
|
|
7
|
-
| Part | Location |
|
|
8
|
-
| --- | --- |
|
|
9
|
-
| Metric columns and their order | `source.metrics` ([studio-instantiation.md](studio-instantiation.md)) |
|
|
10
|
-
| Dimension columns | `source.dimensions` |
|
|
11
|
-
| Steps | `pins.marketEquation.steps` ([studio-stories.md](studio-stories.md#pins)) |
|
|
12
|
-
| `formula`, `totalStepName`, `totalStepUnit`, `totalStepEmoji` | `pins.marketEquation.inputs` |
|
|
3
|
+
The market equation explains a main KPI as a chain of steps (volumes and ratios). Compare decomposes a change along it, Explore and Detect plot its steps, Pivot builds its KPI tree from it. Getting it right is what makes the analysis read as business.
|
|
13
4
|
|
|
14
5
|
## Automatic or explicit
|
|
15
6
|
|
|
16
|
-
- **Automatic** (
|
|
17
|
-
- **Explicit** (`
|
|
18
|
-
|
|
19
|
-
## Column mapping (strict)
|
|
20
|
-
|
|
21
|
-
- Use the exact column names of the dataset: never pluralize, translate, rename or re-case them (`Session` stays `Session`).
|
|
22
|
-
- `source.dimensions` and `source.metrics` are arrays of plain strings.
|
|
7
|
+
- **Automatic** (only `metrics`): step 1 is the first metric, step i is `<metric i> per <metric i-1>`, formula = product of every step, main KPI = last metric. Order and restrict `metrics` to control it. This covers funnels, the most frequent case.
|
|
8
|
+
- **Explicit** (`steps` + `formula`): when the formula is not a plain product (sum of costs, NPS, branching funnel), when a step divides by a column that is not the previous metric, or when the user names a KPI the last metric is not.
|
|
9
|
+
- `totalStepName` / `totalStepUnit`: write them in both cases, they name what the page explains.
|
|
23
10
|
|
|
24
11
|
## Metric scope
|
|
25
12
|
|
|
26
|
-
-
|
|
27
|
-
- The user names metrics →
|
|
28
|
-
-
|
|
29
|
-
-
|
|
13
|
+
- Metric columns only, with their exact names (never pluralize, translate, rename or re-case).
|
|
14
|
+
- The user names metrics → only those. Otherwise every raw numeric metric.
|
|
15
|
+
- Leave out precomputed rates, ratios and averages unless asked for (`rate`, `ratio`, `avg`, `mean`, `%`, `ROAS`, `CPA`, `CPC`, `CTR`, `CVR`, `AOV`, `ROI`, `NPS`): the equation recomputes them from raw counts, and a ratio summed over segments is wrong.
|
|
16
|
+
- A numeric column that is a label (year, store id) is a dimension: list `dimensions` explicitly.
|
|
30
17
|
|
|
31
18
|
## Metric order
|
|
32
19
|
|
|
33
|
-
|
|
20
|
+
Business flow first, upstream to downstream:
|
|
34
21
|
|
|
35
|
-
- Web
|
|
36
|
-
- Acquisition
|
|
37
|
-
- Subscription: `expirations → renewals →
|
|
22
|
+
- Web: `sessions → product views → add to cart → checkout → orders → revenue`
|
|
23
|
+
- Acquisition: `cost → impressions → clicks → sessions → leads → conversions → revenue`
|
|
24
|
+
- Subscription: `expirations → renewals → revenue`
|
|
25
|
+
- Retail: `visitors → tickets → items → revenue`
|
|
38
26
|
|
|
39
|
-
Without a clear flow: numeric sequence in the names, then column order
|
|
27
|
+
Without a clear flow: numeric sequence in the names, then column order. Never invent a metric.
|
|
40
28
|
|
|
41
29
|
## Steps
|
|
42
30
|
|
|
43
|
-
One step per included metric, in metric order:
|
|
44
|
-
|
|
45
31
|
```json
|
|
46
|
-
{"
|
|
32
|
+
{"numerator": "Orders", "denominator": "Sessions", "unit": "%"}
|
|
47
33
|
```
|
|
48
34
|
|
|
49
35
|
| Key | Rule |
|
|
50
36
|
| --- | --- |
|
|
51
|
-
| `numerator` | Metric column |
|
|
52
|
-
| `denominator` | Metric column, or
|
|
53
|
-
| `name` |
|
|
54
|
-
| `
|
|
55
|
-
| `unit` | Optional: `"€"` (or the currency the user implies) for money, `"%"` only for a true rate, otherwise omit or `""` |
|
|
37
|
+
| `numerator` | Metric column (required) |
|
|
38
|
+
| `denominator` | Metric column, or omitted for a volume step |
|
|
39
|
+
| `name` | Optional. Default: the numerator for a volume step, `"<numerator> per <denominator>"` for a ratio step. Keep that naming: Explore measures and what-if KPIs refer to it |
|
|
40
|
+
| `unit` | Optional: `"€"` (or the currency the user implies) for money, `"%"` only for a true rate. Never inside `name` |
|
|
56
41
|
|
|
57
|
-
|
|
58
|
-
- Step i: `numerator = metrics[i]`, `denominator = metrics[i-1]`.
|
|
59
|
-
- A denominator may be a column that is not itself a step (NPS answers, units). Keep it in `source.metrics` only if the user wants it as a metric.
|
|
60
|
-
- Never put a unit inside `name`.
|
|
42
|
+
A denominator may be a column that is not a step (answers for NPS, units for a unit cost): keep it in `metrics` so it exists in the source.
|
|
61
43
|
|
|
62
44
|
## Formula
|
|
63
45
|
|
|
64
|
-
`
|
|
65
|
-
|
|
66
|
-
- Single step: `"[1]"`
|
|
67
|
-
- Sequential funnel: `"[1]*[2]*[3]*…*[N]"`
|
|
68
|
-
- Additive: `"[1]+[2]+[3]+[4]"`
|
|
69
|
-
- NPS-style: `"([1]-[2])*100"`
|
|
70
|
-
- Branching: `"[1]*[2]*([3]*[4]+(1-[3])*[5])*[6]"`
|
|
71
|
-
|
|
72
|
-
Reference only existing indices. When unsure, use the sequential product of every step.
|
|
46
|
+
`formula` uses 1-based step indices, never column names: `"[1]"`, `"[1]*[2]*[3]"` (product), `"[1]+[2]+[3]"` (sum), `"([1]-[2])*100"` (NPS), `"[1]*[2]*([3]*[4]+(1-[3])*[5])"` (branching). Reference only existing indices; when unsure, use the product of every step.
|
|
73
47
|
|
|
74
48
|
## Main KPI
|
|
75
49
|
|
|
76
|
-
- `totalStepName`:
|
|
77
|
-
- `totalStepUnit`: `"€"`
|
|
78
|
-
-
|
|
79
|
-
- Recompute both whenever steps or formula change.
|
|
50
|
+
- `totalStepName`: what the formula computes, in business words. Priority: the KPI the user names → the KPI the formula implies (`ROAS` for cost → revenue, `NPS`, `Cost per unit`) → the last metric. Never a step name like `"Revenue per Orders"`.
|
|
51
|
+
- `totalStepUnit`: `"€"` for money, `"%"` for a percentage KPI, otherwise `""`. `totalStepEmoji`: optional, one emoji.
|
|
52
|
+
- Rewrite both whenever the steps or the formula change.
|
|
80
53
|
|
|
81
54
|
## Examples
|
|
82
55
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
56
|
+
E-commerce funnel, automatic:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{"solution": "compare", "metrics": ["Sessions", "Orders", "Revenue"], "context": "Year", "start": ["2024"], "end": ["2025"],
|
|
60
|
+
"totalStepName": "Revenue", "totalStepUnit": "€", "title": "Why did revenue change in 2025?", "language": "en-US"}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Acquisition, ROAS: the automatic steps without the cost volume, so each funnel stage explains its share of the ROAS change (`[1]` is `Cost`, `[2]` `Impressions per Cost`, …, `[6]` `Revenue per Orders`):
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{"solution": "compare", "metrics": ["Cost", "Impressions", "Clicks", "Sessions", "Orders", "Revenue"],
|
|
67
|
+
"formula": "[2]*[3]*[4]*[5]*[6]", "totalStepName": "ROAS", "totalStepUnit": "",
|
|
68
|
+
"context": "Year", "start": ["2024"], "end": ["2025"], "language": "en-US"}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
NPS, a difference of two shares of the same denominator:
|
|
90
72
|
|
|
91
|
-
|
|
73
|
+
```json
|
|
74
|
+
{"solution": "compare", "metrics": ["Promoters", "Detractors", "Answers"],
|
|
75
|
+
"steps": [{"numerator": "Promoters", "denominator": "Answers"}, {"numerator": "Detractors", "denominator": "Answers"}],
|
|
76
|
+
"formula": "([1]-[2])*100", "totalStepName": "NPS", "totalStepUnit": "", "context": "Year", "start": ["2024"], "end": ["2025"], "language": "en-US"}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Cost per unit, a sum of unit costs:
|
|
92
80
|
|
|
93
81
|
```json
|
|
94
|
-
{"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
{"name": "Session", "numerator": "Session", "denominator": "", "exclude": []},
|
|
98
|
-
{"name": "Checkout per Session", "numerator": "Checkout", "denominator": "Session", "exclude": [], "unit": "%"},
|
|
99
|
-
{"name": "Revenue per Checkout", "numerator": "Revenue", "denominator": "Checkout", "exclude": [], "unit": "€"}
|
|
100
|
-
]
|
|
101
|
-
}}
|
|
82
|
+
{"solution": "compare", "metrics": ["Product_cost", "Shipping_cost", "Units"],
|
|
83
|
+
"steps": [{"numerator": "Product_cost", "denominator": "Units", "unit": "€"}, {"numerator": "Shipping_cost", "denominator": "Units", "unit": "€"}],
|
|
84
|
+
"formula": "[1]+[2]", "totalStepName": "Cost per unit", "totalStepUnit": "€", "context": "Year", "start": ["2024"], "end": ["2025"], "language": "en-US"}
|
|
102
85
|
```
|
|
103
86
|
|
|
104
|
-
|
|
87
|
+
When a drop of the KPI is good news (costs, churn), say so in the summary and swap the rise and drop colors ([theming.md](theming.md#custom-colors-palette-custom)).
|
|
88
|
+
|
|
89
|
+
## Checks
|
|
105
90
|
|
|
106
|
-
- Every column
|
|
107
|
-
-
|
|
108
|
-
- `
|
|
109
|
-
- `totalStepName` is a non-empty main KPI name; `totalStepUnit` is present (may be `""`).
|
|
91
|
+
- Every column of `metrics` and `steps` exists in the data.
|
|
92
|
+
- `formula` references existing step indices only.
|
|
93
|
+
- `totalStepName` is a business KPI name, `totalStepUnit` matches it.
|
|
@@ -4,121 +4,98 @@ Explains **why** a main KPI changed between two sides (two periods, two segments
|
|
|
4
4
|
|
|
5
5
|
## When
|
|
6
6
|
|
|
7
|
-
- "Why did revenue drop?", "compare Q1 vs Q2", "decompose the conversion change", "Mobile vs Desktop".
|
|
8
|
-
-
|
|
7
|
+
- "Why did revenue drop?", "compare Q1 vs Q2", "decompose the conversion change", "Mobile vs Desktop", "budget vs actual".
|
|
8
|
+
- `start` is the reference (before, budget, A), `end` the side explained (after, actual, B). Without a comparison, Studio compares the older half of the first date column with its newer half.
|
|
9
9
|
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
1. `source`: rows + `dimensions` (every dimension worth drilling into, the comparison dimension included) + `metrics` in funnel order ([studio-instantiation.md](../studio-instantiation.md)).
|
|
13
|
-
2. `pins.comparison`: the two sides ([studio-stories.md](../studio-stories.md#comparisons)).
|
|
14
|
-
3. `pins.marketEquation`: only when the user names the KPI or the formula is not a plain funnel ([market-equation.md](../market-equation.md)).
|
|
15
|
-
4. Module `{"module": "compare.waterfall", "inputs": {…}}` with only the inputs below that the request needs.
|
|
16
|
-
5. Story `title`: the question, in the user's language.
|
|
10
|
+
## Minimal
|
|
17
11
|
|
|
18
12
|
```json
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
"title": "Mobile vs Desktop: what explains the revenue gap?",
|
|
22
|
-
"pins": {"comparison": {"inputs": {"comparisons": [{"mode": "dimension",
|
|
23
|
-
"start": {"column": "Device", "operator": "in", "value": ["Desktop"]},
|
|
24
|
-
"end": {"column": "Device", "operator": "in", "value": ["Mobile"]}}], "relative": false, "order": "desc"}}},
|
|
25
|
-
"modules": [{"module": "compare.waterfall", "inputs": {"analysisMethod": "auto"}}]
|
|
26
|
-
}},
|
|
27
|
-
"activeStory": "story-mobile-vs-desktop"
|
|
28
|
-
}
|
|
13
|
+
{"solution": "compare", "metrics": ["Sessions", "Orders", "Revenue"], "context": "Device", "start": ["Desktop"], "end": ["Mobile"],
|
|
14
|
+
"totalStepName": "Revenue", "totalStepUnit": "€", "title": "Mobile vs Desktop: what explains the revenue gap?", "language": "en-US"}
|
|
29
15
|
```
|
|
30
16
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
| `outOfScopeAddComparablePillar` | boolean, default `true` | Add a "Comparable" pillar after the out-of-scope block |
|
|
77
|
-
|
|
78
|
-
### Tree view (`view: "tree-default"`)
|
|
79
|
-
|
|
80
|
-
| Key | Values | Meaning |
|
|
81
|
-
| --- | --- | --- |
|
|
82
|
-
| `hierarchyExplorationMethod` | `"hierarchy"` · `"top"` | Expand along the dimension order, or pick the most contributing leaves |
|
|
83
|
-
| `hierarchyTopLeaves` | integer ≥ 1, default `4` | Leaves per node with `top` |
|
|
84
|
-
| `treeCardMainKpiRatio` / `treeCardSubKpiRatio` / `treeCardTitleRatio` | `0.75` · `1` · `1.25` | Font size of the card headline / sub lines / title |
|
|
17
|
+
Two date periods: `"context": "Date", "start": ["2025-01-01", "2025-01-31"], "end": ["2025-02-01", "2025-02-28"]`. Periods of the same length make the clearest analysis. Every dimension left in the data is a drill-down axis: drop (`dimensions`) those that make no business sense.
|
|
18
|
+
|
|
19
|
+
## Business rules
|
|
20
|
+
|
|
21
|
+
- The waterfall explains `totalStepName`: get the market equation right first ([market-equation.md](../market-equation.md)).
|
|
22
|
+
- Both sides must hold rows after filters; a filter on the comparison dimension can empty one side.
|
|
23
|
+
- A drop that is good news (costs, churn): say so in the summary, swap the colors ([theming.md](../theming.md#custom-colors-palette-custom)).
|
|
24
|
+
- Summarize the `Datama comment:` lines; never recompute the drivers from the rows.
|
|
25
|
+
|
|
26
|
+
## Inputs
|
|
27
|
+
|
|
28
|
+
All optional. Defaults: `python3 scripts/datama.py settings compare`. Change only what the request asks.
|
|
29
|
+
|
|
30
|
+
| Key | Values | Meaning |
|
|
31
|
+
| --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| `view` | `"waterfall-default"` · `"tree-default"` | Waterfall of drivers, or tree of cards decomposing the KPI dimension by dimension |
|
|
33
|
+
| `analysisMethod` | `"auto"` · `"steps"` · `"dimensions"` | `auto` picks the most interesting; `steps` starts from the equation steps, then segments; `dimensions` starts from segments, then steps |
|
|
34
|
+
| `waterfallMeasure` | `"Impact"` · `"Pts_gap"` | Bar value: contribution to the KPI (in `totalStepUnit`), or gap in points (rate steps) |
|
|
35
|
+
| `Split_Mix_and_Perf` | `"Auto"` · `"Always"` · `"Never"` | Split each segment bar into mix (share shift) and performance (rate change) |
|
|
36
|
+
| `separateCovariance` | `"Never"` · `"Auto"` · `"Always"` | Isolate the interaction between steps in a "Covariance" bar (`Auto`: above `separateCovarianceThreshold`, %) |
|
|
37
|
+
| `covarianceWarningThreshold` | number 0–100 | Above it, the page warns the two sides may not be comparable |
|
|
38
|
+
| `mixPerfCovariance` | `"pro-rata"` · `"performance"` · `"mix"` | Who carries the mix × performance cross term |
|
|
39
|
+
| `waterfallOpenBarByDefault` | boolean, default `true` | Drill into the main bars on load |
|
|
40
|
+
| `waterfallExpandDepth` / `waterfallExplorationDepth` | `1` · `2` · `3` | How deep a drilled bar opens / dimension levels explored automatically |
|
|
41
|
+
| `waterfallCommentThreshold` | number (points), default `1` | Minimum impact for a segment to be cited: higher = shorter comment |
|
|
42
|
+
| `segment_complement` | `"Variation relative to avg"` · `"Variation %"` · `"Nothing"` | Text after each segment name |
|
|
43
|
+
| `waterfallValueLabels` | boolean, default `true` | Value on each bar; `false` on a dense waterfall |
|
|
44
|
+
| `waterfallGroupEquationSteps` | boolean | Also fold small step bars into "Remaining" |
|
|
45
|
+
| `chartTitle` / `chartSubtitle` | string, default `""` | Bands above the chart, verbatim, in the user's language. Empty = the generated insight speaks |
|
|
46
|
+
| `stylePreset` | `datama.py settings theme stylePreset` | One-key look (shapes, typography, comment placement); applies its palette too |
|
|
47
|
+
| `clusteringThreshold` | number 0–100 (%), default `2` | Segments under this share of `metricForClustering` grouped into "Other" |
|
|
48
|
+
| `clusteringMethod` | `"threshold"` · `"tail"` | Group by share threshold, or keep the top segments and group the tail |
|
|
49
|
+
| `clusteringBins` | integer 2–20, default `5` | Bins for numeric dimensions |
|
|
50
|
+
| `metricForClustering` | metric column | Metric weighing the segments (default: the first metric) |
|
|
51
|
+
| `dimensionsHierarchy` | `[{"name": "Country", "level": 0, "pinned": false}, {"name": "City", "level": 1, "pinned": false}]` | Drill-down order (parent before child) |
|
|
52
|
+
| `hierarchicalMix` | boolean | Measure each level's mix against its parent (with `dimensionsHierarchy`); `clusteringAtParentLevel` (default `true`) rebuilds "Other" inside every parent |
|
|
53
|
+
| `outOfScopeDimensions` | dimension names | Segments present on one side only (new stores, closed products) grouped in an "Out of scope" block; `outOfScopeLabel`, `outOfScopeAddComparablePillar` (default `true`) |
|
|
54
|
+
| `hierarchyExplorationMethod` | `"hierarchy"` · `"top"` | Tree view: expand along the dimension order, or pick the most contributing leaves (`hierarchyTopLeaves`, default `4`) |
|
|
55
|
+
| `treeCardMainKpiRatio` / `treeCardSubKpiRatio` / `treeCardTitleRatio` | `0.75` · `1` · `1.25` | Tree view: font size of the card headline / sub lines / title |
|
|
56
|
+
|
|
57
|
+
## Advanced
|
|
58
|
+
|
|
59
|
+
**Like-for-like** (stores, products present on both sides only): `"outOfScopeDimensions": ["City"]`.
|
|
60
|
+
|
|
61
|
+
**Drill-down by hierarchy**, shared by every module of the story:
|
|
85
62
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
| --- | --- | --- |
|
|
92
|
-
| `splitOrientation` | `"horizontal"` · `"vertical"` | Waterfalls side by side, or stacked |
|
|
93
|
-
| `splitDisplayMode` | `"grouped"` · `"overlay"` | Bars grouped per comparison, or overlaid |
|
|
63
|
+
```json
|
|
64
|
+
{"solution": "compare", "metrics": ["Sessions", "Orders", "Revenue"], "context": "Year", "start": ["2024"], "end": ["2025"],
|
|
65
|
+
"shared": {"dimensionsHierarchy": [{"name": "Country", "level": 0, "pinned": false}, {"name": "City", "level": 1, "pinned": false}], "hierarchicalMix": true},
|
|
66
|
+
"totalStepName": "Revenue", "totalStepUnit": "€", "language": "en-US"}
|
|
67
|
+
```
|
|
94
68
|
|
|
95
|
-
|
|
69
|
+
**Two metric columns of the same rows** (budget vs actual, forecast vs real): `comparisons` with `mode: "metric"`. Each pair names one compared measure; the equation is built from the pair names.
|
|
96
70
|
|
|
97
|
-
|
|
71
|
+
```json
|
|
72
|
+
{"solution": "compare", "metrics": ["Revenue_budget", "Revenue"],
|
|
73
|
+
"comparisons": [{"mode": "metric", "pairs": [{"start": "Revenue_budget", "end": "Revenue", "name": "Revenue"}], "startSegment": "Budget", "endSegment": "Actual"}],
|
|
74
|
+
"title": "Revenue vs budget", "language": "en-US"}
|
|
75
|
+
```
|
|
98
76
|
|
|
99
|
-
`
|
|
77
|
+
**Explicit sides, or a second comparison** (Start vs End twice, side by side): `comparisons` holds one entry per comparison, the first is the primary one. Each side is `{"column", "operator", "value"}`, the same column on both sides: `between [first, last]` for a date or numeric range, `in [values]` otherwise. Layout: `splitOrientation` (`horizontal` · `vertical`), `splitDisplayMode` (`grouped` · `overlay`), `waterfallMergeOnCommonBars`.
|
|
100
78
|
|
|
101
79
|
```json
|
|
102
|
-
|
|
80
|
+
{"solution": "compare", "metrics": ["Sessions", "Orders", "Revenue"], "comparisons": [
|
|
81
|
+
{"mode": "dimension", "start": {"column": "Year", "operator": "in", "value": ["2024"]}, "end": {"column": "Year", "operator": "in", "value": ["2025"]}},
|
|
82
|
+
{"mode": "dimension", "start": {"column": "Device", "operator": "in", "value": ["Desktop"]}, "end": {"column": "Device", "operator": "in", "value": ["Mobile"]}}],
|
|
83
|
+
"totalStepName": "Revenue", "totalStepUnit": "€", "language": "en-US"}
|
|
103
84
|
```
|
|
104
85
|
|
|
105
|
-
|
|
106
|
-
| --- | --- |
|
|
107
|
-
| `fromAnchorKey` / `toAnchorKey` | Exact bar labels (segment name, step name, `Start`, `End`) |
|
|
108
|
-
| `kind` | `level` (adjacent bars) · `total` (spans the bars between) · `cagr` (compound rate per period) |
|
|
109
|
-
| `mode` | `percent` · `absolute` · `both` (ignored by `cagr`) |
|
|
110
|
-
| `direction` | `to` · `from` · `both` |
|
|
111
|
-
| `position` | −0.5 … 1.5, default `0.5` (`level` arrows) |
|
|
112
|
-
| `lift` | 0 … 1, default `0` (`total` arrows) |
|
|
113
|
-
|
|
114
|
-
Add pillars and arrows only when the user asks for them.
|
|
86
|
+
**What-if simulation**, only when asked ("what if mobile conversion rose 10 %?"): `kpis[].name` is a step name of the equation, `impact` `relative` in percent.
|
|
115
87
|
|
|
116
|
-
|
|
88
|
+
```json
|
|
89
|
+
{"solution": "compare", "metrics": ["Sessions", "Orders", "Revenue"], "context": "Year", "start": ["2024"], "end": ["2025"],
|
|
90
|
+
"whatIf": {"scenarios": [{"name": "Mobile conversion +10 %", "enabled": true, "comparison": true,
|
|
91
|
+
"baseline": {"name": "", "dimension": "Device", "segments": ["Mobile"]},
|
|
92
|
+
"kpis": [{"name": "Orders per Sessions", "scope": {}, "impact": {"type": "relative", "value": 10}, "pinned": true}]}]},
|
|
93
|
+
"totalStepName": "Revenue", "totalStepUnit": "€", "language": "en-US"}
|
|
94
|
+
```
|
|
117
95
|
|
|
118
|
-
|
|
96
|
+
**Subtotals and arrows**, only when asked. `waterfallCustomPillars`: `[{"id": "pillar-eu", "anchorKey": "<bar label>", "position": "before", "label": "Subtotal EU"}]`. `waterfallDifferenceArrows`: `[{"id": "start-vs-end", "fromAnchorKey": "Start", "toAnchorKey": "End", "kind": "total", "mode": "both"}]`, with `kind` `level` (adjacent bars) · `total` · `cagr`, `mode` `percent` · `absolute` · `both`, `direction` `to` · `from` · `both`. Anchors are exact bar labels (segment, step, `Start`, `End`).
|
|
119
97
|
|
|
120
98
|
## Checks
|
|
121
99
|
|
|
122
|
-
- Both
|
|
123
|
-
-
|
|
124
|
-
- Every name in `dimensionsHierarchy`, `outOfScopeDimensions`, `metricForClustering` exists in the source.
|
|
100
|
+
- Both sides use the same column and values that exist in it, are not identical, and keep rows after filters.
|
|
101
|
+
- Every name in `dimensionsHierarchy`, `outOfScopeDimensions`, `metricForClustering`, `kpis[].name` exists.
|