Skip to content

sree-sanak/dynamic_pricing

Repository files navigation

Dynamic Pricing

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.

Architecture

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)
  1. Webhook (src/dynamic_pricing/webhook/) — Flask endpoints (/dev-webhook, /prod-webhook) that receive order events, validate pos_item_id on every line, ACK order.status_update events back to Deliveroo via OAuth2 client-credentials, and forward the payload to the OMS.
  2. 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.py provisions the schema; order_manager.py handles webhook-driven and backfill inserts.
  3. 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.

Tech stack

Python 3.10 - Flask 2.2 - gunicorn - PostgreSQL - SQLAlchemy 2.0 - psycopg - pandas - plotly - prophet - JupyterLab - pytest - pytest-postgresql - black - pylint - pre-commit.

Quick start

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 install

Initialize the schema (destructive — drops existing tables):

python src/dynamic_pricing/core/db_init.py

Run the webhook locally, or via Procfile for production:

python src/dynamic_pricing/webhook/app.py
gunicorn src.dynamic_pricing.webhook.app:app

Testing

pytest                                      # unit tests
pytest --cov=src --cov-report=html          # coverage report

pytest-postgresql spins up an ephemeral Postgres for DB tests — no external database required.

Docker

docker build -t dynamic_pricing .
docker run -p 80:80 --env-file .env dynamic_pricing

Point Deliveroo's webhook configuration at http(s)://<host>/dev-webhook (sandbox) or /prod-webhook (production).

Environment

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.

About

Deliveroo Orders API webhook plus Jupyter notebooks measuring the revenue impact of dynamic pricing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors