---
title: "Calls for service, September"
subtitle: "A Quarto report rendered in Vulcan Veil (synthetic data)"
author: "Vulcan Veil demo"
date: today
format:
  html:
    toc: true
    code-fold: true
  typst:
    toc: true
execute:
  echo: true
---

This report is made up. The data below is generated by the document itself, so it renders
anywhere and contains no real records. Open it in the desktop app to run its Python chunks one at
a time, like a notebook, then click **Render HTML** or **Render PDF**: the app runs the chunks again
in its sandbox (no network), and Quarto turns the results into the report.

## The data

```{python}
#| label: setup
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

rng = np.random.default_rng(2026)
days = pd.date_range("2026-09-01", "2026-09-30", freq="D")
types = ["Disturbance", "Traffic", "Theft", "Welfare check", "Alarm"]
rates = [14, 11, 6, 5, 4]
rows = []
for day in days:
    busy = 1.25 if day.dayofweek >= 4 else 1.0  # Friday to Sunday
    for kind, rate in zip(types, rates):
        rows.append({"date": day, "type": kind, "calls": rng.poisson(rate * busy)})
calls = pd.DataFrame(rows)
print(f"{calls['calls'].sum():,} calls over {len(days)} days")
```

## Calls by type

```{python}
#| label: tbl-types
#| tbl-cap: Calls by type, with the share of the month and the busiest day.
by_type = calls.groupby("type")["calls"].agg(total="sum", busiest_day="max")
by_type = by_type.sort_values("total", ascending=False)
share = by_type["total"] / by_type["total"].sum()
by_type["share"] = share.map("{:.0%}".format)
by_type
```

Disturbances lead, as they do in most months. Fridays and weekends run about a quarter
higher, which the next chart shows.

## Calls by day

```{python}
#| label: fig-daily
#| fig-cap: Calls per day. Shaded days are Fridays and weekends.
daily = calls.groupby("date")["calls"].sum()
fig, ax = plt.subplots(figsize=(8, 3.2))
half = pd.Timedelta(hours=12)
for day in daily.index[daily.index.dayofweek >= 4]:
    ax.axvspan(day - half, day + half, color="#e8eef5", lw=0)
ax.plot(daily.index, daily.values, color="#1f4e79", lw=2, marker="o", ms=3)
ax.set_ylabel("Calls")
ax.spines[["top", "right"]].set_visible(False)
fig.autofmt_xdate()
plt.show()
```

## A note on the rate

Each type's daily count is drawn from a Poisson distribution, with a mean $\lambda$ that is 25%
higher from Friday to Sunday:

$$
P(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}
$$

```{python}
#| echo: false
weekend = daily[daily.index.dayofweek >= 4].mean()
weekday = daily[daily.index.dayofweek < 4].mean()
print(f"Average day: {weekday:.1f} calls Monday to Thursday, {weekend:.1f} Friday to Sunday.")
```

::: {.callout-note}
The chunk above has `#| echo: false`, so the report shows its result and not its code. Chunk
options such as `echo`, `eval`, `fig-cap`, and `tbl-cap` work as they do in Quarto.
:::
