@pie-element/categorize 8.15.0 → 8.15.1-next.1
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/configure/package.json +1 -1
- package/controller/package.json +1 -1
- package/package.json +3 -3
- package/configure/lib/defaults.js +0 -207
- package/configure/lib/defaults.js.map +0 -1
- package/configure/lib/design/builder.js +0 -74
- package/configure/lib/design/builder.js.map +0 -1
- package/configure/lib/design/buttons.js +0 -127
- package/configure/lib/design/buttons.js.map +0 -1
- package/configure/lib/design/categories/RowLabel.js +0 -78
- package/configure/lib/design/categories/RowLabel.js.map +0 -1
- package/configure/lib/design/categories/alternateResponses.js +0 -293
- package/configure/lib/design/categories/alternateResponses.js.map +0 -1
- package/configure/lib/design/categories/category.js +0 -219
- package/configure/lib/design/categories/category.js.map +0 -1
- package/configure/lib/design/categories/choice-preview.js +0 -136
- package/configure/lib/design/categories/choice-preview.js.map +0 -1
- package/configure/lib/design/categories/droppable-placeholder.js +0 -187
- package/configure/lib/design/categories/droppable-placeholder.js.map +0 -1
- package/configure/lib/design/categories/index.js +0 -408
- package/configure/lib/design/categories/index.js.map +0 -1
- package/configure/lib/design/choices/choice.js +0 -297
- package/configure/lib/design/choices/choice.js.map +0 -1
- package/configure/lib/design/choices/config.js +0 -114
- package/configure/lib/design/choices/config.js.map +0 -1
- package/configure/lib/design/choices/index.js +0 -276
- package/configure/lib/design/choices/index.js.map +0 -1
- package/configure/lib/design/header.js +0 -107
- package/configure/lib/design/header.js.map +0 -1
- package/configure/lib/design/index.js +0 -538
- package/configure/lib/design/index.js.map +0 -1
- package/configure/lib/design/input-header.js +0 -166
- package/configure/lib/design/input-header.js.map +0 -1
- package/configure/lib/design/utils.js +0 -23
- package/configure/lib/design/utils.js.map +0 -1
- package/configure/lib/index.js +0 -196
- package/configure/lib/index.js.map +0 -1
- package/configure/lib/main.js +0 -88
- package/configure/lib/main.js.map +0 -1
- package/configure/lib/utils.js +0 -40
- package/configure/lib/utils.js.map +0 -1
- package/controller/lib/defaults.js +0 -31
- package/controller/lib/defaults.js.map +0 -1
- package/controller/lib/index.js +0 -484
- package/controller/lib/index.js.map +0 -1
- package/controller/lib/utils.js +0 -60
- package/controller/lib/utils.js.map +0 -1
- package/lib/categorize/categories.js +0 -193
- package/lib/categorize/categories.js.map +0 -1
- package/lib/categorize/category.js +0 -135
- package/lib/categorize/category.js.map +0 -1
- package/lib/categorize/choice.js +0 -228
- package/lib/categorize/choice.js.map +0 -1
- package/lib/categorize/choices.js +0 -162
- package/lib/categorize/choices.js.map +0 -1
- package/lib/categorize/droppable-placeholder.js +0 -111
- package/lib/categorize/droppable-placeholder.js.map +0 -1
- package/lib/categorize/grid-content.js +0 -103
- package/lib/categorize/grid-content.js.map +0 -1
- package/lib/categorize/index.js +0 -368
- package/lib/categorize/index.js.map +0 -1
- package/lib/index.js +0 -137
- package/lib/index.js.map +0 -1
package/controller/lib/index.js
DELETED
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.outcome = exports.normalize = exports.model = exports.getTotalScore = exports.getPartialScore = exports.getCorrectness = exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
|
|
9
|
-
Object.defineProperty(exports, "score", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function get() {
|
|
12
|
-
return _categorize.score;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
exports.validate = void 0;
|
|
16
|
-
|
|
17
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
18
|
-
|
|
19
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
20
|
-
|
|
21
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
22
|
-
|
|
23
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
24
|
-
|
|
25
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
26
|
-
|
|
27
|
-
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
28
|
-
|
|
29
|
-
var _categorize = require("@pie-lib/pie-toolbox/categorize");
|
|
30
|
-
|
|
31
|
-
var _feedback = require("@pie-lib/pie-toolbox/feedback");
|
|
32
|
-
|
|
33
|
-
var _controllerUtils = require("@pie-lib/pie-toolbox/controller-utils");
|
|
34
|
-
|
|
35
|
-
var _translator = _interopRequireDefault(require("@pie-lib/pie-toolbox/translator"));
|
|
36
|
-
|
|
37
|
-
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
38
|
-
|
|
39
|
-
var _utils = require("./utils");
|
|
40
|
-
|
|
41
|
-
var _excluded = ["alternateResponses"];
|
|
42
|
-
|
|
43
|
-
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; }
|
|
44
|
-
|
|
45
|
-
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; }
|
|
46
|
-
|
|
47
|
-
var translator = _translator["default"].translator;
|
|
48
|
-
|
|
49
|
-
// PD-2960: make sure we don't have alternates in model or possibility to add them (temporary solution)
|
|
50
|
-
// this function is used in configure part, too
|
|
51
|
-
var disableAlternateResponses = function disableAlternateResponses(question) {
|
|
52
|
-
var _ref = question || {},
|
|
53
|
-
correctResponse = _ref.correctResponse;
|
|
54
|
-
|
|
55
|
-
correctResponse = correctResponse || [];
|
|
56
|
-
var mappedCorrectResponse = correctResponse.map(function (cr) {
|
|
57
|
-
var alternateResponses = cr.alternateResponses,
|
|
58
|
-
response = (0, _objectWithoutProperties2["default"])(cr, _excluded);
|
|
59
|
-
return response;
|
|
60
|
-
});
|
|
61
|
-
return _objectSpread(_objectSpread({}, question), {}, {
|
|
62
|
-
correctResponse: mappedCorrectResponse,
|
|
63
|
-
allowAlternateEnabled: false
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
var getPartialScore = function getPartialScore(correctResponse, builtCategories) {
|
|
68
|
-
// in the resulted best scenario we make a sum with all the correct responses
|
|
69
|
-
// and all the placements
|
|
70
|
-
var _builtCategories$redu = builtCategories.reduce(function (acc, _ref2) {
|
|
71
|
-
var _ref2$choices = _ref2.choices,
|
|
72
|
-
choices = _ref2$choices === void 0 ? [] : _ref2$choices;
|
|
73
|
-
return {
|
|
74
|
-
placements: acc.placements + choices.length,
|
|
75
|
-
score: acc.score + choices.filter(function (ch) {
|
|
76
|
-
return ch.correct;
|
|
77
|
-
}).length
|
|
78
|
-
};
|
|
79
|
-
}, {
|
|
80
|
-
placements: 0,
|
|
81
|
-
score: 0
|
|
82
|
-
}),
|
|
83
|
-
placements = _builtCategories$redu.placements,
|
|
84
|
-
score = _builtCategories$redu.score; // in the correct response, we make a sum of the max possible score
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var _correctResponse$redu = correctResponse.reduce(function (acc, _ref3) {
|
|
88
|
-
var choices = _ref3.choices;
|
|
89
|
-
return {
|
|
90
|
-
maxScore: acc.maxScore + choices.length
|
|
91
|
-
};
|
|
92
|
-
}, {
|
|
93
|
-
maxScore: 0
|
|
94
|
-
}),
|
|
95
|
-
maxScore = _correctResponse$redu.maxScore; // if there are any extra placements, we subtract from the obtained score
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var extraPlacements = placements > maxScore ? placements - maxScore : 0;
|
|
99
|
-
var totalScore = (score - extraPlacements) / maxScore;
|
|
100
|
-
return totalScore < 0 ? 0 : parseFloat(totalScore.toFixed(2));
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
exports.getPartialScore = getPartialScore;
|
|
104
|
-
|
|
105
|
-
var getAlternates = function getAlternates(correctResponse) {
|
|
106
|
-
return correctResponse.map(function (c) {
|
|
107
|
-
return c.alternateResponses;
|
|
108
|
-
}).filter(function (alternate) {
|
|
109
|
-
return alternate;
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
var getTotalScore = function getTotalScore(question, session, env) {
|
|
114
|
-
if (!session) {
|
|
115
|
-
return 0;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (Object.keys(session).length === 0) {
|
|
119
|
-
return 0;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
var _ref4 = question || {},
|
|
123
|
-
categories = _ref4.categories,
|
|
124
|
-
choices = _ref4.choices;
|
|
125
|
-
|
|
126
|
-
var _ref5 = question || {},
|
|
127
|
-
correctResponse = _ref5.correctResponse;
|
|
128
|
-
|
|
129
|
-
var _ref6 = session || {},
|
|
130
|
-
answers = _ref6.answers;
|
|
131
|
-
|
|
132
|
-
answers = answers || [];
|
|
133
|
-
correctResponse = correctResponse || []; // this function is used in pie-ui/categorize as well, in order to get the best scenario
|
|
134
|
-
// so we get the best scenario and calculate the score
|
|
135
|
-
|
|
136
|
-
var _buildState = (0, _categorize.buildState)(categories, choices, answers, correctResponse),
|
|
137
|
-
builtCategories = _buildState.categories,
|
|
138
|
-
correct = _buildState.correct;
|
|
139
|
-
|
|
140
|
-
var alternates = getAlternates(correctResponse);
|
|
141
|
-
|
|
142
|
-
var enabled = _controllerUtils.partialScoring.enabled(question, env); // if there are any alternates, there will be no partial scoring!
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (enabled && !alternates.length) {
|
|
146
|
-
// we apply partial scoring
|
|
147
|
-
return getPartialScore(correctResponse, builtCategories);
|
|
148
|
-
} // else we apply dichotomous
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return correct ? 1 : 0;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
exports.getTotalScore = getTotalScore;
|
|
155
|
-
|
|
156
|
-
var getCorrectness = function getCorrectness(question, session, env) {
|
|
157
|
-
return new Promise(function (resolve) {
|
|
158
|
-
if (env.mode === 'evaluate') {
|
|
159
|
-
var _score = getTotalScore(question, session, env);
|
|
160
|
-
|
|
161
|
-
if (_score === 1) {
|
|
162
|
-
resolve('correct');
|
|
163
|
-
} else if (_score === 0) {
|
|
164
|
-
resolve('incorrect');
|
|
165
|
-
} else {
|
|
166
|
-
resolve('partially-correct');
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
resolve(undefined);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
exports.getCorrectness = getCorrectness;
|
|
175
|
-
|
|
176
|
-
var createDefaultModel = function createDefaultModel() {
|
|
177
|
-
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
178
|
-
return new Promise(function (resolve) {
|
|
179
|
-
resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
exports.createDefaultModel = createDefaultModel;
|
|
184
|
-
|
|
185
|
-
var normalize = function normalize(question) {
|
|
186
|
-
var newQuestion = disableAlternateResponses(question);
|
|
187
|
-
return _objectSpread(_objectSpread({}, _defaults["default"]), newQuestion);
|
|
188
|
-
};
|
|
189
|
-
/**
|
|
190
|
-
*
|
|
191
|
-
* @param {*} question
|
|
192
|
-
* @param {*} session
|
|
193
|
-
* @param {*} env
|
|
194
|
-
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
195
|
-
*/
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
exports.normalize = normalize;
|
|
199
|
-
|
|
200
|
-
var model = function model(question, session, env, updateSession) {
|
|
201
|
-
return new Promise( /*#__PURE__*/function () {
|
|
202
|
-
var _ref7 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
|
|
203
|
-
var normalizedQuestion, answerCorrectness, _ref8, mode, role, categories, categoriesPerRow, choicesLabel, choicesPosition, correctResponse, feedback, feedbackEnabled, promptEnabled, prompt, rowLabels, rationaleEnabled, rationale, teacherInstructionsEnabled, teacherInstructions, language, maxChoicesPerCategory, choices, note, fb, lockChoiceOrder, filteredCorrectResponse, alternates, out;
|
|
204
|
-
|
|
205
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
206
|
-
while (1) {
|
|
207
|
-
switch (_context.prev = _context.next) {
|
|
208
|
-
case 0:
|
|
209
|
-
normalizedQuestion = normalize(question);
|
|
210
|
-
_context.next = 3;
|
|
211
|
-
return getCorrectness(normalizedQuestion, session, env);
|
|
212
|
-
|
|
213
|
-
case 3:
|
|
214
|
-
answerCorrectness = _context.sent;
|
|
215
|
-
_ref8 = env || {}, mode = _ref8.mode, role = _ref8.role;
|
|
216
|
-
categories = normalizedQuestion.categories, categoriesPerRow = normalizedQuestion.categoriesPerRow, choicesLabel = normalizedQuestion.choicesLabel, choicesPosition = normalizedQuestion.choicesPosition, correctResponse = normalizedQuestion.correctResponse, feedback = normalizedQuestion.feedback, feedbackEnabled = normalizedQuestion.feedbackEnabled, promptEnabled = normalizedQuestion.promptEnabled, prompt = normalizedQuestion.prompt, rowLabels = normalizedQuestion.rowLabels, rationaleEnabled = normalizedQuestion.rationaleEnabled, rationale = normalizedQuestion.rationale, teacherInstructionsEnabled = normalizedQuestion.teacherInstructionsEnabled, teacherInstructions = normalizedQuestion.teacherInstructions, language = normalizedQuestion.language, maxChoicesPerCategory = normalizedQuestion.maxChoicesPerCategory;
|
|
217
|
-
choices = normalizedQuestion.choices, note = normalizedQuestion.note;
|
|
218
|
-
lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
|
|
219
|
-
filteredCorrectResponse = correctResponse.map(function (response) {
|
|
220
|
-
var filteredChoices = (response.choices || []).filter(function (choice) {
|
|
221
|
-
return choice !== 'null';
|
|
222
|
-
});
|
|
223
|
-
return _objectSpread(_objectSpread({}, response), {}, {
|
|
224
|
-
choices: filteredChoices
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
if (!(mode === 'evaluate' && feedbackEnabled)) {
|
|
229
|
-
_context.next = 13;
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
_context.next = 12;
|
|
234
|
-
return (0, _feedback.getFeedbackForCorrectness)(answerCorrectness, feedback);
|
|
235
|
-
|
|
236
|
-
case 12:
|
|
237
|
-
fb = _context.sent;
|
|
238
|
-
|
|
239
|
-
case 13:
|
|
240
|
-
if (lockChoiceOrder) {
|
|
241
|
-
_context.next = 17;
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
_context.next = 16;
|
|
246
|
-
return (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'id');
|
|
247
|
-
|
|
248
|
-
case 16:
|
|
249
|
-
choices = _context.sent;
|
|
250
|
-
|
|
251
|
-
case 17:
|
|
252
|
-
if (!note) {
|
|
253
|
-
note = translator.t('common:commonCorrectAnswerWithAlternates', {
|
|
254
|
-
lng: language
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
alternates = getAlternates(filteredCorrectResponse);
|
|
259
|
-
out = {
|
|
260
|
-
categories: categories || [],
|
|
261
|
-
categoriesPerRow: categoriesPerRow || 2,
|
|
262
|
-
maxChoicesPerCategory: maxChoicesPerCategory,
|
|
263
|
-
correctness: answerCorrectness,
|
|
264
|
-
choices: choices || [],
|
|
265
|
-
choicesLabel: choicesLabel || '',
|
|
266
|
-
choicesPosition: choicesPosition,
|
|
267
|
-
disabled: mode !== 'gather',
|
|
268
|
-
feedback: fb,
|
|
269
|
-
lockChoiceOrder: lockChoiceOrder,
|
|
270
|
-
prompt: promptEnabled ? prompt : null,
|
|
271
|
-
rowLabels: rowLabels,
|
|
272
|
-
note: note,
|
|
273
|
-
env: env,
|
|
274
|
-
showNote: alternates && alternates.length > 0,
|
|
275
|
-
correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined,
|
|
276
|
-
language: language
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
|
|
280
|
-
out.rationale = rationaleEnabled ? rationale : null;
|
|
281
|
-
out.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;
|
|
282
|
-
} else {
|
|
283
|
-
out.rationale = null;
|
|
284
|
-
out.teacherInstructions = null;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
resolve(out);
|
|
288
|
-
|
|
289
|
-
case 22:
|
|
290
|
-
case "end":
|
|
291
|
-
return _context.stop();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}, _callee);
|
|
295
|
-
}));
|
|
296
|
-
|
|
297
|
-
return function (_x) {
|
|
298
|
-
return _ref7.apply(this, arguments);
|
|
299
|
-
};
|
|
300
|
-
}());
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
exports.model = model;
|
|
304
|
-
|
|
305
|
-
var outcome = function outcome(question, session, env) {
|
|
306
|
-
if (env.mode !== 'evaluate') {
|
|
307
|
-
return Promise.reject(new Error('Can not call outcome when mode is not evaluate'));
|
|
308
|
-
} else {
|
|
309
|
-
return new Promise(function (resolve) {
|
|
310
|
-
resolve({
|
|
311
|
-
score: getTotalScore(question, session, env),
|
|
312
|
-
empty: !session || (0, _isEmpty["default"])(session)
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
exports.outcome = outcome;
|
|
319
|
-
|
|
320
|
-
var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
|
|
321
|
-
return new Promise(function (resolve) {
|
|
322
|
-
var _ref9 = env || {},
|
|
323
|
-
mode = _ref9.mode,
|
|
324
|
-
role = _ref9.role;
|
|
325
|
-
|
|
326
|
-
if (mode !== 'evaluate' && role === 'instructor') {
|
|
327
|
-
var correctResponse = question.correctResponse;
|
|
328
|
-
resolve({
|
|
329
|
-
answers: correctResponse,
|
|
330
|
-
id: 1
|
|
331
|
-
});
|
|
332
|
-
} else {
|
|
333
|
-
return resolve(null);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
}; // remove all html tags
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
340
|
-
|
|
341
|
-
var getInnerText = function getInnerText(html) {
|
|
342
|
-
return (html || '').replaceAll(/<[^>]*>/g, '');
|
|
343
|
-
}; // remove all html tags except img and iframe
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
var getContent = function getContent(html) {
|
|
347
|
-
return (html || '').replace(/(<(?!img|iframe)([^>]+)>)/gi, '');
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
var validate = function validate() {
|
|
351
|
-
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
352
|
-
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
353
|
-
var categories = model.categories,
|
|
354
|
-
choices = model.choices,
|
|
355
|
-
correctResponse = model.correctResponse;
|
|
356
|
-
var _config$minChoices = config.minChoices,
|
|
357
|
-
minChoices = _config$minChoices === void 0 ? 1 : _config$minChoices,
|
|
358
|
-
_config$maxChoices = config.maxChoices,
|
|
359
|
-
maxChoices = _config$maxChoices === void 0 ? 15 : _config$maxChoices,
|
|
360
|
-
_config$minCategories = config.minCategories,
|
|
361
|
-
minCategories = _config$minCategories === void 0 ? 1 : _config$minCategories,
|
|
362
|
-
_config$maxCategories = config.maxCategories,
|
|
363
|
-
maxCategories = _config$maxCategories === void 0 ? 12 : _config$maxCategories,
|
|
364
|
-
_config$maxLengthPerC = config.maxLengthPerChoice,
|
|
365
|
-
maxLengthPerChoice = _config$maxLengthPerC === void 0 ? 300 : _config$maxLengthPerC,
|
|
366
|
-
_config$maxLengthPerC2 = config.maxLengthPerCategory,
|
|
367
|
-
maxLengthPerCategory = _config$maxLengthPerC2 === void 0 ? 150 : _config$maxLengthPerC2;
|
|
368
|
-
var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
|
|
369
|
-
var errors = {};
|
|
370
|
-
var choicesErrors = {};
|
|
371
|
-
var categoriesErrors = {};
|
|
372
|
-
['teacherInstructions', 'prompt', 'rationale'].forEach(function (field) {
|
|
373
|
-
var _config$field;
|
|
374
|
-
|
|
375
|
-
if ((_config$field = config[field]) !== null && _config$field !== void 0 && _config$field.required && !getContent(model[field])) {
|
|
376
|
-
errors[field] = 'This field is required.';
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
(categories || []).forEach(function (category) {
|
|
380
|
-
var id = category.id,
|
|
381
|
-
label = category.label;
|
|
382
|
-
|
|
383
|
-
if (getInnerText(label).length > maxLengthPerCategory) {
|
|
384
|
-
categoriesErrors[id] = "Category labels should be no more than ".concat(maxLengthPerCategory, " characters long.");
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
(reversedChoices || []).forEach(function (choice, index) {
|
|
388
|
-
var id = choice.id,
|
|
389
|
-
content = choice.content;
|
|
390
|
-
|
|
391
|
-
if (getInnerText(content).length > maxLengthPerChoice) {
|
|
392
|
-
choicesErrors[id] = "Tokens should be no more than ".concat(maxLengthPerChoice, " characters long.");
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (!getContent(content)) {
|
|
396
|
-
choicesErrors[id] = 'Tokens should not be empty.';
|
|
397
|
-
} else {
|
|
398
|
-
var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
|
|
399
|
-
return c.content === content;
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
if (identicalAnswer) {
|
|
403
|
-
choicesErrors[id] = 'Tokens content should be unique.';
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
var nbOfCategories = (categories || []).length;
|
|
408
|
-
var nbOfChoices = (choices || []).length;
|
|
409
|
-
|
|
410
|
-
if (nbOfCategories > maxCategories) {
|
|
411
|
-
errors.categoriesError = "No more than ".concat(maxCategories, " categories should be defined.");
|
|
412
|
-
} else if (nbOfCategories < minCategories) {
|
|
413
|
-
errors.categoriesError = "There should be at least ".concat(minCategories, " category defined.");
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (nbOfChoices < minChoices) {
|
|
417
|
-
errors.choicesError = "There should be at least ".concat(minChoices, " choices defined.");
|
|
418
|
-
} else if (nbOfChoices > maxChoices) {
|
|
419
|
-
errors.choicesError = "No more than ".concat(maxChoices, " choices should be defined.");
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
if (nbOfChoices && nbOfCategories) {
|
|
423
|
-
var hasAssociations = false;
|
|
424
|
-
(correctResponse || []).forEach(function (response) {
|
|
425
|
-
var _response$choices = response.choices,
|
|
426
|
-
choices = _response$choices === void 0 ? [] : _response$choices,
|
|
427
|
-
_response$alternateRe = response.alternateResponses,
|
|
428
|
-
alternateResponses = _response$alternateRe === void 0 ? [] : _response$alternateRe;
|
|
429
|
-
|
|
430
|
-
if (choices.length) {
|
|
431
|
-
hasAssociations = true;
|
|
432
|
-
} else {
|
|
433
|
-
alternateResponses.forEach(function (alternate) {
|
|
434
|
-
if ((alternate || []).length) {
|
|
435
|
-
hasAssociations = true;
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
var duplicateAlternateIndex = -1;
|
|
441
|
-
var duplicateCategory = '';
|
|
442
|
-
(correctResponse || []).forEach(function (response) {
|
|
443
|
-
var _response$choices2 = response.choices,
|
|
444
|
-
choices = _response$choices2 === void 0 ? [] : _response$choices2,
|
|
445
|
-
_response$alternateRe2 = response.alternateResponses,
|
|
446
|
-
alternateResponses = _response$alternateRe2 === void 0 ? [] : _response$alternateRe2,
|
|
447
|
-
category = response.category;
|
|
448
|
-
|
|
449
|
-
if (duplicateAlternateIndex === -1) {
|
|
450
|
-
duplicateAlternateIndex = (0, _utils.isCorrectResponseDuplicated)(choices, alternateResponses);
|
|
451
|
-
|
|
452
|
-
if (duplicateAlternateIndex === -1) {
|
|
453
|
-
duplicateAlternateIndex = (0, _utils.isAlternateDuplicated)(alternateResponses);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
duplicateCategory = category;
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
if (duplicateAlternateIndex > -1) {
|
|
461
|
-
errors.duplicateAlternate = {
|
|
462
|
-
index: duplicateAlternateIndex,
|
|
463
|
-
category: duplicateCategory
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
if (!hasAssociations) {
|
|
468
|
-
errors.associationError = 'At least one token should be assigned to at least one category.';
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
if (!(0, _isEmpty["default"])(choicesErrors)) {
|
|
473
|
-
errors.choicesErrors = choicesErrors;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (!(0, _isEmpty["default"])(categoriesErrors)) {
|
|
477
|
-
errors.categoriesErrors = categoriesErrors;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
return errors;
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
exports.validate = validate;
|
|
484
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["translator","Translator","disableAlternateResponses","question","correctResponse","mappedCorrectResponse","map","cr","alternateResponses","response","allowAlternateEnabled","getPartialScore","builtCategories","reduce","acc","choices","placements","length","score","filter","ch","correct","maxScore","extraPlacements","totalScore","parseFloat","toFixed","getAlternates","c","alternate","getTotalScore","session","env","Object","keys","categories","answers","alternates","enabled","partialScoring","getCorrectness","Promise","resolve","mode","undefined","createDefaultModel","model","defaults","normalize","newQuestion","updateSession","normalizedQuestion","answerCorrectness","role","categoriesPerRow","choicesLabel","choicesPosition","feedback","feedbackEnabled","promptEnabled","prompt","rowLabels","rationaleEnabled","rationale","teacherInstructionsEnabled","teacherInstructions","language","maxChoicesPerCategory","note","lockChoiceOrder","filteredCorrectResponse","filteredChoices","choice","fb","t","lng","out","correctness","disabled","showNote","outcome","reject","Error","empty","createCorrectResponseSession","id","getInnerText","html","replaceAll","getContent","replace","validate","config","minChoices","maxChoices","minCategories","maxCategories","maxLengthPerChoice","maxLengthPerCategory","reversedChoices","reverse","errors","choicesErrors","categoriesErrors","forEach","field","required","category","label","index","content","identicalAnswer","slice","some","nbOfCategories","nbOfChoices","categoriesError","choicesError","hasAssociations","duplicateAlternateIndex","duplicateCategory","duplicateAlternate","associationError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;;;;;;;AAFA,IAAQA,UAAR,GAAuBC,sBAAvB,CAAQD,UAAR;;AAQA;AACA;AACA,IAAME,yBAAyB,GAAG,SAA5BA,yBAA4B,CAACC,QAAD,EAAc;AAC9C,aAA0BA,QAAQ,IAAI,EAAtC;AAAA,MAAMC,eAAN,QAAMA,eAAN;;AACAA,EAAAA,eAAe,GAAGA,eAAe,IAAI,EAArC;AACA,MAAMC,qBAAqB,GAAGD,eAAe,CAACE,GAAhB,CAAoB,UAACC,EAAD,EAAQ;AACxD,QAAQC,kBAAR,GAA4CD,EAA5C,CAAQC,kBAAR;AAAA,QAA+BC,QAA/B,6CAA4CF,EAA5C;AACA,WAAOE,QAAP;AACD,GAH6B,CAA9B;AAIA,yCACKN,QADL;AAEEC,IAAAA,eAAe,EAAEC,qBA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,UAA+CmG,QAA/C,GAA4DlG,QAA5D,CAA+CkG,QAA/C;;AAEA,UAAIY,uBAAuB,KAAK,CAAC,CAAjC,EAAoC;AAClCA,QAAAA,uBAAuB,GAAG,wCAA4BxG,OAA5B,EAAqCP,kBAArC,CAA1B;;AAEA,YAAI+G,uBAAuB,KAAK,CAAC,CAAjC,EAAoC;AAClCA,UAAAA,uBAAuB,GAAG,kCAAsB/G,kBAAtB,CAA1B;AACD;;AAEDgH,QAAAA,iBAAiB,GAAGb,QAApB;AACD;AACF,KAZD;;AAcA,QAAIY,uBAAuB,GAAG,CAAC,CAA/B,EAAkC;AAChClB,MAAAA,MAAM,CAACoB,kBAAP,GAA4B;AAAEZ,QAAAA,KAAK,EAAEU,uBAAT;AAAkCZ,QAAAA,QAAQ,EAAEa;AAA5C,OAA5B;AACD;;AAED,QAAI,CAACF,eAAL,EAAsB;AACpBjB,MAAAA,MAAM,CAACqB,gBAAP,GAA0B,iEAA1B;AACD;AACF;;AAED,MAAI,CAAC,yBAAQpB,aAAR,CAAL,EAA6B;AAC3BD,IAAAA,MAAM,CAACC,aAAP,GAAuBA,aAAvB;AACD;;AAED,MAAI,CAAC,yBAAQC,gBAAR,CAAL,EAAgC;AAC9BF,IAAAA,MAAM,CAACE,gBAAP,GAA0BA,gBAA1B;AACD;;AAED,SAAOF,MAAP;AACD,CAjHM","sourcesContent":["import isEmpty from 'lodash/isEmpty';\nimport { buildState, score } from '@pie-lib/pie-toolbox/categorize';\nimport { getFeedbackForCorrectness } from '@pie-lib/pie-toolbox/feedback';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/pie-toolbox/controller-utils';\nimport Translator from '@pie-lib/pie-toolbox/translator';\n\nconst { translator } = Translator;\nimport defaults from './defaults';\nimport { isAlternateDuplicated, isCorrectResponseDuplicated } from './utils';\n\n// eslint-disable-next-line no-console\n\nexport { score };\n\n// PD-2960: make sure we don't have alternates in model or possibility to add them (temporary solution)\n// this function is used in configure part, too\nconst disableAlternateResponses = (question) => {\n let { correctResponse } = question || {};\n correctResponse = correctResponse || [];\n const mappedCorrectResponse = correctResponse.map((cr) => {\n const { alternateResponses, ...response } = cr;\n return response;\n });\n return {\n ...question,\n correctResponse: mappedCorrectResponse,\n allowAlternateEnabled: false,\n };\n};\n\nexport const getPartialScore = (correctResponse, builtCategories) => {\n // in the resulted best scenario we make a sum with all the correct responses\n // and all the placements\n const { placements, score } = builtCategories.reduce(\n (acc, { choices = [] }) => ({\n placements: acc.placements + choices.length,\n score: acc.score + choices.filter((ch) => ch.correct).length,\n }),\n { placements: 0, score: 0 },\n );\n\n // in the correct response, we make a sum of the max possible score\n const { maxScore } = correctResponse.reduce(\n (acc, { choices }) => ({\n maxScore: acc.maxScore + choices.length,\n }),\n { maxScore: 0 },\n );\n\n // if there are any extra placements, we subtract from the obtained score\n const extraPlacements = placements > maxScore ? placements - maxScore : 0;\n const totalScore = (score - extraPlacements) / maxScore;\n\n return totalScore < 0 ? 0 : parseFloat(totalScore.toFixed(2));\n};\n\nconst getAlternates = (correctResponse) =>\n correctResponse.map((c) => c.alternateResponses).filter((alternate) => alternate);\n\nexport const getTotalScore = (question, session, env) => {\n if (!session) {\n return 0;\n }\n\n if (Object.keys(session).length === 0) {\n return 0;\n }\n const { categories, choices } = question || {};\n let { correctResponse } = question || {};\n let { answers } = session || {};\n answers = answers || [];\n correctResponse = correctResponse || [];\n\n // this function is used in pie-ui/categorize as well, in order to get the best scenario\n // so we get the best scenario and calculate the score\n const { categories: builtCategories, correct } = buildState(categories, choices, answers, correctResponse);\n\n const alternates = getAlternates(correctResponse);\n const enabled = partialScoring.enabled(question, env);\n\n // if there are any alternates, there will be no partial scoring!\n if (enabled && !alternates.length) {\n // we apply partial scoring\n return getPartialScore(correctResponse, builtCategories);\n }\n\n // else we apply dichotomous\n return correct ? 1 : 0;\n};\n\nexport const getCorrectness = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode === 'evaluate') {\n const score = getTotalScore(question, session, env);\n if (score === 1) {\n resolve('correct');\n } else if (score === 0) {\n resolve('incorrect');\n } else {\n resolve('partially-correct');\n }\n } else {\n resolve(undefined);\n }\n });\n};\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nexport const normalize = (question) => {\n const newQuestion = disableAlternateResponses(question);\n return {\n ...defaults,\n ...newQuestion,\n };\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 const model = (question, session, env, updateSession) =>\n new Promise(async (resolve) => {\n const normalizedQuestion = normalize(question);\n const answerCorrectness = await getCorrectness(normalizedQuestion, session, env);\n\n const { mode, role } = env || {};\n\n const {\n categories,\n categoriesPerRow,\n choicesLabel,\n choicesPosition,\n correctResponse,\n feedback,\n feedbackEnabled,\n promptEnabled,\n prompt,\n rowLabels,\n rationaleEnabled,\n rationale,\n teacherInstructionsEnabled,\n teacherInstructions,\n language,\n maxChoicesPerCategory,\n } = normalizedQuestion;\n let { choices, note } = normalizedQuestion;\n let fb;\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n const filteredCorrectResponse = correctResponse.map((response) => {\n const filteredChoices = (response.choices || []).filter((choice) => choice !== 'null');\n return { ...response, choices: filteredChoices };\n });\n\n if (mode === 'evaluate' && feedbackEnabled) {\n fb = await getFeedbackForCorrectness(answerCorrectness, feedback);\n }\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'id');\n }\n\n if (!note) {\n note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: language });\n }\n\n const alternates = getAlternates(filteredCorrectResponse);\n const out = {\n categories: categories || [],\n categoriesPerRow: categoriesPerRow || 2,\n maxChoicesPerCategory,\n correctness: answerCorrectness,\n choices: choices || [],\n choicesLabel: choicesLabel || '',\n choicesPosition,\n disabled: mode !== 'gather',\n feedback: fb,\n lockChoiceOrder,\n prompt: promptEnabled ? prompt : null,\n rowLabels,\n note,\n env,\n showNote: alternates && alternates.length > 0,\n correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined,\n language\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = rationaleEnabled ? rationale : null;\n out.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n\nexport const outcome = (question, session, env) => {\n if (env.mode !== 'evaluate') {\n return Promise.reject(new Error('Can not call outcome when mode is not evaluate'));\n } else {\n return new Promise((resolve) => {\n resolve({\n score: getTotalScore(question, session, env),\n empty: !session || isEmpty(session),\n });\n });\n }\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n const { mode, role } = env || {};\n\n if (mode !== 'evaluate' && role === 'instructor') {\n const { correctResponse } = question;\n\n resolve({ answers: correctResponse, id: 1 });\n } else {\n return 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 { categories, choices, correctResponse } = model;\n const {\n minChoices = 1,\n maxChoices = 15,\n minCategories = 1,\n maxCategories = 12,\n maxLengthPerChoice = 300,\n maxLengthPerCategory = 150,\n } = config;\n const reversedChoices = [...(choices || [])].reverse();\n const errors = {};\n const choicesErrors = {};\n const categoriesErrors = {};\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 (categories || []).forEach((category) => {\n const { id, label } = category;\n\n if (getInnerText(label).length > maxLengthPerCategory) {\n categoriesErrors[id] = `Category labels should be no more than ${maxLengthPerCategory} characters long.`;\n }\n });\n\n (reversedChoices || []).forEach((choice, index) => {\n const { id, content } = choice;\n\n if (getInnerText(content).length > maxLengthPerChoice) {\n choicesErrors[id] = `Tokens should be no more than ${maxLengthPerChoice} characters long.`;\n }\n\n if (!getContent(content)) {\n choicesErrors[id] = 'Tokens should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.content === content);\n\n if (identicalAnswer) {\n choicesErrors[id] = 'Tokens content should be unique.';\n }\n }\n });\n\n const nbOfCategories = (categories || []).length;\n const nbOfChoices = (choices || []).length;\n\n if (nbOfCategories > maxCategories) {\n errors.categoriesError = `No more than ${maxCategories} categories should be defined.`;\n } else if (nbOfCategories < minCategories) {\n errors.categoriesError = `There should be at least ${minCategories} category defined.`;\n }\n\n if (nbOfChoices < minChoices) {\n errors.choicesError = `There should be at least ${minChoices} choices defined.`;\n } else if (nbOfChoices > maxChoices) {\n errors.choicesError = `No more than ${maxChoices} choices should be defined.`;\n }\n\n if (nbOfChoices && nbOfCategories) {\n let hasAssociations = false;\n\n (correctResponse || []).forEach((response) => {\n const { choices = [], alternateResponses = [] } = response;\n\n if (choices.length) {\n hasAssociations = true;\n } else {\n alternateResponses.forEach((alternate) => {\n if ((alternate || []).length) {\n hasAssociations = true;\n }\n });\n }\n });\n\n let duplicateAlternateIndex = -1;\n let duplicateCategory = '';\n (correctResponse || []).forEach((response) => {\n const { choices = [], alternateResponses = [], category } = response;\n\n if (duplicateAlternateIndex === -1) {\n duplicateAlternateIndex = isCorrectResponseDuplicated(choices, alternateResponses);\n\n if (duplicateAlternateIndex === -1) {\n duplicateAlternateIndex = isAlternateDuplicated(alternateResponses);\n }\n\n duplicateCategory = category;\n }\n });\n\n if (duplicateAlternateIndex > -1) {\n errors.duplicateAlternate = { index: duplicateAlternateIndex, category: duplicateCategory };\n }\n\n if (!hasAssociations) {\n errors.associationError = 'At least one token should be assigned to at least one category.';\n }\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n if (!isEmpty(categoriesErrors)) {\n errors.categoriesErrors = categoriesErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
|
package/controller/lib/utils.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.multiplePlacements = exports.isCorrectResponseDuplicated = exports.isAlternateDuplicated = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
// used in configure too, for consistency modify it there too
|
|
13
|
-
var multiplePlacements = {
|
|
14
|
-
enabled: 'Yes',
|
|
15
|
-
disabled: 'No',
|
|
16
|
-
perChoice: 'Set Per Choice'
|
|
17
|
-
}; // used to validate the config
|
|
18
|
-
|
|
19
|
-
exports.multiplePlacements = multiplePlacements;
|
|
20
|
-
|
|
21
|
-
var isCorrectResponseDuplicated = function isCorrectResponseDuplicated(choices, alternate) {
|
|
22
|
-
if (choices.length < 1 || alternate.length < 1) {
|
|
23
|
-
return -1;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var stringChoices = JSON.stringify(choices.sort());
|
|
27
|
-
var stringAlternate = alternate.reduce(function (total, current) {
|
|
28
|
-
return current.length > 0 ? [].concat((0, _toConsumableArray2["default"])(total), [JSON.stringify(current.sort())]) : total;
|
|
29
|
-
}, []);
|
|
30
|
-
var foundIndexDuplicate = stringAlternate.findIndex(function (alternate) {
|
|
31
|
-
return alternate.length && alternate === stringChoices;
|
|
32
|
-
});
|
|
33
|
-
return foundIndexDuplicate;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
exports.isCorrectResponseDuplicated = isCorrectResponseDuplicated;
|
|
37
|
-
|
|
38
|
-
var isAlternateDuplicated = function isAlternateDuplicated(alternate) {
|
|
39
|
-
if (alternate.length <= 1) {
|
|
40
|
-
return -1;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
var elementSet = new Set();
|
|
44
|
-
var stringAlternate = alternate.reduce(function (total, current) {
|
|
45
|
-
return current.length > 0 ? [].concat((0, _toConsumableArray2["default"])(total), [JSON.stringify(current.sort())]) : total;
|
|
46
|
-
}, []);
|
|
47
|
-
|
|
48
|
-
for (var i = 0; i < stringAlternate.length; i++) {
|
|
49
|
-
if (elementSet.has(stringAlternate[i]) && stringAlternate[i]) {
|
|
50
|
-
return i;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
elementSet.add(stringAlternate[i]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return -1;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
exports.isAlternateDuplicated = isAlternateDuplicated;
|
|
60
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.js"],"names":["multiplePlacements","enabled","disabled","perChoice","isCorrectResponseDuplicated","choices","alternate","length","stringChoices","JSON","stringify","sort","stringAlternate","reduce","total","current","foundIndexDuplicate","findIndex","isAlternateDuplicated","elementSet","Set","i","has","add"],"mappings":";;;;;;;;;;;AAAA;AACO,IAAMA,kBAAkB,GAAG;AAAEC,EAAAA,OAAO,EAAE,KAAX;AAAkBC,EAAAA,QAAQ,EAAE,IAA5B;AAAkCC,EAAAA,SAAS,EAAE;AAA7C,CAA3B,C,CAEP;;;;AACO,IAAMC,2BAA2B,GAAG,SAA9BA,2BAA8B,CAACC,OAAD,EAASC,SAAT,EAAuB;AAC9D,MAAID,OAAO,CAACE,MAAR,GAAiB,CAAjB,IAAsBD,SAAS,CAACC,MAAV,GAAmB,CAA7C,EAA+C;AAC3C,WAAO,CAAC,CAAR;AACH;;AAED,MAAMC,aAAa,GAAIC,IAAI,CAACC,SAAL,CAAeL,OAAO,CAACM,IAAR,EAAf,CAAvB;AACA,MAAMC,eAAe,GAAGN,SAAS,CAACO,MAA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ePlacements = { enabled: 'Yes', disabled: 'No', perChoice: 'Set Per Choice' };\n\n// used to validate the config\nexport const isCorrectResponseDuplicated = (choices,alternate) => {\n if (choices.length < 1 || alternate.length < 1){\n return -1;\n }\n\n const stringChoices = JSON.stringify(choices.sort());\n const stringAlternate = alternate.reduce((total, current) => current.length > 0 ? [...total, JSON.stringify(current.sort())] : total, []);\n const foundIndexDuplicate = stringAlternate.findIndex(alternate => alternate.length && alternate === stringChoices);\n\n return foundIndexDuplicate;\n};\n\nexport const isAlternateDuplicated = (alternate) => {\n if (alternate.length <= 1){\n return -1;\n }\n\n const elementSet = new Set();\n const stringAlternate = alternate.reduce((total, current) => current.length > 0 ? [...total, JSON.stringify(current.sort())] : total, []);\n\n for (let i = 0; i < stringAlternate.length; i++) {\n if (elementSet.has(stringAlternate[i]) && stringAlternate[i]) {\n return i;\n }\n\n elementSet.add(stringAlternate[i]);\n }\n\n return -1;\n};\n"],"file":"utils.js"}
|