Skip to content

Non-profit · climate · 2018 – 2020

WWF-UK

The public carbon footprint calculator for WWF-UK — a four-part questionnaire covering food, home, travel and possessions that turns everyday lifestyle answers into an annual carbon figure, then shows you how it compares to the UK and world averages. Built end to end as the sole developer, through an agency, for a charity whose name is on the front of it.

Laravel 5.6PHP 7.1Vue 2MySQLBootstrap 4SCSSLaravel MixBitbucket Pipelines
footprint.wwf.org.uk

Outcome

Spreadsheet → public tool

WWF's carbon model rebuilt as a tested application

The problem

WWF's carbon model existed as a research spreadsheet — hundreds of coefficients wired together with deeply nested Excel formulas — and it needed to become a public web tool that anyone in the UK could use, without the science being altered in translation.

The approach

  1. 01Documented every spreadsheet formula alongside its intended logic before writing any code
  2. 02Rebuilt the model as four section classes, one per part of the questionnaire
  3. 03Made the questionnaire itself data, so WWF could reword questions without a deploy
  4. 04Covered the calculation in unit tests and ran them on every push
  5. 05Built the questionnaire and results as a Vue front end over a small JSON API

How it works

Translating the spreadsheet

The source of truth was an Excel model: formulas like a four-level nested IF that picks one of sixteen coefficients based on house type and bedroom count, then scales the result by whether you switch appliances off standby. Porting that straight to PHP would have produced code nobody could ever check against the original. Instead each formula was first written up in a translation document — the raw Excel expression, its cell references intact, beside the plain-language logic and the PHP equivalent. The code was then written from the document rather than from the spreadsheet, which meant the scientists' model and the developer's model could be compared line by line.

The calculation engine

Four section classes — food, home, travel and stuff — each extend a common base that loads the questionnaire, its section and the answers given so far. Every question gets its own calculation method, around fifty across the four sections, so a coefficient can be corrected in one place without disturbing anything else. Two questions in the home section were involved enough to earn dedicated traits of their own. A calculator trait sums the sections, adds the per-capita share of government spending, and expresses the total against the UK average of 13.56 tonnes and the world average of 5.28.

A questionnaire made of data

Sections, questions and answers are database records rather than code, and a separate state table tracks how far each visitor has got. Progress is keyed to an anonymous client identifier, so someone can answer half the questions, close the tab, and come back to the exact question they left on without ever creating an account — the state lookup walks the sections and returns the first one with unanswered questions. For a campaign tool aimed at the general public, a login wall would have cost more completions than it could possibly return.

Front end and API

Fifteen JSON endpoints carry the whole interaction: fetch the current section and question, submit an answer, step backwards, check completion, finish, and return the result. The questionnaire and the results — carbon breakdown, comparison infographic, share buttons — are Vue components over that API, which keeps the calculation entirely server-side where it can be tested, rather than shipping the model to the browser.

Decisions

Decision 01

Write the translation document first

The instinct is to port formulas directly and move on. I wrote the whole model up first — every formula, its cell references, the branching in prose, and the PHP it became — because the real risk on this project was never a crash, it was a wrong number published under a conservation charity's brand. That document cost time up front and made the calculation auditable by someone who does not read PHP, which for a client whose credibility rests on the science was the more valuable property.

Decision 02

Test the model, not the interface

Forty-four unit tests sit on the calculation and run in CI on every push, seeded from factories so each question can be exercised in isolation. Coverage was deliberately spent on the arithmetic rather than spread evenly: a broken button is obvious and someone reports it, whereas a coefficient that is quietly wrong produces a plausible number that nobody catches. The most intricate section is the most heavily covered as a result.

Decision 03

Keep the questions editable without a release

Modelling the questionnaire as data rather than templates meant wording, ordering and answer options were WWF's to change without an engineering cycle. The trade-off is a heavier data model and more indirection than hard-coded pages would need — worth it for a public campaign asset whose copy gets revised on a schedule the development timeline does not control.

What it doesn't do

  • Test coverage is uneven by design and by circumstance — the home section is covered question by question, while food and travel are thinner. Even coverage across all four would have been the better end state.
  • Vue 2, Bootstrap 4 and jQuery alongside each other date the front end precisely to when it was built. None of it was wrong at the time; none of it is what I would reach for now.
  • I have no usage figures for it. Completion rates and traffic sat with WWF and the agency, so the case study describes what was built rather than what it went on to achieve.

Where it stands

The calculator is still a live WWF-UK service, though it has since been rebuilt on a newer front-end toolchain — the version described here ran from 2018. WWF has published revised footprint methodology since, so the coefficients in the current tool are not the ones I worked with.