@pie-qti/assessment-player 1.0.0-beta.4 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -7
- package/dist/components/createPlayerConnection.svelte.d.ts +90 -0
- package/dist/components/createPlayerConnection.svelte.js +151 -0
- package/dist/components/createPlayerConnection.svelte.js.map +1 -0
- package/dist/components/displaySettings.svelte.d.ts +23 -0
- package/dist/components/displaySettings.svelte.js +40 -0
- package/dist/components/displaySettings.svelte.js.map +1 -0
- package/dist/components/srOnly.d.ts +29 -0
- package/dist/components/srOnly.js +55 -0
- package/dist/components/srOnly.js.map +1 -0
- package/dist/components/submitDialogAction.d.ts +25 -0
- package/dist/components/submitDialogAction.js +89 -0
- package/dist/components/submitDialogAction.js.map +1 -0
- package/dist/core/AssessmentPlayer.d.ts +1102 -53
- package/dist/core/AssessmentPlayer.js +2836 -457
- package/dist/core/AssessmentPlayer.js.map +1 -1
- package/dist/core/AssessmentSessionCoordinator.d.ts +76 -7
- package/dist/core/AssessmentSessionCoordinator.js +185 -10
- package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
- package/dist/core/AutosaveManager.d.ts +104 -0
- package/dist/core/AutosaveManager.js +181 -0
- package/dist/core/AutosaveManager.js.map +1 -0
- package/dist/core/ItemSessionController.d.ts +17 -26
- package/dist/core/ItemSessionController.js +33 -73
- package/dist/core/ItemSessionController.js.map +1 -1
- package/dist/core/NavigationManager.d.ts +18 -50
- package/dist/core/NavigationManager.js +21 -83
- package/dist/core/NavigationManager.js.map +1 -1
- package/dist/core/TimeManager.d.ts +62 -16
- package/dist/core/TimeManager.js +148 -57
- package/dist/core/TimeManager.js.map +1 -1
- package/dist/core/autosave.d.ts +44 -0
- package/dist/core/autosave.js +46 -0
- package/dist/core/autosave.js.map +1 -0
- package/dist/core/deliveryStructure.d.ts +54 -0
- package/dist/core/deliveryStructure.js +72 -0
- package/dist/core/deliveryStructure.js.map +1 -0
- package/dist/core/errors.d.ts +116 -0
- package/dist/core/errors.js +77 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/exitBoundaries.d.ts +64 -0
- package/dist/core/exitBoundaries.js +98 -0
- package/dist/core/exitBoundaries.js.map +1 -0
- package/dist/core/feedback.d.ts +46 -0
- package/dist/core/feedback.js +47 -0
- package/dist/core/feedback.js.map +1 -0
- package/dist/core/formatTime.d.ts +8 -0
- package/dist/core/formatTime.js +20 -0
- package/dist/core/formatTime.js.map +1 -0
- package/dist/core/index.d.ts +7 -4
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/navigationPolicy.d.ts +46 -0
- package/dist/core/navigationPolicy.js +66 -0
- package/dist/core/navigationPolicy.js.map +1 -0
- package/dist/core/pause.d.ts +58 -0
- package/dist/core/pause.js +101 -0
- package/dist/core/pause.js.map +1 -0
- package/dist/core/playerEvents.d.ts +51 -0
- package/dist/core/playerEvents.js +66 -0
- package/dist/core/playerEvents.js.map +1 -0
- package/dist/core/reviewState.d.ts +81 -0
- package/dist/core/reviewState.js +113 -0
- package/dist/core/reviewState.js.map +1 -0
- package/dist/core/reviewViews.d.ts +43 -0
- package/dist/core/reviewViews.js +88 -0
- package/dist/core/reviewViews.js.map +1 -0
- package/dist/core/scopeLocks.d.ts +36 -0
- package/dist/core/scopeLocks.js +78 -0
- package/dist/core/scopeLocks.js.map +1 -0
- package/dist/core/sessionRecords.d.ts +31 -0
- package/dist/core/sessionRecords.js +74 -0
- package/dist/core/sessionRecords.js.map +1 -0
- package/dist/core/submissionPolicy.d.ts +65 -0
- package/dist/core/submissionPolicy.js +71 -0
- package/dist/core/submissionPolicy.js.map +1 -0
- package/dist/core/templateDefaults.d.ts +26 -0
- package/dist/core/templateDefaults.js +54 -0
- package/dist/core/templateDefaults.js.map +1 -0
- package/dist/core/testStructure.d.ts +118 -3
- package/dist/core/testStructure.js +255 -6
- package/dist/core/testStructure.js.map +1 -1
- package/dist/core/timePolicy.d.ts +40 -0
- package/dist/core/timePolicy.js +106 -0
- package/dist/core/timePolicy.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts +64 -101
- package/dist/integration/ReferenceBackendAdapter.js +214 -1033
- package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
- package/dist/integration/api-contract.d.ts +175 -10
- package/dist/integration/api-contract.js.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +56 -5
- package/dist/integration/assessment-item-scorer.js +116 -13
- package/dist/integration/assessment-item-scorer.js.map +1 -1
- package/dist/integration/index.d.ts +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/qti-test-parser.d.ts +44 -0
- package/dist/integration/qti-test-parser.js +558 -0
- package/dist/integration/qti-test-parser.js.map +1 -0
- package/dist/integration/session-store.d.ts +54 -0
- package/dist/integration/session-store.js +75 -0
- package/dist/integration/session-store.js.map +1 -0
- package/dist/integration/test-navigation.d.ts +23 -0
- package/dist/integration/test-navigation.js +32 -0
- package/dist/integration/test-navigation.js.map +1 -0
- package/dist/integration/toSectionComposition.js +8 -1
- package/dist/integration/toSectionComposition.js.map +1 -1
- package/dist/reporting/index.d.ts +3 -0
- package/dist/reporting/index.js +3 -0
- package/dist/reporting/index.js.map +1 -0
- package/dist/reporting/inferBaseType.d.ts +13 -0
- package/dist/reporting/inferBaseType.js +26 -0
- package/dist/reporting/inferBaseType.js.map +1 -0
- package/dist/reporting/serializeAssessmentResult.d.ts +27 -0
- package/dist/reporting/serializeAssessmentResult.js +377 -0
- package/dist/reporting/serializeAssessmentResult.js.map +1 -0
- package/dist/reporting/toAssessmentResultXml.d.ts +39 -0
- package/dist/reporting/toAssessmentResultXml.js +304 -0
- package/dist/reporting/toAssessmentResultXml.js.map +1 -0
- package/dist/reporting/types.d.ts +85 -0
- package/dist/reporting/types.js +8 -0
- package/dist/reporting/types.js.map +1 -0
- package/dist/types/index.d.ts +96 -9
- package/dist/types/index.js.map +1 -1
- package/package.json +19 -13
- package/dist/core/StatePersistenceManager.d.ts +0 -125
- package/dist/core/StatePersistenceManager.js +0 -268
- package/dist/core/StatePersistenceManager.js.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts +0 -114
- package/dist/utils/PerformanceMonitor.js +0 -172
- package/dist/utils/PerformanceMonitor.js.map +0 -1
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { durationSeconds } from '@pie-qti/qti-processing';
|
|
2
|
+
import { inferBaseType } from './inferBaseType.js';
|
|
3
|
+
/**
|
|
4
|
+
* The QTI Results Reporting namespaces and schema locations, as the 1EdTech schemas declare them:
|
|
5
|
+
* `imsqti_result_v2p2.xsd` (QTI 2.2) and `imsqti_resultv3p0_v1p0.xsd` (QTI 3.0). Both versions use
|
|
6
|
+
* the same camelCase element and attribute names.
|
|
7
|
+
*/
|
|
8
|
+
export const ASSESSMENT_RESULT_NAMESPACES = {
|
|
9
|
+
'2.2': {
|
|
10
|
+
namespace: 'http://www.imsglobal.org/xsd/imsqti_result_v2p2',
|
|
11
|
+
schemaLocation: 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_result_v2p2.xsd',
|
|
12
|
+
},
|
|
13
|
+
'3.0': {
|
|
14
|
+
namespace: 'http://www.imsglobal.org/xsd/imsqti_result_v3p0',
|
|
15
|
+
schemaLocation: 'https://purl.imsglobal.org/spec/qti/v3p0/schema/xsd/imsqti_resultv3p0_v1p0.xsd',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
/** The report cannot be written as a schema-valid `assessmentResult` of the requested version. */
|
|
19
|
+
export class AssessmentResultSerializationError extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(`[QTI results] ${message}`);
|
|
22
|
+
this.name = 'AssessmentResultSerializationError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const BASE_TYPES = new Set([
|
|
26
|
+
'boolean',
|
|
27
|
+
'directedPair',
|
|
28
|
+
'duration',
|
|
29
|
+
'file',
|
|
30
|
+
'float',
|
|
31
|
+
'identifier',
|
|
32
|
+
'integer',
|
|
33
|
+
'pair',
|
|
34
|
+
'point',
|
|
35
|
+
'string',
|
|
36
|
+
'uri',
|
|
37
|
+
]);
|
|
38
|
+
const CARDINALITIES = new Set(['single', 'multiple', 'ordered', 'record']);
|
|
39
|
+
const SESSION_STATUSES = {
|
|
40
|
+
'2.2': new Set(['final', 'initial', 'pendingResponseProcessing', 'pendingSubmission']),
|
|
41
|
+
'3.0': new Set(['final', 'initial', 'pendingExternalScoring', 'pendingResponseProcessing', 'pendingSubmission']),
|
|
42
|
+
};
|
|
43
|
+
const VIEWS = new Set(['author', 'candidate', 'proctor', 'scorer', 'testConstructor', 'tutor']);
|
|
44
|
+
/** XML 1.0 (5th edition) NCName: a Name without colons. */
|
|
45
|
+
const NAME_START = 'A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D' +
|
|
46
|
+
'\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\u{10000}-\\u{EFFFF}';
|
|
47
|
+
const NCNAME = new RegExp(`^[${NAME_START}][${NAME_START}\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$`, 'u');
|
|
48
|
+
/**
|
|
49
|
+
* Writes a QTI Results Reporting `assessmentResult` document. Every value and attribute is
|
|
50
|
+
* XML-escaped (characters XML 1.0 cannot carry become U+FFFD); identifiers the version's schema
|
|
51
|
+
* types as NCName, an unknown base type or cardinality, a session status the version lacks, or an
|
|
52
|
+
* invalid date throw an `AssessmentResultSerializationError`. Durations are written as seconds,
|
|
53
|
+
* the xsd:double form QTI defines.
|
|
54
|
+
*/
|
|
55
|
+
export function serializeAssessmentResult(report, options) {
|
|
56
|
+
const { version } = options;
|
|
57
|
+
const target = ASSESSMENT_RESULT_NAMESPACES[version];
|
|
58
|
+
if (!target)
|
|
59
|
+
throw new AssessmentResultSerializationError(`Unsupported results version "${String(version)}"`);
|
|
60
|
+
const out = new XmlWriter();
|
|
61
|
+
out.line('<?xml version="1.0" encoding="UTF-8"?>');
|
|
62
|
+
const rootAttributes = [['xmlns', target.namespace]];
|
|
63
|
+
if (options.schemaLocation !== false) {
|
|
64
|
+
rootAttributes.push(['xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'], ['xsi:schemaLocation', `${target.namespace} ${target.schemaLocation}`]);
|
|
65
|
+
}
|
|
66
|
+
out.open('assessmentResult', rootAttributes);
|
|
67
|
+
const { sourcedId, sessionIdentifiers = [] } = report.context;
|
|
68
|
+
const contextAttributes = [
|
|
69
|
+
['sourcedId', sourcedId === undefined ? undefined : ncName(sourcedId, 'context sourcedId')],
|
|
70
|
+
];
|
|
71
|
+
if (sessionIdentifiers.length === 0) {
|
|
72
|
+
out.empty('context', contextAttributes);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
out.open('context', contextAttributes);
|
|
76
|
+
for (const session of sessionIdentifiers) {
|
|
77
|
+
out.empty('sessionIdentifier', [
|
|
78
|
+
['sourceID', required(session.sourceID, 'sessionIdentifier sourceID')],
|
|
79
|
+
['identifier', identifierFor(version, session.identifier, 'sessionIdentifier identifier')],
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
out.close('context');
|
|
83
|
+
}
|
|
84
|
+
if (report.testResult) {
|
|
85
|
+
const test = report.testResult;
|
|
86
|
+
const attributes = [
|
|
87
|
+
['identifier', identifierFor(version, test.identifier, 'testResult identifier')],
|
|
88
|
+
['datestamp', dateTime(test.datestamp, 'testResult datestamp')],
|
|
89
|
+
];
|
|
90
|
+
writeVariablesElement(out, 'testResult', attributes, test.variables, version);
|
|
91
|
+
}
|
|
92
|
+
for (const item of report.itemResults)
|
|
93
|
+
writeItemResult(out, item, version);
|
|
94
|
+
out.close('assessmentResult');
|
|
95
|
+
return out.toString();
|
|
96
|
+
}
|
|
97
|
+
function writeItemResult(out, item, version) {
|
|
98
|
+
if (!SESSION_STATUSES[version].has(item.sessionStatus)) {
|
|
99
|
+
throw new AssessmentResultSerializationError(`itemResult "${item.identifier}" has sessionStatus "${item.sessionStatus}", which QTI ${version} results do not define`);
|
|
100
|
+
}
|
|
101
|
+
if (item.sequenceIndex !== undefined && !Number.isInteger(item.sequenceIndex)) {
|
|
102
|
+
throw new AssessmentResultSerializationError(`itemResult "${item.identifier}" sequenceIndex must be an integer, not ${item.sequenceIndex}`);
|
|
103
|
+
}
|
|
104
|
+
const attributes = [
|
|
105
|
+
['identifier', identifierFor(version, item.identifier, 'itemResult identifier')],
|
|
106
|
+
['sequenceIndex', item.sequenceIndex === undefined ? undefined : String(item.sequenceIndex)],
|
|
107
|
+
['datestamp', dateTime(item.datestamp, `itemResult "${item.identifier}" datestamp`)],
|
|
108
|
+
['sessionStatus', item.sessionStatus],
|
|
109
|
+
];
|
|
110
|
+
writeVariablesElement(out, 'itemResult', attributes, item.variables, version, item.candidateComment);
|
|
111
|
+
}
|
|
112
|
+
function writeVariablesElement(out, name, attributes, variables, version, candidateComment) {
|
|
113
|
+
const written = variables.filter((variable) => variable.kind !== 'context' || version === '3.0');
|
|
114
|
+
if (written.length === 0 && candidateComment === undefined) {
|
|
115
|
+
out.empty(name, attributes);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
out.open(name, attributes);
|
|
119
|
+
for (const variable of written)
|
|
120
|
+
writeVariable(out, variable);
|
|
121
|
+
if (candidateComment !== undefined)
|
|
122
|
+
out.text('candidateComment', candidateComment, { normalized: false });
|
|
123
|
+
out.close(name);
|
|
124
|
+
}
|
|
125
|
+
function writeVariable(out, variable) {
|
|
126
|
+
const where = `variable "${variable.identifier}"`;
|
|
127
|
+
if (!CARDINALITIES.has(variable.cardinality)) {
|
|
128
|
+
throw new AssessmentResultSerializationError(`${where} has unknown cardinality "${variable.cardinality}"`);
|
|
129
|
+
}
|
|
130
|
+
const record = variable.cardinality === 'record';
|
|
131
|
+
if (!record && (!variable.baseType || !BASE_TYPES.has(variable.baseType))) {
|
|
132
|
+
throw new AssessmentResultSerializationError(`${where} has unknown baseType "${String(variable.baseType)}"`);
|
|
133
|
+
}
|
|
134
|
+
const attributes = [
|
|
135
|
+
['identifier', ncName(variable.identifier, `${where} identifier`)],
|
|
136
|
+
['cardinality', variable.cardinality],
|
|
137
|
+
['baseType', record ? undefined : variable.baseType],
|
|
138
|
+
];
|
|
139
|
+
switch (variable.kind) {
|
|
140
|
+
case 'response': {
|
|
141
|
+
if (variable.choiceSequence?.length) {
|
|
142
|
+
attributes.push([
|
|
143
|
+
'choiceSequence',
|
|
144
|
+
variable.choiceSequence.map((id) => ncName(id, `${where} choiceSequence`)).join(' '),
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
out.open('responseVariable', attributes);
|
|
148
|
+
const correct = valueElements(variable.correctResponse, variable, where);
|
|
149
|
+
if (correct.length > 0) {
|
|
150
|
+
out.open('correctResponse');
|
|
151
|
+
for (const value of correct)
|
|
152
|
+
out.text('value', value.text, { attributes: value.attributes });
|
|
153
|
+
out.close('correctResponse');
|
|
154
|
+
}
|
|
155
|
+
writeValues(out, 'candidateResponse', valueElements(variable.value, variable, where));
|
|
156
|
+
out.close('responseVariable');
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
case 'outcome': {
|
|
160
|
+
const view = (variable.view ?? []).filter((role) => VIEWS.has(role));
|
|
161
|
+
attributes.push(['view', view.length > 0 ? view.join(' ') : undefined], ['interpretation', variable.interpretation], ['longInterpretation', variable.longInterpretation], ['normalMaximum', optionalDouble(variable.normalMaximum)], ['normalMinimum', optionalDouble(variable.normalMinimum)], ['masteryValue', optionalDouble(variable.masteryValue)]);
|
|
162
|
+
writeValues(out, 'outcomeVariable', valueElements(variable.value, variable, where), attributes);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
case 'template':
|
|
166
|
+
writeValues(out, 'templateVariable', valueElements(variable.value, variable, where), attributes);
|
|
167
|
+
return;
|
|
168
|
+
case 'context':
|
|
169
|
+
writeValues(out, 'contextVariable', valueElements(variable.value, variable, where), attributes);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function writeValues(out, name, values, attributes = []) {
|
|
174
|
+
if (values.length === 0) {
|
|
175
|
+
out.empty(name, attributes);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
out.open(name, attributes);
|
|
179
|
+
for (const value of values)
|
|
180
|
+
out.text('value', value.text, { attributes: value.attributes });
|
|
181
|
+
out.close(name);
|
|
182
|
+
}
|
|
183
|
+
/** The `value` elements of a variable value: none for NULL, one per member of a container. */
|
|
184
|
+
function valueElements(raw, variable, where) {
|
|
185
|
+
if (raw === null || raw === undefined)
|
|
186
|
+
return [];
|
|
187
|
+
if (variable.cardinality === 'record')
|
|
188
|
+
return recordValueElements(raw, where);
|
|
189
|
+
const baseType = variable.baseType;
|
|
190
|
+
const members = variable.cardinality === 'single' ? [raw] : Array.isArray(raw) ? raw : [raw];
|
|
191
|
+
const values = [];
|
|
192
|
+
for (const member of members) {
|
|
193
|
+
const text = formatValue(baseType, member);
|
|
194
|
+
if (text !== null)
|
|
195
|
+
values.push({ text });
|
|
196
|
+
}
|
|
197
|
+
return values;
|
|
198
|
+
}
|
|
199
|
+
/** A record's fields, each as a `value` carrying its fieldIdentifier and baseType. */
|
|
200
|
+
function recordValueElements(raw, where) {
|
|
201
|
+
if (typeof raw !== 'object' || Array.isArray(raw))
|
|
202
|
+
return [];
|
|
203
|
+
const values = [];
|
|
204
|
+
for (const [fieldIdentifier, field] of Object.entries(raw)) {
|
|
205
|
+
// A serialized field is { baseType, cardinality, value }; a public one is the plain value.
|
|
206
|
+
const serialized = field !== null && typeof field === 'object' && !Array.isArray(field) && 'value' in field;
|
|
207
|
+
const fieldValue = serialized ? field.value : field;
|
|
208
|
+
if (fieldValue === null || fieldValue === undefined || Array.isArray(fieldValue))
|
|
209
|
+
continue;
|
|
210
|
+
const declared = serialized ? field.baseType : undefined;
|
|
211
|
+
const baseType = typeof declared === 'string' && BASE_TYPES.has(declared) ? declared : inferBaseType(fieldValue);
|
|
212
|
+
const text = formatValue(baseType, fieldValue);
|
|
213
|
+
if (text === null)
|
|
214
|
+
continue;
|
|
215
|
+
values.push({
|
|
216
|
+
text,
|
|
217
|
+
attributes: [
|
|
218
|
+
['fieldIdentifier', ncName(fieldIdentifier, `${where} field identifier`)],
|
|
219
|
+
['baseType', baseType],
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return values;
|
|
224
|
+
}
|
|
225
|
+
/** A single value in its QTI lexical form, or null when there is nothing to write. */
|
|
226
|
+
function formatValue(baseType, value) {
|
|
227
|
+
if (value === null || value === undefined)
|
|
228
|
+
return null;
|
|
229
|
+
switch (baseType) {
|
|
230
|
+
case 'boolean':
|
|
231
|
+
if (typeof value === 'boolean')
|
|
232
|
+
return value ? 'true' : 'false';
|
|
233
|
+
if (value === 'true' || value === '1' || value === 1)
|
|
234
|
+
return 'true';
|
|
235
|
+
if (value === 'false' || value === '0' || value === 0)
|
|
236
|
+
return 'false';
|
|
237
|
+
return String(value);
|
|
238
|
+
case 'integer':
|
|
239
|
+
return typeof value === 'number' ? formatInteger(value) : String(value).trim();
|
|
240
|
+
case 'float':
|
|
241
|
+
return typeof value === 'number' ? formatDouble(value) : String(value).trim();
|
|
242
|
+
case 'duration': {
|
|
243
|
+
// QTI durations are seconds, written as xsd:double.
|
|
244
|
+
const seconds = durationSeconds(value);
|
|
245
|
+
return seconds === null ? String(value).trim() : formatDouble(seconds);
|
|
246
|
+
}
|
|
247
|
+
case 'pair':
|
|
248
|
+
case 'directedPair':
|
|
249
|
+
return String(value).trim().split(/\s+/).join(' ');
|
|
250
|
+
case 'point':
|
|
251
|
+
if (typeof value === 'object' && value !== null && 'x' in value && 'y' in value) {
|
|
252
|
+
const { x, y } = value;
|
|
253
|
+
return `${String(x)} ${String(y)}`;
|
|
254
|
+
}
|
|
255
|
+
return String(value).trim().split(/\s+/).join(' ');
|
|
256
|
+
case 'file':
|
|
257
|
+
if (typeof value === 'object') {
|
|
258
|
+
const file = value;
|
|
259
|
+
if (typeof file.dataUrl === 'string' && file.dataUrl)
|
|
260
|
+
return file.dataUrl;
|
|
261
|
+
if (typeof file.name === 'string' && file.name)
|
|
262
|
+
return file.name;
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
return String(value);
|
|
266
|
+
default:
|
|
267
|
+
return typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/** xsd:double: the shortest round-tripping decimal, INF, -INF or NaN. */
|
|
271
|
+
function formatDouble(value) {
|
|
272
|
+
if (Number.isNaN(value))
|
|
273
|
+
return 'NaN';
|
|
274
|
+
if (value === Number.POSITIVE_INFINITY)
|
|
275
|
+
return 'INF';
|
|
276
|
+
if (value === Number.NEGATIVE_INFINITY)
|
|
277
|
+
return '-INF';
|
|
278
|
+
return String(value);
|
|
279
|
+
}
|
|
280
|
+
function formatInteger(value) {
|
|
281
|
+
if (!Number.isFinite(value))
|
|
282
|
+
return formatDouble(value);
|
|
283
|
+
const integer = Math.trunc(value);
|
|
284
|
+
return Number.isSafeInteger(integer) ? String(integer) : BigInt(integer).toString();
|
|
285
|
+
}
|
|
286
|
+
function optionalDouble(value) {
|
|
287
|
+
return value === undefined ? undefined : formatDouble(value);
|
|
288
|
+
}
|
|
289
|
+
function ncName(value, what) {
|
|
290
|
+
if (!NCNAME.test(value)) {
|
|
291
|
+
throw new AssessmentResultSerializationError(`${what} "${value}" is not an NCName`);
|
|
292
|
+
}
|
|
293
|
+
return value;
|
|
294
|
+
}
|
|
295
|
+
/** Item, test and session identifiers are NCNames in QTI 3.0 results, normalized strings in 2.2. */
|
|
296
|
+
function identifierFor(version, value, what) {
|
|
297
|
+
return version === '3.0' ? ncName(value, what) : required(value, what);
|
|
298
|
+
}
|
|
299
|
+
function required(value, what) {
|
|
300
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
301
|
+
throw new AssessmentResultSerializationError(`${what} is required`);
|
|
302
|
+
}
|
|
303
|
+
return value;
|
|
304
|
+
}
|
|
305
|
+
function dateTime(value, what) {
|
|
306
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
307
|
+
if (Number.isNaN(date.getTime())) {
|
|
308
|
+
throw new AssessmentResultSerializationError(`${what} "${String(value)}" is not a valid date-time`);
|
|
309
|
+
}
|
|
310
|
+
return date.toISOString();
|
|
311
|
+
}
|
|
312
|
+
/** Characters XML 1.0 can carry: tab, newline, carriage return, and #x20 upward minus surrogates and #xFFFE/#xFFFF. */
|
|
313
|
+
function xmlCharacters(value) {
|
|
314
|
+
let out = '';
|
|
315
|
+
for (const character of value) {
|
|
316
|
+
const code = character.codePointAt(0);
|
|
317
|
+
const allowed = code === 0x9 ||
|
|
318
|
+
code === 0xa ||
|
|
319
|
+
code === 0xd ||
|
|
320
|
+
(code >= 0x20 && code <= 0xd7ff) ||
|
|
321
|
+
(code >= 0xe000 && code <= 0xfffd) ||
|
|
322
|
+
code >= 0x10000;
|
|
323
|
+
out += allowed ? character : '\uFFFD';
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Escapes markup characters. `normalized` text (attributes, and `value`, an xs:normalizedString)
|
|
329
|
+
* also writes tab and newline as character references, so a consumer that does not normalize
|
|
330
|
+
* whitespace reads the original; a carriage return is always a reference, or XML end-of-line
|
|
331
|
+
* handling would drop it.
|
|
332
|
+
*/
|
|
333
|
+
function escapeXml(value, { normalized, attribute }) {
|
|
334
|
+
let escaped = xmlCharacters(value)
|
|
335
|
+
.replace(/&/g, '&')
|
|
336
|
+
.replace(/</g, '<')
|
|
337
|
+
.replace(/>/g, '>')
|
|
338
|
+
.replace(/\r/g, ' ');
|
|
339
|
+
if (attribute)
|
|
340
|
+
escaped = escaped.replace(/"/g, '"');
|
|
341
|
+
if (normalized || attribute)
|
|
342
|
+
escaped = escaped.replace(/\t/g, '	').replace(/\n/g, ' ');
|
|
343
|
+
return escaped;
|
|
344
|
+
}
|
|
345
|
+
class XmlWriter {
|
|
346
|
+
constructor() {
|
|
347
|
+
this.lines = [];
|
|
348
|
+
this.depth = 0;
|
|
349
|
+
}
|
|
350
|
+
line(text) {
|
|
351
|
+
this.lines.push(`${' '.repeat(this.depth)}${text}`);
|
|
352
|
+
}
|
|
353
|
+
open(name, attributes = []) {
|
|
354
|
+
this.line(`<${name}${formatAttributes(attributes)}>`);
|
|
355
|
+
this.depth++;
|
|
356
|
+
}
|
|
357
|
+
close(name) {
|
|
358
|
+
this.depth--;
|
|
359
|
+
this.line(`</${name}>`);
|
|
360
|
+
}
|
|
361
|
+
empty(name, attributes = []) {
|
|
362
|
+
this.line(`<${name}${formatAttributes(attributes)}/>`);
|
|
363
|
+
}
|
|
364
|
+
text(name, value, { attributes = [], normalized = true } = {}) {
|
|
365
|
+
this.line(`<${name}${formatAttributes(attributes)}>${escapeXml(value, { normalized, attribute: false })}</${name}>`);
|
|
366
|
+
}
|
|
367
|
+
toString() {
|
|
368
|
+
return `${this.lines.join('\n')}\n`;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function formatAttributes(attributes) {
|
|
372
|
+
return attributes
|
|
373
|
+
.filter((attribute) => attribute[1] !== undefined)
|
|
374
|
+
.map(([name, value]) => ` ${name}="${escapeXml(value, { normalized: true, attribute: true })}"`)
|
|
375
|
+
.join('');
|
|
376
|
+
}
|
|
377
|
+
//# sourceMappingURL=serializeAssessmentResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializeAssessmentResult.js","sourceRoot":"","sources":["../../src/reporting/serializeAssessmentResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,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,IAAI,GAAG,gBAAgB,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;IACtH,CAAC;IAED,QAAQ;QACP,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACrC,CAAC;CACD;AAED,SAAS,gBAAgB,CAAC,UAA+C;IACxE,OAAO,UAAU;SACf,MAAM,CAAC,CAAC,SAAS,EAAiC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SAChF,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,KAAK,SAAS,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC;SAC/F,IAAI,CAAC,EAAE,CAAC,CAAC;AACZ,CAAC","sourcesContent":["import { durationSeconds } from '@pie-qti/qti-processing';\nimport { inferBaseType } from './inferBaseType.js';\nimport type {\n\tAssessmentItemResult,\n\tAssessmentResultReport,\n\tAssessmentResultVersion,\n\tResultBaseType,\n\tResultCardinality,\n\tResultDatestamp,\n\tResultSessionStatus,\n\tResultVariable,\n} from './types.js';\n\n/**\n * The QTI Results Reporting namespaces and schema locations, as the 1EdTech schemas declare them:\n * `imsqti_result_v2p2.xsd` (QTI 2.2) and `imsqti_resultv3p0_v1p0.xsd` (QTI 3.0). Both versions use\n * the same camelCase element and attribute names.\n */\nexport const ASSESSMENT_RESULT_NAMESPACES: Readonly<\n\tRecord<AssessmentResultVersion, { readonly namespace: string; readonly schemaLocation: string }>\n> = {\n\t'2.2': {\n\t\tnamespace: 'http://www.imsglobal.org/xsd/imsqti_result_v2p2',\n\t\tschemaLocation: 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_result_v2p2.xsd',\n\t},\n\t'3.0': {\n\t\tnamespace: 'http://www.imsglobal.org/xsd/imsqti_result_v3p0',\n\t\tschemaLocation: 'https://purl.imsglobal.org/spec/qti/v3p0/schema/xsd/imsqti_resultv3p0_v1p0.xsd',\n\t},\n};\n\nexport interface SerializeAssessmentResultOptions {\n\treadonly version: AssessmentResultVersion;\n\t/** Declare `xsi:schemaLocation` for the version's results schema. Default: true. */\n\treadonly schemaLocation?: boolean;\n}\n\n/** The report cannot be written as a schema-valid `assessmentResult` of the requested version. */\nexport class AssessmentResultSerializationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(`[QTI results] ${message}`);\n\t\tthis.name = 'AssessmentResultSerializationError';\n\t}\n}\n\nconst BASE_TYPES: ReadonlySet<string> = new Set<ResultBaseType>([\n\t'boolean',\n\t'directedPair',\n\t'duration',\n\t'file',\n\t'float',\n\t'identifier',\n\t'integer',\n\t'pair',\n\t'point',\n\t'string',\n\t'uri',\n]);\nconst CARDINALITIES: ReadonlySet<string> = new Set<ResultCardinality>(['single', 'multiple', 'ordered', 'record']);\nconst SESSION_STATUSES: Readonly<Record<AssessmentResultVersion, ReadonlySet<ResultSessionStatus>>> = {\n\t'2.2': new Set(['final', 'initial', 'pendingResponseProcessing', 'pendingSubmission']),\n\t'3.0': new Set(['final', 'initial', 'pendingExternalScoring', 'pendingResponseProcessing', 'pendingSubmission']),\n};\nconst VIEWS: ReadonlySet<string> = new Set(['author', 'candidate', 'proctor', 'scorer', 'testConstructor', 'tutor']);\n\n/** XML 1.0 (5th edition) NCName: a Name without colons. */\nconst NAME_START =\n\t'A-Z_a-z\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u02FF\\\\u0370-\\\\u037D\\\\u037F-\\\\u1FFF\\\\u200C-\\\\u200D' +\n\t'\\\\u2070-\\\\u218F\\\\u2C00-\\\\u2FEF\\\\u3001-\\\\uD7FF\\\\uF900-\\\\uFDCF\\\\uFDF0-\\\\uFFFD\\\\u{10000}-\\\\u{EFFFF}';\nconst NCNAME = new RegExp(`^[${NAME_START}][${NAME_START}\\\\-.0-9\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040]*$`, 'u');\n\n/**\n * Writes a QTI Results Reporting `assessmentResult` document. Every value and attribute is\n * XML-escaped (characters XML 1.0 cannot carry become U+FFFD); identifiers the version's schema\n * types as NCName, an unknown base type or cardinality, a session status the version lacks, or an\n * invalid date throw an `AssessmentResultSerializationError`. Durations are written as seconds,\n * the xsd:double form QTI defines.\n */\nexport function serializeAssessmentResult(\n\treport: AssessmentResultReport,\n\toptions: SerializeAssessmentResultOptions,\n): string {\n\tconst { version } = options;\n\tconst target = ASSESSMENT_RESULT_NAMESPACES[version];\n\tif (!target) throw new AssessmentResultSerializationError(`Unsupported results version \"${String(version)}\"`);\n\n\tconst out = new XmlWriter();\n\tout.line('<?xml version=\"1.0\" encoding=\"UTF-8\"?>');\n\tconst rootAttributes: Array<[string, string | undefined]> = [['xmlns', target.namespace]];\n\tif (options.schemaLocation !== false) {\n\t\trootAttributes.push(\n\t\t\t['xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'],\n\t\t\t['xsi:schemaLocation', `${target.namespace} ${target.schemaLocation}`],\n\t\t);\n\t}\n\tout.open('assessmentResult', rootAttributes);\n\n\tconst { sourcedId, sessionIdentifiers = [] } = report.context;\n\tconst contextAttributes: Array<[string, string | undefined]> = [\n\t\t['sourcedId', sourcedId === undefined ? undefined : ncName(sourcedId, 'context sourcedId')],\n\t];\n\tif (sessionIdentifiers.length === 0) {\n\t\tout.empty('context', contextAttributes);\n\t} else {\n\t\tout.open('context', contextAttributes);\n\t\tfor (const session of sessionIdentifiers) {\n\t\t\tout.empty('sessionIdentifier', [\n\t\t\t\t['sourceID', required(session.sourceID, 'sessionIdentifier sourceID')],\n\t\t\t\t['identifier', identifierFor(version, session.identifier, 'sessionIdentifier identifier')],\n\t\t\t]);\n\t\t}\n\t\tout.close('context');\n\t}\n\n\tif (report.testResult) {\n\t\tconst test = report.testResult;\n\t\tconst attributes: Array<[string, string | undefined]> = [\n\t\t\t['identifier', identifierFor(version, test.identifier, 'testResult identifier')],\n\t\t\t['datestamp', dateTime(test.datestamp, 'testResult datestamp')],\n\t\t];\n\t\twriteVariablesElement(out, 'testResult', attributes, test.variables, version);\n\t}\n\n\tfor (const item of report.itemResults) writeItemResult(out, item, version);\n\n\tout.close('assessmentResult');\n\treturn out.toString();\n}\n\nfunction writeItemResult(out: XmlWriter, item: AssessmentItemResult, version: AssessmentResultVersion): void {\n\tif (!SESSION_STATUSES[version].has(item.sessionStatus)) {\n\t\tthrow new AssessmentResultSerializationError(\n\t\t\t`itemResult \"${item.identifier}\" has sessionStatus \"${item.sessionStatus}\", which QTI ${version} results do not define`,\n\t\t);\n\t}\n\tif (item.sequenceIndex !== undefined && !Number.isInteger(item.sequenceIndex)) {\n\t\tthrow new AssessmentResultSerializationError(\n\t\t\t`itemResult \"${item.identifier}\" sequenceIndex must be an integer, not ${item.sequenceIndex}`,\n\t\t);\n\t}\n\tconst attributes: Array<[string, string | undefined]> = [\n\t\t['identifier', identifierFor(version, item.identifier, 'itemResult identifier')],\n\t\t['sequenceIndex', item.sequenceIndex === undefined ? undefined : String(item.sequenceIndex)],\n\t\t['datestamp', dateTime(item.datestamp, `itemResult \"${item.identifier}\" datestamp`)],\n\t\t['sessionStatus', item.sessionStatus],\n\t];\n\twriteVariablesElement(out, 'itemResult', attributes, item.variables, version, item.candidateComment);\n}\n\nfunction writeVariablesElement(\n\tout: XmlWriter,\n\tname: 'testResult' | 'itemResult',\n\tattributes: Array<[string, string | undefined]>,\n\tvariables: readonly ResultVariable[],\n\tversion: AssessmentResultVersion,\n\tcandidateComment?: string,\n): void {\n\tconst written = variables.filter((variable) => variable.kind !== 'context' || version === '3.0');\n\tif (written.length === 0 && candidateComment === undefined) {\n\t\tout.empty(name, attributes);\n\t\treturn;\n\t}\n\tout.open(name, attributes);\n\tfor (const variable of written) writeVariable(out, variable);\n\tif (candidateComment !== undefined) out.text('candidateComment', candidateComment, { normalized: false });\n\tout.close(name);\n}\n\nfunction writeVariable(out: XmlWriter, variable: ResultVariable): void {\n\tconst where = `variable \"${variable.identifier}\"`;\n\tif (!CARDINALITIES.has(variable.cardinality)) {\n\t\tthrow new AssessmentResultSerializationError(`${where} has unknown cardinality \"${variable.cardinality}\"`);\n\t}\n\tconst record = variable.cardinality === 'record';\n\tif (!record && (!variable.baseType || !BASE_TYPES.has(variable.baseType))) {\n\t\tthrow new AssessmentResultSerializationError(`${where} has unknown baseType \"${String(variable.baseType)}\"`);\n\t}\n\tconst attributes: Array<[string, string | undefined]> = [\n\t\t['identifier', ncName(variable.identifier, `${where} identifier`)],\n\t\t['cardinality', variable.cardinality],\n\t\t['baseType', record ? undefined : variable.baseType],\n\t];\n\n\tswitch (variable.kind) {\n\t\tcase 'response': {\n\t\t\tif (variable.choiceSequence?.length) {\n\t\t\t\tattributes.push([\n\t\t\t\t\t'choiceSequence',\n\t\t\t\t\tvariable.choiceSequence.map((id) => ncName(id, `${where} choiceSequence`)).join(' '),\n\t\t\t\t]);\n\t\t\t}\n\t\t\tout.open('responseVariable', attributes);\n\t\t\tconst correct = valueElements(variable.correctResponse, variable, where);\n\t\t\tif (correct.length > 0) {\n\t\t\t\tout.open('correctResponse');\n\t\t\t\tfor (const value of correct) out.text('value', value.text, { attributes: value.attributes });\n\t\t\t\tout.close('correctResponse');\n\t\t\t}\n\t\t\twriteValues(out, 'candidateResponse', valueElements(variable.value, variable, where));\n\t\t\tout.close('responseVariable');\n\t\t\treturn;\n\t\t}\n\t\tcase 'outcome': {\n\t\t\tconst view = (variable.view ?? []).filter((role) => VIEWS.has(role));\n\t\t\tattributes.push(\n\t\t\t\t['view', view.length > 0 ? view.join(' ') : undefined],\n\t\t\t\t['interpretation', variable.interpretation],\n\t\t\t\t['longInterpretation', variable.longInterpretation],\n\t\t\t\t['normalMaximum', optionalDouble(variable.normalMaximum)],\n\t\t\t\t['normalMinimum', optionalDouble(variable.normalMinimum)],\n\t\t\t\t['masteryValue', optionalDouble(variable.masteryValue)],\n\t\t\t);\n\t\t\twriteValues(out, 'outcomeVariable', valueElements(variable.value, variable, where), attributes);\n\t\t\treturn;\n\t\t}\n\t\tcase 'template':\n\t\t\twriteValues(out, 'templateVariable', valueElements(variable.value, variable, where), attributes);\n\t\t\treturn;\n\t\tcase 'context':\n\t\t\twriteValues(out, 'contextVariable', valueElements(variable.value, variable, where), attributes);\n\t\t\treturn;\n\t}\n}\n\ninterface ValueElement {\n\treadonly text: string;\n\treadonly attributes?: Array<[string, string | undefined]>;\n}\n\nfunction writeValues(\n\tout: XmlWriter,\n\tname: string,\n\tvalues: readonly ValueElement[],\n\tattributes: Array<[string, string | undefined]> = [],\n): void {\n\tif (values.length === 0) {\n\t\tout.empty(name, attributes);\n\t\treturn;\n\t}\n\tout.open(name, attributes);\n\tfor (const value of values) out.text('value', value.text, { attributes: value.attributes });\n\tout.close(name);\n}\n\n/** The `value` elements of a variable value: none for NULL, one per member of a container. */\nfunction valueElements(\n\traw: unknown,\n\tvariable: Pick<ResultVariable, 'baseType' | 'cardinality'>,\n\twhere: string,\n): ValueElement[] {\n\tif (raw === null || raw === undefined) return [];\n\tif (variable.cardinality === 'record') return recordValueElements(raw, where);\n\tconst baseType = variable.baseType as ResultBaseType;\n\tconst members = variable.cardinality === 'single' ? [raw] : Array.isArray(raw) ? raw : [raw];\n\tconst values: ValueElement[] = [];\n\tfor (const member of members) {\n\t\tconst text = formatValue(baseType, member);\n\t\tif (text !== null) values.push({ text });\n\t}\n\treturn values;\n}\n\n/** A record's fields, each as a `value` carrying its fieldIdentifier and baseType. */\nfunction recordValueElements(raw: unknown, where: string): ValueElement[] {\n\tif (typeof raw !== 'object' || Array.isArray(raw)) return [];\n\tconst values: ValueElement[] = [];\n\tfor (const [fieldIdentifier, field] of Object.entries(raw as Record<string, unknown>)) {\n\t\t// A serialized field is { baseType, cardinality, value }; a public one is the plain value.\n\t\tconst serialized =\n\t\t\tfield !== null && typeof field === 'object' && !Array.isArray(field) && 'value' in field;\n\t\tconst fieldValue = serialized ? (field as { value: unknown }).value : field;\n\t\tif (fieldValue === null || fieldValue === undefined || Array.isArray(fieldValue)) continue;\n\t\tconst declared = serialized ? (field as { baseType?: unknown }).baseType : undefined;\n\t\tconst baseType =\n\t\t\ttypeof declared === 'string' && BASE_TYPES.has(declared) ? (declared as ResultBaseType) : inferBaseType(fieldValue);\n\t\tconst text = formatValue(baseType, fieldValue);\n\t\tif (text === null) continue;\n\t\tvalues.push({\n\t\t\ttext,\n\t\t\tattributes: [\n\t\t\t\t['fieldIdentifier', ncName(fieldIdentifier, `${where} field identifier`)],\n\t\t\t\t['baseType', baseType],\n\t\t\t],\n\t\t});\n\t}\n\treturn values;\n}\n\n/** A single value in its QTI lexical form, or null when there is nothing to write. */\nfunction formatValue(baseType: ResultBaseType, value: unknown): string | null {\n\tif (value === null || value === undefined) return null;\n\tswitch (baseType) {\n\t\tcase 'boolean':\n\t\t\tif (typeof value === 'boolean') return value ? 'true' : 'false';\n\t\t\tif (value === 'true' || value === '1' || value === 1) return 'true';\n\t\t\tif (value === 'false' || value === '0' || value === 0) return 'false';\n\t\t\treturn String(value);\n\t\tcase 'integer':\n\t\t\treturn typeof value === 'number' ? formatInteger(value) : String(value).trim();\n\t\tcase 'float':\n\t\t\treturn typeof value === 'number' ? formatDouble(value) : String(value).trim();\n\t\tcase 'duration': {\n\t\t\t// QTI durations are seconds, written as xsd:double.\n\t\t\tconst seconds = durationSeconds(value);\n\t\t\treturn seconds === null ? String(value).trim() : formatDouble(seconds);\n\t\t}\n\t\tcase 'pair':\n\t\tcase 'directedPair':\n\t\t\treturn String(value).trim().split(/\\s+/).join(' ');\n\t\tcase 'point':\n\t\t\tif (typeof value === 'object' && value !== null && 'x' in value && 'y' in value) {\n\t\t\t\tconst { x, y } = value as { x: unknown; y: unknown };\n\t\t\t\treturn `${String(x)} ${String(y)}`;\n\t\t\t}\n\t\t\treturn String(value).trim().split(/\\s+/).join(' ');\n\t\tcase 'file':\n\t\t\tif (typeof value === 'object') {\n\t\t\t\tconst file = value as { dataUrl?: unknown; name?: unknown };\n\t\t\t\tif (typeof file.dataUrl === 'string' && file.dataUrl) return file.dataUrl;\n\t\t\t\tif (typeof file.name === 'string' && file.name) return file.name;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn String(value);\n\t\tdefault:\n\t\t\treturn typeof value === 'object' ? JSON.stringify(value) : String(value);\n\t}\n}\n\n/** xsd:double: the shortest round-tripping decimal, INF, -INF or NaN. */\nfunction formatDouble(value: number): string {\n\tif (Number.isNaN(value)) return 'NaN';\n\tif (value === Number.POSITIVE_INFINITY) return 'INF';\n\tif (value === Number.NEGATIVE_INFINITY) return '-INF';\n\treturn String(value);\n}\n\nfunction formatInteger(value: number): string {\n\tif (!Number.isFinite(value)) return formatDouble(value);\n\tconst integer = Math.trunc(value);\n\treturn Number.isSafeInteger(integer) ? String(integer) : BigInt(integer).toString();\n}\n\nfunction optionalDouble(value: number | undefined): string | undefined {\n\treturn value === undefined ? undefined : formatDouble(value);\n}\n\nfunction ncName(value: string, what: string): string {\n\tif (!NCNAME.test(value)) {\n\t\tthrow new AssessmentResultSerializationError(`${what} \"${value}\" is not an NCName`);\n\t}\n\treturn value;\n}\n\n/** Item, test and session identifiers are NCNames in QTI 3.0 results, normalized strings in 2.2. */\nfunction identifierFor(version: AssessmentResultVersion, value: string, what: string): string {\n\treturn version === '3.0' ? ncName(value, what) : required(value, what);\n}\n\nfunction required(value: string, what: string): string {\n\tif (typeof value !== 'string' || value.trim() === '') {\n\t\tthrow new AssessmentResultSerializationError(`${what} is required`);\n\t}\n\treturn value;\n}\n\nfunction dateTime(value: ResultDatestamp, what: string): string {\n\tconst date = value instanceof Date ? value : new Date(value);\n\tif (Number.isNaN(date.getTime())) {\n\t\tthrow new AssessmentResultSerializationError(`${what} \"${String(value)}\" is not a valid date-time`);\n\t}\n\treturn date.toISOString();\n}\n\n/** Characters XML 1.0 can carry: tab, newline, carriage return, and #x20 upward minus surrogates and #xFFFE/#xFFFF. */\nfunction xmlCharacters(value: string): string {\n\tlet out = '';\n\tfor (const character of value) {\n\t\tconst code = character.codePointAt(0) as number;\n\t\tconst allowed =\n\t\t\tcode === 0x9 ||\n\t\t\tcode === 0xa ||\n\t\t\tcode === 0xd ||\n\t\t\t(code >= 0x20 && code <= 0xd7ff) ||\n\t\t\t(code >= 0xe000 && code <= 0xfffd) ||\n\t\t\tcode >= 0x10000;\n\t\tout += allowed ? character : '\\uFFFD';\n\t}\n\treturn out;\n}\n\n/**\n * Escapes markup characters. `normalized` text (attributes, and `value`, an xs:normalizedString)\n * also writes tab and newline as character references, so a consumer that does not normalize\n * whitespace reads the original; a carriage return is always a reference, or XML end-of-line\n * handling would drop it.\n */\nfunction escapeXml(value: string, { normalized, attribute }: { normalized: boolean; attribute: boolean }): string {\n\tlet escaped = xmlCharacters(value)\n\t\t.replace(/&/g, '&')\n\t\t.replace(/</g, '<')\n\t\t.replace(/>/g, '>')\n\t\t.replace(/\\r/g, ' ');\n\tif (attribute) escaped = escaped.replace(/\"/g, '"');\n\tif (normalized || attribute) escaped = escaped.replace(/\\t/g, '	').replace(/\\n/g, ' ');\n\treturn escaped;\n}\n\nclass XmlWriter {\n\tprivate readonly lines: string[] = [];\n\tprivate depth = 0;\n\n\tline(text: string): void {\n\t\tthis.lines.push(`${' '.repeat(this.depth)}${text}`);\n\t}\n\n\topen(name: string, attributes: Array<[string, string | undefined]> = []): void {\n\t\tthis.line(`<${name}${formatAttributes(attributes)}>`);\n\t\tthis.depth++;\n\t}\n\n\tclose(name: string): void {\n\t\tthis.depth--;\n\t\tthis.line(`</${name}>`);\n\t}\n\n\tempty(name: string, attributes: Array<[string, string | undefined]> = []): void {\n\t\tthis.line(`<${name}${formatAttributes(attributes)}/>`);\n\t}\n\n\ttext(\n\t\tname: string,\n\t\tvalue: string,\n\t\t{ attributes = [], normalized = true }: { attributes?: Array<[string, string | undefined]>; normalized?: boolean } = {},\n\t): void {\n\t\tthis.line(`<${name}${formatAttributes(attributes)}>${escapeXml(value, { normalized, attribute: false })}</${name}>`);\n\t}\n\n\ttoString(): string {\n\t\treturn `${this.lines.join('\\n')}\\n`;\n\t}\n}\n\nfunction formatAttributes(attributes: Array<[string, string | undefined]>): string {\n\treturn attributes\n\t\t.filter((attribute): attribute is [string, string] => attribute[1] !== undefined)\n\t\t.map(([name, value]) => ` ${name}=\"${escapeXml(value, { normalized: true, attribute: true })}\"`)\n\t\t.join('');\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AssessmentSessionState, FinalizeAssessmentResponse, SecureAssessment, TestOutcomeValues } from '../integration/api-contract.js';
|
|
2
|
+
import { type SerializeAssessmentResultOptions } from './serializeAssessmentResult.js';
|
|
3
|
+
import type { AssessmentResultReport, ResultDatestamp, ResultSessionIdentifier } from './types.js';
|
|
4
|
+
/** The assessment results a host holds: the delivered test, its session state, and the finalize response. */
|
|
5
|
+
export interface AssessmentResultsData {
|
|
6
|
+
/** The assessment as delivered (drawn) for this session; its order gives each item's sequenceIndex. */
|
|
7
|
+
readonly assessment: SecureAssessment;
|
|
8
|
+
/** The session state: responses, item sessions, scores, comments and timing. */
|
|
9
|
+
readonly state: AssessmentSessionState;
|
|
10
|
+
/** The finalize response, once the test has ended: final item scores and test outcomes. */
|
|
11
|
+
readonly finalized?: FinalizeAssessmentResponse;
|
|
12
|
+
/** Test outcome values, when the host has them without a finalize response. */
|
|
13
|
+
readonly outcomes?: TestOutcomeValues;
|
|
14
|
+
}
|
|
15
|
+
export interface AssessmentResultXmlOptions extends SerializeAssessmentResultOptions {
|
|
16
|
+
/** `context@sourcedId`: the candidate's sourcedId (an NCName). */
|
|
17
|
+
readonly candidateSourcedId?: string;
|
|
18
|
+
readonly sessionIdentifiers?: readonly ResultSessionIdentifier[];
|
|
19
|
+
/** `testResult@datestamp`. Default: `finalized.finalizedAt`, else now. */
|
|
20
|
+
readonly datestamp?: ResultDatestamp;
|
|
21
|
+
/** Report the correct responses the scoring results carry. Default: false. */
|
|
22
|
+
readonly includeCorrectResponses?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Writes the assessment's results as a QTI Results Reporting `assessmentResult` document (QTI 2.2
|
|
26
|
+
* or 3.0, per `options.version`).
|
|
27
|
+
*
|
|
28
|
+
* The test result carries the test outcomes, typed by the test's outcome declarations, and the
|
|
29
|
+
* built-in `duration` response variables of the test, each test part and each section
|
|
30
|
+
* (`PART.duration`, `SECTION.duration`), in seconds. Each item with recorded data gets an item
|
|
31
|
+
* result in delivery order, with its `sequenceIndex`, its `sessionStatus` derived from the session
|
|
32
|
+
* lifecycle and scoring, its response, outcome, template and (QTI 3.0) context variables, the
|
|
33
|
+
* built-in `numAttempts` and `duration` (seconds) response variables, and the candidate comment.
|
|
34
|
+
* Item session snapshots give variables their types; the item's declarations fill in where a
|
|
35
|
+
* snapshot is missing.
|
|
36
|
+
*/
|
|
37
|
+
export declare function toAssessmentResultXml(results: AssessmentResultsData, options: AssessmentResultXmlOptions): string;
|
|
38
|
+
/** The Results Reporting model `toAssessmentResultXml` writes, for hosts that adjust it first. */
|
|
39
|
+
export declare function buildAssessmentResultReport(results: AssessmentResultsData, options?: Omit<AssessmentResultXmlOptions, 'version' | 'schemaLocation'>): AssessmentResultReport;
|