Skip to content

Commit 42f4fe4

Browse files
JakobMiesnerkpsherva
authored andcommitted
reference: stats: add document for order and document request stats
1 parent 80cecb9 commit 42f4fe4

File tree

7 files changed

+131
-33
lines changed

7 files changed

+131
-33
lines changed

docs/customize/configure.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ EXTEND_LOANS_SCHEDULE_TIME = datetime.time(2)
166166

167167
Enable or disable Self-Checkout feature.
168168

169+
### ILS_EXTEND_INDICES_WITH_STATS_ENABLED (True/False)
170+
171+
Enable or disable extended statistics fields in record indices. When enabled, additional computed fields are indexed for loans, acquisition orders, and document requests to support KPI reporting.
172+
173+
```python
174+
ILS_EXTEND_INDICES_WITH_STATS_ENABLED = True
175+
```
176+
177+
See the statistics reference for available fields: [Loans](../reference/stats/loan_stats.md#stats-fields), [Acquisition Orders](../reference/stats/acquisition_orders.md#stats-fields), [Document Requests](../reference/stats/document_requests.md#stats-fields). See the [v7 upgrade guide](../releases/version7/upgrade.md) for setup instructions.
178+
169179
## JSONSchemas Configuration
170180

171181
### JSONSCHEMAS_HOST
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Acquisition Order Statistics
2+
3+
See [Histogram Endpoints](histogram.md) for general parameter documentation.
4+
5+
```
6+
GET /api/acquisition/stats
7+
```
8+
9+
## Stats Fields
10+
11+
The following fields are added to acquisition orders specifically for statistics. They require [`ILS_EXTEND_INDICES_WITH_STATS_ENABLED`](../../customize/configure.md#ils_extend_indices_with_stats_enabled-truefalse) to be enabled.
12+
13+
| Field | Description |
14+
| ------------------------------------- | ------------------------------------------------------------------------- |
15+
| `stats.document_request_waiting_time` | Days between related literature request creation and order received date. |
16+
| `stats.order_processing_time` | Days between order creation and received date. |
17+
18+
## Example
19+
20+
Average order processing time by month:
21+
22+
```shell
23+
curl --get \
24+
--url 'https://127.0.0.1:5000/api/acquisition/stats' \
25+
--data-urlencode 'group_by=[{"field":"_created","interval":"1M"}]' \
26+
--data-urlencode 'metrics=[{"field":"stats.order_processing_time","aggregation":"avg"}]' \
27+
--header 'authorization: Bearer <auth token>'
28+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Document Request Statistics
2+
3+
See [Histogram Endpoints](histogram.md) for general parameter documentation.
4+
5+
```
6+
GET /api/document-requests/stats
7+
```
8+
9+
## Stats Fields
10+
11+
The following fields are added to document requests specifically for statistics. They require [`ILS_EXTEND_INDICES_WITH_STATS_ENABLED`](../../customize/configure.md#ils_extend_indices_with_stats_enabled-truefalse) to be enabled.
12+
13+
| Field | Description |
14+
| ------------------------------- | ------------------------------------------------------------------------------------ |
15+
| `stats.provider_creation_delay` | Days between document request creation and associated order/borrowing request creation. |
16+
17+
## Example
18+
19+
Average time to create purchase order or borrowing request:
20+
21+
```shell
22+
curl --get \
23+
--url 'https://127.0.0.1:5000/api/document-requests/stats' \
24+
--data-urlencode 'group_by=[{"field":"_created","interval":"1M"}]' \
25+
--data-urlencode 'metrics=[{"field":"stats.provider_creation_delay","aggregation":"avg"}]' \
26+
--header 'authorization: Bearer <auth token>'
27+
```

docs/reference/stats/histogram.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Histogram Endpoints
2+
3+
Several record types in InvenioILS expose a `/stats` endpoint for flexible aggregation queries. These endpoints provide real-time aggregation of records from their respective indices, allowing flexible grouping by any field and computation of statistical metrics on numeric fields.
4+
5+
Each response returns the count for the records matching the filter and grouping criteria under the field `doc_count` and the requested aggregated metrics.
6+
7+
## Available Endpoints
8+
9+
| Endpoint | Description |
10+
| -------------------------------- | ------------------------------- |
11+
| `/api/circulation/loans/stats` | Loan aggregations |
12+
| `/api/acquisition/stats` | Purchase order aggregations |
13+
| `/api/document-requests/stats` | Literature request aggregations |
14+
15+
## Parameters
16+
17+
| Name | Type | Location | Required | Description |
18+
| ---------- | ---------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19+
| `group_by` | JSON array | query || Array of grouping definitions. Each item is an object with `field` (required) and `interval` (required for date fields). See [format details below](#group_by-field-format). |
20+
| `metrics` | JSON array | query || Array of metric definitions. Each item is an object with `field` (required) and `aggregation` (required). See [format details below](#metrics-field-format). |
21+
| `q` | string | query || Search query string for filtering records (uses standard search syntax). |
22+
23+
### `group_by` Field Format
24+
25+
Each grouping object can be:
26+
27+
- **Term field**: `{"field": "field_name"}` - Groups by exact values (e.g., `state`, `patron_pid`)
28+
- **Date field**: `{"field": "date_field", "interval": "time_interval"}` - Groups by time intervals
29+
- Available intervals for date fields: `1d` (day), `1w` (week), `1M` (month), `1q` (quarter), `1y` (year)
30+
31+
### `metrics` Field Format
32+
33+
Each metrics object is:
34+
35+
- `{"field": "field_name", "aggregation": "aggregation_type"}`
36+
- Available aggregation types: `avg` (average), `sum` (total), `min` (minimum), `max` (maximum), `median` (50th percentile)
37+
38+
## Example
39+
40+
Group by month with an average metric:
41+
42+
```shell
43+
curl --get \
44+
--url 'https://127.0.0.1:5000/api/circulation/loans/stats' \
45+
--data-urlencode 'group_by=[{"field":"start_date","interval":"1M"}]' \
46+
--data-urlencode 'metrics=[{"field":"extension_count","aggregation":"avg"}]' \
47+
--header 'content-type: application/json' \
48+
--header 'authorization: Bearer <auth token>'
49+
```

docs/reference/stats/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
InvenioILS exposes statistics through REST API endpoints for analyzing library operations.
44

5+
Several record types (loans, acquisition orders, document requests) share a common [histogram endpoint](histogram.md) pattern for flexible aggregation queries.
6+
57
## Available Statistics
68

9+
- [Histogram Endpoints](histogram.md) - Flexible aggregation queries for loans, orders, and document requests
710
- [Loan Statistics](loan_stats.md) - Loan histogram aggregations and transition tracking
11+
- [Acquisition Order Statistics](acquisition_orders.md) - Purchase order timing and workflow metrics
12+
- [Document Request Statistics](document_requests.md) - Literature request fulfillment metrics
813
- [Record Changes](record_changes.md) - Track insertions, updates, and deletions per record type

docs/reference/stats/loan_stats.md

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,21 @@ InvenioILS provides two complementary endpoints for analyzing loan data:
88

99
## Loan Histogram
1010

11-
The Loan Histogram endpoint provides real-time aggregation of loan records from the loans index.
12-
It allows flexible grouping by any field and computation of statistical metrics on numeric fields.
13-
Each response returns the count for the loans matching the filter and grouping criteria under the field `doc_count` and the requested aggregated metrics.
14-
15-
16-
### Endpoint
11+
See [Histogram Endpoints](histogram.md) for general parameter documentation.
1712

1813
```
1914
GET /api/circulation/loans/stats
2015
```
2116

22-
### Parameters
23-
24-
| Name | Type | Location | Required | Description |
25-
| ---------- | ---------- | -------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26-
| `group_by` | JSON array | query || Array of grouping definitions. Each item is an object with `field` (required) and `interval` (required for date fields). See [format details below](#group_by-field-format). |
27-
| `metrics` | JSON array | query || Array of metric definitions. Each item is an object with `field` (required) and `aggregation` (required). See [format details below](#metrics-field-format). |
28-
| `q` | string | query || Search query string for filtering loans (uses standard search syntax). |
29-
30-
#### `group_by` Field Format
31-
32-
Each grouping object can be:
33-
34-
- **Term field**: `{"field": "field_name"}` - Groups by exact values (e.g., `state`, `patron_pid`)
35-
- **Date field**: `{"field": "date_field", "interval": "time_interval"}` - Groups by time intervals
36-
- Available intervals for date fields: `1d` (day), `1w` (week), `1M` (month), `1q` (quarter), `1y` (year)
37-
38-
#### `metrics` Field Format
39-
40-
Each metrics object is:
17+
### Stats Fields
4118

42-
- `{"field": "field_name", "aggregation": "aggregation_type"}`
43-
- Available aggregation types: `avg` (average), `sum` (total), `min` (minimum), `max` (maximum), `median` (50th percentile)
19+
The following fields are added to loans specifically for statistics. They require [`ILS_EXTEND_INDICES_WITH_STATS_ENABLED`](../../customize/configure.md#ils_extend_indices_with_stats_enabled-truefalse) to be enabled.
4420

45-
!!! tip "Discovering available fields"
46-
To see all available loan fields for grouping and metrics, query the loans endpoint:
47-
```
48-
GET /api/circulation/loans
49-
```
21+
| Field | Description |
22+
| ------------------------------------------------ | --------------------------------------------------------------- |
23+
| `extra_data.stats.available_items_during_request` | Whether loanable items were available when the loan was requested. |
24+
| `extra_data.stats.loan_duration` | Duration of the loan in days (for completed loans). |
25+
| `extra_data.stats.waiting_time` | Days between request creation and checkout. |
5026

5127
### Examples
5228

mkdocs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ nav:
7474
- Provider API: reference/api/provider.md
7575
- Statistics:
7676
- Overview: reference/stats/index.md
77-
- Record Changes: reference/stats/record_changes.md
77+
- Histogram Endpoints: reference/stats/histogram.md
7878
- Loan Statistics: reference/stats/loan_stats.md
79+
- Acquisition Orders: reference/stats/acquisition_orders.md
80+
- Document Requests: reference/stats/document_requests.md
81+
- Record Changes: reference/stats/record_changes.md
7982
- Features:
8083
- Fast, Responsive User Interface: features/user_interface.md
8184
- Scalable, Optimised. Fast Search: features/search.md

0 commit comments

Comments
 (0)