diff --git a/openapi.yaml b/openapi.yaml
index fbf7267..4cb34ad 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -5282,6 +5282,131 @@ paths:
"404":
$ref: '#/components/responses/NotFound'
+ /story_categories/{id}/itemised_totals:
+ get:
+ tags: [Story Categories]
+ summary: Get a Survey's itemised totals
+ description: |
+ A Survey's results side by side across Projects or Albums, as on its Itemised totals page: one table per tracker
+ in the Survey (in question order), plus Verdict tables when the Survey has Verdicts on, with a row per Project, or per
+ Album adding up its Projects. Only Projects that use the Survey and that you may view are included. An answer is one
+ Contact's response in one Story. Pages run over tables.
+
+ Table kinds: `activity` (Activity change amount), `engagement` (Participation change amount), `achievement` (Yes and
+ Not ticked answers with percentages), `choice` (answers per choice, with percentages), `numerical` (sum and mean
+ average, with `unit`), `verdicts`, `verdicts_across_intervals` and `change_in_verdicts_across_intervals` (grouped by
+ Shared Interval in `column_groups`). Each row's `values` line up with the table's `columns`.
+ operationId: getStoryCategoryItemisedTotals
+ security: [{tokenAuth: []}]
+ parameters:
+ - name: id
+ in: path
+ required: true
+ schema:
+ type: integer
+ description: Survey (Story Category) ID
+ - name: project_ids
+ in: query
+ required: false
+ schema:
+ type: array
+ items:
+ type: integer
+ description: Projects to show, a row each, as project_ids[]=1&project_ids[]=2 or a JSON array. Leave out for every Project you may view that uses the Survey.
+ - name: album_ids
+ in: query
+ required: false
+ schema:
+ type: array
+ items:
+ type: integer
+ description: Albums to show, a row each adding up its Projects. Overrides project_ids.
+ - name: date_happened_from
+ in: query
+ required: false
+ schema:
+ type: string
+ format: date
+ description: Only Stories that happened on or after this date (YYYY-MM-DD).
+ - name: date_happened_to
+ in: query
+ required: false
+ schema:
+ type: string
+ format: date
+ description: Only Stories that happened on or before this date (YYYY-MM-DD).
+ - name: date_posted_from
+ in: query
+ required: false
+ schema:
+ type: string
+ format: date
+ description: Only Stories posted on or after this date (YYYY-MM-DD).
+ - name: date_posted_to
+ in: query
+ required: false
+ schema:
+ type: string
+ format: date
+ description: Only Stories posted on or before this date (YYYY-MM-DD).
+ - name: label_ids
+ in: query
+ required: false
+ schema:
+ type: array
+ items:
+ type: integer
+ description: Only Stories with one of these Labels.
+ - name: group_ids
+ in: query
+ required: false
+ schema:
+ type: array
+ items:
+ type: integer
+ description: Only answers from Contacts in one of these Contact Groups.
+ - name: scope
+ in: query
+ required: false
+ schema:
+ type: string
+ enum: [all, earliest, latest]
+ description: Which responses from each Contact count, by Date Posted (default all).
+ - $ref: '#/components/parameters/Page'
+ - $ref: '#/components/parameters/PerPage'
+ responses:
+ "200":
+ description: The tables, one per entry in data
+ content:
+ application/json:
+ example:
+ story_category_id: 12
+ story_category_name: Wellbeing check
+ row_type: project
+ rows: [{id: 7, name: Meadow}, {id: 3, name: Orchard}]
+ page: 1
+ page_size: 1
+ page_count: 1
+ total_count: 1
+ data:
+ - key: indicator-41
+ kind: choice
+ description: Choice tracker (Indicator of Scale type)
+ title: Confidence
+ metric_id: 41
+ unit: null
+ column_groups: null
+ columns: [{key: sub_ratio_5, title: Low}, {key: sub_ratio_6, title: High}]
+ rows:
+ - {id: 7, name: Meadow, values: [1.0, 3.0], percentages: [25, 75]}
+ - {id: 3, name: Orchard, values: [2.0, 2.0], percentages: [50, 50]}
+ "401":
+ $ref: '#/components/responses/Unauthorized'
+ "404":
+ $ref: '#/components/responses/NotFound'
+ "422":
+ $ref: '#/components/responses/UnprocessableEntity'
+
/project_story_categories:
get:
tags: [Project Story Categories]
diff --git a/server.js b/server.js
index eb38d7e..53f0974 100644
--- a/server.js
+++ b/server.js
@@ -2027,6 +2027,21 @@ function buildDocsPage() {
{ name: "project_id", type: "integer", required: true, desc: "Project the Survey Campaign belongs to" },
{ name: "page", type: "integer", required: false, desc: "Page number" }
], [{ code: "200", cls: "response-2xx", desc: "Total points per Contact per submission, grouped by beneficiary" }])}
+ ${endpointCard("GET", "/story_categories/{id}/itemised_totals", "Get a Survey's itemised totals", true, [
+ { name: "id", in: "path", type: "integer", required: true, desc: "Survey ID" },
+ { name: "project_ids", type: "integer[]", required: false, desc: "Projects to show, a row each. Leave out for every Project you may view that uses the Survey" },
+ { name: "album_ids", type: "integer[]", required: false, desc: "Albums to show, a row each adding up its Projects. Overrides project_ids" },
+ { name: "date_happened_from", type: "date", required: false, desc: "YYYY-MM-DD. Also date_happened_to, date_posted_from and date_posted_to" },
+ { name: "label_ids", type: "integer[]", required: false, desc: "Only Stories with one of these Labels" },
+ { name: "group_ids", type: "integer[]", required: false, desc: "Only answers from Contacts in one of these Contact Groups" },
+ { name: "scope", type: "string", required: false, desc: "all (default), earliest or latest: which responses from each Contact count" },
+ { name: "page", type: "integer", required: false, desc: "Page number (pages run over tables)" },
+ { name: "per_page", type: "integer", required: false, desc: "Tables per page (default 10, max 200)" }
+ ], [
+ { code: "200", cls: "response-2xx", desc: "row_type (project or album), rows, and one table per data entry: kind, title, columns, optional column_groups and unit, and rows of {id, name, values, percentages}" },
+ { code: "404", cls: "response-4xx", desc: "Survey not found, or not used on any Project you can view" },
+ { code: "422", cls: "response-4xx", desc: "Bad ids, date, scope or per_page" }
+ ], "The Survey's Itemised totals page as data: its results side by side, with a table per tracker (Activity change, Participation change, Achievement, Choice, Numerical) and, when Verdicts are on, Verdicts, Verdicts across intervals and Change in verdicts across intervals. An answer is one Contact's response in one Story.")}
${endpointCard("GET", "/project_story_categories", "List Survey Campaigns", true, [
{ name: "page", type: "integer", required: false, desc: "Page number" },
{ name: "per_page", type: "integer", required: false, desc: "Records per page" }