@pie-qti/assessment-player 0.1.14 → 0.1.16
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/dist/core/AssessmentPlayer.d.ts +10 -1
- package/dist/core/AssessmentPlayer.js +187 -39
- package/dist/core/AssessmentPlayer.js.map +1 -1
- package/dist/core/AssessmentSessionCoordinator.js +6 -0
- package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
- package/dist/core/NavigationManager.d.ts +1 -1
- package/dist/core/NavigationManager.js +5 -13
- package/dist/core/NavigationManager.js.map +1 -1
- package/dist/core/TimeManager.d.ts +42 -1
- package/dist/core/TimeManager.js +235 -42
- package/dist/core/TimeManager.js.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts +4 -0
- package/dist/integration/ReferenceBackendAdapter.js +209 -52
- package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
- package/dist/integration/api-contract.d.ts +38 -0
- package/dist/integration/api-contract.js.map +1 -1
- package/package.json +10 -10
|
@@ -32,6 +32,22 @@ export interface TimeManagerConfig {
|
|
|
32
32
|
active: boolean;
|
|
33
33
|
multiplier: number;
|
|
34
34
|
};
|
|
35
|
+
/** Injectable monotonic wall clock for deterministic hosts/tests. */
|
|
36
|
+
now?: () => number;
|
|
37
|
+
}
|
|
38
|
+
export interface ActiveTimeScopes {
|
|
39
|
+
testPart?: {
|
|
40
|
+
identifier: string;
|
|
41
|
+
timeLimits?: TimeLimits;
|
|
42
|
+
};
|
|
43
|
+
section?: {
|
|
44
|
+
identifier: string;
|
|
45
|
+
timeLimits?: TimeLimits;
|
|
46
|
+
};
|
|
47
|
+
item?: {
|
|
48
|
+
identifier: string;
|
|
49
|
+
timeLimits?: TimeLimits;
|
|
50
|
+
};
|
|
35
51
|
}
|
|
36
52
|
export interface TimeTrackingState {
|
|
37
53
|
/** Total elapsed time (ms) */
|
|
@@ -40,12 +56,22 @@ export interface TimeTrackingState {
|
|
|
40
56
|
itemTimes: Record<string, number>;
|
|
41
57
|
/** Time spent per section identifier (ms) */
|
|
42
58
|
sectionTimes: Record<string, number>;
|
|
59
|
+
/** Time spent per testPart identifier (ms) */
|
|
60
|
+
testPartTimes: Record<string, number>;
|
|
43
61
|
/** Session start timestamp */
|
|
44
62
|
startedAt: number;
|
|
45
63
|
/** Current item start time (for tracking) */
|
|
46
64
|
currentItemStartTime?: number;
|
|
65
|
+
/** Current item identifier */
|
|
66
|
+
currentItemId?: string;
|
|
47
67
|
/** Current section identifier */
|
|
48
68
|
currentSectionId?: string;
|
|
69
|
+
/** Current section start time */
|
|
70
|
+
currentSectionStartTime?: number;
|
|
71
|
+
/** Current testPart identifier */
|
|
72
|
+
currentTestPartId?: string;
|
|
73
|
+
/** Current testPart start time */
|
|
74
|
+
currentTestPartStartTime?: number;
|
|
49
75
|
/** Is timer currently paused */
|
|
50
76
|
isPaused: boolean;
|
|
51
77
|
}
|
|
@@ -55,11 +81,19 @@ export declare class TimeManager {
|
|
|
55
81
|
private intervalId;
|
|
56
82
|
private maxTimeSeconds;
|
|
57
83
|
private warningTriggered;
|
|
84
|
+
private expirationTriggered;
|
|
85
|
+
private activeScopes;
|
|
86
|
+
private lastTickAt;
|
|
58
87
|
constructor(config: TimeManagerConfig);
|
|
88
|
+
private now;
|
|
89
|
+
private applyExtendedTime;
|
|
59
90
|
/**
|
|
60
91
|
* Start or resume the timer
|
|
61
92
|
*/
|
|
62
93
|
private startTimer;
|
|
94
|
+
private getActiveCandidates;
|
|
95
|
+
private nearestRemaining;
|
|
96
|
+
private getActiveRemaining;
|
|
63
97
|
/**
|
|
64
98
|
* Handle time expiration
|
|
65
99
|
*/
|
|
@@ -79,7 +113,7 @@ export declare class TimeManager {
|
|
|
79
113
|
/**
|
|
80
114
|
* Start tracking time for an item
|
|
81
115
|
*/
|
|
82
|
-
startItem(
|
|
116
|
+
startItem(itemIdentifier: string): void;
|
|
83
117
|
/**
|
|
84
118
|
* End tracking time for current item
|
|
85
119
|
*/
|
|
@@ -92,6 +126,11 @@ export declare class TimeManager {
|
|
|
92
126
|
* Start tracking time for a section
|
|
93
127
|
*/
|
|
94
128
|
startSection(sectionIdentifier: string): void;
|
|
129
|
+
startTestPart(testPartIdentifier: string): void;
|
|
130
|
+
activateScopes(scopes: ActiveTimeScopes): void;
|
|
131
|
+
private endCurrentSection;
|
|
132
|
+
private endCurrentTestPart;
|
|
133
|
+
private checkpointActiveScopes;
|
|
95
134
|
/**
|
|
96
135
|
* Get remaining time in seconds (null if no limit)
|
|
97
136
|
*/
|
|
@@ -100,10 +139,12 @@ export declare class TimeManager {
|
|
|
100
139
|
* Get elapsed time in seconds
|
|
101
140
|
*/
|
|
102
141
|
getElapsedSeconds(): number;
|
|
142
|
+
private getTotalElapsedMs;
|
|
103
143
|
/**
|
|
104
144
|
* Get time spent on a specific item (ms)
|
|
105
145
|
*/
|
|
106
146
|
getItemTime(itemIdentifier: string): number;
|
|
147
|
+
getScopeElapsedMs(scope: 'assessment' | 'testPart' | 'section' | 'item', identifier?: string): number;
|
|
107
148
|
/**
|
|
108
149
|
* Get current tracking state (for persistence)
|
|
109
150
|
*/
|
package/dist/core/TimeManager.js
CHANGED
|
@@ -16,15 +16,19 @@ export class TimeManager {
|
|
|
16
16
|
// Timer internals
|
|
17
17
|
this.intervalId = null;
|
|
18
18
|
this.maxTimeSeconds = null;
|
|
19
|
-
this.warningTriggered =
|
|
19
|
+
this.warningTriggered = new Set();
|
|
20
|
+
this.expirationTriggered = new Set();
|
|
21
|
+
this.activeScopes = {};
|
|
20
22
|
this.config = config;
|
|
21
23
|
this.state = {
|
|
22
24
|
totalElapsed: 0,
|
|
23
25
|
itemTimes: {},
|
|
24
26
|
sectionTimes: {},
|
|
25
|
-
|
|
27
|
+
testPartTimes: {},
|
|
28
|
+
startedAt: this.now(),
|
|
26
29
|
isPaused: false,
|
|
27
30
|
};
|
|
31
|
+
this.lastTickAt = this.now();
|
|
28
32
|
// Initialize timer if time limit exists, applying PNP extended-time multiplier if set.
|
|
29
33
|
if (config.assessmentTimeLimits?.maxTime) {
|
|
30
34
|
const base = config.assessmentTimeLimits.maxTime;
|
|
@@ -39,10 +43,22 @@ export class TimeManager {
|
|
|
39
43
|
else {
|
|
40
44
|
this.maxTimeSeconds = base;
|
|
41
45
|
}
|
|
42
|
-
if (this.maxTimeSeconds !== null) {
|
|
43
|
-
this.startTimer();
|
|
44
|
-
}
|
|
45
46
|
}
|
|
47
|
+
// Scope timing is required even when the assessment itself has no maxTime.
|
|
48
|
+
this.startTimer();
|
|
49
|
+
}
|
|
50
|
+
now() {
|
|
51
|
+
return this.config.now?.() ?? Date.now();
|
|
52
|
+
}
|
|
53
|
+
applyExtendedTime(seconds) {
|
|
54
|
+
if (seconds === undefined)
|
|
55
|
+
return null;
|
|
56
|
+
const extended = this.config.extendedTime;
|
|
57
|
+
if (extended?.active && extended.multiplier === Infinity)
|
|
58
|
+
return null;
|
|
59
|
+
if (extended?.active && extended.multiplier > 0)
|
|
60
|
+
return seconds * extended.multiplier;
|
|
61
|
+
return seconds;
|
|
46
62
|
}
|
|
47
63
|
/**
|
|
48
64
|
* Start or resume the timer
|
|
@@ -52,30 +68,35 @@ export class TimeManager {
|
|
|
52
68
|
return; // Already running
|
|
53
69
|
}
|
|
54
70
|
this.state.isPaused = false;
|
|
71
|
+
this.lastTickAt = this.now();
|
|
55
72
|
this.intervalId = setInterval(() => {
|
|
73
|
+
const now = this.now();
|
|
56
74
|
if (this.state.isPaused) {
|
|
75
|
+
this.lastTickAt = now;
|
|
57
76
|
return;
|
|
58
77
|
}
|
|
59
|
-
this.state.totalElapsed +=
|
|
78
|
+
this.state.totalElapsed += Math.max(0, now - this.lastTickAt);
|
|
79
|
+
this.lastTickAt = now;
|
|
60
80
|
const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
81
|
+
const candidates = this.getActiveCandidates();
|
|
82
|
+
for (const candidate of candidates) {
|
|
83
|
+
if (candidate.remainingSeconds > 0 || this.expirationTriggered.has(candidate.key))
|
|
84
|
+
continue;
|
|
85
|
+
this.expirationTriggered.add(candidate.key);
|
|
86
|
+
if (!candidate.allowLateSubmission) {
|
|
87
|
+
this.handleExpiration();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
64
90
|
}
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
const remainingSeconds =
|
|
91
|
+
const activeRemaining = this.nearestRemaining(candidates);
|
|
92
|
+
if (activeRemaining) {
|
|
93
|
+
const { key, remainingSeconds } = activeRemaining;
|
|
68
94
|
// Trigger warning
|
|
69
|
-
const warningThreshold = this.config.warningThreshold
|
|
70
|
-
if (!this.warningTriggered && remainingSeconds <= warningThreshold && remainingSeconds > 0) {
|
|
71
|
-
this.warningTriggered
|
|
95
|
+
const warningThreshold = this.config.warningThreshold ?? 60;
|
|
96
|
+
if (!this.warningTriggered.has(key) && remainingSeconds <= warningThreshold && remainingSeconds > 0) {
|
|
97
|
+
this.warningTriggered.add(key);
|
|
72
98
|
this.config.onWarning?.(remainingSeconds);
|
|
73
99
|
}
|
|
74
|
-
// Trigger expiration
|
|
75
|
-
if (remainingSeconds <= 0) {
|
|
76
|
-
this.handleExpiration();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
100
|
// Tick callback
|
|
80
101
|
this.config.onTick?.(remainingSeconds, elapsedSeconds);
|
|
81
102
|
}
|
|
@@ -85,6 +106,36 @@ export class TimeManager {
|
|
|
85
106
|
}
|
|
86
107
|
}, 1000);
|
|
87
108
|
}
|
|
109
|
+
getActiveCandidates() {
|
|
110
|
+
const candidates = [];
|
|
111
|
+
if (this.maxTimeSeconds !== null) {
|
|
112
|
+
candidates.push({
|
|
113
|
+
key: 'assessment',
|
|
114
|
+
remainingSeconds: this.maxTimeSeconds - this.getElapsedSeconds(),
|
|
115
|
+
allowLateSubmission: this.config.assessmentTimeLimits?.allowLateSubmission === true,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
for (const scope of ['testPart', 'section', 'item']) {
|
|
119
|
+
const active = this.activeScopes[scope];
|
|
120
|
+
const max = this.applyExtendedTime(active?.timeLimits?.maxTime);
|
|
121
|
+
if (!active || max === null)
|
|
122
|
+
continue;
|
|
123
|
+
candidates.push({
|
|
124
|
+
key: `${scope}:${active.identifier}`,
|
|
125
|
+
remainingSeconds: max - this.getScopeElapsedMs(scope, active.identifier) / 1000,
|
|
126
|
+
allowLateSubmission: active.timeLimits?.allowLateSubmission === true,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return candidates;
|
|
130
|
+
}
|
|
131
|
+
nearestRemaining(candidates) {
|
|
132
|
+
if (candidates.length === 0)
|
|
133
|
+
return null;
|
|
134
|
+
return candidates.reduce((nearest, candidate) => candidate.remainingSeconds < nearest.remainingSeconds ? candidate : nearest);
|
|
135
|
+
}
|
|
136
|
+
getActiveRemaining() {
|
|
137
|
+
return this.nearestRemaining(this.getActiveCandidates());
|
|
138
|
+
}
|
|
88
139
|
/**
|
|
89
140
|
* Handle time expiration
|
|
90
141
|
*/
|
|
@@ -105,23 +156,41 @@ export class TimeManager {
|
|
|
105
156
|
* Pause the timer
|
|
106
157
|
*/
|
|
107
158
|
pause() {
|
|
159
|
+
if (this.state.isPaused)
|
|
160
|
+
return;
|
|
161
|
+
this.state.totalElapsed = this.getTotalElapsedMs();
|
|
162
|
+
this.lastTickAt = this.now();
|
|
163
|
+
this.checkpointActiveScopes(false);
|
|
108
164
|
this.state.isPaused = true;
|
|
109
165
|
}
|
|
110
166
|
/**
|
|
111
167
|
* Resume the timer
|
|
112
168
|
*/
|
|
113
169
|
resume() {
|
|
170
|
+
if (!this.state.isPaused)
|
|
171
|
+
return;
|
|
114
172
|
this.state.isPaused = false;
|
|
173
|
+
const now = this.now();
|
|
174
|
+
if (this.state.currentItemId)
|
|
175
|
+
this.state.currentItemStartTime = now;
|
|
176
|
+
if (this.state.currentSectionId)
|
|
177
|
+
this.state.currentSectionStartTime = now;
|
|
178
|
+
if (this.state.currentTestPartId)
|
|
179
|
+
this.state.currentTestPartStartTime = now;
|
|
180
|
+
this.lastTickAt = now;
|
|
115
181
|
}
|
|
116
182
|
/**
|
|
117
183
|
* Start tracking time for an item
|
|
118
184
|
*/
|
|
119
|
-
startItem(
|
|
185
|
+
startItem(itemIdentifier) {
|
|
186
|
+
if (this.state.currentItemId === itemIdentifier && this.state.currentItemStartTime)
|
|
187
|
+
return;
|
|
120
188
|
// End previous item if any
|
|
121
189
|
if (this.state.currentItemStartTime) {
|
|
122
190
|
this.endCurrentItem();
|
|
123
191
|
}
|
|
124
|
-
this.state.
|
|
192
|
+
this.state.currentItemId = itemIdentifier;
|
|
193
|
+
this.state.currentItemStartTime = this.state.isPaused ? undefined : this.now();
|
|
125
194
|
}
|
|
126
195
|
/**
|
|
127
196
|
* End tracking time for current item
|
|
@@ -130,10 +199,13 @@ export class TimeManager {
|
|
|
130
199
|
if (!this.state.currentItemStartTime) {
|
|
131
200
|
return;
|
|
132
201
|
}
|
|
133
|
-
const timeSpent =
|
|
134
|
-
|
|
135
|
-
|
|
202
|
+
const timeSpent = this.now() - this.state.currentItemStartTime;
|
|
203
|
+
if (this.state.currentItemId) {
|
|
204
|
+
this.state.itemTimes[this.state.currentItemId] =
|
|
205
|
+
(this.state.itemTimes[this.state.currentItemId] || 0) + Math.max(0, timeSpent);
|
|
206
|
+
}
|
|
136
207
|
this.state.currentItemStartTime = undefined;
|
|
208
|
+
this.state.currentItemId = undefined;
|
|
137
209
|
}
|
|
138
210
|
/**
|
|
139
211
|
* End tracking time for an item
|
|
@@ -142,49 +214,167 @@ export class TimeManager {
|
|
|
142
214
|
if (!this.state.currentItemStartTime) {
|
|
143
215
|
return;
|
|
144
216
|
}
|
|
145
|
-
const timeSpent =
|
|
146
|
-
|
|
217
|
+
const timeSpent = this.now() - this.state.currentItemStartTime;
|
|
218
|
+
const activeIdentifier = this.state.currentItemId ?? itemIdentifier;
|
|
219
|
+
this.state.itemTimes[activeIdentifier] = (this.state.itemTimes[activeIdentifier] || 0) + Math.max(0, timeSpent);
|
|
147
220
|
this.state.currentItemStartTime = undefined;
|
|
221
|
+
this.state.currentItemId = undefined;
|
|
148
222
|
}
|
|
149
223
|
/**
|
|
150
224
|
* Start tracking time for a section
|
|
151
225
|
*/
|
|
152
226
|
startSection(sectionIdentifier) {
|
|
227
|
+
if (this.state.currentSectionId === sectionIdentifier && this.state.currentSectionStartTime)
|
|
228
|
+
return;
|
|
229
|
+
this.endCurrentSection();
|
|
153
230
|
this.state.currentSectionId = sectionIdentifier;
|
|
231
|
+
this.state.currentSectionStartTime = this.state.isPaused ? undefined : this.now();
|
|
232
|
+
}
|
|
233
|
+
startTestPart(testPartIdentifier) {
|
|
234
|
+
if (this.state.currentTestPartId === testPartIdentifier && this.state.currentTestPartStartTime)
|
|
235
|
+
return;
|
|
236
|
+
this.endCurrentTestPart();
|
|
237
|
+
this.state.currentTestPartId = testPartIdentifier;
|
|
238
|
+
this.state.currentTestPartStartTime = this.state.isPaused ? undefined : this.now();
|
|
239
|
+
}
|
|
240
|
+
activateScopes(scopes) {
|
|
241
|
+
if (scopes.testPart)
|
|
242
|
+
this.startTestPart(scopes.testPart.identifier);
|
|
243
|
+
if (scopes.section)
|
|
244
|
+
this.startSection(scopes.section.identifier);
|
|
245
|
+
if (scopes.item)
|
|
246
|
+
this.startItem(scopes.item.identifier);
|
|
247
|
+
this.activeScopes = scopes;
|
|
248
|
+
}
|
|
249
|
+
endCurrentSection() {
|
|
250
|
+
if (this.state.currentSectionId && this.state.currentSectionStartTime) {
|
|
251
|
+
const elapsed = Math.max(0, this.now() - this.state.currentSectionStartTime);
|
|
252
|
+
this.state.sectionTimes[this.state.currentSectionId] =
|
|
253
|
+
(this.state.sectionTimes[this.state.currentSectionId] || 0) + elapsed;
|
|
254
|
+
}
|
|
255
|
+
this.state.currentSectionStartTime = undefined;
|
|
256
|
+
}
|
|
257
|
+
endCurrentTestPart() {
|
|
258
|
+
if (this.state.currentTestPartId && this.state.currentTestPartStartTime) {
|
|
259
|
+
const elapsed = Math.max(0, this.now() - this.state.currentTestPartStartTime);
|
|
260
|
+
this.state.testPartTimes[this.state.currentTestPartId] =
|
|
261
|
+
(this.state.testPartTimes[this.state.currentTestPartId] || 0) + elapsed;
|
|
262
|
+
}
|
|
263
|
+
this.state.currentTestPartStartTime = undefined;
|
|
264
|
+
}
|
|
265
|
+
checkpointActiveScopes(restart) {
|
|
266
|
+
const itemId = this.state.currentItemId;
|
|
267
|
+
const sectionId = this.state.currentSectionId;
|
|
268
|
+
const testPartId = this.state.currentTestPartId;
|
|
269
|
+
this.endCurrentItem();
|
|
270
|
+
this.endCurrentSection();
|
|
271
|
+
this.endCurrentTestPart();
|
|
272
|
+
this.state.currentItemId = itemId;
|
|
273
|
+
this.state.currentSectionId = sectionId;
|
|
274
|
+
this.state.currentTestPartId = testPartId;
|
|
275
|
+
if (restart && !this.state.isPaused) {
|
|
276
|
+
const now = this.now();
|
|
277
|
+
if (itemId)
|
|
278
|
+
this.state.currentItemStartTime = now;
|
|
279
|
+
if (sectionId)
|
|
280
|
+
this.state.currentSectionStartTime = now;
|
|
281
|
+
if (testPartId)
|
|
282
|
+
this.state.currentTestPartStartTime = now;
|
|
283
|
+
}
|
|
154
284
|
}
|
|
155
285
|
/**
|
|
156
286
|
* Get remaining time in seconds (null if no limit)
|
|
157
287
|
*/
|
|
158
288
|
getRemainingSeconds() {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
|
|
163
|
-
return Math.max(0, this.maxTimeSeconds - elapsedSeconds);
|
|
289
|
+
const active = this.getActiveRemaining();
|
|
290
|
+
return active ? Math.max(0, Math.ceil(active.remainingSeconds)) : null;
|
|
164
291
|
}
|
|
165
292
|
/**
|
|
166
293
|
* Get elapsed time in seconds
|
|
167
294
|
*/
|
|
168
295
|
getElapsedSeconds() {
|
|
169
|
-
return Math.floor(this.
|
|
296
|
+
return Math.floor(this.getTotalElapsedMs() / 1000);
|
|
297
|
+
}
|
|
298
|
+
getTotalElapsedMs() {
|
|
299
|
+
if (this.state.isPaused)
|
|
300
|
+
return this.state.totalElapsed;
|
|
301
|
+
return this.state.totalElapsed + Math.max(0, this.now() - this.lastTickAt);
|
|
170
302
|
}
|
|
171
303
|
/**
|
|
172
304
|
* Get time spent on a specific item (ms)
|
|
173
305
|
*/
|
|
174
306
|
getItemTime(itemIdentifier) {
|
|
175
|
-
return this.
|
|
307
|
+
return this.getScopeElapsedMs('item', itemIdentifier);
|
|
308
|
+
}
|
|
309
|
+
getScopeElapsedMs(scope, identifier) {
|
|
310
|
+
if (scope === 'assessment')
|
|
311
|
+
return this.getTotalElapsedMs();
|
|
312
|
+
const now = this.now();
|
|
313
|
+
if (scope === 'item') {
|
|
314
|
+
const id = identifier ?? this.state.currentItemId;
|
|
315
|
+
if (!id)
|
|
316
|
+
return 0;
|
|
317
|
+
const active = id === this.state.currentItemId && this.state.currentItemStartTime && !this.state.isPaused
|
|
318
|
+
? Math.max(0, now - this.state.currentItemStartTime)
|
|
319
|
+
: 0;
|
|
320
|
+
return (this.state.itemTimes[id] || 0) + active;
|
|
321
|
+
}
|
|
322
|
+
if (scope === 'section') {
|
|
323
|
+
const id = identifier ?? this.state.currentSectionId;
|
|
324
|
+
if (!id)
|
|
325
|
+
return 0;
|
|
326
|
+
const active = id === this.state.currentSectionId && this.state.currentSectionStartTime && !this.state.isPaused
|
|
327
|
+
? Math.max(0, now - this.state.currentSectionStartTime)
|
|
328
|
+
: 0;
|
|
329
|
+
return (this.state.sectionTimes[id] || 0) + active;
|
|
330
|
+
}
|
|
331
|
+
const id = identifier ?? this.state.currentTestPartId;
|
|
332
|
+
if (!id)
|
|
333
|
+
return 0;
|
|
334
|
+
const active = id === this.state.currentTestPartId && this.state.currentTestPartStartTime && !this.state.isPaused
|
|
335
|
+
? Math.max(0, now - this.state.currentTestPartStartTime)
|
|
336
|
+
: 0;
|
|
337
|
+
return (this.state.testPartTimes[id] || 0) + active;
|
|
176
338
|
}
|
|
177
339
|
/**
|
|
178
340
|
* Get current tracking state (for persistence)
|
|
179
341
|
*/
|
|
180
342
|
getState() {
|
|
181
|
-
|
|
343
|
+
if (!this.state.isPaused) {
|
|
344
|
+
this.state.totalElapsed = this.getTotalElapsedMs();
|
|
345
|
+
this.lastTickAt = this.now();
|
|
346
|
+
}
|
|
347
|
+
this.checkpointActiveScopes(true);
|
|
348
|
+
return {
|
|
349
|
+
...this.state,
|
|
350
|
+
itemTimes: { ...this.state.itemTimes },
|
|
351
|
+
sectionTimes: { ...this.state.sectionTimes },
|
|
352
|
+
testPartTimes: { ...this.state.testPartTimes },
|
|
353
|
+
};
|
|
182
354
|
}
|
|
183
355
|
/**
|
|
184
356
|
* Restore tracking state (for resume)
|
|
185
357
|
*/
|
|
186
358
|
restoreState(state) {
|
|
187
|
-
this.state = {
|
|
359
|
+
this.state = {
|
|
360
|
+
...state,
|
|
361
|
+
itemTimes: { ...state.itemTimes },
|
|
362
|
+
sectionTimes: { ...state.sectionTimes },
|
|
363
|
+
testPartTimes: { ...(state.testPartTimes ?? {}) },
|
|
364
|
+
currentItemStartTime: undefined,
|
|
365
|
+
currentSectionStartTime: undefined,
|
|
366
|
+
currentTestPartStartTime: undefined,
|
|
367
|
+
};
|
|
368
|
+
if (!this.state.isPaused) {
|
|
369
|
+
const now = this.now();
|
|
370
|
+
if (this.state.currentItemId)
|
|
371
|
+
this.state.currentItemStartTime = now;
|
|
372
|
+
if (this.state.currentSectionId)
|
|
373
|
+
this.state.currentSectionStartTime = now;
|
|
374
|
+
if (this.state.currentTestPartId)
|
|
375
|
+
this.state.currentTestPartStartTime = now;
|
|
376
|
+
this.lastTickAt = now;
|
|
377
|
+
}
|
|
188
378
|
// Restart timer if not expired
|
|
189
379
|
if (this.maxTimeSeconds) {
|
|
190
380
|
const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
|
|
@@ -197,17 +387,19 @@ export class TimeManager {
|
|
|
197
387
|
* Check if time has expired
|
|
198
388
|
*/
|
|
199
389
|
isExpired() {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
|
|
204
|
-
return elapsedSeconds >= this.maxTimeSeconds;
|
|
390
|
+
const active = this.getActiveRemaining();
|
|
391
|
+
return active !== null && active.remainingSeconds <= 0;
|
|
205
392
|
}
|
|
206
393
|
/**
|
|
207
394
|
* Check if late submission is allowed
|
|
208
395
|
*/
|
|
209
396
|
allowsLateSubmission() {
|
|
210
|
-
|
|
397
|
+
const candidates = this.getActiveCandidates();
|
|
398
|
+
const expired = candidates.filter((candidate) => candidate.remainingSeconds <= 0);
|
|
399
|
+
if (expired.length > 0) {
|
|
400
|
+
return expired.every((candidate) => candidate.allowLateSubmission);
|
|
401
|
+
}
|
|
402
|
+
return this.nearestRemaining(candidates)?.allowLateSubmission ?? false;
|
|
211
403
|
}
|
|
212
404
|
/**
|
|
213
405
|
* Format time as MM:SS or HH:MM:SS
|
|
@@ -225,6 +417,7 @@ export class TimeManager {
|
|
|
225
417
|
* Cleanup - stop all timers
|
|
226
418
|
*/
|
|
227
419
|
destroy() {
|
|
420
|
+
this.checkpointActiveScopes(false);
|
|
228
421
|
this.stopTimer();
|
|
229
422
|
}
|
|
230
423
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeManager.js","sourceRoot":"","sources":["../../src/core/TimeManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAwCH,MAAM,OAAO,WAAW;IASvB,YAAY,MAAyB;QALrC,kBAAkB;QACV,eAAU,GAA0C,IAAI,CAAC;QACzD,mBAAc,GAAkB,IAAI,CAAC;QACrC,qBAAgB,GAAG,KAAK,CAAC;QAGhC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG;YACZ,YAAY,EAAE,CAAC;YACf,SAAS,EAAE,EAAE;YACb,YAAY,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AED,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;QAClE,OAAO,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,oBAAoB;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,mBAAmB,IAAI,KAAK,CAAC;IACvE,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,OAAe;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,OAAO,GAAG,EAAE,CAAC;QAE1B,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,OAAO,GAAG,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QAC9F,CAAC;QAED,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,OAAO;QACN,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD","sourcesContent":["/**\n * TimeManager\n *\n * Manages time limits and tracking for QTI assessments.\n * Supports test-level, section-level, and item-level time limits.\n *\n * Features:\n * - Countdown timers with warnings\n * - Auto-submission when time expires\n * - Time spent tracking per item\n * - Pause/resume support\n * - Late submission handling\n */\n\nimport type { TimeLimits } from '../types/index.js';\n\nexport interface TimeManagerConfig {\n\t/** Assessment-level time limits */\n\tassessmentTimeLimits?: TimeLimits;\n\t/** Warning threshold (seconds before expiry) */\n\twarningThreshold?: number;\n\t/** Callback when time warning is triggered */\n\tonWarning?: (remainingSeconds: number) => void;\n\t/** Callback when time expires */\n\tonExpired?: () => void;\n\t/** Callback for time updates (fires every second) */\n\tonTick?: (remainingSeconds: number, elapsedSeconds: number) => void;\n\t/**\n\t * QTI 3.0 PNP extended time accommodation.\n\t * When active, multiplies assessmentTimeLimits.maxTime by the given multiplier.\n\t * multiplier: Infinity removes the time limit entirely.\n\t */\n\textendedTime?: { active: boolean; multiplier: number };\n}\n\nexport interface TimeTrackingState {\n\t/** Total elapsed time (ms) */\n\ttotalElapsed: number;\n\t/** Time spent per item identifier (ms) */\n\titemTimes: Record<string, number>;\n\t/** Time spent per section identifier (ms) */\n\tsectionTimes: Record<string, number>;\n\t/** Session start timestamp */\n\tstartedAt: number;\n\t/** Current item start time (for tracking) */\n\tcurrentItemStartTime?: number;\n\t/** Current section identifier */\n\tcurrentSectionId?: string;\n\t/** Is timer currently paused */\n\tisPaused: boolean;\n}\n\nexport class TimeManager {\n\tprivate config: TimeManagerConfig;\n\tprivate state: TimeTrackingState;\n\n\t// Timer internals\n\tprivate intervalId: ReturnType<typeof setInterval> | null = null;\n\tprivate maxTimeSeconds: number | null = null;\n\tprivate warningTriggered = false;\n\n\tconstructor(config: TimeManagerConfig) {\n\t\tthis.config = config;\n\t\tthis.state = {\n\t\t\ttotalElapsed: 0,\n\t\t\titemTimes: {},\n\t\t\tsectionTimes: {},\n\t\t\tstartedAt: Date.now(),\n\t\t\tisPaused: false,\n\t\t};\n\n\t\t// Initialize timer if time limit exists, applying PNP extended-time multiplier if set.\n\t\tif (config.assessmentTimeLimits?.maxTime) {\n\t\t\tconst base = config.assessmentTimeLimits.maxTime;\n\t\t\tconst et = config.extendedTime;\n\t\t\tif (et?.active && et.multiplier === Infinity) {\n\t\t\t\t// multiplier: Infinity → unlimited time (no countdown)\n\t\t\t\tthis.maxTimeSeconds = null;\n\t\t\t} else if (et?.active && et.multiplier > 0) {\n\t\t\t\tthis.maxTimeSeconds = base * et.multiplier;\n\t\t\t} else {\n\t\t\t\tthis.maxTimeSeconds = base;\n\t\t\t}\n\t\t\tif (this.maxTimeSeconds !== null) {\n\t\t\t\tthis.startTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Start or resume the timer\n\t */\n\tprivate startTimer(): void {\n\t\tif (this.intervalId) {\n\t\t\treturn; // Already running\n\t\t}\n\n\t\tthis.state.isPaused = false;\n\n\t\tthis.intervalId = setInterval(() => {\n\t\t\tif (this.state.isPaused) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.state.totalElapsed += 1000; // Increment by 1 second\n\n\t\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\n\t\t\t// Track item time if active\n\t\t\tif (this.state.currentItemStartTime) {\n\t\t\t\t// Item tracking handled by startItem/endItem\n\t\t\t}\n\n\t\t\t// Calculate remaining time\n\t\t\tif (this.maxTimeSeconds) {\n\t\t\t\tconst remainingSeconds = this.maxTimeSeconds - elapsedSeconds;\n\n\t\t\t\t// Trigger warning\n\t\t\t\tconst warningThreshold = this.config.warningThreshold || 60;\n\t\t\t\tif (!this.warningTriggered && remainingSeconds <= warningThreshold && remainingSeconds > 0) {\n\t\t\t\t\tthis.warningTriggered = true;\n\t\t\t\t\tthis.config.onWarning?.(remainingSeconds);\n\t\t\t\t}\n\n\t\t\t\t// Trigger expiration\n\t\t\t\tif (remainingSeconds <= 0) {\n\t\t\t\t\tthis.handleExpiration();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Tick callback\n\t\t\t\tthis.config.onTick?.(remainingSeconds, elapsedSeconds);\n\t\t\t} else {\n\t\t\t\t// No limit - just count up\n\t\t\t\tthis.config.onTick?.(0, elapsedSeconds);\n\t\t\t}\n\t\t}, 1000);\n\t}\n\n\t/**\n\t * Handle time expiration\n\t */\n\tprivate handleExpiration(): void {\n\t\tthis.stopTimer();\n\t\tthis.config.onExpired?.();\n\t}\n\n\t/**\n\t * Stop the timer\n\t */\n\tstopTimer(): void {\n\t\tif (this.intervalId) {\n\t\t\tclearInterval(this.intervalId);\n\t\t\tthis.intervalId = null;\n\t\t}\n\t}\n\n\t/**\n\t * Pause the timer\n\t */\n\tpause(): void {\n\t\tthis.state.isPaused = true;\n\t}\n\n\t/**\n\t * Resume the timer\n\t */\n\tresume(): void {\n\t\tthis.state.isPaused = false;\n\t}\n\n\t/**\n\t * Start tracking time for an item\n\t */\n\tstartItem(_itemIdentifier: string): void {\n\t\t// End previous item if any\n\t\tif (this.state.currentItemStartTime) {\n\t\t\tthis.endCurrentItem();\n\t\t}\n\n\t\tthis.state.currentItemStartTime = Date.now();\n\t}\n\n\t/**\n\t * End tracking time for current item\n\t */\n\tprivate endCurrentItem(): void {\n\t\tif (!this.state.currentItemStartTime) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeSpent = Date.now() - this.state.currentItemStartTime;\n\t\t// Note: We need the item identifier, which should be tracked separately\n\t\t// For now, we'll handle this in the endItem method\n\t\tthis.state.currentItemStartTime = undefined;\n\t}\n\n\t/**\n\t * End tracking time for an item\n\t */\n\tendItem(itemIdentifier: string): void {\n\t\tif (!this.state.currentItemStartTime) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeSpent = Date.now() - this.state.currentItemStartTime;\n\t\tthis.state.itemTimes[itemIdentifier] = (this.state.itemTimes[itemIdentifier] || 0) + timeSpent;\n\t\tthis.state.currentItemStartTime = undefined;\n\t}\n\n\t/**\n\t * Start tracking time for a section\n\t */\n\tstartSection(sectionIdentifier: string): void {\n\t\tthis.state.currentSectionId = sectionIdentifier;\n\t}\n\n\t/**\n\t * Get remaining time in seconds (null if no limit)\n\t */\n\tgetRemainingSeconds(): number | null {\n\t\tif (!this.maxTimeSeconds) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\treturn Math.max(0, this.maxTimeSeconds - elapsedSeconds);\n\t}\n\n\t/**\n\t * Get elapsed time in seconds\n\t */\n\tgetElapsedSeconds(): number {\n\t\treturn Math.floor(this.state.totalElapsed / 1000);\n\t}\n\n\t/**\n\t * Get time spent on a specific item (ms)\n\t */\n\tgetItemTime(itemIdentifier: string): number {\n\t\treturn this.state.itemTimes[itemIdentifier] || 0;\n\t}\n\n\t/**\n\t * Get current tracking state (for persistence)\n\t */\n\tgetState(): TimeTrackingState {\n\t\treturn { ...this.state };\n\t}\n\n\t/**\n\t * Restore tracking state (for resume)\n\t */\n\trestoreState(state: TimeTrackingState): void {\n\t\tthis.state = { ...state };\n\n\t\t// Restart timer if not expired\n\t\tif (this.maxTimeSeconds) {\n\t\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\t\tif (elapsedSeconds < this.maxTimeSeconds) {\n\t\t\t\tthis.startTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Check if time has expired\n\t */\n\tisExpired(): boolean {\n\t\tif (!this.maxTimeSeconds) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\treturn elapsedSeconds >= this.maxTimeSeconds;\n\t}\n\n\t/**\n\t * Check if late submission is allowed\n\t */\n\tallowsLateSubmission(): boolean {\n\t\treturn this.config.assessmentTimeLimits?.allowLateSubmission || false;\n\t}\n\n\t/**\n\t * Format time as MM:SS or HH:MM:SS\n\t */\n\tstatic formatTime(seconds: number): string {\n\t\tconst hours = Math.floor(seconds / 3600);\n\t\tconst minutes = Math.floor((seconds % 3600) / 60);\n\t\tconst secs = seconds % 60;\n\n\t\tif (hours > 0) {\n\t\t\treturn `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;\n\t\t}\n\n\t\treturn `${minutes}:${secs.toString().padStart(2, '0')}`;\n\t}\n\n\t/**\n\t * Cleanup - stop all timers\n\t */\n\tdestroy(): void {\n\t\tthis.st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AAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,mBAAmB,IAAI,KAAK,CAAC;IACxE,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,OAAe;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,OAAO,GAAG,EAAE,CAAC;QAE1B,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,OAAO,GAAG,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QAC9F,CAAC;QAED,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,OAAO;QACN,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD","sourcesContent":["/**\n * TimeManager\n *\n * Manages time limits and tracking for QTI assessments.\n * Supports test-level, section-level, and item-level time limits.\n *\n * Features:\n * - Countdown timers with warnings\n * - Auto-submission when time expires\n * - Time spent tracking per item\n * - Pause/resume support\n * - Late submission handling\n */\n\nimport type { TimeLimits } from '../types/index.js';\n\nexport interface TimeManagerConfig {\n\t/** Assessment-level time limits */\n\tassessmentTimeLimits?: TimeLimits;\n\t/** Warning threshold (seconds before expiry) */\n\twarningThreshold?: number;\n\t/** Callback when time warning is triggered */\n\tonWarning?: (remainingSeconds: number) => void;\n\t/** Callback when time expires */\n\tonExpired?: () => void;\n\t/** Callback for time updates (fires every second) */\n\tonTick?: (remainingSeconds: number, elapsedSeconds: number) => void;\n\t/**\n\t * QTI 3.0 PNP extended time accommodation.\n\t * When active, multiplies assessmentTimeLimits.maxTime by the given multiplier.\n\t * multiplier: Infinity removes the time limit entirely.\n\t */\n\textendedTime?: { active: boolean; multiplier: number };\n\t/** Injectable monotonic wall clock for deterministic hosts/tests. */\n\tnow?: () => number;\n}\n\nexport interface ActiveTimeScopes {\n\ttestPart?: { identifier: string; timeLimits?: TimeLimits };\n\tsection?: { identifier: string; timeLimits?: TimeLimits };\n\titem?: { identifier: string; timeLimits?: TimeLimits };\n}\n\nexport interface TimeTrackingState {\n\t/** Total elapsed time (ms) */\n\ttotalElapsed: number;\n\t/** Time spent per item identifier (ms) */\n\titemTimes: Record<string, number>;\n\t/** Time spent per section identifier (ms) */\n\tsectionTimes: Record<string, number>;\n\t/** Time spent per testPart identifier (ms) */\n\ttestPartTimes: Record<string, number>;\n\t/** Session start timestamp */\n\tstartedAt: number;\n\t/** Current item start time (for tracking) */\n\tcurrentItemStartTime?: number;\n\t/** Current item identifier */\n\tcurrentItemId?: string;\n\t/** Current section identifier */\n\tcurrentSectionId?: string;\n\t/** Current section start time */\n\tcurrentSectionStartTime?: number;\n\t/** Current testPart identifier */\n\tcurrentTestPartId?: string;\n\t/** Current testPart start time */\n\tcurrentTestPartStartTime?: number;\n\t/** Is timer currently paused */\n\tisPaused: boolean;\n}\n\nexport class TimeManager {\n\tprivate config: TimeManagerConfig;\n\tprivate state: TimeTrackingState;\n\n\t// Timer internals\n\tprivate intervalId: ReturnType<typeof setInterval> | null = null;\n\tprivate maxTimeSeconds: number | null = null;\n\tprivate warningTriggered = new Set<string>();\n\tprivate expirationTriggered = new Set<string>();\n\tprivate activeScopes: ActiveTimeScopes = {};\n\tprivate lastTickAt: number;\n\n\tconstructor(config: TimeManagerConfig) {\n\t\tthis.config = config;\n\t\tthis.state = {\n\t\t\ttotalElapsed: 0,\n\t\t\titemTimes: {},\n\t\t\tsectionTimes: {},\n\t\t\ttestPartTimes: {},\n\t\t\tstartedAt: this.now(),\n\t\t\tisPaused: false,\n\t\t};\n\t\tthis.lastTickAt = this.now();\n\n\t\t// Initialize timer if time limit exists, applying PNP extended-time multiplier if set.\n\t\tif (config.assessmentTimeLimits?.maxTime) {\n\t\t\tconst base = config.assessmentTimeLimits.maxTime;\n\t\t\tconst et = config.extendedTime;\n\t\t\tif (et?.active && et.multiplier === Infinity) {\n\t\t\t\t// multiplier: Infinity → unlimited time (no countdown)\n\t\t\t\tthis.maxTimeSeconds = null;\n\t\t\t} else if (et?.active && et.multiplier > 0) {\n\t\t\t\tthis.maxTimeSeconds = base * et.multiplier;\n\t\t\t} else {\n\t\t\t\tthis.maxTimeSeconds = base;\n\t\t\t}\n\t\t}\n\t\t// Scope timing is required even when the assessment itself has no maxTime.\n\t\tthis.startTimer();\n\t}\n\n\tprivate now(): number {\n\t\treturn this.config.now?.() ?? Date.now();\n\t}\n\n\tprivate applyExtendedTime(seconds: number | undefined): number | null {\n\t\tif (seconds === undefined) return null;\n\t\tconst extended = this.config.extendedTime;\n\t\tif (extended?.active && extended.multiplier === Infinity) return null;\n\t\tif (extended?.active && extended.multiplier > 0) return seconds * extended.multiplier;\n\t\treturn seconds;\n\t}\n\n\t/**\n\t * Start or resume the timer\n\t */\n\tprivate startTimer(): void {\n\t\tif (this.intervalId) {\n\t\t\treturn; // Already running\n\t\t}\n\n\t\tthis.state.isPaused = false;\n\t\tthis.lastTickAt = this.now();\n\n\t\tthis.intervalId = setInterval(() => {\n\t\t\tconst now = this.now();\n\t\t\tif (this.state.isPaused) {\n\t\t\t\tthis.lastTickAt = now;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.state.totalElapsed += Math.max(0, now - this.lastTickAt);\n\t\t\tthis.lastTickAt = now;\n\n\t\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\t\tconst candidates = this.getActiveCandidates();\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.remainingSeconds > 0 || this.expirationTriggered.has(candidate.key)) continue;\n\t\t\t\tthis.expirationTriggered.add(candidate.key);\n\t\t\t\tif (!candidate.allowLateSubmission) {\n\t\t\t\t\tthis.handleExpiration();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst activeRemaining = this.nearestRemaining(candidates);\n\t\t\tif (activeRemaining) {\n\t\t\t\tconst { key, remainingSeconds } = activeRemaining;\n\n\t\t\t\t// Trigger warning\n\t\t\t\tconst warningThreshold = this.config.warningThreshold ?? 60;\n\t\t\t\tif (!this.warningTriggered.has(key) && remainingSeconds <= warningThreshold && remainingSeconds > 0) {\n\t\t\t\t\tthis.warningTriggered.add(key);\n\t\t\t\t\tthis.config.onWarning?.(remainingSeconds);\n\t\t\t\t}\n\n\t\t\t\t// Tick callback\n\t\t\t\tthis.config.onTick?.(remainingSeconds, elapsedSeconds);\n\t\t\t} else {\n\t\t\t\t// No limit - just count up\n\t\t\t\tthis.config.onTick?.(0, elapsedSeconds);\n\t\t\t}\n\t\t}, 1000);\n\t}\n\n\tprivate getActiveCandidates(): Array<{\n\t\tkey: string;\n\t\tremainingSeconds: number;\n\t\tallowLateSubmission: boolean;\n\t}> {\n\t\tconst candidates: Array<{ key: string; remainingSeconds: number; allowLateSubmission: boolean }> = [];\n\t\tif (this.maxTimeSeconds !== null) {\n\t\t\tcandidates.push({\n\t\t\t\tkey: 'assessment',\n\t\t\t\tremainingSeconds: this.maxTimeSeconds - this.getElapsedSeconds(),\n\t\t\t\tallowLateSubmission: this.config.assessmentTimeLimits?.allowLateSubmission === true,\n\t\t\t});\n\t\t}\n\t\tfor (const scope of ['testPart', 'section', 'item'] as const) {\n\t\t\tconst active = this.activeScopes[scope];\n\t\t\tconst max = this.applyExtendedTime(active?.timeLimits?.maxTime);\n\t\t\tif (!active || max === null) continue;\n\t\t\tcandidates.push({\n\t\t\t\tkey: `${scope}:${active.identifier}`,\n\t\t\t\tremainingSeconds: max - this.getScopeElapsedMs(scope, active.identifier) / 1000,\n\t\t\t\tallowLateSubmission: active.timeLimits?.allowLateSubmission === true,\n\t\t\t});\n\t\t}\n\t\treturn candidates;\n\t}\n\n\tprivate nearestRemaining(\n\t\tcandidates: Array<{ key: string; remainingSeconds: number; allowLateSubmission: boolean }>,\n\t): { key: string; remainingSeconds: number; allowLateSubmission: boolean } | null {\n\t\tif (candidates.length === 0) return null;\n\t\treturn candidates.reduce((nearest, candidate) =>\n\t\t\tcandidate.remainingSeconds < nearest.remainingSeconds ? candidate : nearest\n\t\t);\n\t}\n\n\tprivate getActiveRemaining(): { key: string; remainingSeconds: number; allowLateSubmission: boolean } | null {\n\t\treturn this.nearestRemaining(this.getActiveCandidates());\n\t}\n\n\t/**\n\t * Handle time expiration\n\t */\n\tprivate handleExpiration(): void {\n\t\tthis.stopTimer();\n\t\tthis.config.onExpired?.();\n\t}\n\n\t/**\n\t * Stop the timer\n\t */\n\tstopTimer(): void {\n\t\tif (this.intervalId) {\n\t\t\tclearInterval(this.intervalId);\n\t\t\tthis.intervalId = null;\n\t\t}\n\t}\n\n\t/**\n\t * Pause the timer\n\t */\n\tpause(): void {\n\t\tif (this.state.isPaused) return;\n\t\tthis.state.totalElapsed = this.getTotalElapsedMs();\n\t\tthis.lastTickAt = this.now();\n\t\tthis.checkpointActiveScopes(false);\n\t\tthis.state.isPaused = true;\n\t}\n\n\t/**\n\t * Resume the timer\n\t */\n\tresume(): void {\n\t\tif (!this.state.isPaused) return;\n\t\tthis.state.isPaused = false;\n\t\tconst now = this.now();\n\t\tif (this.state.currentItemId) this.state.currentItemStartTime = now;\n\t\tif (this.state.currentSectionId) this.state.currentSectionStartTime = now;\n\t\tif (this.state.currentTestPartId) this.state.currentTestPartStartTime = now;\n\t\tthis.lastTickAt = now;\n\t}\n\n\t/**\n\t * Start tracking time for an item\n\t */\n\tstartItem(itemIdentifier: string): void {\n\t\tif (this.state.currentItemId === itemIdentifier && this.state.currentItemStartTime) return;\n\t\t// End previous item if any\n\t\tif (this.state.currentItemStartTime) {\n\t\t\tthis.endCurrentItem();\n\t\t}\n\n\t\tthis.state.currentItemId = itemIdentifier;\n\t\tthis.state.currentItemStartTime = this.state.isPaused ? undefined : this.now();\n\t}\n\n\t/**\n\t * End tracking time for current item\n\t */\n\tprivate endCurrentItem(): void {\n\t\tif (!this.state.currentItemStartTime) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeSpent = this.now() - this.state.currentItemStartTime;\n\t\tif (this.state.currentItemId) {\n\t\t\tthis.state.itemTimes[this.state.currentItemId] =\n\t\t\t\t(this.state.itemTimes[this.state.currentItemId] || 0) + Math.max(0, timeSpent);\n\t\t}\n\t\tthis.state.currentItemStartTime = undefined;\n\t\tthis.state.currentItemId = undefined;\n\t}\n\n\t/**\n\t * End tracking time for an item\n\t */\n\tendItem(itemIdentifier: string): void {\n\t\tif (!this.state.currentItemStartTime) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeSpent = this.now() - this.state.currentItemStartTime;\n\t\tconst activeIdentifier = this.state.currentItemId ?? itemIdentifier;\n\t\tthis.state.itemTimes[activeIdentifier] = (this.state.itemTimes[activeIdentifier] || 0) + Math.max(0, timeSpent);\n\t\tthis.state.currentItemStartTime = undefined;\n\t\tthis.state.currentItemId = undefined;\n\t}\n\n\t/**\n\t * Start tracking time for a section\n\t */\n\tstartSection(sectionIdentifier: string): void {\n\t\tif (this.state.currentSectionId === sectionIdentifier && this.state.currentSectionStartTime) return;\n\t\tthis.endCurrentSection();\n\t\tthis.state.currentSectionId = sectionIdentifier;\n\t\tthis.state.currentSectionStartTime = this.state.isPaused ? undefined : this.now();\n\t}\n\n\tstartTestPart(testPartIdentifier: string): void {\n\t\tif (this.state.currentTestPartId === testPartIdentifier && this.state.currentTestPartStartTime) return;\n\t\tthis.endCurrentTestPart();\n\t\tthis.state.currentTestPartId = testPartIdentifier;\n\t\tthis.state.currentTestPartStartTime = this.state.isPaused ? undefined : this.now();\n\t}\n\n\tactivateScopes(scopes: ActiveTimeScopes): void {\n\t\tif (scopes.testPart) this.startTestPart(scopes.testPart.identifier);\n\t\tif (scopes.section) this.startSection(scopes.section.identifier);\n\t\tif (scopes.item) this.startItem(scopes.item.identifier);\n\t\tthis.activeScopes = scopes;\n\t}\n\n\tprivate endCurrentSection(): void {\n\t\tif (this.state.currentSectionId && this.state.currentSectionStartTime) {\n\t\t\tconst elapsed = Math.max(0, this.now() - this.state.currentSectionStartTime);\n\t\t\tthis.state.sectionTimes[this.state.currentSectionId] =\n\t\t\t\t(this.state.sectionTimes[this.state.currentSectionId] || 0) + elapsed;\n\t\t}\n\t\tthis.state.currentSectionStartTime = undefined;\n\t}\n\n\tprivate endCurrentTestPart(): void {\n\t\tif (this.state.currentTestPartId && this.state.currentTestPartStartTime) {\n\t\t\tconst elapsed = Math.max(0, this.now() - this.state.currentTestPartStartTime);\n\t\t\tthis.state.testPartTimes[this.state.currentTestPartId] =\n\t\t\t\t(this.state.testPartTimes[this.state.currentTestPartId] || 0) + elapsed;\n\t\t}\n\t\tthis.state.currentTestPartStartTime = undefined;\n\t}\n\n\tprivate checkpointActiveScopes(restart: boolean): void {\n\t\tconst itemId = this.state.currentItemId;\n\t\tconst sectionId = this.state.currentSectionId;\n\t\tconst testPartId = this.state.currentTestPartId;\n\t\tthis.endCurrentItem();\n\t\tthis.endCurrentSection();\n\t\tthis.endCurrentTestPart();\n\t\tthis.state.currentItemId = itemId;\n\t\tthis.state.currentSectionId = sectionId;\n\t\tthis.state.currentTestPartId = testPartId;\n\t\tif (restart && !this.state.isPaused) {\n\t\t\tconst now = this.now();\n\t\t\tif (itemId) this.state.currentItemStartTime = now;\n\t\t\tif (sectionId) this.state.currentSectionStartTime = now;\n\t\t\tif (testPartId) this.state.currentTestPartStartTime = now;\n\t\t}\n\t}\n\n\t/**\n\t * Get remaining time in seconds (null if no limit)\n\t */\n\tgetRemainingSeconds(): number | null {\n\t\tconst active = this.getActiveRemaining();\n\t\treturn active ? Math.max(0, Math.ceil(active.remainingSeconds)) : null;\n\t}\n\n\t/**\n\t * Get elapsed time in seconds\n\t */\n\tgetElapsedSeconds(): number {\n\t\treturn Math.floor(this.getTotalElapsedMs() / 1000);\n\t}\n\n\tprivate getTotalElapsedMs(): number {\n\t\tif (this.state.isPaused) return this.state.totalElapsed;\n\t\treturn this.state.totalElapsed + Math.max(0, this.now() - this.lastTickAt);\n\t}\n\n\t/**\n\t * Get time spent on a specific item (ms)\n\t */\n\tgetItemTime(itemIdentifier: string): number {\n\t\treturn this.getScopeElapsedMs('item', itemIdentifier);\n\t}\n\n\tgetScopeElapsedMs(scope: 'assessment' | 'testPart' | 'section' | 'item', identifier?: string): number {\n\t\tif (scope === 'assessment') return this.getTotalElapsedMs();\n\t\tconst now = this.now();\n\t\tif (scope === 'item') {\n\t\t\tconst id = identifier ?? this.state.currentItemId;\n\t\t\tif (!id) return 0;\n\t\t\tconst active = id === this.state.currentItemId && this.state.currentItemStartTime && !this.state.isPaused\n\t\t\t\t? Math.max(0, now - this.state.currentItemStartTime)\n\t\t\t\t: 0;\n\t\t\treturn (this.state.itemTimes[id] || 0) + active;\n\t\t}\n\t\tif (scope === 'section') {\n\t\t\tconst id = identifier ?? this.state.currentSectionId;\n\t\t\tif (!id) return 0;\n\t\t\tconst active = id === this.state.currentSectionId && this.state.currentSectionStartTime && !this.state.isPaused\n\t\t\t\t? Math.max(0, now - this.state.currentSectionStartTime)\n\t\t\t\t: 0;\n\t\t\treturn (this.state.sectionTimes[id] || 0) + active;\n\t\t}\n\t\tconst id = identifier ?? this.state.currentTestPartId;\n\t\tif (!id) return 0;\n\t\tconst active = id === this.state.currentTestPartId && this.state.currentTestPartStartTime && !this.state.isPaused\n\t\t\t? Math.max(0, now - this.state.currentTestPartStartTime)\n\t\t\t: 0;\n\t\treturn (this.state.testPartTimes[id] || 0) + active;\n\t}\n\n\t/**\n\t * Get current tracking state (for persistence)\n\t */\n\tgetState(): TimeTrackingState {\n\t\tif (!this.state.isPaused) {\n\t\t\tthis.state.totalElapsed = this.getTotalElapsedMs();\n\t\t\tthis.lastTickAt = this.now();\n\t\t}\n\t\tthis.checkpointActiveScopes(true);\n\t\treturn {\n\t\t\t...this.state,\n\t\t\titemTimes: { ...this.state.itemTimes },\n\t\t\tsectionTimes: { ...this.state.sectionTimes },\n\t\t\ttestPartTimes: { ...this.state.testPartTimes },\n\t\t};\n\t}\n\n\t/**\n\t * Restore tracking state (for resume)\n\t */\n\trestoreState(state: TimeTrackingState): void {\n\t\tthis.state = {\n\t\t\t...state,\n\t\t\titemTimes: { ...state.itemTimes },\n\t\t\tsectionTimes: { ...state.sectionTimes },\n\t\t\ttestPartTimes: { ...(state.testPartTimes ?? {}) },\n\t\t\tcurrentItemStartTime: undefined,\n\t\t\tcurrentSectionStartTime: undefined,\n\t\t\tcurrentTestPartStartTime: undefined,\n\t\t};\n\t\tif (!this.state.isPaused) {\n\t\t\tconst now = this.now();\n\t\t\tif (this.state.currentItemId) this.state.currentItemStartTime = now;\n\t\t\tif (this.state.currentSectionId) this.state.currentSectionStartTime = now;\n\t\t\tif (this.state.currentTestPartId) this.state.currentTestPartStartTime = now;\n\t\t\tthis.lastTickAt = now;\n\t\t}\n\n\t\t// Restart timer if not expired\n\t\tif (this.maxTimeSeconds) {\n\t\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\t\tif (elapsedSeconds < this.maxTimeSeconds) {\n\t\t\t\tthis.startTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Check if time has expired\n\t */\n\tisExpired(): boolean {\n\t\tconst active = this.getActiveRemaining();\n\t\treturn active !== null && active.remainingSeconds <= 0;\n\t}\n\n\t/**\n\t * Check if late submission is allowed\n\t */\n\tallowsLateSubmission(): boolean {\n\t\tconst candidates = this.getActiveCandidates();\n\t\tconst expired = candidates.filter((candidate) => candidate.remainingSeconds <= 0);\n\t\tif (expired.length > 0) {\n\t\t\treturn expired.every((candidate) => candidate.allowLateSubmission);\n\t\t}\n\t\treturn this.nearestRemaining(candidates)?.allowLateSubmission ?? false;\n\t}\n\n\t/**\n\t * Format time as MM:SS or HH:MM:SS\n\t */\n\tstatic formatTime(seconds: number): string {\n\t\tconst hours = Math.floor(seconds / 3600);\n\t\tconst minutes = Math.floor((seconds % 3600) / 60);\n\t\tconst secs = seconds % 60;\n\n\t\tif (hours > 0) {\n\t\t\treturn `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;\n\t\t}\n\n\t\treturn `${minutes}:${secs.toString().padStart(2, '0')}`;\n\t}\n\n\t/**\n\t * Cleanup - stop all timers\n\t */\n\tdestroy(): void {\n\t\tthis.checkpointActiveScopes(false);\n\t\tthis.stopTimer();\n\t}\n}\n"]}
|
|
@@ -118,6 +118,10 @@ export declare class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
118
118
|
itemXmlMap?: Record<string, string>;
|
|
119
119
|
fileResolver?: (href: string) => Promise<string>;
|
|
120
120
|
baseUrl?: string;
|
|
121
|
+
sectionReferenceLimits?: {
|
|
122
|
+
/** Maximum total inline and external assessmentSection nesting. Defaults to 32. */
|
|
123
|
+
maxDepth?: number;
|
|
124
|
+
};
|
|
121
125
|
}): Promise<SecureAssessment>;
|
|
122
126
|
private evaluateConditionXml;
|
|
123
127
|
private getItemOrder;
|