@pie-qti/assessment-player 0.1.4 → 0.1.6
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 +19 -16
- package/dist/core/AssessmentPlayer.d.ts +21 -2
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +144 -15
- package/dist/core/TimeManager.d.ts +9 -0
- package/dist/core/TimeManager.d.ts.map +1 -1
- package/dist/core/TimeManager.js +16 -3
- package/dist/integration/ReferenceBackendAdapter.d.ts +28 -8
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.js +409 -51
- package/dist/integration/api-contract.d.ts +82 -2
- package/dist/integration/api-contract.d.ts.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +12 -0
- package/dist/integration/assessment-item-scorer.d.ts.map +1 -0
- package/dist/integration/assessment-item-scorer.js +40 -0
- package/dist/integration/index.d.ts +1 -0
- package/dist/integration/index.d.ts.map +1 -1
- package/dist/integration/index.js +1 -0
- package/package.json +6 -6
- package/src/components/AccessibilityAnnouncer.svelte +13 -2
- package/src/components/AssessmentShell.svelte +13 -8
- package/src/components/AssessmentTimer.svelte +23 -0
- package/src/components/ItemRenderer.svelte +7 -3
- package/src/components/NavigationBar.svelte +2 -0
- package/src/components/SectionMenu.svelte +72 -5
- package/src/components/index.ts +1 -1
- package/src/core/AssessmentPlayer.ts +162 -17
- package/src/core/TimeManager.ts +20 -3
- package/src/integration/ReferenceBackendAdapter.ts +467 -54
- package/src/integration/api-contract.ts +84 -2
- package/src/integration/assessment-item-scorer.ts +53 -0
- package/src/integration/index.ts +5 -0
|
@@ -61,6 +61,18 @@ export interface InitSessionResponse {
|
|
|
61
61
|
*
|
|
62
62
|
* Security: NO correct answers, NO scoring rules, NO sensitive rubrics
|
|
63
63
|
*/
|
|
64
|
+
export interface TestFeedbackItem {
|
|
65
|
+
identifier: string;
|
|
66
|
+
/** Outcome variable name to evaluate (e.g. "PASS", "GRADE") */
|
|
67
|
+
outcomeIdentifier: string;
|
|
68
|
+
/** 'show' = show when outcome equals identifier; 'hide' = show when it does not */
|
|
69
|
+
showHide: 'show' | 'hide';
|
|
70
|
+
/** 'atEnd' = only after submission; 'during' = also during attempt */
|
|
71
|
+
access: 'atEnd' | 'during';
|
|
72
|
+
/** HTML content to display */
|
|
73
|
+
content: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
export interface SecureAssessment {
|
|
65
77
|
identifier: string;
|
|
66
78
|
title: string;
|
|
@@ -75,6 +87,19 @@ export interface SecureAssessment {
|
|
|
75
87
|
maxTime?: number; // seconds
|
|
76
88
|
allowLateSubmission?: boolean;
|
|
77
89
|
};
|
|
90
|
+
/** QTI outcomeDeclarations for test-level variables */
|
|
91
|
+
outcomeDeclarations?: Array<{
|
|
92
|
+
identifier: string;
|
|
93
|
+
baseType: string;
|
|
94
|
+
cardinality: string;
|
|
95
|
+
defaultValue?: unknown;
|
|
96
|
+
}>;
|
|
97
|
+
/** Raw <outcomeProcessing> XML string, if present */
|
|
98
|
+
outcomeProcessingXml?: string;
|
|
99
|
+
/** Base URL/path for resolving relative hrefs (e.g. assessmentSectionRef) */
|
|
100
|
+
baseUrl?: string;
|
|
101
|
+
/** QTI testFeedback blocks for post-submission display */
|
|
102
|
+
testFeedback?: TestFeedbackItem[];
|
|
78
103
|
}
|
|
79
104
|
|
|
80
105
|
export interface SecureTestPart {
|
|
@@ -103,7 +128,7 @@ export interface SecureSection {
|
|
|
103
128
|
title?: string;
|
|
104
129
|
/** Visible determines if section appears in navigation */
|
|
105
130
|
visible: boolean;
|
|
106
|
-
/** Assessment item references */
|
|
131
|
+
/** Assessment item references (order reflects selection/ordering already applied server-side) */
|
|
107
132
|
assessmentItemRefs: SecureItemRef[];
|
|
108
133
|
/** Section-level time limit */
|
|
109
134
|
timeLimits?: {
|
|
@@ -111,6 +136,35 @@ export interface SecureSection {
|
|
|
111
136
|
};
|
|
112
137
|
/** Candidate instructions (safe for display) */
|
|
113
138
|
rubricBlocks?: AssessmentRubricBlock[];
|
|
139
|
+
/**
|
|
140
|
+
* QTI selection: how many items to present from this section.
|
|
141
|
+
* When present the server has already applied selection; client uses this for progress display.
|
|
142
|
+
*/
|
|
143
|
+
selection?: {
|
|
144
|
+
/** Number of items selected for this session */
|
|
145
|
+
select: number;
|
|
146
|
+
withReplacement?: boolean;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* QTI ordering: whether items were shuffled.
|
|
150
|
+
* When true the server has already shuffled assessmentItemRefs.
|
|
151
|
+
*/
|
|
152
|
+
ordering?: {
|
|
153
|
+
shuffle: boolean;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Item session control (QTI assessmentSection/itemSessionControl).
|
|
157
|
+
* Section-level values take precedence over testPart-level when present.
|
|
158
|
+
*/
|
|
159
|
+
itemSessionControl?: {
|
|
160
|
+
maxAttempts?: number;
|
|
161
|
+
showFeedback?: boolean;
|
|
162
|
+
allowReview?: boolean;
|
|
163
|
+
showSolution?: boolean;
|
|
164
|
+
allowComment?: boolean;
|
|
165
|
+
allowSkipping?: boolean;
|
|
166
|
+
validateResponses?: boolean;
|
|
167
|
+
};
|
|
114
168
|
}
|
|
115
169
|
|
|
116
170
|
export interface SecureItemRef {
|
|
@@ -122,6 +176,18 @@ export interface SecureItemRef {
|
|
|
122
176
|
role: QTIRole;
|
|
123
177
|
/** Required=true means item must be attempted */
|
|
124
178
|
required?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* QTI branchRule: ordered list of branch rules on this item.
|
|
181
|
+
* The backend evaluates these after scoring and returns nextItemIdentifier in SubmitResponsesResponse.
|
|
182
|
+
* Carried here so reference/demo adapters can evaluate them client-side.
|
|
183
|
+
*/
|
|
184
|
+
branchRule?: Array<{
|
|
185
|
+
/** Identifier of the target item, section, testPart, or one of the special values:
|
|
186
|
+
* EXIT_TEST | EXIT_TESTPART | EXIT_SECTION */
|
|
187
|
+
target: string;
|
|
188
|
+
/** Serialised QTI expression XML (the child of <branchRule>). Absent means unconditional. */
|
|
189
|
+
conditionXml?: string;
|
|
190
|
+
}>;
|
|
125
191
|
}
|
|
126
192
|
|
|
127
193
|
export interface AssessmentRubricBlock {
|
|
@@ -245,6 +311,8 @@ export interface AssessmentSessionState {
|
|
|
245
311
|
itemResponses: Record<string, Record<string, ResponseValue>>;
|
|
246
312
|
/** Scoring results per item (populated after submission) */
|
|
247
313
|
itemScores?: Record<string, AssessmentScoringResult>;
|
|
314
|
+
/** ItemSession lifecycle hints per item, used to restore attempt/review UI state */
|
|
315
|
+
itemSessionStates?: Record<string, AssessmentItemSessionState>;
|
|
248
316
|
/** Time tracking */
|
|
249
317
|
timing: {
|
|
250
318
|
/** Session start time */
|
|
@@ -256,6 +324,14 @@ export interface AssessmentSessionState {
|
|
|
256
324
|
};
|
|
257
325
|
}
|
|
258
326
|
|
|
327
|
+
export interface AssessmentItemSessionState {
|
|
328
|
+
itemIdentifier: string;
|
|
329
|
+
attemptCount: number;
|
|
330
|
+
isAnswered: boolean;
|
|
331
|
+
isSubmitted: boolean;
|
|
332
|
+
lastSubmissionTime?: number;
|
|
333
|
+
}
|
|
334
|
+
|
|
259
335
|
// ============================================================================
|
|
260
336
|
// FINALIZE ASSESSMENT
|
|
261
337
|
// ============================================================================
|
|
@@ -277,8 +353,14 @@ export interface FinalizeAssessmentResponse {
|
|
|
277
353
|
maxScore: number;
|
|
278
354
|
/** Per-item results */
|
|
279
355
|
itemScores: Record<string, AssessmentScoringResult>;
|
|
280
|
-
/** Assessment-level feedback */
|
|
356
|
+
/** Assessment-level feedback (legacy: single string; prefer outcomes + assessment.testFeedback) */
|
|
281
357
|
feedback?: string;
|
|
358
|
+
/**
|
|
359
|
+
* Test-level outcome variable values after outcomeProcessing.
|
|
360
|
+
* Used to evaluate testFeedback visibility via string equality.
|
|
361
|
+
* Keys are outcome identifiers (e.g. "PASS", "GRADE"); values are their string representations.
|
|
362
|
+
*/
|
|
363
|
+
outcomes?: Record<string, string>;
|
|
282
364
|
/** Server timestamp */
|
|
283
365
|
finalizedAt: number;
|
|
284
366
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Player } from '@pie-qti/item-player';
|
|
2
|
+
import type { AssessmentScoringResult, ResponseValue } from './api-contract.js';
|
|
3
|
+
|
|
4
|
+
export interface AssessmentItemScoringInput {
|
|
5
|
+
itemXml: string;
|
|
6
|
+
responses: Record<string, ResponseValue>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getAssessmentItemIdentifier(itemXml: string): string {
|
|
10
|
+
const identifierMatch = itemXml.match(/assessmentItem[^>]+identifier=["']([^"']+)["']/);
|
|
11
|
+
return identifierMatch?.[1] || 'unknown';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Runs QTI ResponseProcessing for one AssessmentItem and normalizes the result
|
|
16
|
+
* to the BackendAdapter scoring shape used by AssessmentPlayer.
|
|
17
|
+
*/
|
|
18
|
+
export function scoreAssessmentItem({
|
|
19
|
+
itemXml,
|
|
20
|
+
responses,
|
|
21
|
+
}: AssessmentItemScoringInput): AssessmentScoringResult {
|
|
22
|
+
const itemIdentifier = getAssessmentItemIdentifier(itemXml);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
// Use a scorer-grade view of the item for accurate scoring.
|
|
26
|
+
// NOTE: This reference scorer is intentionally insecure and runs client-side.
|
|
27
|
+
// In production, scoring must happen server-side with secured item content.
|
|
28
|
+
const player = new Player({
|
|
29
|
+
itemXml,
|
|
30
|
+
role: 'scorer',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
player.setResponses(responses);
|
|
34
|
+
const result = player.processResponses();
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
itemIdentifier,
|
|
38
|
+
score: result.score,
|
|
39
|
+
maxScore: result.maxScore,
|
|
40
|
+
completed: result.completed,
|
|
41
|
+
outcomeValues: result.outcomeValues,
|
|
42
|
+
};
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error('Scoring error:', error);
|
|
45
|
+
return {
|
|
46
|
+
itemIdentifier,
|
|
47
|
+
score: 0,
|
|
48
|
+
maxScore: 1,
|
|
49
|
+
completed: false,
|
|
50
|
+
outcomeValues: {},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/integration/index.ts
CHANGED
|
@@ -68,3 +68,8 @@ export type {
|
|
|
68
68
|
|
|
69
69
|
// Export reference implementation (for development/demos)
|
|
70
70
|
export { ReferenceBackendAdapter } from './ReferenceBackendAdapter.js';
|
|
71
|
+
export {
|
|
72
|
+
getAssessmentItemIdentifier,
|
|
73
|
+
scoreAssessmentItem,
|
|
74
|
+
type AssessmentItemScoringInput,
|
|
75
|
+
} from './assessment-item-scorer.js';
|