# Analytics and Reports reference

> The facts of Analytics and Reports in one place - the relations and columns of each dataset family, the quality helpers, parameter types and the defaults vocabulary, the limits per kind of run, the report template's elements, placeholders, page fields and formats, the eight rights, the run record and statuses, the result hash, schedules and their triggers (cron, shift calendars, batch, tag), signature plans and signatures, the archive (retention, Verify statuses, purge), delivery outcomes and rules, HA replication, what stays open after a downgrade, the analytics workspace's routes and limits, the audit events, ALM-SYS-REPORTS, the HTTP routes and the configuration keys.

Product: eaxScada · Type: Reference · Editions: Pro, Enterprise
Source: https://eaxware.com/docs/eaxscada/reference/analytics-and-reports/
Verified against commit 4e830ea.

The rules behind these facts are explained in [Analytics and Reports](/docs/eaxscada/explanation/analytics-and-reports/).

## Relations and columns

A dataset reads one **family**. Its SQL may name only the family's relations, never a stored table, a schema-qualified name, a file or a table function. The server builds each relation for the person who runs the dataset: only readable tags, inside the dataset's tag scope and the run's time window.

### Historian: `samples`

| Column | Type | Meaning |
|---|---|---|
| `ts` | timestamp with time zone | The sample's time. |
| `ts_ns` | integer (BIGINT) | The same time, in nanoseconds since 1970 (UTC). |
| `tag_path` | text | The tag. |
| `value` | number (DOUBLE) | The value. |
| `quality` | integer | The stored quality code. |
| `quality_class` | text | `good`, `uncertain` or `bad`, from the quality code (the historian's own rule). |
| `simulated` | boolean | The sample came from a simulated source. |

### Alarms: `alarm_events` and `alarm_definitions`

`alarm_events` is the alarm journal in the run's window:

| Column | Type | Column | Type |
|---|---|---|---|
| `ts` | timestamp with time zone | `ts_ns` | integer |
| `event_id` | text | `alarm_id` | text |
| `tag_path` | text | `name` | text |
| `description` | text | `event_type` | text |
| `previous_state` | text | `current_state` | text |
| `severity` | text | `category` | text |
| `value` | number | `setpoint` | number |
| `user_id` | text | `reason` | text |
| `simulated` | boolean | `quality` | text (`Good` when the journal holds none) |

`alarm_definitions` is the current alarm configuration (no time window): `alarm_id`, `tag_path`, `name`, `description`, `category`, `severity`, `condition` (text), `setpoint`, `deadband` (numbers), `trip_delay_ms`, `clear_delay_ms` (integers), `ack_required` (boolean, `true` when not set), `updated_at` (timestamp).

A row of either relation is there when its tag is readable to the user (an alarm without a tag: only for users who may read every tag, or when it is a built-in safety alarm) **and** the user sees the alarm under the routing rule of the live alarm views.

### Shift log (Enterprise only): `shiftlog_*`

The family `shiftlog` reads the [shift log](/docs/eaxscada/explanation/shift-log/) of the run's time window, from its read index, never from the audit trail directly. It is refused outside Enterprise, asked again at each run. Its relations:

| Relation | One row per |
|---|---|
| `shiftlog_entries` | entry of each shift (every type but the handover, voided ones included), and entry of an earlier shift recorded during it (`section` `late`); with its state, its current title and text after corrections, its signatures and references in text, and `verified` |
| `shiftlog_refs` | reference of an entry, with what it showed when the entry was recorded (`snapshot`); a tag the runner may not read keeps its row without its path or snapshot (`hidden`) |
| `shiftlog_signatures` | signature of an entry, reviews included: the decision, the meaning, the signer, the time |
| `shiftlog_open_items` | open item carried into each shift |
| `shiftlog_handover` | log and shift: the handover with both signatures, its state (`handed_over`, `signed_out`, `due`, `missing`, `open`, `not_required` or `failed_verification`) and the shift's counts |

A log is read only when the runner may read it (`shiftlog_view`, narrowed by the log's readers). The parameter `log` (text) names one log; without it, every log the runner may read. A shift log dataset has no tag parameter. One run reads at most 2,000 shifts. An entry that fails verification is never shown as valid. The starter report uses these relations: [Add the shift report](/docs/eaxscada/how-to/set-up-shift-logs/#8-add-the-shift-report).

### OEE and downtime: `production`

The family `production` reads the results of [OEE and downtime](/docs/eaxscada/explanation/oee-and-downtime/) (Pro and Enterprise): `machines`, `shifts`, `state_intervals`, `downtime_events`, `event_pieces`, `slices`, `count_notes` and `reason_codes`, with the helpers `prod_availability`, `prod_performance`, `prod_quality`, `prod_oee`, `prod_coverage`, `prod_row_quality`, `prod_warnings`, `prod_planned` and `prod_machine`. It needs the licence and the runner's `production_view`, asked at each run; a machine is in the relations only when it is in the tag scope and the runner may read every one of its source tags. A dataset returning a ratio or a count must return its quality. The analytics workspace accepts it as well (`"family": "production"`). Columns, helpers and rules: [Dataset family production](/docs/eaxscada/reference/oee-and-downtime/#dataset-family-production).

`GET /api/reports/sources` returns the families, their relations and columns, the helpers and the parameter types, and whether this server has each family's database.

## Quality helpers

Defined on every dataset run; `qc` is a `quality_class` column.

| Helper | Returns |
|---|---|
| `good_avg(value, qc)` | The average of the good samples only; NULL when there is none. |
| `good_count(qc)` | The number of good samples. |
| `bad_count(qc)` | The number of bad samples. |
| `uncertain_count(qc)` | The number of uncertain samples. |
| `agg_quality(qc)` | `good` if every sample is good; else `bad` if any is bad **or is not a known class** (NULL, any other text); else `uncertain`. NULL over no row. |

The report engine uses the same rule for figures it computes (subtotals, totals, KPI tiles): good only if every input is good, uncertain if any is uncertain and none is bad, bad otherwise, an unknown quality counting as bad.

**Save rule (historian family).** A query that reads `value` must return `quality_class` or `quality`, or `agg_quality(...)`, or a `*` that keeps them; or filter or split on quality (`WHERE`, `HAVING`, `FILTER`, `CASE WHEN`, `GROUP BY` on `quality_class`); or read `value` only through `good_avg`. Otherwise the save is refused with the hint **Add quality column**.

## Parameter types

| Type | Value | Notes |
|---|---|---|
| `timestamp` | A time (RFC 3339 over the API) | `from` and `to` are required timestamps in every dataset: the run's window. |
| `duration` | `15m`, `1h30m` | |
| `number`, `integer` | `42.5`, `42` | Finite numbers only. |
| `text` | Any text, or one of its **choices** | |
| `bool` | `true`, `false` | |
| `tag` | One tag path, no wildcard | Must be readable to the user and inside the tag scope (and the parameter's own scope, if set); refused before the query runs otherwise. |
| `tag_list` | Tag paths, comma-separated in a default | The same check for each path. |

Names: lower-case letters, digits and `_`, starting with a letter, at most 63 characters; the prefix `eax_` is reserved. In SQL a parameter is `$name`. An optional parameter without a value is NULL.

## Parameter defaults

A timestamp default is an anchor, optionally followed by offsets. Spaces are ignored and case does not matter.

| Anchor | Means (on the site's clock, `site.time_zone`) |
|---|---|
| `now` | The time the run starts. |
| `today`, `yesterday` | `start_of_day(0)`, `start_of_day(-1)`. |
| `start_of_day(n)` | The first instant of the day `n` days from today. |
| `start_of_week(n)` | Monday 00:00 of the week `n` weeks from this one. |
| `start_of_month(n)` | The 1st, 00:00, of the month `n` months from this one. |
| `start_of_year(n)` | 1 January, 00:00, of the year `n` years from this one. |
| `this_shift`, `last_shift`, `start_of_shift(n)` | The start of the current, the previous, or the `n`th shift. Needs the shift calendar: refused on a server that has none. |
| `batch.start`, `batch.end` | Reserved for the batches family; refused today. |

Offsets: `+` or `-` then a number and a unit, several in a row: `-24h`, `+1d`, `-1h30m`, `+1w`. `s`, `m`, `h` are elapsed time; `d`, `w` are calendar days and weeks on the site's clock (the same clock time, `n` days later). A day's start is its first instant, also on a day whose midnight is skipped or repeated by a clock change. `n` is at most 10,000; an offset at most 10,000 days.

The default of another type is a plain value of that type. A report's **date** parameter takes the same anchors (and `YYYY-MM-DD`), resolved once at the start of the run to the day it names.

## Limits

| Limit | Default | Key |
|---|---|---|
| Rows per dataset, preview | 10,000 | `reports.preview.max_rows` |
| Rows per dataset, PDF | 100,000 | `reports.pdf.max_rows` |
| Rows of one PDF table | 20,000 | `reports.pdf.max_table_rows` |
| Rows per dataset, Excel | 1,000,000 | `reports.xlsx.max_rows` |
| Query time, preview | 15 s | |
| Query time, report run | 60 s | `reports.query_timeout` |
| Query time, scheduled run | 300 s | `reports.scheduled_query_timeout` |
| Whole run | 10 min | `reports.run_timeout` |
| Time window of a run | 400 days | `reports.max_window` |
| One dataset result in memory | 256 MiB | `reports.max_result_bytes` |
| Pages of one PDF | 2,000 | `reports.max_pages` |
| Runs rendered at a time | 2 | `reports.workers` |
| Runs waiting | 20 (2 per user) | `reports.queue` |
| Dataset SQL | 64 KiB | |

A dataset's own `max_rows` and `timeout_s` can lower its ceilings, never raise them.

## Report template

A report template is a screen of kind `report`; its `report` member is described field by field in the [screen document reference](/docs/eaxscada/reference/generated/config/screen-document/#reporttemplate). A member the server does not model is kept when a stored report is read and refused when one is saved.

**Page.** Paper `A4` (default, 210 × 297 mm), `A3` (297 × 420), `Letter` (215.9 × 279.4), `Legal` (215.9 × 355.6); orientation `portrait` (default) or `landscape`; margins top, right, bottom, left in mm (default 15, 0 to 100); language and number locale as language tags (`fr`, `en-GB`); time zone `site` (default), `UTC` or a zone name; outputs `pdf` (default), `xlsx`.

**Report parameters** (the screen's declared parameters): `date`, `text`, `number`, `tagFolder`. Not named `page`, `pages`, `run_time`, `parameters` or `template_rev`.

**Dataset references.** `ref` (the dataset id), `alias` (a letter, then letters, digits or `_`), `bind` (dataset parameter to value): `{param}`, `{param}+1d`, `{param}-2h`, or a literal. At most 16 per report.

**Elements.**

| Type | Members | Notes |
|---|---|---|
| `text` | `text` | Placeholders `{param}`, `{alias.column}`. |
| `kpi` | `label`, `value` (`dataset`, `column`, `aggregate`, `format`), `unit` | Aggregates: `first` (default), `last`, `min`, `max`, `avg`, `sum`, `count`. Good samples only; "No good data" when none. |
| `table` | `label`, `dataset`, `columns`, `group_by`, `subtotal`, `total` | Subtotal: `avg`, `sum`, `min`, `max`, `count`, after each group (`group_by`) and/or as a total row (`total`). |
| `chart` | `label`, `dataset`, `columns`, `chart` (`kind`, `x`, `series`) | Kinds: `line`, `area`, `bar`, `scatter`, `pie`. `series`: a column whose values split the rows into one series each. |
| `repeat_group` | `dataset`, `children` | Its children repeat once per row; nests at most 3 deep. |
| `page_break` | none | |

Every element has an `id` (unique in the report) and an optional `height_mm` (0 to 2,000). A column has `column`, `label` and `format`.

**Placeholders.**

| Placeholder | Where | Filled with |
|---|---|---|
| `{Name}` | Texts, labels, bands, bindings | The report parameter's value. |
| `{alias.column}` | Element texts and labels | The dataset's first row, or the current row inside a repeat group over that dataset; a value that is not good keeps its quality mark. |
| `{page}`, `{pages}` | Bands | Page number, page count. |
| `{run_time}` | Bands | When the run started. |
| `{parameters}` | Bands | Every run parameter as `name = value`. |
| `{template_rev}` | Bands | The deployed template's revision (`DRAFT` in a PDF draft). |
| `{Area/Tag}` | Nowhere | A live tag reference is refused on save. |

A placeholder the run cannot fill stays as written.

**Formats.** `0`, `0.0`, `0.00` (decimals), `percent` or `0.0%` (times 100, with `%`), `date`, `datetime`. Another name keeps the default format.

**Template limits.** 2,000 elements, 16 datasets, 64 columns per table or chart, 16 texts per band, 4,000 bytes per text, 64 characters per format name, bands up to 100 mm.

`GET /api/reports/elements` (`reports_design`) returns these lists as the server checks them.

## Rights

| Right | Grants |
|---|---|
| `reports_view` | The workspace, the deployed reports and datasets, on-demand runs, one's own run files, a dataset's export (`POST /api/reports/datasets/<id>/export`) and one's own exports' status, file and removal, and the dataset read for viewing (dashboard dataset cards). |
| `reports_design` | The designer's report tools (palette, preview, PDF draft), dataset preview and the dataset read for viewing (dashboard dataset cards). |
| `datasets_edit` | Create, change and delete datasets. |
| `reports_schedule` | The **Schedules** tab: create, change, turn on and off, run now and delete the schedules one owns (the owner of a scheduled run must hold it, with `reports_view`, at every run). |
| `reports_distribute_external` | E-mail addresses outside eaxScada as schedule recipients: checked when a schedule is saved (the user saving it) and at each delivery (the schedule's owner). |
| `reports_sign` | Signing archived runs one may open, for the plan's steps whose roles one holds. |
| `analytics` | The **Analytics** tab and every `/api/analytics` route (queries, exports, extracts; the export status, file and removal also with `reports_view`); dataset preview, the dataset read for viewing and the SQL check. |
| `reports_admin` | Every user's runs and archived runs, the **Settings** tab and the SMTP password, every schedule (other owners, enabling a restored schedule), the archive's use and the purge, the **May be sent outside** mark of a report. |

Users with `reports_view` see the dataset cards on dashboards. The rows are read with the viewer's tag read rights, and each view is recorded in the audit trail once per hour per user, dataset, parameters and outcome. The AI co-pilot can't read datasets this way.

Feature rules with the right's name (or `feature:<name>`) as pattern; DENY wins, the Administrator's included, and a DENY whose pattern is `*`, `feature:*` or a prefix ending in `*` (`reports*`) refuses every right it covers; with no rule naming a right only the Administrator holds it; `*` or a prefix in an ALLOW rule grants none of them; the AI co-pilot holds at most `reports_view`. New installations' defaults and the steps after an upgrade: [Grant report rights](/docs/eaxscada/how-to/grant-report-rights/).

## Run record and statuses

Statuses: `queued`, `running`, `succeeded` (shown **Done**), `failed`, `refused`, `cancelled`. A run that was queued or running when the server stopped is closed as failed at the next start.

**Diagram: The states of a report run** (state machine)

A run is queued, then running, and ends succeeded, failed, cancelled or refused. Only a succeeded run has archived files; it is kept as Standard, becomes Signed with its first signature and is then never purged. A Standard run past its keep date can be purged by a reports administrator; its record stays, marked purged.

**States**

- **queued** (state): start recorded
- **running** (state): reads and renders
- **succeeded** (state): Done: archived, kept as Standard
- **purged** (state): record kept
- **cancelled** (state): no file
- **failed** (state): no file
- **refused** (state): no file
- **Signed** (state): never purged

**Transitions**

- **Start → queued** (transition). The start is recorded in the audit trail, then the queued record is written.
- **queued → running** (transition)
- **running → succeeded** (transition): archived. The files are written once to the archive and checked; the run record keeps their hashes.
- **running → cancelled** (transition). A queued or running run can be cancelled on request.
- **running → failed** (transition). An error, a time-out, the server stopping during the run, or an archive that cannot be written. A run found queued or running when the server starts is closed failed too.
- **running → refused** (refusal). A dataset refused the run, for example a tag outside the user's read rights.
- **succeeded → Signed** (transition): first signature. With a signature plan, the run waits for review, then is reviewed and approved. Its retention class becomes Signed.
- **succeeded → purged** (transition): past its keep date, purged. A reports administrator purges Standard runs past their keep date, with an e-signature; each file's deletion is recorded first.

A cancelled, failed or refused run made no file: its record can be removed. The audit trail keeps every run.

Delivery has its own status: pending until signed, then delivered, partly delivered or not delivered.

A record with archived files stays; only a run that made no file can be removed.

The record (`GET /api/reports/runs/<id>`) holds: `id` (`run_<yyyymmdd>T<hhmmss>Z_<12 hex>`), `template` (`id`, `name`, `rev`, `draft`), `trigger`, `requested_by`, `run_as`, `parameters`, `formats`, `datasets` (each: `id`, `alias`, `rev`, `rows`, `truncated`, `result_sha256`, `result_hash_v`, `quality` counts, `tag_scope`, `tags_allowed`, `tags_hidden`, `source`, `read_paths`), `read_scope` (`full_read`, `tags_allowed`, `tags_hidden`, `paths_recorded`), `data_sha256`, `result_hash_v`, `simulated`, `node`, `queued_at`, `started_at`, `finished_at`, `status`, `error`, `outputs` (each: `format`, `bytes`, `sha256`, `pages`, `pdfa`, `path`), `warnings`, and:

| Field | Holds |
|---|---|
| `trigger` | `kind`: `on_demand`, `draft` or `schedule`. A scheduled run adds `schedule` (its id), `key` (the slot's idempotency key), `slot` (the slot time), `source` (the trigger: `time`, `shift_end`, `batch_end`, `event`, `shiftlog_handover`, or `manual` for **Run now**), `late` and `note` (a catch-up, or "late, re-run after failover"). Records written before schedules existed read `on_demand`. |
| `requested_by` | The user who asked for the run; for a scheduled run `schedule:<id>` (or the user who clicked **Run now**). `run_as` is the owner. |
| `as_of` | The instant the relative parameters and defaults were resolved at: the slot of a scheduled run, the moment an on-demand run was asked for. |
| `scheduled` | The scheduled ceilings applied (`reports.scheduled_query_timeout`). |
| `window` | The data period of the run (`from`, `to`: the first dataset's window). |
| `outputs[].pdfa` | `3b` when the archived PDF was written as PDF/A-3b; empty otherwise. |
| `signature` | The run's signature status as the server decides it: state, plan, the step it waits for, signatures given, retention, hold (in `GET /api/reports/runs` and `GET /api/reports/runs/<id>`). |
| `retention` | `class` (`standard`, `signed`; a draft is never archived) and `keep_until` (the date recorded at archiving). |
| `archive` | `sidecar` (the path of the `.json` copy in the archive) and `sidecar_sha256`: the server's own copy of its hash, compared by Verify. |
| `signature_plan` | The template's [signature plan](#signatures) when the run was made. |
| `signatures` | The [signatures](#signatures) given, in order. |
| `delivery` | A scheduled run's [delivery](#delivery-outcomes): `status`, `at`, `note`, `outcomes` (one per recipient or folder), `pending` (while it waits for signatures), `signed_rendition` (the signed copy that was sent). |
| `purged_at` | The run's files were purged (its `outputs` are then empty). |
| `result_hash_v` | The encoding of the stored result hashes: on the record for `data_sha256`, on each dataset for its `result_sha256`. New runs record `eax-dataset-v2`. Records made before this version have no `result_hash_v`; read them as `eax-dataset-v1`. The archive sidecar and the `run.succeed` and `run.fail` audit records carry it with the datasets. See [Result hash](#result-hash). |

Files: `reports.archive.dir` (default `data/reports/archive`), `<yyyy>/<mm>/<run id>.pdf`, `.xlsx` and `.json` (the sidecar), and for signed runs `<run id>.signed-<n>.pdf` and `<run id>.signed-<n>.json` (signed copy n and its link record). Records: `data/reports/runs`. Datasets: `data/reports/datasets`. Schedules: `data/reports/schedules` (project content). The schedules' slot claims on a single server: `data/reports/schedule-state.json`; on an HA cluster, a replicated key-value bucket of the cluster's broker (`eax_reports_schedule`). The server's identity for schedules: `data/reports/server-identity` (created at the first start; on a cluster the identity is `nats.cluster.name`).

### Result hash

Each dataset of a run records `result_sha256`, the SHA-256 of its result. A query of the analytics workspace gives the same hash as `sha256`, and its `analytics.query` audit record keeps it; a query over extracts uses the same rules. The run's `data_sha256`, printed in the default report footer and on the workbook's About sheet, is a hash over the datasets' result hashes.

The hash covers:

- the columns: their names and types, in order;
- the rows as a set, in any order: each value with its type and its exact text (a decimal value to its full precision, NULL and NaN each marked as such, times in UTC to the nanosecond);
- the row count: a duplicate row counts;
- whether the result was truncated: a capped result never hashes like the full one.

The same rows in another order give the same hash. A changed, added or removed row or value, a changed column or a changed truncated flag gives another hash. The hash does not depend on the order the database returns the rows in: DuckDB reads in parallel, so the rows of a query without `ORDER BY`, and rows that tie on its `ORDER BY`, can come back in another order from one run to the next.

Hashes recorded before eaxScada 82cb5ee5 were computed over the rows in the order they were read. They stay as recorded; nothing recomputes them. The values shown in reports and workbooks are unchanged. A stored hash names its encoding in `result_hash_v` beside it (`eax-dataset-v2`, or `eax-extract-v2` for a query over extracts; a record without it holds an `eax-dataset-v1` hash), so compare a hash only with one of the same encoding.

To write a dataset whose hash you can check again on unchanged data:

- **Sums and averages of decimal values.** Computed in parallel, a `sum` or `avg` over decimal (floating-point) values can differ in its last digits from one run to the next, so its hash can differ. Write an ordered aggregate, for example `avg(value ORDER BY ts)`, or round to the precision you need, for example `round(avg(value), 3)`.
- **Results that can be capped.** When a result can reach its row limit (10,000 rows for a preview, 100,000 for a PDF or an analytics query, 1,000,000 for a workbook or an export: see [Limits](#limits)), or has a `LIMIT` of its own, add an `ORDER BY` over columns that make each row unique, for example `ORDER BY ts, tag_path`. The same rows are then kept on each run.

## Schedules

A schedule (`GET /api/reports/schedules/<id>`, member `schedule`):

| Field | Value |
|---|---|
| `id` | `sch_` then 1 to 60 lower-case letters, digits or `_`. Fixed once created. |
| `name` | Up to 200 bytes. |
| `template` | The report template's id. It must be deployed and pass its check at each run. |
| `enabled` | The on/off switch. Changed only by `POST .../enable`; a `PUT` keeps it. |
| `trigger` | See [Triggers](#triggers). |
| `parameters` | The run's values by report parameter name: text (up to 4,000 bytes), number or `true`/`false`; a date as `YYYY-MM-DD` or a relative date (`yesterday`, `start_of_week(-1)`...). At most 64. |
| `run_as` | The owner: the user every run runs as. Default: the user who creates it; only a `reports_admin` sets another or changes it. The owner must hold `reports_view` and `reports_schedule` (`422 REPORTS_SCHEDULE_OWNER` otherwise). |
| `outputs` | `pdf`, `xlsx` or both; empty: the template's own. |
| `delivery` | Up to 10 destinations: `{"kind": "email", "to": [...], "mode": "link" \| "attachment"}` (1 to 50 recipients: user names, or addresses, which need `reports_distribute_external`) or `{"kind": "folder", "dir": "<name>[/<sub>...]"}` (a folder of `reports.folders.allowed` by its last part, up to 3 sub-folders). |
| `catch_up` | `last_missed` (default), `all` (the newest 10 missed slots at most) or `none`. |
| `grace` | How late a slot may still run: `1m` to `7d`, default `1h` (`"6h"`, `"2d"`). |
| `enabled_on`, `enabled_at`, `created_at`, `created_by`, `updated_at`, `updated_by` | Set by the server. `enabled_on` is the identity of the server that turned it on: a schedule whose `enabled_on` is not this server's is inactive ("restored from another server"). |

The answer also holds `rev` (the revision, also the `ETag`), `active` and `inactive` (why it does not run: off, or restored from another server).

### Triggers

| `kind` | Members | Slots |
|---|---|---|
| `time` | `cron`, `time_zone` (`site`, the default, or a zone name such as `Europe/Paris`) | Each time the cron expression matches, in that zone. |
| `shift_end` | `calendar` (a calendar of `reports.shifts`; default `default`) | The end of each shift (the start of the next). The run gets `shift_name`, `shift_start`, `shift_end` (or `shift.name`, `shift.start`, `shift.end`) for the report parameters it declares. |
| `batch_end` | `recipe` (a master recipe's id or name, up to 128 bytes; empty: every batch) | A batch record of the recipe engine closes. The report must declare `batch_id`; the run also gets `batch_start`, `batch_end` (or `batch.start`, `batch.end`) when declared. |
| `event` | `tag` (one boolean tag path, no wildcard), `edge` (`rising`, the only one), `min_interval` (`1s` to `7d`, default `1m`) | A good false followed by a good true; at most once per `min_interval`. The tag is only read. |
| `shiftlog_handover` (Enterprise only) | `log` (a shift log id) | Once per shift of the log, on the log's own shift calendar: when its handover is signed by both sides, or when the grace ends without one, whichever comes first. The schedule's parameter `log` is set to the trigger's log (another value is refused); the run gets `shift_name`, `shift_start`, `shift_end` as for `shift_end`. Outside Enterprise no slot runs. Runs on the HA primary only, once per shift across a failover. See [Add the shift report](/docs/eaxscada/how-to/set-up-shift-logs/#8-add-the-shift-report). |

A member of another kind is refused (`422 REPORTS_SCHEDULE_INVALID`).

**Cron expressions.** Five fields: minute (0-59), hour (0-23), day of the month (1-31), month (1-12 or `jan`-`dec`), day of the week (0-7, 0 and 7 being Sunday, or `sun`-`sat`). Each field is `*`, a number, a range `a-b`, a list `a,b,c`, a step `*/n` or `a-b/n` (`a/n`: from a to the end). When both day fields are restricted, a day matching either runs (the usual cron rule). A day that never comes (`0 0 30 2 *`) is refused. Shortcuts: `@hourly` (`0 * * * *`), `@daily` and `@midnight` (`0 0 * * *`), `@weekly` (`0 0 * * 1`, Monday), `@monthly` (`0 0 1 * *`), `@yearly` and `@annually` (`0 0 1 1 *`). The editor's presets write these: **Every day** at 06:30 is `30 6 * * *`, **Every week** on Mon, Wed, Fri at 06:30 is `30 6 * * 1,3,5`, **Every month** on day 1 at 06:00 is `0 6 1 * *`, **Every hour** at minute 15 is `15 * * * *`.

**Clock changes.** A wall time the clock skips runs once, at the first instant after the gap; a wall time it repeats runs once, at its first occurrence. Several skipped times of one night are one slot. Shift starts follow the same rule (a shift spanning the change lasts 23 or 25 hours; two starts in one gap are one start).

**Shift calendars** (`reports.shifts` in `config.yaml`, server setting, read at start-up): a calendar name (lower-case letters, digits, `_`, `-`, up to 32) and 1 to 24 shifts, each `<name> HH:MM` (the start, on the site's clock; a name of letters, digits, space, `_`, `-`, up to 32; no two with one name or one start). A shift ends where the next starts. The calendar `default` is also the one of `this_shift`, `last_shift` and `start_of_shift(n)`.

```yaml
reports:
  shifts:
    default:
      - early 06:00
      - late 14:00
      - night 22:00
    packaging: day 07:00, evening 15:00
```

### Runs of a schedule

- On the HA primary only; each slot is claimed once across the cluster under the node's fencing term before it runs. A slot whose claimer died is re-run once by the next primary while within `grace` (`late`, "re-run after failover").
- Missed slots (the server stopped, no primary): the newest slot within `grace` runs, marked late; the older ones follow `catch_up`. A schedule's slots count from the moment it was enabled on this server.
- At each run: the owner must exist, be active and hold `reports_view` and `reports_schedule`; the template must be deployed and pass its check. Otherwise `run.refuse` and the alarm.
- `as_of` is the slot: relative parameters and defaults resolve at it.

### Schedule routes and answers

Every schedule route needs a person (`403 REPORTS_AI` for the AI co-pilot, `403 REPORTS_TOKEN` for an API token) with `reports_schedule` (own schedules) or `reports_admin` (any); another user's schedule answers `404`. Through eaxCloud remote access the status is view, every change, enable and run-now is refused.

| Route | Does |
|---|---|
| `GET /api/reports/schedules` | The schedules you may see. |
| `POST /api/reports/schedules` | Creates one; `If-None-Match: *` (another value: `412`). `201` with `Location` and `ETag`. |
| `GET /api/reports/schedules/<id>` | One schedule, with `ETag`. |
| `PUT /api/reports/schedules/<id>`, `DELETE ...` | Changes or deletes it; `If-Match` required (`428` without, `409` when it changed since). |
| `POST /api/reports/schedules/<id>/enable` | `{"enabled": true \| false}`, with `If-Match`. Only a `reports_admin` enables a restored schedule. |
| `POST /api/reports/schedules/<id>/run-now` | Runs it once now, as its owner (`202` with the run's `Location`). |
| `GET /api/reports/schedules/status` | Each schedule's state, next slot and problem; for a `reports_admin` also the alarm's reasons. |
| `GET /api/reports/schedules/due` | The due slots. |
| `GET /api/reports/schedules/options` | The schedule editor's lists for every scheduler: the shift calendar names, the delivery folders' base names (never a path; a name two allowed folders share is left out, and a schedule cannot use it), whether attachments are allowed, whether any external domain is (the domains themselves only for `reports_distribute_external`), whether e-mail is configured. |
| `GET /api/reports/recipients` | The active user accounts as `{id, username, full_name, has_email}`: never an address or a role, never the AI co-pilot (`reports_schedule` or `reports_admin`). |

`GET /api/reports/roles` (`reports_design`, a person) lists the role names for a signature plan. The schedule editor and the designer's signature plan offer these lists to users who are not administrators; through eaxCloud remote access they are *view*.

Other answers: `422 REPORTS_SCHEDULE_INVALID` (a field refused, with the reason), `409` (an id that exists already), `409 REPORTS_STANDBY` (an HA standby), `503 REPORTS_SCHEDULER_OFF` (no scheduler on this server), `503 AUDIT_NOT_WRITTEN`.

## Signatures

**Signature plan** (member `signatures` of a report template; described field by field in the [screen document reference](/docs/eaxscada/reference/generated/config/screen-document/#reportsignatureplan)):

| Field | Value |
|---|---|
| `mode` | `none` (also when empty), `review`, or `review_approve`. |
| `review`, `approve` | The steps: `roles` (up to 16 role names; empty: any holder of `reports_sign`) and `meaning` (one printable line of up to 120 characters, no braces; empty: `Reviewed by`, `Approved by`). `approve` only with `review_approve`. |
| `approver_differs_from_reviewer`, `approver_differs_from_runner` | The separation-of-duties rules of the approval. Unset: on; only an explicit `false` lifts one. Only with `review_approve`. |

A plan with steps needs `pdf` in the template's outputs. A member the plan does not model is kept when a stored report is read and refused when a report is saved. The template's `external_delivery_allowed` (**May be sent outside**) is set only by a `reports_admin`; a duplicate starts without it.

**Signature** (an item of the run record's `signatures`): `n` (1, 2...), `step` (`review`, `approve`), `decision`, `meaning`, `user_id`, `username`, `printed_name` (the account's full name, else its user name), `signed_at` (UTC), `site_time` and `site_zone`, `ticket_id` (the first 12 hex digits of the ticket's key; the ticket itself is never recorded), `original_sha256` (the archived PDF's hash the signature is over), `rendition` (the signed copy: `format`, `bytes`, `sha256`, `pages`, `path`, and `pdfa: "3b"` when the copy is PDF/A-3b, which it is when the archived original is; signed copies made by an earlier version have no `pdfa` and stay plain PDF). A signed copy is about the size of the original plus the signature page.

**Signature states**: `unsigned`, `reviewed`, `approved` (shown with the step the run waits for: "Reviewed, waits for approval"). E-signature decisions: `report_review` and `report_approve`, over the object `report-run:<run id>` and the archived PDF's hash; `report_purge`, over `report-archive-purge:<plan hash>`. A ticket of one decision and object is never accepted for another.

**Routes** (a person with `reports_sign` who may open the run; the status also with `reports_view`; refused through eaxCloud remote access, the status included): `GET /api/reports/runs/<id>/sign` (status, signatures, plan, and `pending`: what your signature would sign, or `cannot_sign`: why), `POST .../sign/ticket` `{"password"}`, `POST .../sign` `{"ticket"}`, `GET .../files/signed-<n>` (signed copy n). Answers: `403 REPORTS_SIGN_REFUSED`, `409 REPORTS_SIGNATURE_TAKEN`, `409 REPORTS_INTEGRITY`, `409 REPORTS_STANDBY`, `503 REPORTS_SIGN_OFF`, `503 AUDIT_NOT_WRITTEN`; after a downgrade, `403 EDITION` (the status stays open).

**Signature ticket answers** (`POST .../sign/ticket` and the purge's `POST /api/reports/archive/purge/ticket`, as every signature-ticket route of eaxScada): a wrong password, an unknown or disabled signer, the AI co-pilot or an API token answer `403` with `"status": "signature_refused"`; the account locked (the fifth wrong password locks it for 15 minutes) `429`; a missing password `400`; a ticket the server could not hand out `503`. `401` only means "no session": a wrong password never signs you out.

## Archive

| Item | Value |
|---|---|
| Retention classes | `standard` (no signature; kept at least `reports.archive.retention.standard`, default 3 years, and until its `keep_until`), `signed` (holds a signature: never purged), `draft` (never archived). |
| Quota | `reports.archive.quota` (default `20GiB`). The alarm is active from 80 %; a run whose files would pass it fails ("the report archive is full") and is not archived. |
| Disk floor | The larger of `reports.archive.min_free` (default `2GiB`) and `historian.disk.critical_free` on the archive's disk. A run that would go under it fails ("not enough free disk space for the report archive"). |
| PDF/A | `reports.archive.pdfa` (default `true`): archived PDFs written as PDF/A-3b, each dataset's rows embedded as a CSV file (`<alias>.csv`, header row of the column names); their signed copies are PDF/A-3b too. Validated with an independent PDF/A validator, PDF/A-3B profile. |

**Verify** (`POST /api/reports/runs/<id>/verify`, `reports_view` and a run you may open; recorded as `archive.verify`). The answer: `run`, `status`, `checked_at`, `checks` (each: `kind`, `path`, `n`, `expected`, `actual`, `ok`, `problem`).

| `kind` | The item |
|---|---|
| `sidecar` | The run record copy in the archive (`<run>.json`), against the index and the server's own record (and, for signed runs, against what each signature recorded). |
| `original` | The PDF and the workbook, against the sidecar and the run record. |
| `rendition_sidecar` | The link record of signed copy n. |
| `rendition` | Signed copy n, against its link; each link must name the hash of the one before. |

| `status` | Shown | Means |
|---|---|---|
| `ok` | Verified | Every check passed. |
| `mismatch` | Hash mismatch | A hash differs, or the chain does not follow. |
| `missing` | File missing | A recorded file is not on disk. |
| `broken` | Broken chain | A file cannot be read, or a file in the folder is not part of the chain. |
| `unverified` | Not verified yet | No verification recorded (the run's integrity before its first Verify). |

The worst result wins. Nothing is repaired.

**Archive list** (`GET /api/reports/archive`, `reports_view`): the archived runs you may open, with `integrity` and `signature`. Filters `template`, `run_as`, `class`, `from`, `to` (RFC 3339; the workspace's **Archived from / until (UTC)** fields send UTC days), `limit`. For a `reports_admin` also `usage` (bytes used, quota, percent, alarm, free space and floor) and `faults`.

**Purge** (`reports_admin`, a person; refused through eaxCloud remote access): `POST /api/reports/archive/purge/plan` (the dry run: `plan` with `created_at`, `runs`, `files` (`run`, `kind`, `path`, `bytes`, `sha256`), `skipped` (`run`, `reason`), `bytes`, `sha256`; `object_ref`, `decision`, `meaning`), `POST .../purge/ticket` `{"password", "plan_sha256"}`, `POST /api/reports/archive/purge` `{"plan_sha256", "signature_ticket"}`. The plan is computed again at each step: `409 REPORTS_PURGE_PLAN_CHANGED` with the new plan when it changed, `409` when there is nothing to purge, `403` when the ticket is not this plan's or the caller's (a wrong password at the ticket step: `403 signature_refused`, see the signature ticket answers above). Listed: standard runs past their retention whose originals and sidecar still have their recorded hash. Kept: signed runs, runs whose plan waits for a step, runs with a missing or changed file, runs whose record is not on this server. One `archive.purge` record is written before each file is deleted.

## Delivery outcomes

`delivery.status` of a scheduled run:

| Status | Shown | Means |
|---|---|---|
| `delivered` | Delivered (n) | Every destination sent or written. |
| `partial` | Partly delivered (n of m) | Some were. |
| `failed` | Not delivered | None was, or the delivery could not run (`note` says why), or it was interrupted by a restart (never re-sent on its own). |
| `none` | No destination | The schedule has no delivery. |
| `not_configured` | Delivery is off on this server | The server delivers nothing. |
| `pending_signatures` | Pending until signed | The report's signature plan is not complete; kept across restarts. |
| `delivering` | Delivering | Being sent. |

Each item of `outcomes`: `delivery` (its number in the schedule), `kind` (`email`, `folder`), `recipient`, `address`, `external`, `mode`, `status`, `rule`, `reason`, `dir`, `path`, `files` (`format`, `sha256`, `bytes`), `at`.

| Outcome `status` | Means |
|---|---|
| `sent` | The mail server accepted the message. |
| `written` | The file is in the folder. |
| `skipped` | An eaxScada user who may not receive it. |
| `refused` | A rule refused the destination. |
| `failed` | The mail server, the disk, the archive or the audit trail failed. |

| `rule` | Means |
|---|---|
| `run_not_deliverable` | Only a succeeded, archived, non-draft, not purged run is delivered. |
| `email_not_configured` | No `reports.email.smtp.host`. |
| `transport_refused` | The SMTP settings break the transport rules (STARTTLS, plain only to this machine without sign-in, `username` and `password_ref` together, a valid `from`). |
| `no_base_url` | Link mode without a usable `reports.email.base_url`. |
| `attachments_disabled`, `attachment_too_large` | Attachment mode while `reports.email.attachments` is off, or the files are larger than `reports.email.max_attachment`. |
| `unknown_user`, `user_disabled`, `no_address`, `bad_address`, `duplicate` | An eaxScada user who does not exist, is not active, has no or an unusable e-mail address, or an address listed twice. |
| `narrower`, `no_policy`, `scope_not_recorded`, `alarm_data` | The user may not open the run: they may not read every tag it could read (a count is given, never names), their read rights could not be read, the run holds no recorded read scope, or the run has an alarms dataset (only the owner and reports administrators receive it). |
| `no_external_right` | The owner does not hold `reports_distribute_external` now. |
| `template_not_marked` | The deployed report is not marked **May be sent outside**. |
| `domain_not_allowed` | The address's domain is not in `reports.email.allowed_domains`. |
| `folder_not_allowed` | The folder name is not one of `reports.folders.allowed` (or the folder is missing, a link, or leads outside it). |
| `audit_not_written` | The audit record could not be written: nothing was sent. |
| `smtp`, `message`, `archive_unreadable` | The mail server refused or failed, the message could not be built, or the archived file could not be read or no longer has its hash. |

Messages: one per recipient, plain text in English, French, German, Spanish or Italian (the user's language; for an external address, the report's language), holding only the report title, the run time, the run id and, in link mode, `<reports.email.base_url>/studio/?workspace=reports&run=<run id>`.

## Audit events

Category `reports`:

| Event | When |
|---|---|
| `dataset.create`, `dataset.update`, `dataset.delete` | Before the change, with the old and new SQL and the old revision; `_FAILED` after a change that failed. A change whose record cannot be written is refused. |
| `run.start` | Before the run. A run whose record cannot be written does not start. |
| `run.succeed`, `run.fail`, `run.refuse`, `run.cancel` | At the end: template revision, parameters, dataset revisions, rows, result and file hashes. |
| `run.preview` | For a PDF draft (before it runs; a draft whose record cannot be written does not run) and for each dataset preview (`POST /api/reports/datasets/<id>/preview`). For a dataset read for viewing (`POST /api/reports/datasets/<id>/view`, the dashboard's dataset cards), once per user, dataset, parameters and outcome per hour, with `purpose: "view"`: see [Dataset reads for viewing](#dataset-reads-for-viewing). A dataset preview or view that answered records its `result_sha256` and `result_hash_v` (`eax-dataset-v2`). |
| `file.download` | Before a file is sent. |
| `file.view` | When a user opens another user's run (rule `contained` or `admin`). |
| `schedule.create`, `schedule.update`, `schedule.delete`, `schedule.enable`, `schedule.disable`, `schedule.owner_change` | Before the change. A change whose record cannot be written is not made. |
| `run.refuse` (scheduled) | A slot refused: the owner deleted, disabled or without the rights, the template not deployed or failing its check. |
| `sign.review`, `sign.approve` | Before the signature is recorded and its signed copy written, with the signature manifest. A failure after it is noted on the trail. |
| `archive.verify` | After a verification, with its result. |
| `archive.purge` | Before each file of a purge is deleted, with the plan's hash and the administrator's signature. On an HA standby, one per file the replicated purge removes (`replicated: true`). |
| `deliver.email` | Per message, before it is sent (`sending`) and after (`sent`, `failed`), and a summary per e-mail destination (recipients sent to, skipped, refused, with their rules). |
| `deliver.folder` | Per file, before it is written (`writing`) and after (`written`, `failed`). |
| `settings.update` | Before the SMTP password is stored or removed (never the value). |

### Dataset reads for viewing

`POST /api/reports/datasets/<id>/view` is the dataset preview's read for viewing: the dashboard's dataset cards use it, refreshed every few seconds while a dashboard is open. It takes the same body (`{"parameters": {...}}`), runs as the user with the same preview limits, and gives the same answer as `POST .../preview`. It needs `reports_view`, `reports_design` or `analytics`, and it refuses the AI co-pilot whatever its rights (the preview needs `reports_design` or `analytics`).

Only its audit volume differs. It writes a `run.preview` record **once per user, dataset, parameters and outcome per hour**:

- The outcome is the dataset's revision when the read answered, or the error when it failed. A changed dataset, other parameters or a new error each write their own record at once.
- The record's details add `purpose: "view"` and `audit_window_s: 3600`. When identical reads were not recorded since the previous record, `repeats_since_last_record` gives their number.
- A record that could not be written is tried again at the next identical read.
- Repeats not yet written into a record are dropped 24 hours after the last record (the dashboard was closed).

The product does not audit its other reads of operator data per request (history, the alarm history, production reads), and the analytics workspace already records its queries once per user and query per window. `POST .../preview`, used by the dataset editor and the designer, **still writes one record per request**, and every change (datasets, runs, signatures, schedules, settings) is audited as before.

Category `analytics`:

| Event | When |
|---|---|
| `analytics.query` | Every analytics query run, refused or cancelled: the result id, the source, the SHA-256 of the SQL text (the full text is in the server log), the parameters, the tag scope, the duration, and the rows, `truncated`, the result's hash (`result_sha256`) and its encoding (`result_hash_v`: `eax-dataset-v2`, or `eax-extract-v2` for a query over extracts; a record made before this version has none and holds a v1 hash), the hidden tags' count and `ignores_quality` (or `refused`, `error`, `cancelled`). One record per identical query per user per minute; the repeats are counted into the next record (`repeats_since_last_record`). A result whose record cannot be written is not given (`503 AUDIT_NOT_WRITTEN`). A query over extracts records `family: extracts` and the extract names it read. |
| `analytics.export` | Every export, done or refused: the format, rows, bytes, the file's SHA-256, the SHA-256 of the SQL text (the full text is in the server log), the window and parameters, the tag scope, and for a dataset's export the dataset and its revision. An export whose record cannot be written fails (`AUDIT_NOT_WRITTEN`) and its file is deleted. |
| `analytics.extract.create` | Every extract, made or refused (a refusal by the server-wide cap included): the name, family, relation, window, scope, rows, bytes, tags allowed and hidden, the generated SQL's SHA-256, the duration. Written before the extract is kept: an extract whose record cannot be written is dropped (`503 AUDIT_NOT_WRITTEN`). |
| `analytics.extract.drop` | Every extract dropped, with the reason: `user`, `idle` (the sweep, recorded as the session's owner) or `shutdown`. |

## System alarm ALM-SYS-REPORTS

"Scheduled report failed, refused or overdue". Active while:

- a schedule's last attempt failed or was refused (owner deleted, disabled or without `reports_view` or `reports_schedule`; template not deployed or failing its check; the run failed);
- a schedule's next slot is overdue by half a period (1.5 periods after the slot before it);
- the report archive holds 80 % or more of `reports.archive.quota`;
- schedules are paused by the licence ("paused by the licence", one reason per schedule);
- on an HA cluster, a standby has not confirmed an archived file for more than an hour, or refused a file of the primary (another hash).

It clears with the schedule's next run that succeeds (and the archive under 80 %, the licence back, the standby caught up). System Health has an **Analytics and Reports** section (`reports`): the licence (included or read-only), the schedules paused by the licence, the scheduler, the archive's use, quota and disk floor, its faults, the alarm's reasons (also in the attention banner), and the archive replication (`reports.replication`: role, files behind, last pass, files replicated and purged, run records not committed, last error; each standby's last report on the primary; the files a standby refused). `GET /api/reports/schedules/status` gives the reasons to a `reports_admin`.

## HA replication

| What | How |
|---|---|
| Run records | Replicated server state (the cluster store's domain `reportruns`, never part of a checkpoint). Written on the node first, then committed to the cluster (retried). A signature and the taking of a pending delivery are committed to the cluster first; refused there (a standby, a primary without quorum or replaced by a newer term, a copy older than the cluster's), nothing is recorded. The primary's term wins; a record that holds archived files or signatures is never removed by replication. |
| Archived files | The standby pulls the primary's PDFs, workbooks and run sidecars, then each signed copy and its link record once its signature is in the replicated record; by hash, checked against the primary's list, written once, within the standby's own `reports.archive.quota` and disk floor. A purge on the primary removes the purged run's files on the standby. |
| Datasets, schedules | Project documents in the cluster's configuration store (domains `reports.datasets`, `reports.schedules`), replicated and kept across a restart like the other project documents. |
| After a failover | The new primary lists every run, serves and verifies the files, takes the next signature. A run left queued or running by another node: failed ("the server that ran it ... stopped, or stopped being the HA primary, before the run finished"); a delivery another node started: failed, never sent again; a fully signed run whose delivery was pending: delivered once by the new primary (retried every minute until its cluster store accepts it). |
| Upgrade | At the first start of this version on a cluster, the existing run records are copied to the cluster store from the primary; the standby then pulls the existing archive. |

## After a downgrade or a licence expiry

When the licence in force does not include Analytics and Reports (Starter, Free, or an expired licence) and report data exists (`data/reports/runs` or the archive folder), the engine starts read-only. The licence is checked on every change.

| Open (with every other check: sign-in, token, right, which runs you may open) | Refused `403 EDITION` |
|---|---|
| `GET /api/reports/me`, `GET /api/reports/runs`, `GET /api/reports/runs/<id>`, `GET /api/reports/runs/<id>/files/<pdf\|xlsx\|signed-n>`, `POST /api/reports/runs/<id>/verify`, `GET /api/reports/runs/<id>/sign`, `GET /api/reports/archive` | Every other route: new runs, previews, datasets, templates, schedules and run-now, signing a step, the purge, the settings, analytics. |

The workspace shows **Runs** and **Archive** only, read-only, with the chip "Read-only: the licence in force does not include Analytics and Reports; archived reports stay readable". Active schedules are paused (no slot claimed, run-now `refused`, event and batch-end triggers skipped); a licence with the module resumes them, the missed slots following each schedule's `catch_up` (`last_missed`: the newest; `none`: none; `all`: the newest 10). Pending deliveries wait and are delivered once the licence is back. A build without the columnar historian runs no engine, so there the open routes answer `503 REPORTS_ENGINE_OFF`.

## Analytics workspace

Every route: a person with `analytics` (`403 REPORTS_TOKEN` for an API token, `403 REPORTS_AI` for the AI co-pilot, whatever its rights), the Pro or Enterprise edition; through eaxCloud remote access an *engineer* action.

| Route | Does |
|---|---|
| `POST /api/analytics/query` | Runs a query: `{family, sql, parameters: [{name, type, value}], tag_scope?, page_rows?}`. `family`: a dataset family (`historian`, `alarms`, `shiftlog` or `production`, each with its own licence and read rules) or `extracts` (your own extracts: [Extract routes](#extract-routes-and-answers)). For a dataset family, `from` and `to` (RFC 3339 timestamps) are required. `tag_scope` (tag patterns; default every tag) can only narrow. At most 32 parameters; a body of at most 128 KiB. Answers the result and its first page. |
| `GET /api/analytics/query/<id>?offset=&limit=` | A page of your result (at most 10,000 rows; default 2,000). |
| `DELETE /api/analytics/query/<id>` | Drops your result. |
| `DELETE /api/analytics/query` | Cancels your running query (closing the request does too). |
| `GET /api/analytics/queries` | Your saved queries, the limits in force (`max_rows`, `timeout_s`, `max_result_bytes`, `per_user`, `workers`, `page_rows`, `max_page_rows`, `cursor_ttl_s`) and the sources (relations, columns, helpers). |
| `PUT /api/analytics/queries/<id>` | Saves one of your queries: `{name, family, sql, parameters}` (id: a lower-case letter or digit, then letters, digits, `_`, `-`, up to 64; name up to 120). The parameters keep their last values; the time window is not kept. |
| `DELETE /api/analytics/queries/<id>` | Deletes one of your saved queries. |
| `POST /api/analytics/export`, `POST /api/reports/datasets/<id>/export` | An export job ([Export routes](#export-routes-and-answers)). |
| `GET, POST, DELETE /api/analytics/extracts`, `DELETE /api/analytics/extracts/<name>` | Your extracts ([Extract routes](#extract-routes-and-answers)). |

**Result** (`POST`): `id` (`aq_` and 24 hex digits; `ax_` for a query over extracts), `family`, `columns`, `total_rows`, `truncated`, `max_rows`, `sha256`, `warnings`, `tags_allowed`, `tags_hidden`, `duration_ms`, the quality summary, and `page`.

| Quality field | Holds |
|---|---|
| `quality_column`, `simulated_column` | The result's quality column (`quality_class`, else `quality`, any case) and simulated column, when present. |
| `quality` | Rows by class (`good`, `uncertain`, `bad`) and `simulated`. |
| `ignores_quality` | `true` for a historian query that reads values without quality (the dataset save rule), with `quality_reason` and `quality_fix`, `non_good_tags` (each tag's `bad` and `uncertain` samples in the window, listed up to a limit), `non_good_samples`, `affected_rows`, `affected_by_tag`. |

**Page**: `id`, `offset`, `rows`, `row_quality` (each row's class, with a quality column), `row_affected` (each row that may hold non-good samples, for a query that ignores quality: with a `tag_path` column the rows of the tags with non-good samples in the window, else every row when the window holds any), `total_rows`, `next_offset` (`-1` after the last page).

| Limit | Value |
|---|---|
| Rows per query | `analytics.max_rows` (default 100,000) |
| Time per query | `analytics.query_timeout` (default 60 s) |
| One result | 64 MiB |
| Time window | `reports.max_window` (400 days) |
| Running queries | `analytics.per_user` (1) per user; `analytics.workers` (2) on the server, queries over extracts included |
| Results kept | 1 per user (a new query replaces it), 10 minutes idle, 16 on the server (the least recently used dropped first) |
| Saved queries | 200 per user, in `data/analytics/saved_queries.json` by user id; not project content (not in checkpoints, project archives or HA replication) |

| Answer | Means |
|---|---|
| `400` | A `family` other than `historian`, `alarms`, `shiftlog`, `production` or `extracts`; a body that is not valid; `EXTRACT_SPEC`: a `tag_scope` on a query over extracts. |
| `404` | No such result: expired, replaced, or another user's. |
| `409` `ANALYTICS_CANCELLED` | The query was cancelled. |
| `422` `REPORTS_SQL` | An error in the SQL, with `message`, `line` and `column` in the text sent. |
| `422` `REPORTS_REFUSED` | A refused query: a stored table, a file, a table function, `tag_history`, `main.*`, temporary tables, a tag parameter outside your rights, a missing time window, a window over `reports.max_window`. A refused saved query answers `422` too. |
| `429` `ANALYTICS_BUSY` | You already have a query running, or the server runs its maximum: never queued. |
| `504` | The query took longer than `analytics.query_timeout`. |
| `503` `ANALYTICS_OFF`, `ANALYTICS_SOURCE` | The workspace does not run on this server, or the source's database is not available. |
| `503` `AUDIT_NOT_WRITTEN` | The `analytics.query` record could not be written: the result is not given. |

### Export routes and answers

Every route: a person (`403 REPORTS_TOKEN`, `403 REPORTS_AI`), the Pro or Enterprise edition, the right listed; through eaxCloud remote access an *engineer* action. A job is its owner's only.

| Route | Right | Does |
|---|---|---|
| `POST /api/analytics/export` | `analytics` | `{family, sql, parameters, tag_scope?, window?: {from, to}, format, name?}`. `family`: `historian`, `alarms`, `shiftlog`, `production` or `extracts` (over extracts: no `window`, no `tag_scope`). `format`: `csv`, `xlsx` or `parquet`. `window` sets the `from` and `to` parameters. The query is checked before the job is queued. Answers `202` with the job and `Location: /api/analytics/export/<id>`. |
| `POST /api/reports/datasets/<id>/export` | `reports_view` | `{format, parameters?, window?, name?}`: a saved dataset, its parameters' defaults resolved as for a run. `202` as above. |
| `GET /api/analytics/export/<id>` | `analytics` or `reports_view` | The job. |
| `GET /api/analytics/export/<id>/file` | `analytics` or `reports_view` | The file: `Content-Disposition: attachment; filename="<name>_<id>.<ext>"`, `ETag` = its SHA-256, `Cache-Control: no-store`. |
| `DELETE /api/analytics/export/<id>` | `analytics` or `reports_view` | Removes the job and its file. |

**Job**: `id` (`exp_<yyyymmdd>T<hhmmss>Z_<12 hex digits>`), `status` (`queued`, `running`, `done`, `failed`, `expired`), `format`, `name`, `family`, `dataset` and `dataset_rev` for a dataset's export, `rows`, `bytes`, `sha256`, `created`, `expires`, `finished`, `tags_hidden`, `duration_ms`, and `code` and `error` when it failed (`EXPORT_LIMIT`, `AUDIT_NOT_WRITTEN`).

**Files**: written by the server to `<analytics.export.dir>/<user id>/<export id>.<ext>`: CSV in UTF-8 with a cell that a spreadsheet would run as a formula (`=`, `+`, `@`, a tab, a carriage return, or `-` before a non-number) prefixed with `'`; Excel with one data sheet and an **About** sheet (export id, generation time, time zone, parameters, the data's SHA-256, the quality rule); Parquet with the result's column types. Deleted after `analytics.export.keep`, swept at start-up and every 10 minutes (files of an earlier run of the server included).

| Limit | Value |
|---|---|
| Rows of one export | `analytics.export.max_rows` (default 1,000,000) |
| Size of one export | `analytics.export.max_bytes` (default 512 MiB, at most 4 GiB) |
| Exports per user | 1 waiting or running |
| Exports running on the server | `analytics.export.workers` (default 1); the others wait in turn |
| Time per export | 5 minutes |
| Files kept | `analytics.export.keep` (default 24 h) |

| Answer | Means |
|---|---|
| `202` | The job is queued. |
| `400` | A `family` or `format` that is not valid; an export id not of the shape above (before any lookup); a body that is not valid; `EXTRACT_SPEC`: a `window` or `tag_scope` with `family: extracts`. |
| `404` | No such export, or another user's (never `403`); no such dataset. |
| `409` `EXPORT_BUSY` | You already have an export waiting or running. |
| `409` `EXPORT_NOT_READY` | The file is not there: the job is queued, running, expired or failed. |
| `410` | The job is done but its file is no longer there. |
| `413` `EXPORT_LIMIT` | The download of a job that failed over a limit: nothing was cut, no file kept. |
| `422` | The query was refused before the job was queued (`REPORTS_SQL`, `REPORTS_REFUSED`, as for a query). |
| `503` `AUDIT_NOT_WRITTEN` | The download of a job whose `analytics.export` record could not be written: its file was deleted. |
| `503` `ANALYTICS_OFF` | The analytics service does not run on this server. |

### Extract routes and answers

Every route: a person with `analytics` (`403 REPORTS_TOKEN`, `403 REPORTS_AI`), the Pro or Enterprise edition; through eaxCloud remote access an *engineer* action. Sessions are keyed by user id: another user's extract, list or result answers as one that does not exist.

| Route | Does |
|---|---|
| `POST /api/analytics/extracts` | `{name, family, relation, from, to, tag_scope?, parameters?}`: reads one relation (`historian`: `samples`; `alarms`: `alarm_events`, `alarm_definitions`) over the window (RFC 3339, required), as you, into your session under `name`. Answers `201` with the extract. |
| `GET /api/analytics/extracts` | `{extracts, session, limits}`: your extracts, your session (`extracts`, `rows`, `bytes`, `memory_bytes`, `created_at`, `last_used`, `expires_at`; `null` without one) and the limits (`rows`, `bytes`, `idle_s`, `per_user`). |
| `DELETE /api/analytics/extracts/<name>` | Drops one extract. |
| `DELETE /api/analytics/extracts` | Drops all your extracts (`dropped`: how many). |
| `POST /api/analytics/query` with `"family": "extracts"` | One `SELECT` over your extracts only: their names are the only relations; no qualified names, no table functions; the analytics functions and the quality helpers. Only the parameters the query names are bound; no `tag_scope`. Result id `ax_...`; pages, cancel and close as any query. |
| `POST /api/analytics/export` with `"family": "extracts"` | Exports such a query ([Export routes](#export-routes-and-answers)). |

**Extract**: `name`, `family`, `relation`, `from`, `to`, `scope`, `params`, `columns`, `rows`, `bytes`, `tags_allowed`, `tags_hidden`, `warnings`, `sql_sha256` (the generated SQL's hash, never its text).

**Name**: a lower-case letter, then lower-case letters, digits and `_`, at most 41 characters; not a relation or stored table name, not a catalog or schema name, not an SQL reserved word, not taken in your session.

| Limit | Value |
|---|---|
| Rows of a session | `analytics.extract_rows` (default 2,000,000) |
| Size of a session | `analytics.extract_bytes` (default 512 MiB; at most 4 GiB) |
| Extracts per user | `analytics.extract_per_user` (default 8; 1 to 32) |
| Session unused | dropped after `analytics.extract_idle` (default 30 min; 5 min to 24 h) |
| Sessions on the server | `analytics.extract_sessions` (default 4; 1 to 64) |
| Worst-case memory | `extract_sessions × (2 × extract_bytes + 256 MiB)`, 5 GiB with the defaults; above 16 GiB the server does not start |
| Query over extracts | as any query: `analytics.max_rows`, `analytics.query_timeout`, 64 MiB, a place among `analytics.workers` |

| Answer | Means |
|---|---|
| `201` | The extract is in your session. |
| `400` `EXTRACT_NAME` | The name is malformed, reserved or taken. |
| `400` `EXTRACT_SPEC` | A family, relation or window that is not valid (the window is required); a `tag_scope` on a query over extracts. |
| `404` `EXTRACT_UNKNOWN` | No extract of that name in your session. |
| `409` `EXTRACT_TOO_MANY` | Your session holds `analytics.extract_per_user` extracts. |
| `409` `EXTRACT_CANCELLED` | The read was cancelled: nothing kept. |
| `410` `EXTRACT_EXPIRED` | You have no session (dropped, or unused past `analytics.extract_idle`). |
| `413` `EXTRACT_LIMIT` | The extract would take your session over its rows or bytes: refused whole, nothing kept. |
| `422` | A query over extracts refused by the guard (another name, a qualified name, a table function, more than one statement). |
| `429` `EXTRACT_SERVER_FULL` | Your first extract while `analytics.extract_sessions` other users hold extracts: refused, never queued; recorded as a refused create. |
| `429` `ANALYTICS_BUSY` | A query over extracts while `analytics.workers` queries run, or one of yours does. |
| `503` `EXTRACT_CLOSED` | The server is stopping. |
| `503` `AUDIT_NOT_WRITTEN` | The record could not be written: the extract is dropped before any query sees it, or the query's result is not given. |
| `503` `ANALYTICS_OFF` | The extracts do not run on this server. |

## HTTP routes

Every route needs a signed-in user, sign-in turned on, the Pro or Enterprise edition (`403 EDITION` otherwise), the columnar build, and the right listed. The full list, with the methods and rights, is generated from the source: [HTTP API: /api/reports](/docs/eaxscada/reference/generated/http-api/#apireports) and [/api/analytics](/docs/eaxscada/reference/generated/http-api/#apianalytics).

| Answer | Means |
|---|---|
| `401` | Not signed in. |
| `403` `EDITION` | The edition does not include Analytics and Reports (after a downgrade, every route but the archive reads: [After a downgrade](#after-a-downgrade-or-a-licence-expiry)). |
| `403` `REPORTS_RIGHT` | The user lacks the route's right. |
| `403` `REPORTS_TOKEN` | An API token on a route that refuses tokens. |
| `403` `REPORTS_AI` | The AI co-pilot on a schedule, signature, purge, settings, picker or analytics route (even with every right). |
| `403` `signature_refused` (`status`) | A signature ticket refused: wrong password, unknown or disabled signer ([Signatures](#signatures)). |
| `404` | Also another user's run or schedule you may not open: the same answer as for one that does not exist. |
| `409` | A save from an outdated revision; a dataset still used by a report; a run with files, or with a signature or a pending signature step, cannot be removed. |
| `409` `REPORTS_STANDBY` | A schedule change or a signature on an HA standby, or a primary without quorum. |
| `428` | A schedule change without `If-Match`. |
| `409` `EXPORT_BUSY`, `EXPORT_NOT_READY`, `EXTRACT_TOO_MANY`, `EXTRACT_CANCELLED` | See [Export routes](#export-routes-and-answers) and [Extract routes](#extract-routes-and-answers). |
| `413` `EXPORT_LIMIT`, `EXTRACT_LIMIT` | An export or an extract over its limit: refused whole, never cut. |
| `429` | Too many runs waiting (yours or the server's); a locked account at a signature ticket. `429 ANALYTICS_BUSY`: too many analytics queries running. `429 EXTRACT_SERVER_FULL`: the server holds its maximum of extract sessions. |
| `500` `REPORTS_INTEGRITY` | An archived file no longer matches its SHA-256 (download). |
| `501` `RESTART_ONLY` | `PUT /api/reports/settings`: every `reports.*` key is read at start-up (the answer names the keys sent; unknown keys answer `400`). |
| `503` `REPORTS_SCHEDULER_OFF`, `REPORTS_SIGN_OFF`, `REPORTS_SECRETS_OFF` | That service does not run on this server. |
| `503` `REPORTS_ENGINE_OFF` | The engine is not running on this server (`reports.enabled` off, a licence without the module at start-up and no report data to keep readable, or a build without the columnar historian). |
| `503` `REPORTS_UNAVAILABLE` | A Pro licence on a build without the columnar historian. |

## Configuration keys

The `reports:`, `analytics:` and `site:` sections of `config.yaml` are server settings, never part of the project. A refused or out-of-range value stops the server at start. Every key, with its type and default, is in the [server configuration reference](/docs/eaxscada/reference/generated/config/server-config/#reportsconfig). The ones this release uses:

| Key | Default | |
|---|---|---|
| `reports.enabled` | `true` | Run the engine on this server (the edition decides whether it may). |
| `reports.workers`, `reports.queue` | `2`, `20` | Runs rendered at a time (1 to 64), runs waiting (1 to 10,000). |
| `reports.chart_vms` | `2` | Chart renderers (1 to 32). |
| `reports.query_timeout`, `reports.scheduled_query_timeout`, `reports.run_timeout` | `60s`, `300s`, `10m` | Query time of on-demand and scheduled runs; the run timeout must be at least both. |
| `reports.max_window`, `reports.max_pages`, `reports.max_result_bytes` | `400d`, `2000`, `256MiB` | |
| `reports.pdf.max_rows`, `reports.pdf.max_table_rows` | `100000`, `20000` | The table limit is at most the PDF limit. |
| `reports.xlsx.max_rows`, `reports.preview.max_rows` | `1000000`, `10000` | |
| `reports.archive.dir` | `data/reports/archive` | |
| `reports.archive.quota` | `20GiB` | More than 0. Alarm at 80 %; a run that would pass it is not archived. |
| `reports.archive.min_free` | `2GiB` | More than 0. The disk floor is the larger of it and `historian.disk.critical_free`. |
| `reports.archive.retention.standard` | `3y` | Unsigned runs: purgeable after it (at least `1d`; `never` keeps them). |
| `reports.archive.retention.signed` | `never` | Read and checked (at least `1d`, not shorter than `standard`); signed runs are never purged in this release, whatever it says. |
| `reports.archive.pdfa` | `true` | Archived PDFs (and their signed copies) as PDF/A-3b, with the datasets' CSV embedded. |
| `analytics.max_rows` | `100000` | The rows an analytics query returns. |
| `analytics.query_timeout`, `analytics.per_user`, `analytics.workers` | `60s`, `1`, `2` | An analytics query's time limit; running queries per user and on the server (queries over extracts included). Before this version the queries took `reports.query_timeout` and `reports.workers`. |
| `analytics.export.max_rows`, `analytics.export.max_bytes` | `1000000`, `512MiB` | One export's rows and size; more than `4GiB` is refused (the result is held in memory while the file is written). |
| `analytics.export.workers` | `1` | Exports running at once on the server; the others wait. |
| `analytics.export.dir` | `data/analytics/exports` | The export files, one folder per user. A relative folder must be inside `data/` (no `..`); else give an absolute folder. |
| `analytics.export.keep` | `24h` | How long an export file is kept. |
| `analytics.extract_rows`, `analytics.extract_bytes` | `2000000`, `512MiB` | The rows and size of one user's extracts together; `extract_bytes` above `4GiB` is refused. |
| `analytics.extract_per_user` | `8` | Extracts per user (1 to 32). |
| `analytics.extract_idle` | `30m` | A session unused this long is dropped (`5m` to `24h`). |
| `analytics.extract_sessions` | `4` | Users holding extracts at once, server-wide (1 to 64). `extract_sessions × (2 × extract_bytes + 256MiB)` above `16GiB` is refused. |
| `reports.shifts.<calendar>` | none | Shift calendars: a list of `<name> HH:MM`, or `name HH:MM, name HH:MM` on one line ([Shift calendars](#triggers)). |
| `reports.email.smtp.host`, `.port` | none, `587` | Empty host: no e-mail delivery. Implicit TLS (port 465) is not supported. |
| `reports.email.smtp.starttls` | `true` | `false` is refused unless `allow_plain` is `true`, the host is this machine (`localhost` or a loopback address) and there is no `username`. |
| `reports.email.smtp.allow_plain` | `false` | See `starttls`. |
| `reports.email.smtp.username`, `.password_ref` | none | Both or neither. `password_ref` names the password in the reports secret store (letters, digits, `_ . : -`); the password itself never goes in the file. |
| `reports.email.smtp.from` | none | The sender address; required with a host. |
| `reports.email.base_url` | none | The address users open eaxScada at (`http` or `https`, no user name, query or fragment). Without it, link messages are not sent. |
| `reports.email.attachments`, `reports.email.max_attachment` | `false`, `10MiB` | Attachment mode allowed, and its largest total. |
| `reports.email.allowed_domains` | none | Lower-case domains for external addresses (subdomains included). None: no external delivery. |
| `reports.folders.allowed` | none | Absolute folders without `..` that folder deliveries may write to, named by their last part. |
| `reports.fonts.extra_dirs` | none | Absolute folders of extra fonts (for printed names the bundled fonts cannot print). |
| `site.time_zone` | empty (the server's zone) | An IANA name (`Europe/Paris`) or `UTC`. |

Every `reports.*` key is read at start-up: change `config.yaml` and restart (`PUT /api/reports/settings` answers `501 RESTART_ONLY`). The **Settings** tab and `GET /api/reports/settings` (`reports_admin`) show the values in force; the SMTP password is stored with `PUT /api/reports/settings/secrets` `{"password"}` (`""` removes it; a person with `reports_admin`, never remote) and `GET` lists the stored names only.

Every `analytics.*` key is read at start-up too.
