---
title: "Entity flow analysis"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Entity flow analysis}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
resource_files:
- figures/logo.svg
- figures/logo-dark.svg
---
[](https://github.com/CTTIR/dynasimR/actions/workflows/R-CMD-check.yaml)
[](https://cttir.github.io/dynasimR/)
[](https://app.codecov.io/gh/CTTIR/dynasimR?branch=main)
[](https://opensource.org/licenses/MIT)
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
```{r setup, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
```
Many simulations move entities through sequential processing stages
(Stage 1 -> Stage 2 -> Stage 3 -> Stage 4). This vignette shows how
to quantify throughput and identify bottlenecks.
```{r}
library(dynasimR)
sim <- load_example_data()
```
## Stage throughput
```{r}
st <- stage_throughput(sim)
st
```
Only `Stage2` (time_to_stage2) is present in the shipped example,
but the machinery generalises to Stage1..Stage4 when the columns
exist in your simulation output.
## Bottleneck detection
```{r}
detect_bottlenecks(st, threshold = 0.75)
```
## Visualising first-service times
```{r, fig.width = 6, fig.height = 4}
plot_scenario_heatmap(
sim,
metrics = c("median_time_to_first_service",
"median_time_to_stage2")
)
```