This documentation explains how forecast-mmmapi-markets is intended to work
as the governed market-implementation layer for forecasting/MMM API artefacts.
This repo exists to stop market implementations drifting into unreviewed local
copies on SharePoint or analyst machines. It should be the source of truth for
market/KPI logic once a market has been migrated.
Subsections of forecast-mmmapi-markets Documentation
Chapter 1
Getting Started
Start here to understand the repo model, the workflow, and the first command path for a migrated market.
Subsections of Getting Started
Quickstart
This is the shortest supported path for using the repo.
Preconditions
Run commands from the repository root.
Have R available locally.
Install the minimal repo dependency used by validation:
install.packages("yaml")
Create A New Market/KPI
Rscript scripts/scaffold_market.R IT store_visits
This creates:
markets/IT/store_visits/
Fill In The Market Folder
At minimum:
update config.yml
implement transform.R
implement decomp.R
implement build.R
update the market README.md
record exact validated runtime versions in versions.lock
product/engineering reviews for mergeability and standards
What This Does Not Yet Guarantee
The current scaffold enforces structure, config shape, and forbidden local-path
patterns. Full runtime transform/predict/decomp/build verification is still a
next-step enhancement once real market logic is migrated.
Getting Started
This repo is for market-specific implementations that sit on top of the shared
product/package layer in forecast-mmmapi-r.
Run all commands from the repository root.
Typical Workflow
Create or update a market/KPI folder under markets/.
Keep market-specific logic in bounded files such as transform.R and
decomp.R.
Run validation locally.
Open a pull request for product/engineering review.
Build the upload artefact from the repo version, not from a local copy.
The contract exists to stop each market drifting into a private implementation
that is hard to review, hard to reproduce, and inconsistent with the product
workflow.
current scaffold assumes an external RDS-style source, but this can evolve
model.path
explicit path to the model artefact used by the market
model.object_path
object name or object-path identifier within the artefact
model.api_model_policy
expected consistency rule for predict/decomp
model.update_strategy
how model updates are handled, for example explicit replacement or inherited
mapping
where the mapping table comes from
inputs.raw_data
explicit market input artefact used by transform
inputs.fixed_forecast
fixed forecast input if applicable
decomp.*
market-specific decomp regex or configuration
validation.*
switches describing required validation behaviour
Current Limitation
The current repo validates config shape and week-start values. It does not yet
validate a full schema of allowed values for every nested field.
Market README Template
Every market/KPI folder requires a README.md.
Minimum Required Content
Title
market name
KPI name
Purpose
what this market folder implements
Owner
named analyst owner
named product/engineering reviewer if useful
Input Artefacts
what model artefact is expected
what raw data is expected
whether fixed forecast input is required
Market-Specific Assumptions
week start convention
date/calendar assumptions
important transform/decomp quirks
Validation Status
scaffold only
partially migrated
fully migrated and validated
Notes
known risks
transition notes from local scripts
Why This Matters
The market README is meant to make the folder understandable without relying on
oral context or analyst memory.
Chapter 3
Governance
Clarify ownership boundaries, decision rights, and the review path for market changes.
Subsections of Governance
Roles and Ownership
This page defines who owns what in the operating model.
Product/Engineering
Owns:
repository structure
validation standards
build standards
mergeability decisions
what counts as the authoritative repository version
Market Analyst
Owns:
market logic
business context
KPI-specific transform and decomp intent
keeping market assumptions current
Migration Authority
A market/KPI is considered migrated when product/engineering approves the
implementation, validation passes for the agreed scope, and the team accepts
the Git version as authoritative.
Disagreements
If analyst and product/engineering disagree:
analyst owns the market/business intent
product/engineering owns the repository standards and final merge decision
In practice, that means product/engineering decides whether an implementation
is fit to become the authoritative build path in this repo.
Chapter 4
Validation and Release
Capture what validation is enforced, how builds are produced, and how common failures should be diagnosed.
Subsections of Validation and Release
Validation Contract
This page separates what is enforced now from what is intended later.
Enforced Now
Current validation checks:
required market files exist
config.yml loads
required top-level config keys exist
week_start is one of the allowed values
required functions can be sourced
forbidden local-environment patterns are blocked in committed scripts
Planned Next
Not fully enforced yet:
transform runs against real market input
transformed columns match the intended model contract
predict succeeds
decomp succeeds
build produces a traceable artefact
formula regression checks for cases like lead() and I(...)
Why This Distinction Matters
The repo should not overstate its current level of technical assurance. Today,
validation proves that the market scaffold is structurally governed. It does
not yet prove that every migrated market implementation runs end to end.
Validation and Build
Validation is not optional in this repository. The purpose of validation is to
catch the kinds of failures that historically appeared only after packaging or
deployment.
This is not the long-term replacement for the repo-wide validation harness. It
is a market-specific runner used to demonstrate that the local
transform/refit/decomp path works from explicit artefacts.
What Validation Should Prove
Current enforced minimum:
required files exist
config loads
forbidden local-environment patterns are absent
required functions can be sourced
the market contract is satisfied
Planned next-stage validation:
transform runs in a clean session
transformed output matches model requirements
predict works
decomp works
build output is reproducible and traceable
Clean Environment Principle
If a market implementation only works on one analyst machine because of:
attached packages
hidden sourced files
local paths
interactive session state
then it is not ready.
See Validation Contract for the distinction between
enforced and planned checks.
Build and Release
Builds should be reproducible from the repository state.
Once the real China implementation is migrated into markets/CN/store_visits,
this page should be expanded into a true before/after example with exact
technical detail.
Chapter 7
Appendices
Reference material that supports the operating model and shared language used across the repo.
Subsections of Appendices
Glossary
Market
A country or region-specific implementation, for example CN, IT, or UK.
KPI
A market-specific model/output surface such as store_visits.
Migrated
A market/KPI is migrated when the Git folder is approved as the authoritative
implementation and local copies are no longer treated as the source of truth.
Source Of Truth
The repository version that should be used for validation, build, and review.
Forecast/Upload
The downstream workflow this repo is preparing artefacts for. In practice this
may involve scenario-style future input handling rather than formal
out-of-sample forecasting.
Decomp
Model decomposition logic used to produce contribution outputs from the model.
Clean Session
An R runtime that does not rely on accidental attached packages, untracked
helper objects, or analyst-local interactive state.