flowchart TD
A0["1. Streamlit App and Scenario Parameters"]
A1["2. Simulation Runs and Replications"]
A2["3. Sampling Distributions and Random Streams"]
A3["4. Calls and Patient Journeys"]
A4["5. HEMS Resources and Servicing"]
A5["6. Resource Allocation"]
A6["7. Trial Results and Historic Comparison"]
A7["8. Distribution Fitting"]
A0 -- "Launches runs" --> A1
A0 -- "Writes rota and servicing CSVs" --> A4
A0 -- "Displays outputs of" --> A6
A1 -- "Creates and runs" --> A3
A1 -- "Writes run_results.csv for" --> A6
A3 -- "Samples calls and times from" --> A2
A3 -- "Triggers daily servicing check" --> A4
A3 -- "Requests and returns resources" --> A5
A5 -- "Selects from store of" --> A4
A5 -- "Samples ad hoc unavailability" --> A2
A7 -- "Writes distribution files for" --> A2
A7 -- "Writes historical data for" --> A6
A7 -- "Runs historical baseline via" --> A1
Contributor tutorial: how the simulation works
DAA_DES is a discrete event simulation of Devon Air Ambulance HEMS (helicopter emergency medical service) operations. It is built on SimPy and packaged as air_ambulance_des, with a Streamlit web app in app/ for setting parameters, running the model and viewing results. Each run generates daily emergency calls, samples patient characteristics from distributions fitted to historical job data, tries to allocate a helicopter or car according to rotas, servicing schedules and care category priorities, and records every step in an event log. Many seeded replications run in parallel, and the combined results are summarised and set against historical data.
This version is for an experienced engineer who is about to change the code. Each chapter says what the component guarantees, follows the real call path with verbatim excerpts, then tells you where to make typical changes, which tests cover the area, what bites, and why it is shaped the way it is (labelled documented or inferred). It complements the Project Overview and the API reference.
Source repository: https://github.com/RichardPilbery/DAA_DES
Open issues and pull requests were checked on 2026-10-19. See the issue tracker for the current state. Several chapters flag places where the code appears not to do what it intends; those are observations from reading the source, so check the tracker before relying on them.
How the pieces fit together
Arrows show who calls or feeds whom. Chapter 8 sits upstream because it produces the data files the others read.
Domain terms you need
These words appear from chapter 4 onwards. Fuller definitions are in the Glossary.
- Care category: CC (critical care), EC (enhanced care) or REG (regular). It is sampled per patient and decides which allocation path is used (chapters 4 and 6).
- AMPDS card: the dispatch-code category of the 999 call. It drives the sampled care category.
- Callsign, callsign group and registration: a callsign (such as H70) names a crewed unit, a callsign group (such as 70) clusters callsigns, and a registration (such as g-daas) identifies the physical aircraft or car. One aircraft can fly under different callsigns: g-daan is normally H71 but flies as H70 while g-daas is being serviced (Chapter 5).
- Quarter (qtr): Q1 to Q4 of the calendar year, used to stratify most probability tables.
- Stand Down: a job cancelled before the crew reaches the scene (Chapter 4).
Before you change anything
- Run everything from the repository root. Nearly all paths are relative (
actual_data/,data/,distribution_data/), so a different working directory breaks file loading. pytestruns the suite andpytest -m quickruns the fast subset; seetests/README.md.- Suggested start: Chapter 2 for the run API, then Chapter 4.
Chapters
Chapters are self-contained enough to read in any order once you know the diagram above. If you are changing dispatch behaviour, go to chapters 5 and 6; for reproducibility, chapters 2 and 3; for outputs and plots, chapter 7. Chapters 7 and 8 have no tests.
- Streamlit App and Scenario Parameters — How the web app collects parameters, writes them to
actual_data, and triggers a run. - Simulation Runs and Replications — How
runSimandparallelProcessJoblibrun seeded replications and collate their output files. - Sampling Distributions and Random Streams — How
Utilsloads the fitted distributions and samples from them with named, independently seeded random streams. - Calls and Patient Journeys — How
DES_HEMSgenerates daily calls, creates patients and moves each one through the stages of a job while writing the event log. - HEMS Resources and Servicing — How helicopters and cars are modelled, built from the rota files, scheduled for servicing and kept in a SimPy
FilterStore. - Resource Allocation — How
HEMSAvailabilitychooses a primary and secondary resource for each patient, records the reason, and releases them afterwards. - Trial Results and Historic Comparison — How
SimulationInputs,TrialResultsandHistoricResultsturn the event log and historical data into metrics and plots. - Distribution Fitting — How
DistributionFitUtilsturns historical job data into the distribution and historical-data files the rest of the system reads.
For definitions of the terms used throughout, see the Glossary.
Further reading
- Project Overview: the model logic sequence and the output columns.
- Class and function reference: the full API.
Generated by AI Codebase Knowledge Builder from commit 5e73694, 2026-10-19.