@pie-element/categorize 13.1.2-next.5 → 13.1.3

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.
Files changed (158) hide show
  1. package/CHANGELOG.json +1637 -0
  2. package/CHANGELOG.md +2550 -0
  3. package/LICENSE.md +5 -0
  4. package/README.md +5 -0
  5. package/configure/CHANGELOG.json +1202 -0
  6. package/configure/CHANGELOG.md +2131 -0
  7. package/configure/lib/defaults.js +222 -0
  8. package/configure/lib/defaults.js.map +1 -0
  9. package/configure/lib/design/builder.js +55 -0
  10. package/configure/lib/design/builder.js.map +1 -0
  11. package/configure/lib/design/buttons.js +59 -0
  12. package/configure/lib/design/buttons.js.map +1 -0
  13. package/configure/lib/design/categories/RowLabel.js +66 -0
  14. package/configure/lib/design/categories/RowLabel.js.map +1 -0
  15. package/configure/lib/design/categories/alternateResponses.js +116 -0
  16. package/configure/lib/design/categories/alternateResponses.js.map +1 -0
  17. package/configure/lib/design/categories/category.js +153 -0
  18. package/configure/lib/design/categories/category.js.map +1 -0
  19. package/configure/lib/design/categories/choice-preview.js +79 -0
  20. package/configure/lib/design/categories/choice-preview.js.map +1 -0
  21. package/configure/lib/design/categories/droppable-placeholder.js +93 -0
  22. package/configure/lib/design/categories/droppable-placeholder.js.map +1 -0
  23. package/configure/lib/design/categories/index.js +256 -0
  24. package/configure/lib/design/categories/index.js.map +1 -0
  25. package/configure/lib/design/choices/choice.js +187 -0
  26. package/configure/lib/design/choices/choice.js.map +1 -0
  27. package/configure/lib/design/choices/config.js +58 -0
  28. package/configure/lib/design/choices/config.js.map +1 -0
  29. package/configure/lib/design/choices/index.js +197 -0
  30. package/configure/lib/design/choices/index.js.map +1 -0
  31. package/configure/lib/design/header.js +71 -0
  32. package/configure/lib/design/header.js.map +1 -0
  33. package/configure/lib/design/index.js +727 -0
  34. package/configure/lib/design/index.js.map +1 -0
  35. package/configure/lib/design/input-header.js +105 -0
  36. package/configure/lib/design/input-header.js.map +1 -0
  37. package/configure/lib/design/utils.js +12 -0
  38. package/configure/lib/design/utils.js.map +1 -0
  39. package/configure/lib/index.js +147 -0
  40. package/configure/lib/index.js.map +1 -0
  41. package/configure/lib/main.js +44 -0
  42. package/configure/lib/main.js.map +1 -0
  43. package/configure/lib/utils.js +43 -0
  44. package/configure/lib/utils.js.map +1 -0
  45. package/configure/package.json +32 -0
  46. package/controller/CHANGELOG.json +452 -0
  47. package/controller/CHANGELOG.md +1384 -0
  48. package/controller/lib/defaults.js +33 -0
  49. package/controller/lib/defaults.js.map +1 -0
  50. package/controller/lib/index.js +493 -0
  51. package/controller/lib/index.js.map +1 -0
  52. package/controller/lib/utils.js +69 -0
  53. package/controller/lib/utils.js.map +1 -0
  54. package/controller/package.json +18 -0
  55. package/docs/config-schema.json +2897 -0
  56. package/docs/config-schema.json.md +2138 -0
  57. package/docs/demo/config.js +8 -0
  58. package/docs/demo/generate.js +357 -0
  59. package/docs/demo/index.html +1 -0
  60. package/docs/demo/session.js +12 -0
  61. package/docs/pie-schema.json +1784 -0
  62. package/docs/pie-schema.json.md +1046 -0
  63. package/lib/categorize/categories.js +135 -0
  64. package/lib/categorize/categories.js.map +1 -0
  65. package/lib/categorize/category.js +67 -0
  66. package/lib/categorize/category.js.map +1 -0
  67. package/lib/categorize/choice.js +140 -0
  68. package/lib/categorize/choice.js.map +1 -0
  69. package/lib/categorize/choices.js +99 -0
  70. package/lib/categorize/choices.js.map +1 -0
  71. package/lib/categorize/droppable-placeholder.js +84 -0
  72. package/lib/categorize/droppable-placeholder.js.map +1 -0
  73. package/lib/categorize/grid-content.js +55 -0
  74. package/lib/categorize/grid-content.js.map +1 -0
  75. package/lib/categorize/index.js +450 -0
  76. package/lib/categorize/index.js.map +1 -0
  77. package/lib/index.js +316 -0
  78. package/lib/index.js.map +1 -0
  79. package/package.json +22 -85
  80. package/configure.js +0 -2
  81. package/controller.js +0 -1
  82. package/dist/author/defaults.d.ts +0 -223
  83. package/dist/author/defaults.js +0 -170
  84. package/dist/author/design/builder.d.ts +0 -10
  85. package/dist/author/design/builder.js +0 -24
  86. package/dist/author/design/buttons.d.ts +0 -28
  87. package/dist/author/design/buttons.js +0 -36
  88. package/dist/author/design/categories/RowLabel.d.ts +0 -23
  89. package/dist/author/design/categories/RowLabel.js +0 -47
  90. package/dist/author/design/categories/alternateResponses.d.ts +0 -31
  91. package/dist/author/design/categories/alternateResponses.js +0 -62
  92. package/dist/author/design/categories/category.d.ts +0 -44
  93. package/dist/author/design/categories/category.js +0 -98
  94. package/dist/author/design/categories/choice-preview.d.ts +0 -25
  95. package/dist/author/design/categories/choice-preview.js +0 -60
  96. package/dist/author/design/categories/droppable-placeholder.d.ts +0 -11
  97. package/dist/author/design/categories/droppable-placeholder.js +0 -71
  98. package/dist/author/design/categories/index.d.ts +0 -41
  99. package/dist/author/design/categories/index.js +0 -146
  100. package/dist/author/design/choices/choice.d.ts +0 -11
  101. package/dist/author/design/choices/choice.js +0 -129
  102. package/dist/author/design/choices/config.d.ts +0 -21
  103. package/dist/author/design/choices/config.js +0 -33
  104. package/dist/author/design/choices/index.d.ts +0 -41
  105. package/dist/author/design/choices/index.js +0 -110
  106. package/dist/author/design/header.d.ts +0 -24
  107. package/dist/author/design/header.js +0 -49
  108. package/dist/author/design/index.d.ts +0 -52
  109. package/dist/author/design/index.js +0 -417
  110. package/dist/author/design/input-header.d.ts +0 -39
  111. package/dist/author/design/input-header.js +0 -69
  112. package/dist/author/design/utils.d.ts +0 -9
  113. package/dist/author/design/utils.js +0 -7
  114. package/dist/author/index.d.ts +0 -51
  115. package/dist/author/index.js +0 -87
  116. package/dist/author/main.d.ts +0 -23
  117. package/dist/author/main.js +0 -30
  118. package/dist/author/utils.d.ts +0 -16
  119. package/dist/author/utils.js +0 -17
  120. package/dist/browser/author/index.js +0 -2041
  121. package/dist/browser/author/index.js.map +0 -1
  122. package/dist/browser/categorize.css +0 -2
  123. package/dist/browser/controller/index.js +0 -299
  124. package/dist/browser/controller/index.js.map +0 -1
  125. package/dist/browser/delivery/index.js +0 -1051
  126. package/dist/browser/delivery/index.js.map +0 -1
  127. package/dist/browser/dist-7UsF60Ks.js +0 -55705
  128. package/dist/browser/dist-7UsF60Ks.js.map +0 -1
  129. package/dist/browser/dist-DnGF41FP.js +0 -1958
  130. package/dist/browser/dist-DnGF41FP.js.map +0 -1
  131. package/dist/controller/defaults.d.ts +0 -34
  132. package/dist/controller/defaults.js +0 -29
  133. package/dist/controller/index.d.ts +0 -61
  134. package/dist/controller/index.js +0 -155
  135. package/dist/controller/utils.d.ts +0 -20
  136. package/dist/controller/utils.js +0 -35
  137. package/dist/delivery/categorize/categories.d.ts +0 -34
  138. package/dist/delivery/categorize/categories.js +0 -66
  139. package/dist/delivery/categorize/category.d.ts +0 -28
  140. package/dist/delivery/categorize/category.js +0 -48
  141. package/dist/delivery/categorize/choice.d.ts +0 -27
  142. package/dist/delivery/categorize/choice.js +0 -94
  143. package/dist/delivery/categorize/choices.d.ts +0 -39
  144. package/dist/delivery/categorize/choices.js +0 -51
  145. package/dist/delivery/categorize/droppable-placeholder.d.ts +0 -32
  146. package/dist/delivery/categorize/droppable-placeholder.js +0 -64
  147. package/dist/delivery/categorize/grid-content.d.ts +0 -25
  148. package/dist/delivery/categorize/grid-content.js +0 -39
  149. package/dist/delivery/categorize/index.d.ts +0 -57
  150. package/dist/delivery/categorize/index.js +0 -260
  151. package/dist/delivery/index.d.ts +0 -27
  152. package/dist/delivery/index.js +0 -152
  153. package/dist/index.d.ts +0 -1
  154. package/dist/index.iife.d.ts +0 -8
  155. package/dist/index.iife.js +0 -152
  156. package/dist/index.js +0 -2
  157. package/dist/runtime-support.d.ts +0 -12
  158. package/dist/runtime-support.js +0 -12
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _utils = require("./utils");
8
+ var _default = exports.default = {
9
+ allowMultiplePlacementsEnabled: _utils.multiplePlacements.enabled,
10
+ alternates: [],
11
+ categories: [],
12
+ categoriesPerRow: 2,
13
+ choices: [],
14
+ choicesLabel: '',
15
+ choicesPosition: 'below',
16
+ correctResponse: [],
17
+ feedbackEnabled: false,
18
+ lockChoiceOrder: true,
19
+ maxAnswerChoices: 6,
20
+ maxChoicesPerCategory: 0,
21
+ partialScoring: true,
22
+ prompt: '',
23
+ promptEnabled: true,
24
+ rationale: '',
25
+ rationaleEnabled: true,
26
+ rowLabels: [''],
27
+ studentInstructionsEnabled: true,
28
+ teacherInstructions: '',
29
+ teacherInstructionsEnabled: true,
30
+ toolbarEditorPosition: 'bottom',
31
+ minRowHeight: '80px'
32
+ };
33
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","names":["_utils","require","_default","exports","default","allowMultiplePlacementsEnabled","multiplePlacements","enabled","alternates","categories","categoriesPerRow","choices","choicesLabel","choicesPosition","correctResponse","feedbackEnabled","lockChoiceOrder","maxAnswerChoices","maxChoicesPerCategory","partialScoring","prompt","promptEnabled","rationale","rationaleEnabled","rowLabels","studentInstructionsEnabled","teacherInstructions","teacherInstructionsEnabled","toolbarEditorPosition","minRowHeight"],"sources":["../src/defaults.js"],"sourcesContent":["import { multiplePlacements } from './utils';\n\nexport default {\n allowMultiplePlacementsEnabled: multiplePlacements.enabled,\n alternates: [],\n categories: [],\n categoriesPerRow: 2,\n choices: [],\n choicesLabel: '',\n choicesPosition: 'below',\n correctResponse: [],\n feedbackEnabled: false,\n lockChoiceOrder: true,\n maxAnswerChoices: 6,\n maxChoicesPerCategory: 0,\n partialScoring: true,\n prompt: '',\n promptEnabled: true,\n rationale: '',\n rationaleEnabled: true,\n rowLabels: [''],\n studentInstructionsEnabled: true,\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n toolbarEditorPosition: 'bottom',\n minRowHeight: '80px',\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAA6C,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE9B;EACbC,8BAA8B,EAAEC,yBAAkB,CAACC,OAAO;EAC1DC,UAAU,EAAE,EAAE;EACdC,UAAU,EAAE,EAAE;EACdC,gBAAgB,EAAE,CAAC;EACnBC,OAAO,EAAE,EAAE;EACXC,YAAY,EAAE,EAAE;EAChBC,eAAe,EAAE,OAAO;EACxBC,eAAe,EAAE,EAAE;EACnBC,eAAe,EAAE,KAAK;EACtBC,eAAe,EAAE,IAAI;EACrBC,gBAAgB,EAAE,CAAC;EACnBC,qBAAqB,EAAE,CAAC;EACxBC,cAAc,EAAE,IAAI;EACpBC,MAAM,EAAE,EAAE;EACVC,aAAa,EAAE,IAAI;EACnBC,SAAS,EAAE,EAAE;EACbC,gBAAgB,EAAE,IAAI;EACtBC,SAAS,EAAE,CAAC,EAAE,CAAC;EACfC,0BAA0B,EAAE,IAAI;EAChCC,mBAAmB,EAAE,EAAE;EACvBC,0BAA0B,EAAE,IAAI;EAChCC,qBAAqB,EAAE,QAAQ;EAC/BC,YAAY,EAAE;AAChB,CAAC","ignoreList":[]}
@@ -0,0 +1,493 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.outcome = exports.normalize = exports.model = exports.getTotalScore = exports.getPartialScore = exports.getLogTrace = exports.getCorrectness = exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
8
+ Object.defineProperty(exports, "score", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _categorize.score;
12
+ }
13
+ });
14
+ exports.validate = void 0;
15
+ var _lodashEs = require("lodash-es");
16
+ var _categorize = require("@pie-lib/categorize");
17
+ var _feedback = require("@pie-lib/feedback");
18
+ var _controllerUtils = require("@pie-lib/controller-utils");
19
+ var _translator = _interopRequireDefault(require("@pie-lib/translator"));
20
+ var _defaults = _interopRequireDefault(require("./defaults"));
21
+ var _utils = require("./utils");
22
+ const {
23
+ translator
24
+ } = _translator.default;
25
+
26
+ // eslint-disable-next-line no-console
27
+
28
+ const getPartialScore = (correctResponse, builtCategories) => {
29
+ // in the resulted best scenario we make a sum with all the correct responses
30
+ // and all the placements
31
+ const {
32
+ placements,
33
+ score
34
+ } = builtCategories.reduce((acc, {
35
+ choices = []
36
+ }) => ({
37
+ placements: acc.placements + choices.length,
38
+ score: acc.score + choices.filter(ch => ch.correct).length
39
+ }), {
40
+ placements: 0,
41
+ score: 0
42
+ });
43
+
44
+ // in the correct response, we make a sum of the max possible score
45
+ const {
46
+ maxScore
47
+ } = correctResponse.reduce((acc, {
48
+ choices
49
+ }) => ({
50
+ maxScore: acc.maxScore + choices.length
51
+ }), {
52
+ maxScore: 0
53
+ });
54
+
55
+ // if there are any extra placements, we subtract from the obtained score
56
+ const extraPlacements = placements > maxScore ? placements - maxScore : 0;
57
+ const totalScore = (score - extraPlacements) / maxScore;
58
+ return totalScore < 0 ? 0 : parseFloat(totalScore.toFixed(2));
59
+ };
60
+ exports.getPartialScore = getPartialScore;
61
+ const getAlternates = correctResponse => correctResponse.map(c => c.alternateResponses).filter(alternate => alternate);
62
+ const getTotalScore = (question, session, env) => {
63
+ if (!session) {
64
+ return 0;
65
+ }
66
+ if (Object.keys(session).length === 0) {
67
+ return 0;
68
+ }
69
+ const {
70
+ categories,
71
+ choices
72
+ } = question || {};
73
+ let {
74
+ correctResponse
75
+ } = question || {};
76
+ let {
77
+ answers
78
+ } = session || {};
79
+ answers = answers || [];
80
+ correctResponse = correctResponse || [];
81
+
82
+ // this function is used in pie-ui/categorize as well, in order to get the best scenario
83
+ // so we get the best scenario and calculate the score
84
+ const {
85
+ categories: builtCategories,
86
+ correct
87
+ } = (0, _categorize.buildState)(categories, choices, answers, correctResponse);
88
+ const alternates = getAlternates(correctResponse);
89
+ const enabled = _controllerUtils.partialScoring.enabled(question, env);
90
+
91
+ // if there are any alternates, there will be no partial scoring!
92
+ if (enabled && !alternates.length) {
93
+ // we apply partial scoring
94
+ return getPartialScore(correctResponse, builtCategories);
95
+ }
96
+
97
+ // else we apply dichotomous
98
+ return correct ? 1 : 0;
99
+ };
100
+ exports.getTotalScore = getTotalScore;
101
+ const getCorrectness = (question, session, env) => {
102
+ return new Promise(resolve => {
103
+ if (env.mode === 'evaluate') {
104
+ const score = getTotalScore(question, session, env);
105
+ if (score === 1) {
106
+ resolve('correct');
107
+ } else if (score === 0) {
108
+ resolve('incorrect');
109
+ } else {
110
+ resolve('partially-correct');
111
+ }
112
+ } else {
113
+ resolve(undefined);
114
+ }
115
+ });
116
+ };
117
+ exports.getCorrectness = getCorrectness;
118
+ const createDefaultModel = (model = {}) => new Promise(resolve => {
119
+ resolve({
120
+ ..._defaults.default,
121
+ ...model
122
+ });
123
+ });
124
+ exports.createDefaultModel = createDefaultModel;
125
+ const normalize = question => ({
126
+ ..._defaults.default,
127
+ ...question
128
+ });
129
+
130
+ /**
131
+ *
132
+ * @param {*} question
133
+ * @param {*} session
134
+ * @param {*} env
135
+ * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
136
+ */
137
+ exports.normalize = normalize;
138
+ const model = async (question, session, env, updateSession) => {
139
+ const normalizedQuestion = normalize(question);
140
+ const answerCorrectness = await getCorrectness(normalizedQuestion, session, env);
141
+ const {
142
+ mode,
143
+ role
144
+ } = env || {};
145
+ const {
146
+ categories,
147
+ categoriesPerRow,
148
+ choicesLabel,
149
+ choicesPosition,
150
+ correctResponse,
151
+ feedback,
152
+ feedbackEnabled,
153
+ promptEnabled,
154
+ prompt,
155
+ rowLabels,
156
+ rationaleEnabled,
157
+ rationale,
158
+ teacherInstructionsEnabled,
159
+ teacherInstructions,
160
+ language,
161
+ maxChoicesPerCategory,
162
+ extraCSSRules,
163
+ minRowHeight,
164
+ fontSizeFactor,
165
+ autoplayAudioEnabled,
166
+ completeAudioEnabled,
167
+ customAudioButton
168
+ } = normalizedQuestion;
169
+ let {
170
+ choices,
171
+ note
172
+ } = normalizedQuestion;
173
+ let fb;
174
+ const lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
175
+ const filteredCorrectResponse = correctResponse.map(response => {
176
+ const filteredChoices = (response.choices || []).filter(choice => choice !== 'null');
177
+ return {
178
+ ...response,
179
+ choices: filteredChoices
180
+ };
181
+ });
182
+ if (mode === 'evaluate' && feedbackEnabled) {
183
+ fb = await (0, _feedback.getFeedbackForCorrectness)(answerCorrectness, feedback);
184
+ }
185
+ if (!lockChoiceOrder) {
186
+ choices = await (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'id');
187
+ }
188
+ choices = (choices || []).map(c => {
189
+ let categoryCount;
190
+ if (normalizedQuestion.allowMultiplePlacementsEnabled === _utils.multiplePlacements.enabled) {
191
+ categoryCount = 0;
192
+ } else if (normalizedQuestion.allowMultiplePlacementsEnabled === _utils.multiplePlacements.disabled) {
193
+ categoryCount = 1;
194
+ } else {
195
+ categoryCount = c.categoryCount || 0;
196
+ }
197
+ return {
198
+ ...c,
199
+ categoryCount
200
+ };
201
+ });
202
+ if (!note) {
203
+ note = translator.t('common:commonCorrectAnswerWithAlternates', {
204
+ lng: language
205
+ });
206
+ }
207
+ const alternates = getAlternates(filteredCorrectResponse);
208
+ const {
209
+ responseAreasToBeFilled,
210
+ possibleResponses,
211
+ hasUnplacedChoices
212
+ } = (0, _utils.getCompleteResponseDetails)(filteredCorrectResponse, normalizedQuestion.allowAlternateEnabled ? alternates : [], normalizedQuestion.choices);
213
+ const out = {
214
+ categories: categories || [],
215
+ categoriesPerRow: categoriesPerRow || 2,
216
+ maxChoicesPerCategory,
217
+ correctness: answerCorrectness,
218
+ choices: choices || [],
219
+ choicesLabel: choicesLabel || '',
220
+ choicesPosition,
221
+ disabled: mode !== 'gather',
222
+ feedback: fb,
223
+ lockChoiceOrder,
224
+ prompt: promptEnabled ? prompt : null,
225
+ rowLabels,
226
+ note,
227
+ env,
228
+ showNote: alternates && alternates.length > 0,
229
+ correctResponse: mode === 'evaluate' ? filteredCorrectResponse : undefined,
230
+ language,
231
+ extraCSSRules,
232
+ fontSizeFactor,
233
+ minRowHeight: minRowHeight,
234
+ autoplayAudioEnabled,
235
+ completeAudioEnabled,
236
+ customAudioButton,
237
+ possibleResponses,
238
+ responseAreasToBeFilled,
239
+ hasUnplacedChoices
240
+ };
241
+ if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
242
+ out.rationale = rationaleEnabled ? rationale : null;
243
+ out.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;
244
+ } else {
245
+ out.rationale = null;
246
+ out.teacherInstructions = null;
247
+ }
248
+ return out;
249
+ };
250
+
251
+ /**
252
+ * Generates detailed trace log for scoring evaluation
253
+ * @param {Object} model - the question model
254
+ * @param {Object} session - the student session
255
+ * @param {Object} env - the environment
256
+ * @returns {Array} traceLog - array of trace messages
257
+ */
258
+ exports.model = model;
259
+ const getLogTrace = (model, session, env) => {
260
+ const traceLog = [];
261
+ const {
262
+ answers
263
+ } = session || {};
264
+ const {
265
+ categories,
266
+ choices,
267
+ correctResponse
268
+ } = model || {};
269
+ const draggedChoices = answers.reduce((sum, a) => sum + (a.choices?.length || 0), 0);
270
+ const alternates = getAlternates(correctResponse);
271
+ const hasAlternates = alternates.length > 0;
272
+ const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
273
+ const builtState = draggedChoices > 0 ? (0, _categorize.buildState)(categories, choices, answers, correctResponse) : null;
274
+ const builtCategories = builtState?.categories || [];
275
+ if (draggedChoices > 0) {
276
+ traceLog.push(`Student placed ${draggedChoices} choice(s) into categories.`);
277
+ (categories || []).forEach(category => {
278
+ const categoryId = category.id;
279
+ const builtCategory = builtCategories.find(c => c.id === categoryId);
280
+ const studentChoices = builtCategory ? builtCategory.choices || [] : [];
281
+ const correctResponseForCategory = (correctResponse || []).find(cr => cr.category === categoryId);
282
+ const expectedChoices = correctResponseForCategory ? correctResponseForCategory.choices || [] : [];
283
+ if (expectedChoices.length > 0) {
284
+ if (studentChoices.length === 0) {
285
+ traceLog.push(`Category ${categoryId}: student left empty (should contain ${expectedChoices.length} choice(s)).`);
286
+ } else {
287
+ const correctCount = studentChoices.filter(choice => choice.correct).length;
288
+ const incorrectCount = studentChoices.length - correctCount;
289
+ if (correctCount > 0 && incorrectCount === 0) {
290
+ traceLog.push(`Category ${categoryId}: student placed ${correctCount} correct choice(s).`);
291
+ } else if (correctCount === 0 && incorrectCount > 0) {
292
+ traceLog.push(`Category ${categoryId}: student placed ${incorrectCount} incorrect choice(s).`);
293
+ } else {
294
+ traceLog.push(`Category ${categoryId}: student placed ${correctCount} correct and ${incorrectCount} incorrect choice(s).`);
295
+ }
296
+ }
297
+ }
298
+ });
299
+ } else {
300
+ traceLog.push('Student did not place any choices into categories.');
301
+ }
302
+ if (hasAlternates) {
303
+ traceLog.push(`Alternate response combinations are accepted for this question.`);
304
+ }
305
+ if (hasAlternates) {
306
+ traceLog.push('Score calculated using all-or-nothing scoring (alternate responses disable partial scoring).');
307
+ traceLog.push('Student must get all categories completely correct to receive full credit.');
308
+ } else if (partialScoringEnabled) {
309
+ traceLog.push('Score calculated using partial scoring.');
310
+ traceLog.push('Student receives credit for each correct placement, with deductions for incorrect placements beyond required amount.');
311
+ if (draggedChoices > 0) {
312
+ const totalCorrect = builtCategories.reduce((sum, cat) => sum + (cat.choices || []).filter(choice => choice.correct).length, 0);
313
+ const totalIncorrect = draggedChoices - totalCorrect;
314
+ const maxPossible = (correctResponse || []).reduce((sum, cat) => sum + (cat.choices || []).length, 0);
315
+ traceLog.push(`Partial scoring calculation: ${totalCorrect} correct placements, ${totalIncorrect} incorrect placements.`);
316
+ if (draggedChoices > maxPossible) {
317
+ const extraPlacements = draggedChoices - maxPossible;
318
+ traceLog.push(`${extraPlacements} extra placement(s) beyond required amount will be deducted from score.`);
319
+ }
320
+ }
321
+ } else {
322
+ traceLog.push('Score calculated using all-or-nothing scoring.');
323
+ traceLog.push('Student must get all categories completely correct to receive full credit.');
324
+ }
325
+ const score = getTotalScore(model, session, env);
326
+ traceLog.push(`Final score: ${score}.`);
327
+ return traceLog;
328
+ };
329
+ exports.getLogTrace = getLogTrace;
330
+ const outcome = (question, session, env) => {
331
+ if (env.mode !== 'evaluate') {
332
+ return Promise.reject(new Error('Can not call outcome when mode is not evaluate'));
333
+ } else {
334
+ return new Promise(resolve => {
335
+ if (!session || (0, _lodashEs.isEmpty)(session)) {
336
+ resolve({
337
+ score: 0,
338
+ empty: true,
339
+ traceLog: ['Student did not place any choices into categories. Score is 0.']
340
+ });
341
+ } else {
342
+ const traceLog = getLogTrace(question, session, env);
343
+ const score = getTotalScore(question, session, env);
344
+ resolve({
345
+ score,
346
+ empty: false,
347
+ traceLog
348
+ });
349
+ }
350
+ });
351
+ }
352
+ };
353
+ exports.outcome = outcome;
354
+ const createCorrectResponseSession = (question, env) => {
355
+ return new Promise(resolve => {
356
+ const {
357
+ mode,
358
+ role
359
+ } = env || {};
360
+ if (mode !== 'evaluate' && role === 'instructor') {
361
+ const {
362
+ correctResponse
363
+ } = question;
364
+ resolve({
365
+ answers: correctResponse,
366
+ id: 1
367
+ });
368
+ } else {
369
+ return resolve(null);
370
+ }
371
+ });
372
+ };
373
+
374
+ // remove all html tags
375
+ exports.createCorrectResponseSession = createCorrectResponseSession;
376
+ const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
377
+
378
+ // remove all html tags except img, iframe and source tag for audio
379
+ const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
380
+ const validate = (model = {}, config = {}) => {
381
+ const {
382
+ categories,
383
+ choices,
384
+ correctResponse,
385
+ maxAnswerChoices
386
+ } = model;
387
+ const {
388
+ minChoices = 1,
389
+ minCategories = 1,
390
+ maxCategories = 12,
391
+ maxLengthPerChoice = 300,
392
+ maxLengthPerCategory = 150
393
+ } = config;
394
+ const reversedChoices = [...(choices || [])].reverse();
395
+ const errors = {};
396
+ const choicesErrors = {};
397
+ const categoriesErrors = {};
398
+ ['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
399
+ if (config[field]?.required && !getContent(model[field])) {
400
+ errors[field] = 'This field is required.';
401
+ }
402
+ });
403
+ (categories || []).forEach(category => {
404
+ const {
405
+ id,
406
+ label
407
+ } = category;
408
+ if (getInnerText(label).length > maxLengthPerCategory) {
409
+ categoriesErrors[id] = `Category labels should be no more than ${maxLengthPerCategory} characters long.`;
410
+ }
411
+ });
412
+ (reversedChoices || []).forEach((choice, index) => {
413
+ const {
414
+ id,
415
+ content
416
+ } = choice;
417
+ if (getInnerText(content).length > maxLengthPerChoice) {
418
+ choicesErrors[id] = `Tokens should be no more than ${maxLengthPerChoice} characters long.`;
419
+ }
420
+ if (!getContent(content)) {
421
+ choicesErrors[id] = 'Tokens should not be empty.';
422
+ } else {
423
+ const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.content === content);
424
+ if (identicalAnswer) {
425
+ choicesErrors[id] = 'Tokens content should be unique.';
426
+ }
427
+ }
428
+ });
429
+ const nbOfCategories = (categories || []).length;
430
+ const nbOfChoices = (choices || []).length;
431
+ if (nbOfCategories > maxCategories) {
432
+ errors.categoriesError = `No more than ${maxCategories} categories should be defined.`;
433
+ } else if (nbOfCategories < minCategories) {
434
+ errors.categoriesError = `There should be at least ${minCategories} category defined.`;
435
+ }
436
+ if (nbOfChoices < minChoices) {
437
+ errors.choicesError = `There should be at least ${minChoices} choices defined.`;
438
+ } else if (nbOfChoices > maxAnswerChoices) {
439
+ errors.choicesError = `No more than ${maxAnswerChoices} choices should be defined.`;
440
+ }
441
+ if (nbOfChoices && nbOfCategories) {
442
+ let hasAssociations = false;
443
+ (correctResponse || []).forEach(response => {
444
+ const {
445
+ choices = [],
446
+ alternateResponses = []
447
+ } = response;
448
+ if (choices.length) {
449
+ hasAssociations = true;
450
+ } else {
451
+ alternateResponses.forEach(alternate => {
452
+ if ((alternate || []).length) {
453
+ hasAssociations = true;
454
+ }
455
+ });
456
+ }
457
+ });
458
+ let duplicateAlternateIndex = -1;
459
+ let duplicateCategory = '';
460
+ (correctResponse || []).forEach(response => {
461
+ const {
462
+ choices = [],
463
+ alternateResponses = [],
464
+ category
465
+ } = response;
466
+ if (duplicateAlternateIndex === -1) {
467
+ duplicateAlternateIndex = (0, _utils.isCorrectResponseDuplicated)(choices, alternateResponses);
468
+ if (duplicateAlternateIndex === -1) {
469
+ duplicateAlternateIndex = (0, _utils.isAlternateDuplicated)(alternateResponses);
470
+ }
471
+ duplicateCategory = category;
472
+ }
473
+ });
474
+ if (duplicateAlternateIndex > -1) {
475
+ errors.duplicateAlternate = {
476
+ index: duplicateAlternateIndex,
477
+ category: duplicateCategory
478
+ };
479
+ }
480
+ if (!hasAssociations) {
481
+ errors.associationError = 'At least one token should be assigned to at least one category.';
482
+ }
483
+ }
484
+ if (!(0, _lodashEs.isEmpty)(choicesErrors)) {
485
+ errors.choicesErrors = choicesErrors;
486
+ }
487
+ if (!(0, _lodashEs.isEmpty)(categoriesErrors)) {
488
+ errors.categoriesErrors = categoriesErrors;
489
+ }
490
+ return errors;
491
+ };
492
+ exports.validate = validate;
493
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_lodashEs","require","_categorize","_feedback","_controllerUtils","_translator","_interopRequireDefault","_defaults","_utils","translator","Translator","getPartialScore","correctResponse","builtCategories","placements","score","reduce","acc","choices","length","filter","ch","correct","maxScore","extraPlacements","totalScore","parseFloat","toFixed","exports","getAlternates","map","c","alternateResponses","alternate","getTotalScore","question","session","env","Object","keys","categories","answers","buildState","alternates","enabled","partialScoring","getCorrectness","Promise","resolve","mode","undefined","createDefaultModel","model","defaults","normalize","updateSession","normalizedQuestion","answerCorrectness","role","categoriesPerRow","choicesLabel","choicesPosition","feedback","feedbackEnabled","promptEnabled","prompt","rowLabels","rationaleEnabled","rationale","teacherInstructionsEnabled","teacherInstructions","language","maxChoicesPerCategory","extraCSSRules","minRowHeight","fontSizeFactor","autoplayAudioEnabled","completeAudioEnabled","customAudioButton","note","fb","lockChoiceOrder","lockChoices","filteredCorrectResponse","response","filteredChoices","choice","getFeedbackForCorrectness","getShuffledChoices","categoryCount","allowMultiplePlacementsEnabled","multiplePlacements","disabled","t","lng","responseAreasToBeFilled","possibleResponses","hasUnplacedChoices","getCompleteResponseDetails","allowAlternateEnabled","out","correctness","showNote","getLogTrace","traceLog","draggedChoices","sum","a","hasAlternates","partialScoringEnabled","builtState","push","forEach","category","categoryId","id","builtCategory","find","studentChoices","correctResponseForCategory","cr","expectedChoices","correctCount","incorrectCount","totalCorrect","cat","totalIncorrect","maxPossible","outcome","reject","Error","isEmpty","empty","createCorrectResponseSession","getInnerText","html","replaceAll","getContent","replace","validate","config","maxAnswerChoices","minChoices","minCategories","maxCategories","maxLengthPerChoice","maxLengthPerCategory","reversedChoices","reverse","errors","choicesErrors","categoriesErrors","field","required","label","index","content","identicalAnswer","slice","some","nbOfCategories","nbOfChoices","categoriesError","choicesError","hasAssociations","duplicateAlternateIndex","duplicateCategory","isCorrectResponseDuplicated","isAlternateDuplicated","duplicateAlternate","associationError"],"sources":["../src/index.js"],"sourcesContent":["import { isEmpty } from 'lodash-es';\nimport { buildState, score } from '@pie-lib/categorize';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport Translator from '@pie-lib/translator';\n\nconst { translator } = Translator;\nimport defaults from './defaults';\nimport { getCompleteResponseDetails, isAlternateDuplicated, isCorrectResponseDuplicated, multiplePlacements } from './utils';\n\n// eslint-disable-next-line no-console\n\nexport { score };\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) => ({ ...defaults, ...question });\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 = async (question, session, env, updateSession) => {\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 extraCSSRules,\n minRowHeight,\n fontSizeFactor,\n autoplayAudioEnabled,\n completeAudioEnabled,\n customAudioButton,\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 choices = (choices || []).map((c) => {\n let categoryCount;\n if (normalizedQuestion.allowMultiplePlacementsEnabled === multiplePlacements.enabled) {\n categoryCount = 0;\n } else if (normalizedQuestion.allowMultiplePlacementsEnabled === multiplePlacements.disabled) {\n categoryCount = 1;\n } else {\n categoryCount = c.categoryCount || 0;\n }\n return { ...c, categoryCount };\n });\n\n if (!note) {\n note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: language });\n }\n\n const alternates = getAlternates(filteredCorrectResponse);\n const { responseAreasToBeFilled, possibleResponses, hasUnplacedChoices } = getCompleteResponseDetails(\n filteredCorrectResponse,\n normalizedQuestion.allowAlternateEnabled ? alternates : [],\n normalizedQuestion.choices,\n );\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 extraCSSRules,\n fontSizeFactor,\n minRowHeight: minRowHeight,\n autoplayAudioEnabled,\n completeAudioEnabled,\n customAudioButton,\n possibleResponses,\n responseAreasToBeFilled,\n hasUnplacedChoices,\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 return out;\n};\n\n /**\n * Generates detailed trace log for scoring evaluation\n * @param {Object} model - the question model\n * @param {Object} session - the student session\n * @param {Object} env - the environment\n * @returns {Array} traceLog - array of trace messages\n */\nexport const getLogTrace = (model, session, env) => {\n const traceLog = [];\n const { answers } = session || {};\n const { categories, choices, correctResponse } = model || {};\n\n const draggedChoices = answers.reduce(\n (sum, a) => sum + (a.choices?.length || 0),\n 0\n );\n\n const alternates = getAlternates(correctResponse);\n const hasAlternates = alternates.length > 0;\n const partialScoringEnabled = partialScoring.enabled(model, env);\n\n const builtState =\n draggedChoices > 0\n ? buildState(categories, choices, answers, correctResponse)\n : null;\n\n const builtCategories = builtState?.categories || [];\n \n if (draggedChoices > 0) {\n traceLog.push(`Student placed ${draggedChoices} choice(s) into categories.`);\n \n (categories || []).forEach((category) => {\n const categoryId = category.id;\n const builtCategory = builtCategories.find(c => c.id === categoryId);\n const studentChoices = builtCategory ? builtCategory.choices || [] : [];\n const correctResponseForCategory = (correctResponse || []).find(cr => cr.category === categoryId);\n const expectedChoices = correctResponseForCategory ? correctResponseForCategory.choices || [] : [];\n \n if (expectedChoices.length > 0) {\n if (studentChoices.length === 0) {\n traceLog.push(`Category ${categoryId}: student left empty (should contain ${expectedChoices.length} choice(s)).`);\n } else {\n const correctCount = studentChoices.filter(choice => choice.correct).length;\n const incorrectCount = studentChoices.length - correctCount;\n \n if (correctCount > 0 && incorrectCount === 0) {\n traceLog.push(`Category ${categoryId}: student placed ${correctCount} correct choice(s).`);\n } else if (correctCount === 0 && incorrectCount > 0) {\n traceLog.push(`Category ${categoryId}: student placed ${incorrectCount} incorrect choice(s).`);\n } else {\n traceLog.push(`Category ${categoryId}: student placed ${correctCount} correct and ${incorrectCount} incorrect choice(s).`);\n }\n }\n }\n });\n } else {\n traceLog.push('Student did not place any choices into categories.');\n }\n\n if (hasAlternates) {\n traceLog.push(`Alternate response combinations are accepted for this question.`);\n }\n\n if (hasAlternates) {\n traceLog.push('Score calculated using all-or-nothing scoring (alternate responses disable partial scoring).');\n traceLog.push('Student must get all categories completely correct to receive full credit.');\n } else if (partialScoringEnabled) {\n traceLog.push('Score calculated using partial scoring.');\n traceLog.push('Student receives credit for each correct placement, with deductions for incorrect placements beyond required amount.');\n \n if (draggedChoices > 0) {\n const totalCorrect = builtCategories.reduce((sum, cat) => \n sum + (cat.choices || []).filter(choice => choice.correct).length, 0);\n const totalIncorrect = draggedChoices - totalCorrect;\n const maxPossible = (correctResponse || []).reduce((sum, cat) => \n sum + (cat.choices || []).length, 0);\n \n traceLog.push(`Partial scoring calculation: ${totalCorrect} correct placements, ${totalIncorrect} incorrect placements.`);\n \n if (draggedChoices > maxPossible) {\n const extraPlacements = draggedChoices - maxPossible;\n traceLog.push(`${extraPlacements} extra placement(s) beyond required amount will be deducted from score.`);\n }\n }\n } else {\n traceLog.push('Score calculated using all-or-nothing scoring.');\n traceLog.push('Student must get all categories completely correct to receive full credit.');\n }\n\n const score = getTotalScore(model, session, env);\n traceLog.push(`Final score: ${score}.`);\n\n return traceLog;\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 if (!session || isEmpty(session)) {\n resolve({\n score: 0,\n empty: true,\n traceLog: ['Student did not place any choices into categories. Score is 0.'],\n });\n } else {\n const traceLog = getLogTrace(question, session, env);\n const score = getTotalScore(question, session, env);\n \n resolve({\n score,\n empty: false,\n traceLog,\n });\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, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { categories, choices, correctResponse, maxAnswerChoices } = model;\n const {\n minChoices = 1,\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 > maxAnswerChoices) {\n errors.choicesError = `No more than ${maxAnswerChoices} 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"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAC,sBAAA,CAAAL,OAAA;AAGA,IAAAM,SAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAFA,MAAM;EAAEQ;AAAW,CAAC,GAAGC,mBAAU;;AAIjC;;AAIO,MAAMC,eAAe,GAAGA,CAACC,eAAe,EAAEC,eAAe,KAAK;EACnE;EACA;EACA,MAAM;IAAEC,UAAU;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AAE,EAAEoG,OAAO,CAAE5B,QAAQ,IAAK;MAC5C,MAAM;QAAElE,OAAO,GAAG,EAAE;QAAEc,kBAAkB,GAAG,EAAE;QAAEiF;MAAS,CAAC,GAAG7B,QAAQ;MAEpE,IAAIiF,uBAAuB,KAAK,CAAC,CAAC,EAAE;QAClCA,uBAAuB,GAAG,IAAAE,kCAA2B,EAACrJ,OAAO,EAAEc,kBAAkB,CAAC;QAElF,IAAIqI,uBAAuB,KAAK,CAAC,CAAC,EAAE;UAClCA,uBAAuB,GAAG,IAAAG,4BAAqB,EAACxI,kBAAkB,CAAC;QACrE;QAEAsI,iBAAiB,GAAGrD,QAAQ;MAC9B;IACF,CAAC,CAAC;IAEF,IAAIoD,uBAAuB,GAAG,CAAC,CAAC,EAAE;MAChChB,MAAM,CAACoB,kBAAkB,GAAG;QAAEd,KAAK,EAAEU,uBAAuB;QAAEpD,QAAQ,EAAEqD;MAAkB,CAAC;IAC7F;IAEA,IAAI,CAACF,eAAe,EAAE;MACpBf,MAAM,CAACqB,gBAAgB,GAAG,iEAAiE;IAC7F;EACF;EAEA,IAAI,CAAC,IAAAvC,iBAAO,EAACmB,aAAa,CAAC,EAAE;IAC3BD,MAAM,CAACC,aAAa,GAAGA,aAAa;EACtC;EAEA,IAAI,CAAC,IAAAnB,iBAAO,EAACoB,gBAAgB,CAAC,EAAE;IAC9BF,MAAM,CAACE,gBAAgB,GAAGA,gBAAgB;EAC5C;EAEA,OAAOF,MAAM;AACf,CAAC;AAACzH,OAAA,CAAA+G,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.multiplePlacements = exports.isCorrectResponseDuplicated = exports.isAlternateDuplicated = exports.getCompleteResponseDetails = void 0;
7
+ // used in configure too, for consistency modify it there too
8
+ const multiplePlacements = exports.multiplePlacements = {
9
+ enabled: 'Yes',
10
+ disabled: 'No',
11
+ perChoice: 'Set Per Choice'
12
+ };
13
+
14
+ // used to validate the config
15
+ const isCorrectResponseDuplicated = (choices, alternate) => {
16
+ if (choices.length < 1 || alternate.length < 1) {
17
+ return -1;
18
+ }
19
+ const stringChoices = JSON.stringify(choices.sort());
20
+ const stringAlternate = alternate.reduce((total, current) => current.length > 0 ? [...total, JSON.stringify(current.sort())] : total, []);
21
+ const foundIndexDuplicate = stringAlternate.findIndex(alternate => alternate.length && alternate === stringChoices);
22
+ return foundIndexDuplicate;
23
+ };
24
+ exports.isCorrectResponseDuplicated = isCorrectResponseDuplicated;
25
+ const isAlternateDuplicated = alternate => {
26
+ if (alternate.length <= 1) {
27
+ return -1;
28
+ }
29
+ const elementSet = new Set();
30
+ const stringAlternate = alternate.reduce((total, current) => current.length > 0 ? [...total, JSON.stringify(current.sort())] : total, []);
31
+ for (let i = 0; i < stringAlternate.length; i++) {
32
+ if (elementSet.has(stringAlternate[i]) && stringAlternate[i]) {
33
+ return i;
34
+ }
35
+ elementSet.add(stringAlternate[i]);
36
+ }
37
+ return -1;
38
+ };
39
+
40
+ // calculate the minimum number of populated response areas (categories) in the correct answer or alternates
41
+ // and create an array with the possible responses ids
42
+ exports.isAlternateDuplicated = isAlternateDuplicated;
43
+ const getCompleteResponseDetails = (correctResponse, alternates, allChoices) => {
44
+ const choicesPerCategory = correctResponse.map(category => category.choices);
45
+ const possibleResponses = [choicesPerCategory.flat()];
46
+ let responseAreasToBeFilled = choicesPerCategory.filter(choices => choices.length).length;
47
+ if (alternates.length) {
48
+ const alternatesPerChoice = alternates[0]?.length || 0; // number of alternates
49
+
50
+ [...Array(alternatesPerChoice).keys()].forEach(index => {
51
+ const alternatesPerResponse = alternates.map(alternate => alternate[index]);
52
+ const filledCategories = alternatesPerResponse.filter(category => category?.length).length;
53
+ possibleResponses.push(alternatesPerResponse.flat());
54
+ if (filledCategories < responseAreasToBeFilled) {
55
+ responseAreasToBeFilled = filledCategories;
56
+ }
57
+ });
58
+ }
59
+
60
+ // check if any correct answer have any unplaced answer choices
61
+ const hasUnplacedChoices = possibleResponses.some(response => !allChoices.every(val => response.includes(val?.id)));
62
+ return {
63
+ responseAreasToBeFilled,
64
+ possibleResponses,
65
+ hasUnplacedChoices
66
+ };
67
+ };
68
+ exports.getCompleteResponseDetails = getCompleteResponseDetails;
69
+ //# sourceMappingURL=utils.js.map