@pie-element/match 7.9.1-next.1 → 7.9.1-next.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.
@@ -0,0 +1,472 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createCorrectResponseSession = void 0;
9
+ exports.createDefaultModel = createDefaultModel;
10
+ exports.model = model;
11
+ exports.validate = exports.outcome = exports.normalize = void 0;
12
+
13
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
+
15
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
16
+
17
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
18
+
19
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
+
21
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
22
+
23
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
24
+
25
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
26
+
27
+ var _feedback = require("@pie-lib/pie-toolbox/feedback");
28
+
29
+ var _controllerUtils = require("@pie-lib/pie-toolbox/controller-utils");
30
+
31
+ var _debug = _interopRequireDefault(require("debug"));
32
+
33
+ var _defaults = _interopRequireDefault(require("./defaults"));
34
+
35
+ var _excluded = ["feedbackEnabled", "promptEnabled", "prompt", "lockChoiceOrder"];
36
+
37
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
38
+
39
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
40
+
41
+ var log = (0, _debug["default"])('@pie-element:match:controller');
42
+
43
+ var getResponseCorrectness = function getResponseCorrectness(model, answers) {
44
+ var env = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
45
+
46
+ var isPartialScoring = _controllerUtils.partialScoring.enabled(model, env);
47
+
48
+ var rows = model.rows;
49
+ var checkboxMode = model.choiceMode === 'checkbox';
50
+
51
+ if (!answers || Object.keys(answers).length === 0) {
52
+ return 'unanswered';
53
+ }
54
+
55
+ var totalCorrectAnswers = checkboxMode ? getTotalCorrectAnswers(model) : getTotalCorrect(model);
56
+ var correctAnswers;
57
+ var incorrectAnswers = 0;
58
+
59
+ if (checkboxMode) {
60
+ var checkboxes = getCheckboxes(rows, answers);
61
+ correctAnswers = checkboxes.correctAnswers;
62
+ incorrectAnswers = checkboxes.incorrectAnswers;
63
+ } else {
64
+ correctAnswers = getCorrectRadios(rows, answers);
65
+ }
66
+
67
+ if (totalCorrectAnswers === correctAnswers && !incorrectAnswers) {
68
+ return 'correct';
69
+ } else if (correctAnswers === 0) {
70
+ return 'incorrect';
71
+ } else if (isPartialScoring) {
72
+ return 'partial';
73
+ }
74
+
75
+ return 'incorrect';
76
+ };
77
+
78
+ var getCorrectness = function getCorrectness(question, env) {
79
+ var answers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
80
+
81
+ if (env.mode === 'evaluate') {
82
+ return getResponseCorrectness(question, answers, env);
83
+ }
84
+ };
85
+
86
+ var getCheckboxes = function getCheckboxes(rows, answers) {
87
+ var correctAnswers = 0;
88
+ var incorrectAnswers = 0;
89
+ rows.forEach(function (row) {
90
+ var answer = answers[row.id];
91
+
92
+ if (answer) {
93
+ row.values.forEach(function (v, i) {
94
+ if (answer[i] && answer[i] === v) {
95
+ correctAnswers += 1;
96
+ } else if (answer[i] && answer[i] !== v) {
97
+ incorrectAnswers += 1;
98
+ }
99
+ });
100
+ }
101
+ });
102
+ return {
103
+ correctAnswers: correctAnswers,
104
+ incorrectAnswers: incorrectAnswers
105
+ };
106
+ };
107
+
108
+ var getCorrectRadios = function getCorrectRadios(rows, answers) {
109
+ var correctAnswers = 0;
110
+ rows.forEach(function (row) {
111
+ if ((0, _isEqual["default"])(row.values, answers[row.id])) {
112
+ correctAnswers += 1;
113
+ }
114
+ });
115
+ return correctAnswers;
116
+ };
117
+
118
+ var getTotalCorrect = function getTotalCorrect(question) {
119
+ var checkboxMode = question.choiceMode === 'checkbox';
120
+ var matchingTable = checkboxMode ? question.layout - 1 : 1;
121
+ return (question.rows.length || 0) * matchingTable;
122
+ };
123
+
124
+ var getTotalCorrectAnswers = function getTotalCorrectAnswers(question) {
125
+ var noOfTotalCorrectAnswers = 0;
126
+ question.rows.forEach(function (row) {
127
+ row.values.forEach(function (value) {
128
+ if (value) {
129
+ noOfTotalCorrectAnswers += 1;
130
+ }
131
+ });
132
+ });
133
+ return noOfTotalCorrectAnswers;
134
+ };
135
+
136
+ var getPartialScore = function getPartialScore(question, answers) {
137
+ var checkboxMode = question.choiceMode === 'checkbox';
138
+
139
+ if (checkboxMode) {
140
+ var _getCheckboxes = getCheckboxes(question.rows, answers),
141
+ correctAnswers = _getCheckboxes.correctAnswers,
142
+ incorrectAnswers = _getCheckboxes.incorrectAnswers;
143
+
144
+ var totalCorrect = getTotalCorrectAnswers(question);
145
+ var total = totalCorrect === 0 ? 1 : totalCorrect;
146
+
147
+ if (correctAnswers + incorrectAnswers > totalCorrect) {
148
+ var extraAnswers = correctAnswers + incorrectAnswers - totalCorrect;
149
+ var score = parseFloat(((correctAnswers - extraAnswers) / total).toFixed(2));
150
+ return score < 0 ? 0 : score;
151
+ } else {
152
+ return parseFloat((correctAnswers / total).toFixed(2));
153
+ }
154
+ } else {
155
+ var _correctAnswers = getCorrectRadios(question.rows, answers);
156
+
157
+ var _totalCorrect = getTotalCorrect(question) === 0 ? 1 : getTotalCorrect(question);
158
+
159
+ return parseFloat((_correctAnswers / _totalCorrect).toFixed(2));
160
+ }
161
+ };
162
+
163
+ var getOutComeScore = function getOutComeScore(question, env) {
164
+ var answers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
165
+ var correctness = getCorrectness(question, env, answers);
166
+
167
+ var isPartialScoring = _controllerUtils.partialScoring.enabled(question, env);
168
+
169
+ return correctness === 'correct' ? 1 : correctness === 'partial' && isPartialScoring ? getPartialScore(question, answers) : 0;
170
+ };
171
+
172
+ var outcome = function outcome(question, session, env) {
173
+ return new Promise(function (resolve) {
174
+ if (env.mode !== 'evaluate') {
175
+ resolve({
176
+ score: undefined,
177
+ completed: undefined
178
+ });
179
+ } else {
180
+ if (!session || (0, _isEmpty["default"])(session)) {
181
+ resolve({
182
+ score: 0,
183
+ empty: true
184
+ });
185
+ }
186
+
187
+ var out = {
188
+ score: getOutComeScore(question, env, session.answers)
189
+ };
190
+ resolve(out);
191
+ }
192
+ });
193
+ };
194
+
195
+ exports.outcome = outcome;
196
+
197
+ function createDefaultModel() {
198
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
199
+ return new Promise(function (resolve) {
200
+ resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
201
+ });
202
+ }
203
+
204
+ var normalize = function normalize(question) {
205
+ return _objectSpread({
206
+ feedbackEnabled: false,
207
+ promptEnabled: true,
208
+ rationaleEnabled: true,
209
+ teacherInstructionsEnabled: true,
210
+ studentInstructionsEnabled: true
211
+ }, question);
212
+ };
213
+ /**
214
+ *
215
+ * @param {*} question
216
+ * @param {*} session
217
+ * @param {*} env
218
+ * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
219
+ */
220
+
221
+
222
+ exports.normalize = normalize;
223
+
224
+ function model(question, session, env, updateSession) {
225
+ return new Promise( /*#__PURE__*/function () {
226
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
227
+ var normalizedQuestion, correctness, score, correctResponse, correctInfo, lockChoiceOrder, fb;
228
+ return _regenerator["default"].wrap(function _callee$(_context) {
229
+ while (1) {
230
+ switch (_context.prev = _context.next) {
231
+ case 0:
232
+ normalizedQuestion = (0, _cloneDeep["default"])(normalize(question));
233
+
234
+ if ((!session || (0, _isEmpty["default"])(session)) && env.mode === 'evaluate') {
235
+ correctness = 'unanswered';
236
+ score = '0%';
237
+ } else {
238
+ correctness = getCorrectness(normalizedQuestion, env, session && session.answers);
239
+ score = "".concat(getOutComeScore(normalizedQuestion, env, session && session.answers) * 100, "%");
240
+ }
241
+
242
+ correctResponse = {};
243
+ correctInfo = {
244
+ score: score,
245
+ correctness: correctness
246
+ };
247
+ lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
248
+
249
+ if (lockChoiceOrder) {
250
+ _context.next = 9;
251
+ break;
252
+ }
253
+
254
+ _context.next = 8;
255
+ return (0, _controllerUtils.getShuffledChoices)(normalizedQuestion.rows, session, updateSession, 'id');
256
+
257
+ case 8:
258
+ normalizedQuestion.rows = _context.sent;
259
+
260
+ case 9:
261
+ normalizedQuestion.rows.forEach(function (row) {
262
+ correctResponse[row.id] = row.values;
263
+
264
+ if (env.mode !== 'evaluate') {
265
+ delete row.values;
266
+ }
267
+ });
268
+ fb = env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled ? (0, _feedback.getFeedbackForCorrectness)(correctInfo.correctness, normalizedQuestion.feedback) : Promise.resolve(undefined);
269
+ fb.then(function (feedback) {
270
+ var feedbackEnabled = normalizedQuestion.feedbackEnabled,
271
+ promptEnabled = normalizedQuestion.promptEnabled,
272
+ prompt = normalizedQuestion.prompt,
273
+ lockChoiceOrder = normalizedQuestion.lockChoiceOrder,
274
+ essentials = (0, _objectWithoutProperties2["default"])(normalizedQuestion, _excluded);
275
+
276
+ var out = _objectSpread(_objectSpread({}, essentials), {}, {
277
+ allowFeedback: feedbackEnabled,
278
+ prompt: promptEnabled ? prompt : null,
279
+ shuffled: !lockChoiceOrder,
280
+ feedback: feedback,
281
+ disabled: env.mode !== 'gather',
282
+ view: env.mode === 'view'
283
+ });
284
+
285
+ if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
286
+ out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
287
+ out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
288
+ } else {
289
+ out.rationale = null;
290
+ out.teacherInstructions = null;
291
+ }
292
+
293
+ if (env.mode === 'evaluate') {
294
+ Object.assign(out, {
295
+ correctResponse: correctResponse,
296
+ correctness: correctInfo
297
+ });
298
+ }
299
+
300
+ log('out: ', out);
301
+ resolve(out);
302
+ });
303
+
304
+ case 12:
305
+ case "end":
306
+ return _context.stop();
307
+ }
308
+ }
309
+ }, _callee);
310
+ }));
311
+
312
+ return function (_x) {
313
+ return _ref.apply(this, arguments);
314
+ };
315
+ }());
316
+ }
317
+
318
+ var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
319
+ return new Promise(function (resolve) {
320
+ if (env.mode !== 'evaluate' && env.role === 'instructor') {
321
+ var rows = question.rows;
322
+ var answers = {};
323
+ rows.forEach(function (r) {
324
+ answers[r.id] = r.values;
325
+ });
326
+ resolve({
327
+ answers: answers,
328
+ id: '1'
329
+ });
330
+ } else {
331
+ resolve(null);
332
+ }
333
+ });
334
+ }; // remove all html tags
335
+
336
+
337
+ exports.createCorrectResponseSession = createCorrectResponseSession;
338
+
339
+ var getInnerText = function getInnerText(html) {
340
+ return (html || '').replaceAll(/<[^>]*>/g, '');
341
+ }; // remove all html tags except img and iframe
342
+
343
+
344
+ var getContent = function getContent(html) {
345
+ return (html || '').replace(/(<(?!img|iframe)([^>]+)>)/gi, '');
346
+ };
347
+
348
+ var validate = function validate() {
349
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
350
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
351
+ var rows = model.rows,
352
+ choiceMode = model.choiceMode,
353
+ headers = model.headers;
354
+ var minQuestions = config.minQuestions,
355
+ maxQuestions = config.maxQuestions,
356
+ maxLengthQuestionsHeading = config.maxLengthQuestionsHeading,
357
+ maxAnswers = config.maxAnswers,
358
+ maxLengthAnswers = config.maxLengthAnswers,
359
+ maxLengthFirstColumnHeading = config.maxLengthFirstColumnHeading;
360
+ var rowsErrors = {};
361
+ var columnsErrors = {};
362
+ var errors = {};
363
+ ['teacherInstructions', 'prompt', 'rationale'].forEach(function (field) {
364
+ var _config$field;
365
+
366
+ if ((_config$field = config[field]) !== null && _config$field !== void 0 && _config$field.required && !getContent(model[field])) {
367
+ errors[field] = 'This field is required.';
368
+ }
369
+ });
370
+
371
+ if (rows.length < minQuestions) {
372
+ errors.noOfRowsError = "There should be at least ".concat(minQuestions, " question rows.");
373
+ } else if (rows.length > maxQuestions) {
374
+ errors.noOfRowsError = "No more than ".concat(maxQuestions, " question rows should be defined.");
375
+ }
376
+
377
+ (rows || []).forEach(function (row, index) {
378
+ var id = row.id,
379
+ _row$values = row.values,
380
+ values = _row$values === void 0 ? [] : _row$values,
381
+ title = row.title;
382
+ rowsErrors[id] = '';
383
+
384
+ if (maxLengthQuestionsHeading && getInnerText(title).length > maxLengthQuestionsHeading) {
385
+ rowsErrors[id] += "Content length should be maximum ".concat(maxLengthQuestionsHeading, " characters. ");
386
+ }
387
+
388
+ if (!getContent(title)) {
389
+ rowsErrors[id] += 'Content should not be empty. ';
390
+ } else {
391
+ // check for identical content with the previous answers
392
+ var identicalAnswer = rows.slice(0, index).some(function (r) {
393
+ return getContent(r.title) === getContent(title);
394
+ });
395
+
396
+ if (identicalAnswer) {
397
+ rowsErrors[id] += 'Content should be unique. ';
398
+ }
399
+ }
400
+
401
+ var hasCorrectResponse = values.some(function (value) {
402
+ return !!value;
403
+ });
404
+
405
+ if (!hasCorrectResponse) {
406
+ rowsErrors[id] += 'No correct response defined.';
407
+ }
408
+ });
409
+
410
+ if (maxAnswers && headers.length - 1 > maxAnswers) {
411
+ errors.columnsLengthError = "There should be maximum ".concat(maxAnswers, " answers.");
412
+ }
413
+
414
+ if (maxLengthFirstColumnHeading && headers[0].length > maxLengthFirstColumnHeading) {
415
+ columnsErrors[0] = "Content length should be maximum ".concat(maxLengthFirstColumnHeading, " characters.");
416
+ }
417
+
418
+ var headersContent = (headers || []).map(function (heading) {
419
+ return getContent(heading);
420
+ });
421
+ headersContent.shift(); // remove first column since it does not require validation
422
+
423
+ headersContent.forEach(function (heading, index) {
424
+ var headerIndex = index + 1; // we need to add 1 because we removed first header from validation
425
+
426
+ columnsErrors[headerIndex] = '';
427
+
428
+ if (maxLengthAnswers && getInnerText(heading).length > maxLengthAnswers) {
429
+ columnsErrors[headerIndex] += "Content length should be maximum ".concat(maxLengthQuestionsHeading, " characters. ");
430
+ }
431
+
432
+ if (!heading) {
433
+ columnsErrors[headerIndex] += 'Content should not be empty.';
434
+ } else {
435
+ // check for identical content with the previous headers
436
+ var identicalAnswer = headersContent.slice(0, index).some(function (head) {
437
+ return head === heading;
438
+ });
439
+
440
+ if (identicalAnswer) {
441
+ columnsErrors[index + 1] += 'Content should be unique.';
442
+ }
443
+ }
444
+ });
445
+ var hasRowErrors = Object.values(rowsErrors).some(function (error) {
446
+ return (error || '').length;
447
+ });
448
+
449
+ if (hasRowErrors) {
450
+ errors.rowsErrors = rowsErrors;
451
+ var noCorrectAnswer = Object.values(rowsErrors).some(function (error) {
452
+ return (error || '').includes('No correct response defined.');
453
+ });
454
+
455
+ if (noCorrectAnswer) {
456
+ errors.correctResponseError = choiceMode === 'radio' ? 'There should be a correct response defined for every row.' : 'There should be at least one correct response defined for every row.';
457
+ }
458
+ }
459
+
460
+ var hasColumnErrors = Object.values(columnsErrors).some(function (error) {
461
+ return (error || '').length;
462
+ });
463
+
464
+ if (hasColumnErrors) {
465
+ errors.columnsErrors = columnsErrors;
466
+ }
467
+
468
+ return errors;
469
+ };
470
+
471
+ exports.validate = validate;
472
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","getResponseCorrectness","model","answers","env","isPartialScoring","partialScoring","enabled","rows","checkboxMode","choiceMode","Object","keys","length","totalCorrectAnswers","getTotalCorrectAnswers","getTotalCorrect","correctAnswers","incorrectAnswers","checkboxes","getCheckboxes","getCorrectRadios","getCorrectness","question","mode","forEach","row","answer","id","values","v","i","matchingTable","layout","noOfTotalCorrectAnswers","value","getPartialScore","totalCorrect","total","extraAnswers","score","parseFloat","toFixed","getOutComeScore","correctness","outcome","session","Promise","resolve","undefined","completed","empty","out","createDefaultModel","defaults","normalize","feedbackEnabled","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","updateSession","normalizedQuestion","correctResponse","correctInfo","lockChoiceOrder","fb","feedback","then","prompt","essentials","allowFeedback","shuffled","disabled","view","role","teacherInstructions","rationale","assign","createCorrectResponseSession","r","getInnerText","html","replaceAll","getContent","replace","validate","config","headers","minQuestions","maxQuestions","maxLengthQuestionsHeading","maxAnswers","maxLengthAnswers","maxLengthFirstColumnHeading","rowsErrors","columnsErrors","errors","field","required","noOfRowsError","index","title","identicalAnswer","slice","some","hasCorrectResponse","columnsLengthError","headersContent","map","heading","shift","headerIndex","head","hasRowErrors","error","noCorrectAnswer","includes","correctResponseError","hasColumnErrors"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAIA;;;;;;;;AAFA,IAAMA,GAAG,GAAG,uBAAM,+BAAN,CAAZ;;AAIA,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,CAACC,KAAD,EAAQC,OAAR,EAA8B;AAAA,MAAbC,GAAa,uEAAP,EAAO;;AAC3D,MAAMC,gBAAgB,GA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D;AACF;AACF,GAlBD;AAoBA,MAAMa,YAAY,GAAGvG,MAAM,CAACkB,MAAP,CAAckE,UAAd,EAA0BU,IAA1B,CAA+B,UAACU,KAAD;AAAA,WAAW,CAACA,KAAK,IAAI,EAAV,EAActG,MAAzB;AAAA,GAA/B,CAArB;;AAEA,MAAIqG,YAAJ,EAAkB;AAChBjB,IAAAA,MAAM,CAACF,UAAP,GAAoBA,UAApB;AAEA,QAAMqB,eAAe,GAAGzG,MAAM,CAACkB,MAAP,CAAckE,UAAd,EAA0BU,IAA1B,CAA+B,UAACU,KAAD;AAAA,aACrD,CAACA,KAAK,IAAI,EAAV,EAAcE,QAAd,CAAuB,8BAAvB,CADqD;AAAA,KAA/B,CAAxB;;AAIA,QAAID,eAAJ,EAAqB;AACnBnB,MAAAA,MAAM,CAACqB,oBAAP,GACE5G,UAAU,KAAK,OAAf,GACI,2DADJ,GAEI,sEAHN;AAID;AACF;;AAED,MAAM6G,eAAe,GAAG5G,MAAM,CAACkB,MAAP,CAAcmE,aAAd,EAA6BS,IAA7B,CAAkC,UAACU,KAAD;AAAA,WAAW,CAACA,KAAK,IAAI,EAAV,EAActG,MAAzB;AAAA,GAAlC,CAAxB;;AAEA,MAAI0G,eAAJ,EAAqB;AACnBtB,IAAAA,MAAM,CAACD,aAAP,GAAuBA,aAAvB;AACD;;AAED,SAAOC,MAAP;AACD,CA3GM","sourcesContent":["import isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\nimport cloneDeep from 'lodash/cloneDeep';\nimport { getFeedbackForCorrectness } from '@pie-lib/pie-toolbox/feedback';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/pie-toolbox/controller-utils';\nimport debug from 'debug';\n\nconst log = debug('@pie-element:match:controller');\n\nimport defaults from './defaults';\n\nconst getResponseCorrectness = (model, answers, env = {}) => {\n const isPartialScoring = partialScoring.enabled(model, env);\n const rows = model.rows;\n const checkboxMode = model.choiceMode === 'checkbox';\n\n if (!answers || Object.keys(answers).length === 0) {\n return 'unanswered';\n }\n\n const totalCorrectAnswers = checkboxMode ? getTotalCorrectAnswers(model) : getTotalCorrect(model);\n let correctAnswers;\n let incorrectAnswers = 0;\n\n if (checkboxMode) {\n const checkboxes = getCheckboxes(rows, answers);\n\n correctAnswers = checkboxes.correctAnswers;\n incorrectAnswers = checkboxes.incorrectAnswers;\n } else {\n correctAnswers = getCorrectRadios(rows, answers);\n }\n\n if (totalCorrectAnswers === correctAnswers && !incorrectAnswers) {\n return 'correct';\n } else if (correctAnswers === 0) {\n return 'incorrect';\n } else if (isPartialScoring) {\n return 'partial';\n }\n\n return 'incorrect';\n};\n\nconst getCorrectness = (question, env, answers = {}) => {\n if (env.mode === 'evaluate') {\n return getResponseCorrectness(question, answers, env);\n }\n};\n\nconst getCheckboxes = (rows, answers) => {\n let correctAnswers = 0;\n let incorrectAnswers = 0;\n\n rows.forEach((row) => {\n const answer = answers[row.id];\n\n if (answer) {\n row.values.forEach((v, i) => {\n if (answer[i] && answer[i] === v) {\n correctAnswers += 1;\n } else if (answer[i] && answer[i] !== v) {\n incorrectAnswers += 1;\n }\n });\n }\n });\n\n return { correctAnswers, incorrectAnswers };\n};\n\nconst getCorrectRadios = (rows, answers) => {\n let correctAnswers = 0;\n\n rows.forEach((row) => {\n if (isEqual(row.values, answers[row.id])) {\n correctAnswers += 1;\n }\n });\n\n return correctAnswers;\n};\n\nconst getTotalCorrect = (question) => {\n const checkboxMode = question.choiceMode === 'checkbox';\n const matchingTable = checkboxMode ? question.layout - 1 : 1;\n return (question.rows.length || 0) * matchingTable;\n};\n\nconst getTotalCorrectAnswers = (question) => {\n let noOfTotalCorrectAnswers = 0;\n\n question.rows.forEach((row) => {\n row.values.forEach((value) => {\n if (value) {\n noOfTotalCorrectAnswers += 1;\n }\n });\n });\n\n return noOfTotalCorrectAnswers;\n};\n\nconst getPartialScore = (question, answers) => {\n const checkboxMode = question.choiceMode === 'checkbox';\n\n if (checkboxMode) {\n const { correctAnswers, incorrectAnswers } = getCheckboxes(question.rows, answers);\n const totalCorrect = getTotalCorrectAnswers(question);\n\n const total = totalCorrect === 0 ? 1 : totalCorrect;\n\n if (correctAnswers + incorrectAnswers > totalCorrect) {\n const extraAnswers = correctAnswers + incorrectAnswers - totalCorrect;\n const score = parseFloat(((correctAnswers - extraAnswers) / total).toFixed(2));\n\n return score < 0 ? 0 : score;\n } else {\n return parseFloat((correctAnswers / total).toFixed(2));\n }\n } else {\n const correctAnswers = getCorrectRadios(question.rows, answers);\n const totalCorrect = getTotalCorrect(question) === 0 ? 1 : getTotalCorrect(question);\n\n return parseFloat((correctAnswers / totalCorrect).toFixed(2));\n }\n};\n\nconst getOutComeScore = (question, env, answers = {}) => {\n const correctness = getCorrectness(question, env, answers);\n const isPartialScoring = partialScoring.enabled(question, env);\n\n return correctness === 'correct'\n ? 1\n : correctness === 'partial' && isPartialScoring\n ? getPartialScore(question, answers)\n : 0;\n};\n\nexport const outcome = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined });\n } else {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n const out = {\n score: getOutComeScore(question, env, session.answers),\n };\n\n resolve(out);\n }\n });\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n}\n\nexport const normalize = (question) => ({\n feedbackEnabled: false,\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport function model(question, session, env, updateSession) {\n return new Promise(async (resolve) => {\n const normalizedQuestion = cloneDeep(normalize(question));\n let correctness, score;\n\n if ((!session || isEmpty(session)) && env.mode === 'evaluate') {\n correctness = 'unanswered';\n score = '0%';\n } else {\n correctness = getCorrectness(normalizedQuestion, env, session && session.answers);\n score = `${getOutComeScore(normalizedQuestion, env, session && session.answers) * 100}%`;\n }\n\n const correctResponse = {};\n const correctInfo = {\n score,\n correctness,\n };\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n normalizedQuestion.rows = await getShuffledChoices(normalizedQuestion.rows, session, updateSession, 'id');\n }\n\n normalizedQuestion.rows.forEach((row) => {\n correctResponse[row.id] = row.values;\n\n if (env.mode !== 'evaluate') {\n delete row.values;\n }\n });\n\n const fb =\n env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(correctInfo.correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then((feedback) => {\n const { feedbackEnabled, promptEnabled, prompt, lockChoiceOrder, ...essentials } = normalizedQuestion;\n const out = {\n ...essentials,\n allowFeedback: feedbackEnabled,\n prompt: promptEnabled ? prompt : null,\n shuffled: !lockChoiceOrder,\n feedback,\n disabled: env.mode !== 'gather',\n view: env.mode === 'view',\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate') {\n Object.assign(out, {\n correctResponse,\n correctness: correctInfo,\n });\n }\n\n log('out: ', out);\n resolve(out);\n });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { rows } = question;\n const answers = {};\n\n rows.forEach((r) => {\n answers[r.id] = r.values;\n });\n\n resolve({\n answers,\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img and iframe\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { rows, choiceMode, headers } = model;\n const {\n minQuestions,\n maxQuestions,\n maxLengthQuestionsHeading,\n maxAnswers,\n maxLengthAnswers,\n maxLengthFirstColumnHeading,\n } = config;\n const rowsErrors = {};\n const columnsErrors = {};\n const errors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n if (rows.length < minQuestions) {\n errors.noOfRowsError = `There should be at least ${minQuestions} question rows.`;\n } else if (rows.length > maxQuestions) {\n errors.noOfRowsError = `No more than ${maxQuestions} question rows should be defined.`;\n }\n\n (rows || []).forEach((row, index) => {\n const { id, values = [], title } = row;\n rowsErrors[id] = '';\n\n if (maxLengthQuestionsHeading && getInnerText(title).length > maxLengthQuestionsHeading) {\n rowsErrors[id] += `Content length should be maximum ${maxLengthQuestionsHeading} characters. `;\n }\n\n if (!getContent(title)) {\n rowsErrors[id] += 'Content should not be empty. ';\n } else {\n // check for identical content with the previous answers\n const identicalAnswer = rows.slice(0, index).some((r) => getContent(r.title) === getContent(title));\n\n if (identicalAnswer) {\n rowsErrors[id] += 'Content should be unique. ';\n }\n }\n\n const hasCorrectResponse = values.some((value) => !!value);\n\n if (!hasCorrectResponse) {\n rowsErrors[id] += 'No correct response defined.';\n }\n });\n\n if (maxAnswers && headers.length - 1 > maxAnswers) {\n errors.columnsLengthError = `There should be maximum ${maxAnswers} answers.`;\n }\n\n if (maxLengthFirstColumnHeading && headers[0].length > maxLengthFirstColumnHeading) {\n columnsErrors[0] = `Content length should be maximum ${maxLengthFirstColumnHeading} characters.`;\n }\n\n const headersContent = (headers || []).map((heading) => getContent(heading));\n headersContent.shift(); // remove first column since it does not require validation\n\n headersContent.forEach((heading, index) => {\n const headerIndex = index + 1; // we need to add 1 because we removed first header from validation\n columnsErrors[headerIndex] = '';\n\n if (maxLengthAnswers && getInnerText(heading).length > maxLengthAnswers) {\n columnsErrors[headerIndex] += `Content length should be maximum ${maxLengthQuestionsHeading} characters. `;\n }\n\n if (!heading) {\n columnsErrors[headerIndex] += 'Content should not be empty.';\n } else {\n // check for identical content with the previous headers\n const identicalAnswer = headersContent.slice(0, index).some((head) => head === heading);\n\n if (identicalAnswer) {\n columnsErrors[index + 1] += 'Content should be unique.';\n }\n }\n });\n\n const hasRowErrors = Object.values(rowsErrors).some((error) => (error || '').length);\n\n if (hasRowErrors) {\n errors.rowsErrors = rowsErrors;\n\n const noCorrectAnswer = Object.values(rowsErrors).some((error) =>\n (error || '').includes('No correct response defined.'),\n );\n\n if (noCorrectAnswer) {\n errors.correctResponseError =\n choiceMode === 'radio'\n ? 'There should be a correct response defined for every row.'\n : 'There should be at least one correct response defined for every row.';\n }\n }\n\n const hasColumnErrors = Object.values(columnsErrors).some((error) => (error || '').length);\n\n if (hasColumnErrors) {\n errors.columnsErrors = columnsErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -9,7 +9,7 @@
9
9
  "test": "./node_modules/.bin/jest"
10
10
  },
11
11
  "dependencies": {
12
- "@pie-lib/pie-toolbox": "1.16.1-next.28",
12
+ "@pie-lib/pie-toolbox": "1.16.0",
13
13
  "debug": "^3.1.0"
14
14
  },
15
15
  "devDependencies": {