Measure the revenue impact of time-of-day menu pricing on a Deliveroo restaurant.
Most restaurants set one price and leave it. But demand isn't flat — lunch rushes look nothing like a 3pm lull, and weekends diverge from weekdays. This repo ingests live orders from Deliveroo, normalizes them into a Postgres schema, and ships a notebook analysis layer to segment orders by time window, day of week, and pricing period — so "before" and "after" are directly comparable on the same store.
Three pieces, each independently useful:
Deliveroo Orders API ──webhook──> Flask app ──> PostgreSQL
| ^
v |
OAuth2 sync OMS
(status ACKs) (upsert layer)
|
v
Jupyter notebooks
(metrics + plots)
- Webhook (
src/dynamic_pricing/webhook/) — Flask endpoints (/dev-webhook,/prod-webhook) that receive order events, validatepos_item_idon every line, ACKorder.status_updateevents back to Deliveroo via OAuth2 client-credentials, and forward the payload to the OMS. - Order Management System (
src/dynamic_pricing/core/) — SQLAlchemy upsert layer over seven related tables (customers, partners, orders, items, modifiers, order_items, order_item_modifiers).db_init.pyprovisions the schema;order_manager.pyhandles webhook-driven and backfill inserts. - Analysis (
src/dynamic_pricing/analysis/) — metrics and plotters for orders-per-interval, revenue-per-interval, prep-time, day-of-week splits, and a popularity-vs-profitability menu matrix (Star / Puzzle / Cash Cow / Dud). Three notebooks: wraps, non-wraps, and a Prophet seasonality pass.
Python 3.10 - Flask 2.2 - gunicorn - PostgreSQL - SQLAlchemy 2.0 - psycopg - pandas - plotly - prophet - JupyterLab - pytest - pytest-postgresql - black - pylint - pre-commit.
git clone https://github.com/zalatar242/dynamic_pricing
cd dynamic_pricing
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
pip install .
cp .env.sample .env # fill in Deliveroo creds + DB vars
pre-commit installInitialize the schema (destructive — drops existing tables):
python src/dynamic_pricing/core/db_init.pyRun the webhook locally, or via Procfile for production:
python src/dynamic_pricing/webhook/app.py
gunicorn src.dynamic_pricing.webhook.app:apppytest # unit tests
pytest --cov=src --cov-report=html # coverage reportpytest-postgresql spins up an ephemeral Postgres for DB tests — no external database required.
docker build -t dynamic_pricing .
docker run -p 80:80 --env-file .env dynamic_pricingPoint Deliveroo's webhook configuration at http(s)://<host>/dev-webhook (sandbox) or /prod-webhook (production).
See .env.sample: DEV_CLIENT_ID / DEV_SECRET and PROD_CLIENT_ID / PROD_SECRET (Deliveroo OAuth2), AWS_DB_* (Postgres), PARTNER1 / PARTNER2 (tracked restaurants). All Deliveroo integration follows the Orders API spec.