Skip to main content

This page is under review and therefore should not be read as official guidance

Bathing Water Quality Forecasting System

Project summary

The Bathing Water Quality Forecasting System (BWQFS) — formerly the Pollution Risk Forecasting system — is an Environment Agency (EA) environmental prediction service. It issues a daily pollution risk forecast for each of approximately 415 designated bathing waters in England during the bathing season (1 May to 30 September). Each forecast indicates whether a site is expected to exceed the health risk threshold for intestinal enterococci (a faecal indicator bacterium), producing a “warning” or “no warning” result that is published to data.gov.uk for public information.

The legacy system combined a licensed desktop statistical application, desktop databases, spreadsheet macro workbooks, and a specialist operational forecasting platform. The annual model-build cycle was largely manual and depended on locally installed software. There was no web interface. The modernisation rebuilds the statistical modelling pipeline in open-source code, migrates all data into a managed relational database, and delivers a GOV.UK-standard web interface so that the model-build cycle can eventually be operated entirely from a browser.

As a proof of concept, the project demonstrates that the statistical model-building workflow previously carried out in proprietary desktop software can be reproduced in open-source code against migrated data, achieving comparable results for a test site. The full production replacement is still in delivery.

At a glance
Service Bathing Water Quality Forecasting System (BWQFS)
Users EA Marine Modellers; EA FEWS Administrators
Status Proof of concept

As-is

The legacy system was not a single application but a collection of loosely coupled desktop tools held together by manual processes.

  • Statistical modelling. A licensed desktop statistics package built stepwise multiple linear regression (MLR) models for each bathing water site. It is a licensed desktop application and cannot be embedded in an automated pipeline. The model-build cycle ran once a year and required a specialist to operate it manually.
  • Model data storage. Desktop database files held the pre-computed predictor matrix, water quality samples, bivariate regression results, model coefficients, and site configuration. More than a dozen biennial database files stored the raw environmental time-series data (radar rainfall, wind, tide, and river flow). The only integration mechanism between these files was linked tables.
  • Data processing. Spreadsheet macro workbooks formatted and post-processed the statistical output before results were stored.
  • Operational forecasting. A specialist hydrological forecasting platform ran the automated daily forecast using a rainfall-threshold method. Overriding an automated forecast required direct access to the EA file system and a manual file transfer.
  • No web interface. All analytical work required desktop software access. There was no browser-based view of model results or forecast outputs.

The main pain points driving modernisation were:

  • the dependency on a licensed desktop statistical application created a single point of failure for the annual modelling cycle and made it difficult to bring in new team members
  • the desktop databases had no version control, schema history, or reproducible migration path
  • the model-build workflow was manual and not auditable
  • 20 newly designated freshwater bathing water sites required methodology changes that were difficult to implement within the existing desktop tooling

The MLR modelling approach itself was already proven before the modernisation began: prior statistical analysis had demonstrated a 35% improvement in forecast accuracy over the rainfall-threshold method that MLR models are intended to replace (source: BWQFS PRD, Section 1).

To-be

The target is a cloud-ready web application that allows an EA Marine Modeller to run the full annual model-build cycle — data readiness check, predictor computation, MLR model build, and forecast validation — from a browser, with no dependency on licensed desktop software.

The application separates a REST API (which contains the MLR engine and data access layer) from a server-rendered GOV.UK-standard web frontend. A managed relational database replaces the desktop file store, with migration scripts handling the initial transfer of all legacy data.

Key non-functional goals are:

  • removing the statistical software licence dependency so the model-build pipeline is self-contained
  • making the pipeline auditable, reproducible, and runnable without specialist software
  • meeting GOV.UK accessibility and security standards from the outset
  • providing a structured data readiness check before the modelling cycle is triggered

Steps taken

  1. Analysis and documentation to a PRD. The legacy system had no formal specification. The team produced a product requirements document, domain analysis, application analysis, database analysis, and interaction analysis from the available artefacts (system specification documents, legacy database schemas, and exported macro source code) before writing any application code.

  2. Database schema export and analysis. The legacy database schemas were exported to SQL and markdown so the target schema could be designed from accurate source data rather than assumptions.

  3. Column name normalisation. A deterministic normalisation function was written and BDD-tested to convert legacy column names (mixed case, special characters, bare integers) to valid unquoted identifiers in the target database. This was a prerequisite for every subsequent migration step.

  4. Legacy data migration. Migration scripts transferred all 11 MLR modelling and site configuration tables from the legacy databases into the new database. Acceptance tests verify row counts and idempotency.

  5. Stepwise MLR engine. The legacy stepwise ordinary least squares algorithm was re-implemented using an open-source statistics library. The engine applies the same p-to-enter threshold and minimum sample size guard as the legacy system. For the test site, the new implementation reproduces the legacy variable selection and produces an adjusted R² within tolerance of the stored legacy value.

  6. Forecast validation. The new model’s 2025 bathing season forecasts were compared against stored legacy results to quantify reproducibility before any claim could be made that the legacy statistical software output could be retired.

  7. GOV.UK web interface. A site selection page, per-site model comparison page, and per-site forecast page were built using the GOV.UK Design System with server-side templates, conforming to GOV.UK Design System patterns.

  8. Data readiness page. A GOV.UK task list page was built to give modellers a structured view of which input datasets are present in the database before triggering the model build. The call-to-action to start the model build is only enabled when all tasks are complete.

  9. Raw data migration scripts and predictor computation. Scripts were written and tested to load the raw environmental time-series data (radar rainfall, wind, tide, river flow) into the new database, and to compute the aggregated predictor variables from those raw data. The scripts are complete but the full data load for all historical years has not yet been run.

Benefits, outcomes and success metrics

Benefit / outcome Evidence / metric Status
MLR models give a 35% improvement in forecast accuracy over the rainfall-threshold method Evidenced in BWQFS PRD Section 1, from prior statistical analysis Achieved (methodology); the new pipeline is intended to operationalise this benefit at scale
New MLR engine reproduces the legacy model for the test bathing water site New adjusted R² and variable selection compared against stored legacy values in BDD acceptance tests; adjusted R² is within tolerance for the test site Achieved for the test site; cross-site result not yet established
All 11 MLR modelling and site configuration tables migrated from the legacy databases Row count and schema acceptance tests pass; confirmed by gap analysis Achieved
BDD acceptance test suite covers migration, MLR engine, forecast validation, and data readiness Automated acceptance test suite present in the rebuilt codebase Achieved
Statistical software licence dependency removed from the model-build pipeline Depends on cross-site reproducibility report confirming acceptable agreement across all sites — not yet complete Expected
Annual model-build cycle operable from a browser without desktop software Demonstrated for proof-of-concept scope; authentication, async job management, and CI/CD remain as gaps Expected
GOV.UK-standard accessible web interface for modellers GOV.UK Design System applied; no formal WCAG 2.1 AA audit has been performed To be confirmed
Full raw environmental time-series data migrated to the new database Migration scripts complete and tested; full data load for all historical years not yet run To be confirmed

Lessons for reuse

  • Start with a PRD even for internal tools. The legacy system had no formal specification. Producing one first — from documents, database schemas, and source code — revealed scope and constraints before any code was written and prevented significant rework.

  • Export database schemas before writing migration scripts. Exporting legacy schemas to SQL gave the team accurate column names, types, and row counts to design the target schema from, rather than discovering them by trial and error during migration.

  • Normalise identifiers as a first, tested step. Writing and BDD-testing a column-name normalisation function before any data was written prevented a whole class of identifier errors from reaching the migration scripts. This pattern transfers directly to any desktop-database-to-relational migration.

  • Use BDD scenarios to pin legacy behaviour. Writing acceptance scenarios against the stored legacy output made the reproducibility requirement concrete and testable, and gave a clear definition of done for the re-implemented engine.

  • Separate the proof of concept from production. Explicitly documenting what the demo does and does not cover prevented the team from overstating readiness and gave a clear, prioritised list of gaps that must be resolved before production deployment.

  • Embed GOV.UK Design System and security headers from the first sprint. Both are much easier to bake in early than retrofit. The GOV.UK task list pattern was also a natural fit for surfacing data readiness before a long-running compute job is triggered.

Open items / to be confirmed

Item What is needed
Cross-site MLR reproducibility report A systematic comparison of new versus legacy adjusted R², variable selection, and coefficients across all sites is needed before the legacy statistical software can be retired. For the test site the new adjusted R² is below the legacy value; the cause and whether this is typical across all sites is not yet established.
WCAG 2.1 AA accessibility audit No formal audit has been performed. The GOV.UK Design System is applied but independent validation against WCAG 2.1 AA is still required.
Benefits metrics — quantified The 35% forecast accuracy improvement is evidenced from prior analysis. Benefits from the operational pipeline (modeller time saved, licence cost avoided) are not yet measured and should be captured once the production service is live.
Full raw data load into the new database Migration scripts for radar rainfall, wind, tide, and river flow are complete and tested. The physical load of all historical years’ data from the archive has not yet been run.
Production readiness A formal gap analysis has been completed. Key items requiring resolution before production deployment include: authentication and role-based access control, a CI/CD pipeline, asynchronous job management for long-running compute, database schema versioning, and a defined deployment target.
Freshwater site coverage The proof of concept covers coastal and estuarine sites only. Extension of the MLR pipeline to cover 20 newly designated freshwater bathing water sites (which require physicochemical predictor variables) is out of scope for the current phase.