@pie-qti/assessment-player 0.1.18 → 0.1.20
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 +133 -1006
- package/dist/core/AssessmentPlayer.d.ts +22 -10
- package/dist/core/AssessmentPlayer.js +290 -103
- package/dist/core/AssessmentPlayer.js.map +1 -1
- package/dist/core/AssessmentSessionCoordinator.d.ts +1 -0
- package/dist/core/AssessmentSessionCoordinator.js +8 -2
- package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integration/assessment-item-scorer.js +13 -6
- package/dist/integration/assessment-item-scorer.js.map +1 -1
- package/dist/integration/index.d.ts +11 -12
- package/dist/integration/index.js +11 -12
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/toSectionComposition.js +14 -10
- package/dist/integration/toSectionComposition.js.map +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,1080 +1,207 @@
|
|
|
1
1
|
# @pie-qti/assessment-player
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Backend-authoritative orchestration for multi-item QTI 2.2 and QTI 3.0 assessments.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The package owns assessment navigation, timing, item-session lifecycle, state persistence, and the
|
|
6
|
+
`BackendAdapter` boundary. Browser rendering is published separately by
|
|
7
|
+
`@pie-qti/player-elements`; there is no public `@pie-qti/assessment-player/components` export.
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
- ✅ **Navigation modes** - Linear (sequential) and nonlinear (free navigation)
|
|
9
|
-
- ✅ **Sections & hierarchy** - Nested sections with navigation
|
|
10
|
-
- ✅ **Rubric blocks** - Reading passages, instructions, and rubrics
|
|
11
|
-
- ✅ **Progress tracking** - Visual progress indicators
|
|
12
|
-
- ✅ **Section menu** - Quick navigation between sections
|
|
13
|
-
- ✅ **Outcome Processing** - QTI-aligned scoring with total/weighted/percentage/pass-fail templates
|
|
14
|
-
- ✅ **Test Feedback** - Conditional feedback based on outcome variables
|
|
15
|
-
- ✅ **Time Limits** - Assessment-level countdown timers with warnings and auto-submission
|
|
16
|
-
- ✅ **Item Session Control** - Max attempts, review/skip controls, response validation
|
|
17
|
-
- ✅ **State Persistence** - Auto-save with resume capability and optional backend integration
|
|
18
|
-
- ✅ **Selection & Ordering** - Random item selection and shuffling per QTI spec
|
|
19
|
-
- ✅ **QTI Role/View Actors** - candidate, scorer, tutor, author, proctor, testConstructor
|
|
20
|
-
- ✅ **Backend Integration** - Optional secure backend API (client-side by default)
|
|
21
|
-
- ✅ **Svelte 5 components** - Modern reactive UI
|
|
22
|
-
- ✅ **TypeScript** - Full type safety
|
|
9
|
+
## Install
|
|
23
10
|
|
|
24
|
-
|
|
11
|
+
For the framework-neutral orchestration API:
|
|
25
12
|
|
|
26
13
|
```bash
|
|
27
14
|
bun add @pie-qti/assessment-player
|
|
28
15
|
```
|
|
29
16
|
|
|
30
|
-
|
|
17
|
+
For the supported browser elements:
|
|
31
18
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
import '@pie-qti/player-elements/register';
|
|
36
|
-
|
|
37
|
-
const player = document.createElement('qti-assessment-player');
|
|
38
|
-
player.config = {
|
|
39
|
-
role: 'candidate',
|
|
40
|
-
showSections: true,
|
|
41
|
-
allowSectionNavigation: true,
|
|
42
|
-
showProgress: true,
|
|
43
|
-
};
|
|
44
|
-
player.assessmentTestXml = '<qti-assessment-test>...</qti-assessment-test>';
|
|
45
|
-
document.body.append(player);
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Programmatic Usage (JavaScript/TypeScript)
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
import { AssessmentPlayer } from '@pie-qti/assessment-player';
|
|
52
|
-
|
|
53
|
-
const player = new AssessmentPlayer({
|
|
54
|
-
assessment: myAssessment,
|
|
55
|
-
role: 'candidate',
|
|
56
|
-
navigationMode: 'nonlinear',
|
|
57
|
-
showSections: true,
|
|
58
|
-
allowSectionNavigation: true,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Navigate to first item
|
|
62
|
-
await player.navigateTo(0);
|
|
63
|
-
|
|
64
|
-
// Get navigation state
|
|
65
|
-
const navState = player.getNavigationState();
|
|
66
|
-
console.log(`Item ${navState.currentIndex + 1} of ${navState.totalItems}`);
|
|
67
|
-
|
|
68
|
-
// Get current rubric blocks (passages)
|
|
69
|
-
const rubrics = player.getCurrentRubricBlocks();
|
|
70
|
-
|
|
71
|
-
// Navigate next/previous
|
|
72
|
-
await player.next();
|
|
73
|
-
await player.previous();
|
|
74
|
-
|
|
75
|
-
// Navigate to section
|
|
76
|
-
await player.navigateToSection('section-1');
|
|
77
|
-
|
|
78
|
-
// Submit assessment
|
|
79
|
-
const results = await player.submit();
|
|
80
|
-
console.log('Total score:', results.totalScore, '/', results.maxScore);
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Assessment Format
|
|
84
|
-
|
|
85
|
-
The player uses a QTI-aligned JSON format:
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
interface QtiAssessmentTest {
|
|
89
|
-
identifier?: string;
|
|
90
|
-
title?: string;
|
|
91
|
-
testParts?: TestPart[];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
interface TestPart {
|
|
95
|
-
identifier: string;
|
|
96
|
-
navigationMode: 'linear' | 'nonlinear';
|
|
97
|
-
submissionMode: 'individual' | 'simultaneous';
|
|
98
|
-
sections: AssessmentSection[];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
interface AssessmentSection {
|
|
102
|
-
identifier: string;
|
|
103
|
-
title?: string;
|
|
104
|
-
visible?: boolean;
|
|
105
|
-
rubricBlocks?: RubricBlock[];
|
|
106
|
-
questionRefs?: QuestionRef[];
|
|
107
|
-
sections?: AssessmentSection[]; // Nested sections
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
interface QuestionRef {
|
|
111
|
-
identifier: string;
|
|
112
|
-
href?: string; // URL to item XML
|
|
113
|
-
title?: string;
|
|
114
|
-
itemXml?: string; // Loaded item XML (convenience property)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
interface RubricBlock {
|
|
118
|
-
view: string[]; // QTI roles: ['candidate', 'scorer', 'author', 'tutor', 'proctor', 'testConstructor']
|
|
119
|
-
use?: 'passage' | 'instructions' | 'rubric';
|
|
120
|
-
content: string; // HTML content
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
## Backend Integration
|
|
125
|
-
|
|
126
|
-
**By default**, the player runs 100% client-side with no backend required. This is perfect for demos, development, and non-critical assessments.
|
|
127
|
-
|
|
128
|
-
**For production**, integrate with a secure backend for:
|
|
129
|
-
|
|
130
|
-
- Server-side scoring (prevent score manipulation)
|
|
131
|
-
- Role-based data filtering (hide correct answers from candidates)
|
|
132
|
-
- Persistent session storage
|
|
133
|
-
- Authentication and authorization
|
|
134
|
-
|
|
135
|
-
The player can be embedded inside an LTI 1.3 / LTI Advantage tool, but LTI launch validation, Deep Linking, AGS grade passback, and NRPS roster lookup are host-application responsibilities. Use the `BackendAdapter` boundary to connect player sessions and submissions to the host tool's LTI-aware backend.
|
|
136
|
-
|
|
137
|
-
### Quick Start
|
|
138
|
-
|
|
139
|
-
```typescript
|
|
140
|
-
import { ReferenceBackendAdapter } from '@pie-qti/assessment-player/integration';
|
|
141
|
-
|
|
142
|
-
// Development/demo mode - uses localStorage
|
|
143
|
-
const adapter = new ReferenceBackendAdapter();
|
|
144
|
-
|
|
145
|
-
const player = new AssessmentPlayer({
|
|
146
|
-
backend: adapter,
|
|
147
|
-
assessmentId: 'test-001',
|
|
148
|
-
candidateId: 'student-123'
|
|
149
|
-
});
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
### Production Implementation
|
|
153
|
-
|
|
154
|
-
Implement the `BackendAdapter` interface for your backend:
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
import type { BackendAdapter } from '@pie-qti/assessment-player/integration';
|
|
158
|
-
|
|
159
|
-
class MyBackendAdapter implements BackendAdapter {
|
|
160
|
-
async initSession(request) {
|
|
161
|
-
const response = await fetch('/api/qti/sessions/init', {
|
|
162
|
-
method: 'POST',
|
|
163
|
-
headers: { 'Authorization': `Bearer ${token}` },
|
|
164
|
-
body: JSON.stringify(request)
|
|
165
|
-
});
|
|
166
|
-
return response.json();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async submitResponses(request) {
|
|
170
|
-
// Server performs scoring and returns results
|
|
171
|
-
const response = await fetch('/api/qti/responses/submit', {
|
|
172
|
-
method: 'POST',
|
|
173
|
-
body: JSON.stringify(request)
|
|
174
|
-
});
|
|
175
|
-
return response.json();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ... implement other methods
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
**See [BACKEND-INTEGRATION.md](./BACKEND-INTEGRATION.md) for complete implementation guide.**
|
|
183
|
-
|
|
184
|
-
## QTI Role/View Actors
|
|
185
|
-
|
|
186
|
-
QTI roles are audience markers for `view`-controlled content. This player applies the runtime policy below:
|
|
187
|
-
|
|
188
|
-
| Role | Behavior |
|
|
189
|
-
|------|----------|
|
|
190
|
-
| `candidate` | Test-taker - inputs editable, no correct answers shown |
|
|
191
|
-
| `scorer` | Grader/reviewer - inputs readonly, correct answers shown |
|
|
192
|
-
| `author` | Content authoring review - inputs readonly, correct answers shown |
|
|
193
|
-
| `tutor` | Instructional review - inputs readonly, correct answers shown |
|
|
194
|
-
| `proctor` | Test administration view - inputs readonly, no correct answers shown |
|
|
195
|
-
| `testConstructor` | Test construction review - inputs readonly, correct answers shown |
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
// For test-takers
|
|
199
|
-
<AssessmentShell {assessment} config={{ role: 'candidate' }} />
|
|
200
|
-
|
|
201
|
-
// For grading/review
|
|
202
|
-
<AssessmentShell {assessment} config={{ role: 'scorer' }} />
|
|
19
|
+
```bash
|
|
20
|
+
bun add @pie-qti/player-elements
|
|
203
21
|
```
|
|
204
22
|
|
|
205
|
-
##
|
|
23
|
+
## Browser element
|
|
206
24
|
|
|
207
|
-
|
|
25
|
+
Import the registration entry and use the `pie-qti-assessment-player` tag:
|
|
208
26
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
- **Auto-submission** - Automatically submits when time expires (configurable)
|
|
212
|
-
- **Late submission** - Optional allow submission after time expires
|
|
213
|
-
|
|
214
|
-
### Usage
|
|
27
|
+
```ts
|
|
28
|
+
import '@pie-qti/player-elements/register';
|
|
215
29
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
allowLateSubmission: false // Auto-submit when time expires
|
|
222
|
-
},
|
|
223
|
-
testParts: [/* ... */]
|
|
30
|
+
const element = document.createElement('pie-qti-assessment-player');
|
|
31
|
+
element.backend = backend;
|
|
32
|
+
element.initSession = {
|
|
33
|
+
assessmentId: 'algebra-final',
|
|
34
|
+
candidateId: 'candidate-42'
|
|
224
35
|
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// Listen for time events
|
|
232
|
-
player.onTimeWarning((remainingSeconds) => {
|
|
233
|
-
console.log(`Warning: ${remainingSeconds} seconds remaining`);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
player.onTimeExpired(() => {
|
|
237
|
-
console.log('Time expired!');
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
player.onTimeTick((remaining, elapsed) => {
|
|
241
|
-
console.log(`${remaining}s remaining, ${elapsed}s elapsed`);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// Pause/resume timer (e.g., for breaks)
|
|
245
|
-
player.pauseTimer();
|
|
246
|
-
player.resumeTimer();
|
|
247
|
-
|
|
248
|
-
// Check time status
|
|
249
|
-
const remaining = player.getRemainingTime(); // seconds or null if no limit
|
|
250
|
-
const elapsed = player.getElapsedTime(); // seconds
|
|
251
|
-
const isExpired = player.isTimeExpired(); // boolean
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
### Assessment Timer UI
|
|
255
|
-
|
|
256
|
-
The packaged UI is exposed through `@pie-qti/player-elements/register`.
|
|
257
|
-
`@pie-qti/assessment-player` does not publish raw Svelte component entrypoints;
|
|
258
|
-
use the `AssessmentPlayer` time APIs directly for custom UI.
|
|
259
|
-
|
|
260
|
-
## Item Session Control
|
|
261
|
-
|
|
262
|
-
QTI itemSessionControl determines how candidates interact with items:
|
|
263
|
-
|
|
264
|
-
| Setting | Description |
|
|
265
|
-
|---------|-------------|
|
|
266
|
-
| `maxAttempts` | Maximum submission attempts (0 = unlimited) |
|
|
267
|
-
| `showFeedback` | Show feedback after submission |
|
|
268
|
-
| `showSolution` | Show correct answers |
|
|
269
|
-
| `allowReview` | Allow returning to submitted items |
|
|
270
|
-
| `allowSkipping` | Allow skipping items without answering |
|
|
271
|
-
| `validateResponses` | Require valid responses before navigation |
|
|
272
|
-
|
|
273
|
-
### Usage
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
const assessment: QtiAssessmentTest = {
|
|
277
|
-
testParts: [{
|
|
278
|
-
identifier: 'part-1',
|
|
279
|
-
navigationMode: 'nonlinear',
|
|
280
|
-
submissionMode: 'individual',
|
|
281
|
-
itemSessionControl: {
|
|
282
|
-
maxAttempts: 3, // 3 attempts per item
|
|
283
|
-
showFeedback: true,
|
|
284
|
-
showSolution: false,
|
|
285
|
-
allowReview: true,
|
|
286
|
-
allowSkipping: false, // Must answer before moving
|
|
287
|
-
validateResponses: true
|
|
288
|
-
},
|
|
289
|
-
sections: [/* ... */]
|
|
290
|
-
}]
|
|
36
|
+
element.config = {
|
|
37
|
+
showSections: true,
|
|
38
|
+
allowSectionNavigation: true,
|
|
39
|
+
showProgress: true
|
|
291
40
|
};
|
|
292
|
-
|
|
293
|
-
// Get session info for current item
|
|
294
|
-
const info = player.getItemSessionInfo();
|
|
295
|
-
console.log(`Can submit: ${info.canSubmit}`);
|
|
296
|
-
console.log(`Attempts remaining: ${info.remainingAttempts}`);
|
|
297
|
-
console.log(`Attempt count: ${info.attemptCount}`);
|
|
298
|
-
console.log(`Show feedback: ${info.showFeedback}`);
|
|
299
|
-
console.log(`Can skip: ${info.canSkip}`);
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
### Item Session UI
|
|
303
|
-
|
|
304
|
-
The packaged UI is exposed through `@pie-qti/player-elements/register`.
|
|
305
|
-
`@pie-qti/assessment-player` keeps item-session state APIs public, but does
|
|
306
|
-
not publish Svelte component entrypoints.
|
|
307
|
-
|
|
308
|
-
## State Persistence
|
|
309
|
-
|
|
310
|
-
The assessment player supports automatic state persistence for save/resume functionality. This allows candidates to continue their assessment across sessions.
|
|
311
|
-
|
|
312
|
-
### Capabilities
|
|
313
|
-
|
|
314
|
-
- **Auto-save**: Automatic debounced saves (default: 2000ms)
|
|
315
|
-
- **State capture**: Current item, responses, session states, time tracking
|
|
316
|
-
- **Storage fallback**: localStorage → sessionStorage → memory
|
|
317
|
-
- **Resume capability**: Restore exact position and state
|
|
318
|
-
- **Optional backend**: Integrate with server-side storage
|
|
319
|
-
|
|
320
|
-
### Basic Usage
|
|
321
|
-
|
|
322
|
-
Enable state persistence by providing a `sessionId`:
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
const player = new AssessmentPlayer({
|
|
326
|
-
assessment: myAssessment,
|
|
327
|
-
role: 'candidate',
|
|
328
|
-
|
|
329
|
-
// State persistence config
|
|
330
|
-
sessionId: 'candidate-123-assessment-456', // Unique session identifier
|
|
331
|
-
enableAutoSave: true, // Default: true when sessionId provided
|
|
332
|
-
autoSaveDelay: 2000, // Debounce delay in ms (default: 2000)
|
|
333
|
-
storage: 'localStorage', // 'localStorage' | 'sessionStorage' | 'memory'
|
|
334
|
-
|
|
335
|
-
// Callbacks
|
|
336
|
-
onStateSaved: (timestamp) => {
|
|
337
|
-
console.log('State saved at:', new Date(timestamp));
|
|
338
|
-
},
|
|
339
|
-
onStateRestored: (timestamp) => {
|
|
340
|
-
console.log('State restored from:', new Date(timestamp));
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
// Check if saved state exists
|
|
345
|
-
const hasSaved = await player.hasSavedState();
|
|
346
|
-
|
|
347
|
-
// Load and resume from saved state
|
|
348
|
-
if (hasSaved) {
|
|
349
|
-
const restored = await player.loadSavedState();
|
|
350
|
-
console.log('Resumed assessment:', restored);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Manually trigger immediate save (bypasses debounce)
|
|
354
|
-
await player.forceSaveState();
|
|
355
|
-
|
|
356
|
-
// Get last save timestamp
|
|
357
|
-
const lastSave = player.getLastSaveTime();
|
|
358
|
-
|
|
359
|
-
// Clear saved state
|
|
360
|
-
await player.clearSavedState();
|
|
41
|
+
document.body.append(element);
|
|
361
42
|
```
|
|
362
43
|
|
|
363
|
-
|
|
44
|
+
The element also exposes `next()`, `previous()`, `navigateTo()`, `navigateToSection()`, `submit()`,
|
|
45
|
+
`getResponses()`, `getState()`, and `restoreState()`. Its public properties and events are documented
|
|
46
|
+
in [`@pie-qti/player-elements`](../player-elements/README.md).
|
|
364
47
|
|
|
365
|
-
|
|
48
|
+
### Explicit reference/preview mode
|
|
366
49
|
|
|
367
|
-
|
|
368
|
-
import { StatePersistenceManager } from '@pie-qti/assessment-player';
|
|
369
|
-
import type { PersistableState } from '@pie-qti/assessment-player';
|
|
50
|
+
Raw assessment XML is a demo and offline-preview path. Enable it explicitly before assigning XML:
|
|
370
51
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
assessmentId: 'my-assessment',
|
|
374
|
-
autoSave: true,
|
|
375
|
-
autoSaveDelay: 2000,
|
|
376
|
-
storage: 'localStorage', // Fallback if backend fails
|
|
377
|
-
|
|
378
|
-
// Optional backend save callback
|
|
379
|
-
onBackendSave: async (state: PersistableState) => {
|
|
380
|
-
await fetch('/api/assessment/save', {
|
|
381
|
-
method: 'POST',
|
|
382
|
-
headers: { 'Content-Type': 'application/json' },
|
|
383
|
-
body: JSON.stringify(state)
|
|
384
|
-
});
|
|
385
|
-
},
|
|
386
|
-
|
|
387
|
-
onSaveSuccess: (state) => {
|
|
388
|
-
console.log('Saved at:', state.savedAt);
|
|
389
|
-
},
|
|
390
|
-
|
|
391
|
-
onSaveError: (error) => {
|
|
392
|
-
console.error('Save failed:', error);
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
// Update state (triggers auto-save)
|
|
397
|
-
persistenceManager.updateState({
|
|
398
|
-
assessmentId: 'my-assessment',
|
|
399
|
-
currentItemIndex: 5,
|
|
400
|
-
visitedItems: [0, 1, 2, 3, 4, 5],
|
|
401
|
-
responses: { 'RESPONSE_1': 'answer' },
|
|
402
|
-
itemSessionStates: {},
|
|
403
|
-
savedAt: Date.now()
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// Load state
|
|
407
|
-
const savedState = await persistenceManager.load();
|
|
408
|
-
|
|
409
|
-
// Manual save
|
|
410
|
-
await persistenceManager.forceSave();
|
|
411
|
-
|
|
412
|
-
// Pause/resume auto-save (useful during navigation transitions)
|
|
413
|
-
persistenceManager.pauseAutoSave();
|
|
414
|
-
persistenceManager.resumeAutoSave();
|
|
415
|
-
|
|
416
|
-
// Cleanup
|
|
417
|
-
persistenceManager.destroy();
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
### State Structure
|
|
421
|
-
|
|
422
|
-
The `PersistableState` interface captures all necessary data:
|
|
423
|
-
|
|
424
|
-
```typescript
|
|
425
|
-
interface PersistableState {
|
|
426
|
-
assessmentId: string;
|
|
427
|
-
currentItemIndex: number;
|
|
428
|
-
visitedItems: number[];
|
|
429
|
-
responses: Record<string, unknown>;
|
|
430
|
-
itemSessionStates: Record<string, {
|
|
431
|
-
attemptCount: number;
|
|
432
|
-
isAnswered: boolean;
|
|
433
|
-
isSubmitted: boolean;
|
|
434
|
-
lastSubmissionTime?: number;
|
|
435
|
-
}>;
|
|
436
|
-
timeTracking?: {
|
|
437
|
-
startedAt: number;
|
|
438
|
-
totalElapsed: number;
|
|
439
|
-
itemTimes: Record<string, number>;
|
|
440
|
-
sectionTimes: Record<string, number>;
|
|
441
|
-
};
|
|
442
|
-
savedAt: number;
|
|
443
|
-
}
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
## Selection & Ordering
|
|
447
|
-
|
|
448
|
-
The assessment player supports QTI selection and ordering rules for creating randomized assessments and item pools.
|
|
449
|
-
|
|
450
|
-
### Selection Rules
|
|
451
|
-
|
|
452
|
-
Randomly select a subset of items from a pool:
|
|
453
|
-
|
|
454
|
-
```typescript
|
|
455
|
-
const assessment: QtiAssessmentTest = {
|
|
456
|
-
identifier: 'random-assessment',
|
|
457
|
-
title: 'Random Item Assessment',
|
|
458
|
-
testParts: [{
|
|
459
|
-
identifier: 'part-1',
|
|
460
|
-
navigationMode: 'nonlinear',
|
|
461
|
-
submissionMode: 'individual',
|
|
462
|
-
sections: [{
|
|
463
|
-
identifier: 'item-pool',
|
|
464
|
-
title: 'Question Pool',
|
|
465
|
-
|
|
466
|
-
// Selection rule: Pick 5 items from pool of 10
|
|
467
|
-
selection: {
|
|
468
|
-
select: 5, // Number of items to select
|
|
469
|
-
withReplacement: false // Don't allow same item twice (default)
|
|
470
|
-
},
|
|
52
|
+
```ts
|
|
53
|
+
import '@pie-qti/player-elements/register';
|
|
471
54
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
]
|
|
479
|
-
}]
|
|
480
|
-
}]
|
|
55
|
+
const element = document.createElement('pie-qti-assessment-player');
|
|
56
|
+
element.referenceMode = true;
|
|
57
|
+
element.assessmentTestXml = assessmentTestXml;
|
|
58
|
+
element.items = {
|
|
59
|
+
'items/item-1.xml': item1Xml,
|
|
60
|
+
'ITEM-2': item2Xml
|
|
481
61
|
};
|
|
482
|
-
|
|
483
|
-
// Optional: Provide seed for consistent randomization
|
|
484
|
-
const player = new AssessmentPlayer({
|
|
485
|
-
assessment,
|
|
486
|
-
randomSeed: 12345 // Same seed = same item selection
|
|
487
|
-
});
|
|
62
|
+
document.body.append(element);
|
|
488
63
|
```
|
|
489
64
|
|
|
490
|
-
|
|
491
|
-
- `
|
|
492
|
-
|
|
493
|
-
- `fromBank?: string` - Reference to external item bank (not yet implemented)
|
|
494
|
-
|
|
495
|
-
**Behavior:**
|
|
496
|
-
- If `select >= pool size`, all items are included
|
|
497
|
-
- Without replacement: Fisher-Yates shuffle, take first N items
|
|
498
|
-
- With replacement: Can select same item multiple times
|
|
65
|
+
Alternatively, set `itemBaseUrl` so the element can resolve `assessmentItemRef@href`. Reference mode
|
|
66
|
+
uses the client-side `ReferenceBackendAdapter`; item XML, correct answers, and scoring rules are
|
|
67
|
+
therefore available in the browser. Do not use it for authoritative delivery.
|
|
499
68
|
|
|
500
|
-
|
|
69
|
+
## Programmatic API
|
|
501
70
|
|
|
502
|
-
|
|
71
|
+
`AssessmentPlayer` initializes asynchronously. Construct it with `AssessmentPlayer.create()` and
|
|
72
|
+
the exact `BackendAdapter` session request:
|
|
503
73
|
|
|
504
|
-
```
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
identifier: 'part-1',
|
|
508
|
-
navigationMode: 'nonlinear',
|
|
509
|
-
submissionMode: 'individual',
|
|
510
|
-
sections: [{
|
|
511
|
-
identifier: 'section-1',
|
|
512
|
-
title: 'Mixed Questions',
|
|
513
|
-
|
|
514
|
-
// Ordering rule: Shuffle items except fixed ones
|
|
515
|
-
ordering: {
|
|
516
|
-
shuffle: true,
|
|
517
|
-
fixed: ['intro-question', 'summary-question'] // Keep these in place
|
|
518
|
-
},
|
|
519
|
-
|
|
520
|
-
questionRefs: [
|
|
521
|
-
{ identifier: 'intro-question', fixed: true, itemXml: '...' }, // Always first
|
|
522
|
-
{ identifier: 'q1', itemXml: '...' }, // Will be shuffled
|
|
523
|
-
{ identifier: 'q2', itemXml: '...' }, // Will be shuffled
|
|
524
|
-
{ identifier: 'q3', itemXml: '...' }, // Will be shuffled
|
|
525
|
-
{ identifier: 'summary-question', fixed: true, itemXml: '...' } // Always last
|
|
526
|
-
]
|
|
527
|
-
}]
|
|
528
|
-
}]
|
|
529
|
-
};
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
**Ordering Options:**
|
|
533
|
-
- `shuffle?: boolean` - Shuffle items (default: false)
|
|
534
|
-
- `fixed?: string[]` - Item identifiers that should not be shuffled
|
|
535
|
-
|
|
536
|
-
**Per-Item Fixed Flag:**
|
|
537
|
-
Items can also be marked as fixed directly:
|
|
538
|
-
|
|
539
|
-
```typescript
|
|
540
|
-
questionRefs: [
|
|
541
|
-
{ identifier: 'q1', fixed: true, itemXml: '...' }, // Won't shuffle
|
|
542
|
-
{ identifier: 'q2', itemXml: '...' } // Will shuffle
|
|
543
|
-
]
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
### Combined Selection & Ordering
|
|
547
|
-
|
|
548
|
-
You can use both rules together:
|
|
74
|
+
```ts
|
|
75
|
+
import { AssessmentPlayer } from '@pie-qti/assessment-player';
|
|
76
|
+
import type { BackendAdapter } from '@pie-qti/assessment-player/integration';
|
|
549
77
|
|
|
550
|
-
|
|
551
|
-
sections: [{
|
|
552
|
-
identifier: 'random-shuffled-pool',
|
|
78
|
+
declare const backend: BackendAdapter;
|
|
553
79
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
80
|
+
const player = await AssessmentPlayer.create({
|
|
81
|
+
backend,
|
|
82
|
+
initSession: {
|
|
83
|
+
assessmentId: 'algebra-final',
|
|
84
|
+
candidateId: 'candidate-42'
|
|
558
85
|
},
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
ordering: {
|
|
562
|
-
shuffle: true,
|
|
563
|
-
fixed: ['anchor-item'] // But keep anchor item in place
|
|
564
|
-
},
|
|
565
|
-
|
|
566
|
-
questionRefs: [
|
|
567
|
-
{ identifier: 'anchor-item', fixed: true, itemXml: '...' },
|
|
568
|
-
// ... 19 more items in pool
|
|
569
|
-
]
|
|
570
|
-
}]
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
**Processing Order:**
|
|
574
|
-
1. Selection is applied first (if specified)
|
|
575
|
-
2. Ordering is applied to the selected items (if specified)
|
|
576
|
-
3. Fixed items maintain their relative positions
|
|
577
|
-
|
|
578
|
-
### Random Seed
|
|
579
|
-
|
|
580
|
-
Control randomization for reproducibility or testing:
|
|
581
|
-
|
|
582
|
-
```typescript
|
|
583
|
-
// Different candidates get different randomizations
|
|
584
|
-
const player = new AssessmentPlayer({
|
|
585
|
-
assessment,
|
|
586
|
-
randomSeed: candidateId // Each candidate gets unique seed
|
|
86
|
+
security,
|
|
87
|
+
plugins
|
|
587
88
|
});
|
|
588
89
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
const player = new AssessmentPlayer({
|
|
592
|
-
assessment,
|
|
593
|
-
randomSeed: sessionSeed // Same items for whole session
|
|
90
|
+
const unsubscribe = player.onResponseChange((responses) => {
|
|
91
|
+
console.log(responses);
|
|
594
92
|
});
|
|
595
|
-
```
|
|
596
|
-
|
|
597
|
-
**Seed Behavior:**
|
|
598
|
-
- Default: `Date.now()` (different each time)
|
|
599
|
-
- Same seed = same item selection and order
|
|
600
|
-
- Used internally for consistency (resume preserves order)
|
|
601
|
-
- Uses Linear Congruential Generator (LCG) for seeded randomness
|
|
602
|
-
|
|
603
|
-
### Use Cases
|
|
604
|
-
|
|
605
|
-
**1. Item Pools**
|
|
606
|
-
```typescript
|
|
607
|
-
// Create large pool, select subset per candidate
|
|
608
|
-
selection: { select: 20 }, // From pool of 100
|
|
609
|
-
questionRefs: [...100 items...]
|
|
610
|
-
```
|
|
611
|
-
|
|
612
|
-
**2. Randomized Exams**
|
|
613
|
-
```typescript
|
|
614
|
-
// Shuffle all questions to prevent cheating
|
|
615
|
-
ordering: { shuffle: true }
|
|
616
|
-
```
|
|
617
|
-
|
|
618
|
-
**3. Fixed Start/End**
|
|
619
|
-
```typescript
|
|
620
|
-
// Instructions first, reflection last, shuffle middle
|
|
621
|
-
ordering: {
|
|
622
|
-
shuffle: true,
|
|
623
|
-
fixed: ['instructions', 'reflection']
|
|
624
|
-
}
|
|
625
|
-
```
|
|
626
|
-
|
|
627
|
-
**4. Practice Mode**
|
|
628
|
-
```typescript
|
|
629
|
-
// Random subset, shuffled order, new each time
|
|
630
|
-
selection: { select: 10 },
|
|
631
|
-
ordering: { shuffle: true }
|
|
632
|
-
// No randomSeed = different each load
|
|
633
|
-
```
|
|
634
|
-
|
|
635
|
-
**5. Consistent Test Forms**
|
|
636
|
-
```typescript
|
|
637
|
-
// Same questions for all candidates taking "Form A"
|
|
638
|
-
randomSeed: 'form-a'.hashCode(), // Consistent seed
|
|
639
|
-
selection: { select: 50 },
|
|
640
|
-
ordering: { shuffle: true }
|
|
641
|
-
```
|
|
642
|
-
|
|
643
|
-
## Outcome Processing & Scoring
|
|
644
|
-
|
|
645
|
-
The assessment player implements QTI outcome processing patterns for aggregating item scores into assessment-level outcomes.
|
|
646
|
-
|
|
647
|
-
### Scoring Templates
|
|
648
|
-
|
|
649
|
-
The `outcomeProcessing.template` field determines how item scores are combined:
|
|
650
|
-
|
|
651
|
-
#### Total Score (Default)
|
|
652
|
-
|
|
653
|
-
Simple sum of all item scores.
|
|
654
|
-
|
|
655
|
-
```typescript
|
|
656
|
-
const assessment: QtiAssessmentTest = {
|
|
657
|
-
identifier: 'test-1',
|
|
658
|
-
outcomeProcessing: {
|
|
659
|
-
template: 'total_score' // or omit for default
|
|
660
|
-
},
|
|
661
|
-
testParts: [/* ... */]
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
// Results:
|
|
665
|
-
// SCORE = sum of item scores
|
|
666
|
-
// MAXSCORE = sum of item max scores
|
|
667
|
-
```
|
|
668
|
-
|
|
669
|
-
#### Weighted Score
|
|
670
|
-
|
|
671
|
-
Applies weights to individual items. Use `weight` property on `questionRef` to specify item weights (default: 1).
|
|
672
|
-
|
|
673
|
-
```typescript
|
|
674
|
-
const assessment: QtiAssessmentTest = {
|
|
675
|
-
identifier: 'test-1',
|
|
676
|
-
outcomeProcessing: {
|
|
677
|
-
template: 'weighted_score'
|
|
678
|
-
},
|
|
679
|
-
testParts: [{
|
|
680
|
-
identifier: 'part-1',
|
|
681
|
-
navigationMode: 'nonlinear',
|
|
682
|
-
submissionMode: 'simultaneous',
|
|
683
|
-
sections: [{
|
|
684
|
-
identifier: 'section-1',
|
|
685
|
-
questionRefs: [
|
|
686
|
-
{
|
|
687
|
-
identifier: 'q1',
|
|
688
|
-
weight: 2, // Worth 2x other items
|
|
689
|
-
itemXml: '...'
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
identifier: 'q2',
|
|
693
|
-
weight: 1,
|
|
694
|
-
itemXml: '...'
|
|
695
|
-
},
|
|
696
|
-
{
|
|
697
|
-
identifier: 'q3',
|
|
698
|
-
weight: 3, // Worth 3x other items
|
|
699
|
-
itemXml: '...'
|
|
700
|
-
}
|
|
701
|
-
]
|
|
702
|
-
}]
|
|
703
|
-
}]
|
|
704
|
-
};
|
|
705
|
-
|
|
706
|
-
// Results:
|
|
707
|
-
// SCORE = (q1.score * 2) + (q2.score * 1) + (q3.score * 3)
|
|
708
|
-
// MAXSCORE = (q1.maxScore * 2) + (q2.maxScore * 1) + (q3.maxScore * 3)
|
|
709
|
-
```
|
|
710
|
-
|
|
711
|
-
#### Percentage Score
|
|
712
|
-
|
|
713
|
-
Calculates percentage of total possible points (0-100).
|
|
714
|
-
|
|
715
|
-
```typescript
|
|
716
|
-
const assessment: QtiAssessmentTest = {
|
|
717
|
-
outcomeProcessing: {
|
|
718
|
-
template: 'percentage_score'
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
|
|
722
|
-
// Results:
|
|
723
|
-
// SCORE = (total earned / total possible) * 100
|
|
724
|
-
// MAXSCORE = 100
|
|
725
|
-
// PERCENTAGE = same as SCORE
|
|
726
|
-
```
|
|
727
93
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
```typescript
|
|
733
|
-
const assessment: QtiAssessmentTest = {
|
|
734
|
-
outcomeDeclarations: [
|
|
735
|
-
{
|
|
736
|
-
identifier: 'PASSING_THRESHOLD',
|
|
737
|
-
baseType: 'float',
|
|
738
|
-
cardinality: 'single',
|
|
739
|
-
defaultValue: 0.7 // 70% threshold
|
|
740
|
-
}
|
|
741
|
-
],
|
|
742
|
-
outcomeProcessing: {
|
|
743
|
-
template: 'pass_fail'
|
|
744
|
-
}
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
// Results:
|
|
748
|
-
// SCORE = total earned points
|
|
749
|
-
// MAXSCORE = total possible points
|
|
750
|
-
// PASSED = true/false (based on threshold)
|
|
751
|
-
// PERCENTAGE = percentage score
|
|
752
|
-
```
|
|
753
|
-
|
|
754
|
-
### Outcome Variables
|
|
755
|
-
|
|
756
|
-
Define custom outcome variables with `outcomeDeclarations`:
|
|
757
|
-
|
|
758
|
-
```typescript
|
|
759
|
-
const assessment: QtiAssessmentTest = {
|
|
760
|
-
outcomeDeclarations: [
|
|
761
|
-
{
|
|
762
|
-
identifier: 'SCORE',
|
|
763
|
-
baseType: 'float',
|
|
764
|
-
cardinality: 'single',
|
|
765
|
-
defaultValue: 0
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
identifier: 'MAXSCORE',
|
|
769
|
-
baseType: 'float',
|
|
770
|
-
cardinality: 'single',
|
|
771
|
-
defaultValue: 0
|
|
772
|
-
},
|
|
773
|
-
{
|
|
774
|
-
identifier: 'PASSING_THRESHOLD',
|
|
775
|
-
baseType: 'float',
|
|
776
|
-
cardinality: 'single',
|
|
777
|
-
defaultValue: 0.75
|
|
778
|
-
},
|
|
779
|
-
{
|
|
780
|
-
identifier: 'GRADE_LEVEL',
|
|
781
|
-
baseType: 'string',
|
|
782
|
-
cardinality: 'single',
|
|
783
|
-
defaultValue: 'Not Graded'
|
|
784
|
-
}
|
|
785
|
-
]
|
|
786
|
-
};
|
|
787
|
-
```
|
|
788
|
-
|
|
789
|
-
### Accessing Outcomes
|
|
94
|
+
await player.navigateTo(0);
|
|
95
|
+
const session = player.getCurrentItemSession();
|
|
96
|
+
const presentation = session?.present();
|
|
790
97
|
|
|
791
|
-
|
|
98
|
+
// Section/test-part shared rubrics are separate from direct assessmentItem rubrics.
|
|
99
|
+
const sharedRubrics = player.getCurrentSharedRubricBlocks();
|
|
100
|
+
const directRubrics = presentation?.directRubrics ?? [];
|
|
792
101
|
|
|
793
|
-
|
|
102
|
+
await player.next();
|
|
794
103
|
const results = await player.submit();
|
|
795
104
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
105
|
+
unsubscribe();
|
|
106
|
+
player.destroy();
|
|
107
|
+
```
|
|
799
108
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
const allOutcomes = outcomeProcessor.getOutcomes();
|
|
803
|
-
const passed = outcomeProcessor.getOutcome('PASSED');
|
|
804
|
-
const percentage = outcomeProcessor.getOutcome('PERCENTAGE');
|
|
109
|
+
Each secure item fixes the role of its compiled item definition and live session. Callers cannot
|
|
110
|
+
change that role through `ItemSession.present()`.
|
|
805
111
|
|
|
806
|
-
|
|
807
|
-
console.log('Passed:', passed);
|
|
808
|
-
console.log('Percentage:', percentage);
|
|
809
|
-
```
|
|
112
|
+
### Development adapter
|
|
810
113
|
|
|
811
|
-
|
|
114
|
+
The reference adapter is useful for tests and demos when a `SecureAssessment` is already available:
|
|
812
115
|
|
|
813
|
-
|
|
116
|
+
```ts
|
|
117
|
+
import { AssessmentPlayer } from '@pie-qti/assessment-player';
|
|
118
|
+
import { ReferenceBackendAdapter } from '@pie-qti/assessment-player/integration';
|
|
814
119
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
outcomeProcessing: {
|
|
818
|
-
template: 'pass_fail'
|
|
819
|
-
},
|
|
820
|
-
testFeedback: [
|
|
821
|
-
{
|
|
822
|
-
identifier: 'pass-feedback',
|
|
823
|
-
outcomeIdentifier: 'PASSED',
|
|
824
|
-
showHide: 'show', // Show when PASSED is true
|
|
825
|
-
access: 'atEnd',
|
|
826
|
-
content: '<p>Congratulations! You passed the test.</p>'
|
|
827
|
-
},
|
|
828
|
-
{
|
|
829
|
-
identifier: 'fail-feedback',
|
|
830
|
-
outcomeIdentifier: 'PASSED',
|
|
831
|
-
showHide: 'hide', // Show when PASSED is false
|
|
832
|
-
access: 'atEnd',
|
|
833
|
-
content: '<p>Unfortunately, you did not pass. Please review the material and try again.</p>'
|
|
834
|
-
}
|
|
835
|
-
]
|
|
836
|
-
};
|
|
120
|
+
const backend = new ReferenceBackendAdapter();
|
|
121
|
+
backend.registerAssessment('preview', secureAssessment);
|
|
837
122
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
}
|
|
123
|
+
const player = await AssessmentPlayer.create({
|
|
124
|
+
backend,
|
|
125
|
+
initSession: { assessmentId: 'preview', candidateId: 'local-user' }
|
|
126
|
+
});
|
|
843
127
|
```
|
|
844
128
|
|
|
845
|
-
|
|
129
|
+
This adapter stores state and scores in the client. It is not a production security boundary.
|
|
846
130
|
|
|
847
|
-
|
|
131
|
+
## Backend contract
|
|
848
132
|
|
|
849
|
-
|
|
850
|
-
import { OutcomeProcessor, AssessmentPlayer } from '@pie-qti/assessment-player';
|
|
851
|
-
import type { AssessmentPlayerConfig } from '@pie-qti/assessment-player';
|
|
133
|
+
Implement `BackendAdapter` for production:
|
|
852
134
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
135
|
+
```ts
|
|
136
|
+
import type {
|
|
137
|
+
BackendAdapter,
|
|
138
|
+
FinalizeAssessmentRequest,
|
|
139
|
+
InitSessionRequest,
|
|
140
|
+
SaveAssessmentStateRequest,
|
|
141
|
+
SubmitResponsesRequest
|
|
142
|
+
} from '@pie-qti/assessment-player/integration';
|
|
858
143
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
results.outcomes.SCORE += perfectCount * 5; // 5 bonus points per perfect item
|
|
863
|
-
results.outcomes.BONUS_POINTS = perfectCount * 5;
|
|
864
|
-
|
|
865
|
-
return results;
|
|
144
|
+
export class HttpAssessmentBackend implements BackendAdapter {
|
|
145
|
+
initSession(request: InitSessionRequest) {
|
|
146
|
+
return post('/api/qti/session', request);
|
|
866
147
|
}
|
|
867
|
-
}
|
|
868
148
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
constructor(assessment) {
|
|
872
|
-
this.assessment = assessment;
|
|
149
|
+
submitResponses(request: SubmitResponsesRequest) {
|
|
150
|
+
return post('/api/qti/item-submission', request);
|
|
873
151
|
}
|
|
874
152
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
// Must return an AssessmentResults object
|
|
878
|
-
return {
|
|
879
|
-
outcomes: {
|
|
880
|
-
SCORE: /* your calculation */,
|
|
881
|
-
MAXSCORE: /* your calculation */,
|
|
882
|
-
// ... any custom outcome variables
|
|
883
|
-
},
|
|
884
|
-
feedback: []
|
|
885
|
-
};
|
|
153
|
+
saveState(request: SaveAssessmentStateRequest) {
|
|
154
|
+
return post('/api/qti/session/state', request);
|
|
886
155
|
}
|
|
887
156
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
return [];
|
|
157
|
+
finalizeAssessment(request: FinalizeAssessmentRequest) {
|
|
158
|
+
return post('/api/qti/finalize', request);
|
|
891
159
|
}
|
|
892
160
|
}
|
|
893
|
-
|
|
894
|
-
// Use your custom processor
|
|
895
|
-
const config: AssessmentPlayerConfig = {
|
|
896
|
-
assessment,
|
|
897
|
-
outcomeProcessor: new CustomOutcomeProcessor(assessment),
|
|
898
|
-
// ... other config
|
|
899
|
-
};
|
|
900
|
-
|
|
901
|
-
const player = new AssessmentPlayer(config);
|
|
902
|
-
```
|
|
903
|
-
|
|
904
|
-
**Note:** The player does NOT include a full QTI rule interpreter for complex `setOutcomeValue`, `responseCondition`, etc. This is an intentional design decision to avoid unnecessary complexity. The pluggable outcome processor architecture allows you to implement any custom scoring logic you need while keeping the core framework simple and maintainable.
|
|
905
|
-
|
|
906
|
-
### Scoring Use Cases
|
|
907
|
-
|
|
908
|
-
#### 1. Simple Quiz
|
|
909
|
-
|
|
910
|
-
```typescript
|
|
911
|
-
// Just sum the scores
|
|
912
|
-
outcomeProcessing: { template: 'total_score' }
|
|
913
|
-
```
|
|
914
|
-
|
|
915
|
-
#### 2. Weighted Exam
|
|
916
|
-
|
|
917
|
-
```typescript
|
|
918
|
-
// Essay questions worth more than multiple choice
|
|
919
|
-
outcomeProcessing: { template: 'weighted_score' }
|
|
920
|
-
// Set weight: 5 on essay questionRefs, weight: 1 on MC
|
|
921
|
-
```
|
|
922
|
-
|
|
923
|
-
#### 3. Pass/Fail Certification
|
|
924
|
-
|
|
925
|
-
```typescript
|
|
926
|
-
// Must score 80% to pass
|
|
927
|
-
outcomeDeclarations: [
|
|
928
|
-
{ identifier: 'PASSING_THRESHOLD', baseType: 'float', cardinality: 'single', defaultValue: 0.8 }
|
|
929
|
-
],
|
|
930
|
-
outcomeProcessing: { template: 'pass_fail' }
|
|
931
|
-
```
|
|
932
|
-
|
|
933
|
-
#### 4. Grade Levels
|
|
934
|
-
|
|
935
|
-
```typescript
|
|
936
|
-
// Use percentage_score and map to letter grades in your app
|
|
937
|
-
outcomeProcessing: { template: 'percentage_score' }
|
|
938
|
-
// Then: A = 90-100, B = 80-89, etc.
|
|
939
|
-
```
|
|
940
|
-
|
|
941
|
-
#### 5. Adaptive Feedback
|
|
942
|
-
|
|
943
|
-
```typescript
|
|
944
|
-
// Show different feedback based on score ranges
|
|
945
|
-
testFeedback: [
|
|
946
|
-
{ outcomeIdentifier: 'HIGH_SCORE', showHide: 'show', content: 'Excellent work!' },
|
|
947
|
-
{ outcomeIdentifier: 'MEDIUM_SCORE', showHide: 'show', content: 'Good effort!' },
|
|
948
|
-
{ outcomeIdentifier: 'LOW_SCORE', showHide: 'show', content: 'Keep practicing!' }
|
|
949
|
-
]
|
|
950
|
-
```
|
|
951
|
-
|
|
952
|
-
## Components
|
|
953
|
-
|
|
954
|
-
### AssessmentShell
|
|
955
|
-
|
|
956
|
-
Main component that orchestrates the entire assessment experience.
|
|
957
|
-
|
|
958
|
-
**Props:**
|
|
959
|
-
- `assessment: QtiAssessmentTest` - The assessment data
|
|
960
|
-
- `config?: AssessmentPlayerConfig` - Configuration options
|
|
961
|
-
|
|
962
|
-
### NavigationBar
|
|
963
|
-
|
|
964
|
-
Navigation controls with progress indicator.
|
|
965
|
-
|
|
966
|
-
**Props:**
|
|
967
|
-
- `navState: NavigationState` - Current navigation state
|
|
968
|
-
- `onPrevious?: () => void` - Previous button handler
|
|
969
|
-
- `onNext?: () => void` - Next button handler
|
|
970
|
-
- `onSubmit?: () => void` - Submit button handler
|
|
971
|
-
- `showProgress?: boolean` - Show progress bar (default: true)
|
|
972
|
-
|
|
973
|
-
### SectionMenu
|
|
974
|
-
|
|
975
|
-
Dropdown menu for section navigation.
|
|
976
|
-
|
|
977
|
-
**Props:**
|
|
978
|
-
- `sections: Section[]` - List of sections
|
|
979
|
-
- `currentSectionIndex?: number` - Active section index
|
|
980
|
-
- `onSectionSelect?: (index: number) => void` - Section selection handler
|
|
981
|
-
- `disabled?: boolean` - Disable navigation
|
|
982
|
-
|
|
983
|
-
### RubricDisplay
|
|
984
|
-
|
|
985
|
-
Displays rubric blocks (passages, instructions).
|
|
986
|
-
|
|
987
|
-
**Props:**
|
|
988
|
-
- `blocks: RubricBlock[]` - Array of rubric blocks
|
|
989
|
-
- `collapsed?: boolean` - Initial collapsed state
|
|
990
|
-
|
|
991
|
-
### ItemRenderer
|
|
992
|
-
|
|
993
|
-
Renders individual QTI items within the assessment.
|
|
994
|
-
|
|
995
|
-
**Props:**
|
|
996
|
-
- `questionRef: QuestionRef` - Question reference with item XML
|
|
997
|
-
- `role?: QTIRole` - QTI role/view actor (default: 'candidate')
|
|
998
|
-
- `extendedTextEditor?: 'tiptap' | 'textarea'` - Editor type for extended text
|
|
999
|
-
- `responses?: Record<string, unknown>` - Response data
|
|
1000
|
-
- `onResponseChange?: (responseId: string, value: unknown) => void` - Response handler
|
|
1001
|
-
|
|
1002
|
-
## Navigation Modes
|
|
1003
|
-
|
|
1004
|
-
### Linear Navigation
|
|
1005
|
-
|
|
1006
|
-
Sequential navigation only. Students must proceed through items in order but can review previous items.
|
|
1007
|
-
|
|
1008
|
-
```typescript
|
|
1009
|
-
{
|
|
1010
|
-
navigationMode: 'linear'
|
|
1011
|
-
}
|
|
1012
|
-
```
|
|
1013
|
-
|
|
1014
|
-
### Nonlinear Navigation
|
|
1015
|
-
|
|
1016
|
-
Free navigation. Students can jump to any item at any time.
|
|
1017
|
-
|
|
1018
|
-
```typescript
|
|
1019
|
-
{
|
|
1020
|
-
navigationMode: 'nonlinear'
|
|
1021
|
-
}
|
|
1022
161
|
```
|
|
1023
162
|
|
|
1024
|
-
|
|
163
|
+
The backend must authenticate the candidate, authorize the assessment, filter candidate-visible item
|
|
164
|
+
XML, own authoritative scoring state, and validate every client submission. See
|
|
165
|
+
[BACKEND-INTEGRATION.md](./BACKEND-INTEGRATION.md) for the request/response contract.
|
|
1025
166
|
|
|
1026
|
-
|
|
1027
|
-
player.onItemChange((index, total) => {
|
|
1028
|
-
console.log(`Item ${index + 1} of ${total}`);
|
|
1029
|
-
});
|
|
167
|
+
## Submission and lifecycle behavior
|
|
1030
168
|
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
169
|
+
- `updateResponse()` and the current `ItemSession` update local response state.
|
|
170
|
+
- `submitCurrentItem()` provisionally ends the live attempt, then sends the response to the backend.
|
|
171
|
+
If validation or the backend request fails, the player restores the pre-submit item-session
|
|
172
|
+
snapshot so the candidate can retry.
|
|
173
|
+
- In `individual` mode, `next()` submits the current item before navigating and honors the backend's
|
|
174
|
+
`nextItemIdentifier` branch decision.
|
|
175
|
+
- In `simultaneous` mode, `submit()` sends every unsubmitted item before finalization while preserving
|
|
176
|
+
responses and serialized item sessions across backend state replacements.
|
|
177
|
+
- `submit()` finishes by calling `finalizeAssessment()` and returns `AssessmentResults`.
|
|
1034
178
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
179
|
+
The optional `sendItemSessionToBackend` flag includes the rich serialized item-session snapshot in
|
|
180
|
+
submission requests. Treat that snapshot as untrusted client save data; a production backend should
|
|
181
|
+
validate it against server-owned source and state.
|
|
1038
182
|
|
|
1039
|
-
|
|
1040
|
-
console.log('Assessment completed!');
|
|
1041
|
-
});
|
|
1042
|
-
```
|
|
183
|
+
## Core configuration
|
|
1043
184
|
|
|
1044
|
-
|
|
185
|
+
`BackendAssessmentPlayerConfig` requires:
|
|
1045
186
|
|
|
1046
|
-
|
|
187
|
+
- `backend: BackendAdapter`
|
|
188
|
+
- `initSession: InitSessionRequest`
|
|
1047
189
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
190
|
+
It also accepts definition plugins, security and PCI policy, PNP, i18n, deterministic RNG, section
|
|
191
|
+
host/tool configuration, display hints, timing warnings, and compatibility callbacks. Prefer the
|
|
192
|
+
`onItemChange()`, `onSectionChange()`, `onResponseChange()`, `onComplete()`, and timing subscription
|
|
193
|
+
methods when lifecycle-managed unsubscription is useful.
|
|
1052
194
|
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
player.restoreState(savedState);
|
|
1056
|
-
```
|
|
195
|
+
Definition plugins use `AssessmentItemDefinitionPlugin` from `@pie-qti/item-player` and are applied
|
|
196
|
+
to every item definition created by the assessment player.
|
|
1057
197
|
|
|
1058
|
-
##
|
|
1059
|
-
|
|
1060
|
-
Components use DaisyUI classes and can be styled with Tailwind CSS or custom CSS variables.
|
|
1061
|
-
|
|
1062
|
-
## Development
|
|
1063
|
-
|
|
1064
|
-
```bash
|
|
1065
|
-
# Build
|
|
1066
|
-
bun run build
|
|
1067
|
-
|
|
1068
|
-
# Watch mode
|
|
1069
|
-
bun run dev
|
|
1070
|
-
|
|
1071
|
-
# Type check
|
|
1072
|
-
bun run typecheck
|
|
1073
|
-
|
|
1074
|
-
# Lint
|
|
1075
|
-
bun run lint
|
|
1076
|
-
```
|
|
198
|
+
## Public exports
|
|
1077
199
|
|
|
1078
|
-
|
|
200
|
+
- `@pie-qti/assessment-player`: `AssessmentPlayer`, navigation types, and backend contract re-exports.
|
|
201
|
+
- `@pie-qti/assessment-player/integration`: `BackendAdapter`, request/response types,
|
|
202
|
+
`ReferenceBackendAdapter`, and assessment scoring/composition helpers.
|
|
203
|
+
- `@pie-qti/player-elements/register`: complete browser registration entry.
|
|
204
|
+
- `@pie-qti/player-elements/elements`: browser constructors for manual registration.
|
|
1079
205
|
|
|
1080
|
-
|
|
206
|
+
Svelte source components inside this package are implementation details and are not published as a
|
|
207
|
+
package subpath.
|