@pie-lib/categorize 0.6.27-next.36 → 0.6.27-next.53

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/lib/index.js CHANGED
@@ -1,63 +1,47 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.removeChoiceFromCategory = exports.removeCategory = exports.removeAllChoices = exports.moveChoiceToCategory = exports.moveChoiceToAlternate = exports.limitInArrays = exports.limitInArray = exports.limitChoices = exports.getBuiltCategories = exports.getAllPossibleResponses = exports.ensureNoExtraChoicesInAnswer = exports.countInChoices = exports.countInAnswer = exports.countChosen = exports.buildState = exports.buildChoices = exports.buildCategories = exports.FooTwo = void 0;
7
+ exports.removeChoiceFromCategory = exports.removeCategory = exports.removeAllChoices = exports.rearrangeChoices = exports.moveChoiceToCategory = exports.moveChoiceToAlternate = exports.limitInArrays = exports.limitInArray = exports.limitChoices = exports.getBuiltCategories = exports.getAllPossibleResponses = exports.ensureNoExtraChoicesInAnswer = exports.ensureNoExtraChoicesInAlternate = exports.countInChoices = exports.countInAnswer = exports.countChosen = exports.buildState = exports.buildChoices = exports.buildCategories = exports.FooTwo = void 0;
9
8
  Object.defineProperty(exports, "score", {
10
9
  enumerable: true,
11
10
  get: function get() {
12
11
  return _scoring.score;
13
12
  }
14
13
  });
15
- exports.stillSelectable = void 0;
16
-
14
+ exports.verifyAllowMultiplePlacements = exports.stillSelectable = void 0;
17
15
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
-
19
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
-
21
17
  var _compact = _interopRequireDefault(require("lodash/compact"));
22
-
23
18
  var _debug = _interopRequireDefault(require("debug"));
24
-
25
19
  var _clone = _interopRequireDefault(require("lodash/clone"));
26
-
27
20
  var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
28
-
29
21
  var _remove = _interopRequireDefault(require("lodash/remove"));
30
-
31
22
  var _every = _interopRequireDefault(require("lodash/every"));
32
-
33
23
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
34
-
35
24
  var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
36
-
37
25
  var _scoring = require("./scoring");
38
-
39
26
  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; }
40
-
41
27
  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; }
42
-
43
28
  var FooTwo = 'foo-two';
44
29
  exports.FooTwo = FooTwo;
45
30
  var log = (0, _debug["default"])('@pie-lib:categorize');
46
-
47
31
  var limitChoices = function limitChoices(choiceId, count, choices) {
48
32
  var out = choices.reduce(function (acc, id) {
49
- var foundCount = countInChoices(choiceId, acc.choices); // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);
50
-
33
+ var foundCount = countInChoices(choiceId, acc.choices);
34
+ // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);
51
35
  if (id !== choiceId || foundCount < count) {
52
36
  acc.choices.push(id);
53
37
  }
54
-
55
38
  return acc;
56
39
  }, {
57
40
  choices: []
58
41
  });
59
42
  return out.choices;
60
43
  };
44
+
61
45
  /**
62
46
  * Limit in an array of arrays.
63
47
  * So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]
@@ -65,10 +49,7 @@ var limitChoices = function limitChoices(choiceId, count, choices) {
65
49
  * @param {*} arrays
66
50
  * @param {*} limit
67
51
  */
68
-
69
-
70
52
  exports.limitChoices = limitChoices;
71
-
72
53
  var limitInArrays = function limitInArrays(id, arrays, limit) {
73
54
  arrays = arrays || [];
74
55
  var result = arrays.reduce(function (acc, array) {
@@ -83,6 +64,7 @@ var limitInArrays = function limitInArrays(id, arrays, limit) {
83
64
  });
84
65
  return result.out;
85
66
  };
67
+
86
68
  /**
87
69
  * Limit the id in the array to the limit set.
88
70
  * So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]
@@ -90,13 +72,9 @@ var limitInArrays = function limitInArrays(id, arrays, limit) {
90
72
  * @param {string[]} arr
91
73
  * @param {number} limit
92
74
  */
93
-
94
-
95
75
  exports.limitInArrays = limitInArrays;
96
-
97
76
  var limitInArray = function limitInArray(id, arr, limit) {
98
77
  arr = arr || [];
99
-
100
78
  if (limit === 0) {
101
79
  var stripped = arr.filter(function (v) {
102
80
  return v !== id;
@@ -115,7 +93,6 @@ var limitInArray = function limitInArray(id, arr, limit) {
115
93
  } else {
116
94
  acc.out.push(v);
117
95
  }
118
-
119
96
  return acc;
120
97
  }, {
121
98
  out: [],
@@ -127,27 +104,24 @@ var limitInArray = function limitInArray(id, arr, limit) {
127
104
  };
128
105
  }
129
106
  };
107
+
130
108
  /**
131
109
  * Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.
132
110
  * @param {{category: string, choices: string[]}[]} answer
133
111
  * @param {{id:string,categoryCount:number}} choices
134
112
  */
135
-
136
-
137
113
  exports.limitInArray = limitInArray;
138
-
139
114
  var ensureNoExtraChoicesInAnswer = function ensureNoExtraChoicesInAnswer(answer, choices) {
140
115
  choices = choices || [];
141
116
  var out = choices.reduce(function (answerArray, choice) {
142
- log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount); // log('answer array: ', answerArray);
143
-
117
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
118
+ // log('answer array: ', answerArray);
144
119
  if (choice.categoryCount === undefined || choice.categoryCount === 0) {
145
120
  return answerArray;
146
121
  } else {
147
122
  var _choices = answerArray.map(function (a) {
148
123
  return a.choices;
149
124
  });
150
-
151
125
  var result = limitInArrays(choice.id, _choices, choice.categoryCount);
152
126
  var updatedArray = result.map(function (r, index) {
153
127
  return {
@@ -161,15 +135,63 @@ var ensureNoExtraChoicesInAnswer = function ensureNoExtraChoicesInAnswer(answer,
161
135
  }, answer);
162
136
  return out;
163
137
  };
138
+
139
+ /**
140
+ * Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.
141
+ * @param {{category: string, choices: string[]}[]} answer
142
+ * @param {{id:string,categoryCount:number}} choices
143
+ */
144
+ exports.ensureNoExtraChoicesInAnswer = ensureNoExtraChoicesInAnswer;
145
+ var ensureNoExtraChoicesInAlternate = function ensureNoExtraChoicesInAlternate(answer, choices) {
146
+ choices = choices || [];
147
+ var out = choices.reduce(function (answerArray, choice) {
148
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
149
+ // log('answer array: ', answerArray);
150
+ if (choice.categoryCount === undefined || choice.categoryCount === 0) {
151
+ return answerArray;
152
+ } else {
153
+ var alternatePair = {};
154
+ answerArray.forEach(function (answer) {
155
+ return (answer.alternateResponses || []).forEach(function (alternate, index) {
156
+ if (index in alternatePair) {
157
+ alternatePair[index].push(alternate);
158
+ } else {
159
+ alternatePair[index] = [];
160
+ alternatePair[index].push(alternate);
161
+ }
162
+ });
163
+ });
164
+ var recreatedAlternate = [];
165
+ Object.keys(alternatePair).forEach(function (k) {
166
+ var limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);
167
+ alternatePair[k] = limitAlternate;
168
+ alternatePair[k].forEach(function (item, index) {
169
+ if (!recreatedAlternate[index]) {
170
+ recreatedAlternate[index] = [];
171
+ recreatedAlternate[index].push(item);
172
+ } else {
173
+ recreatedAlternate[index].push(item);
174
+ }
175
+ });
176
+ });
177
+ var updatedArray = answerArray.map(function (answer, index) {
178
+ return {
179
+ category: answer.category,
180
+ alternateResponses: recreatedAlternate[index] || answer.alternateResponses,
181
+ choices: answer.choices
182
+ };
183
+ });
184
+ return updatedArray;
185
+ }
186
+ }, answer);
187
+ return out;
188
+ };
164
189
  /**
165
190
  * Count the number of choice ids in a given answer array
166
191
  * @param {string} choiceId
167
192
  * @param {{category: string, choices: string[]}[]} answer
168
193
  */
169
-
170
-
171
- exports.ensureNoExtraChoicesInAnswer = ensureNoExtraChoicesInAnswer;
172
-
194
+ exports.ensureNoExtraChoicesInAlternate = ensureNoExtraChoicesInAlternate;
173
195
  var countInAnswer = function countInAnswer(choiceId, answer) {
174
196
  var out = answer.reduce(function (acc, a) {
175
197
  return acc + countInChoices(choiceId, a.choices);
@@ -177,32 +199,26 @@ var countInAnswer = function countInAnswer(choiceId, answer) {
177
199
  log('[countInAnswer] choiceId:', choiceId, answer);
178
200
  return out;
179
201
  };
180
-
181
202
  exports.countInAnswer = countInAnswer;
182
-
183
203
  var countInChoices = function countInChoices(choiceId, choices) {
184
204
  return (choices || []).filter(function (c) {
185
205
  return c === choiceId;
186
206
  }).length;
187
207
  };
208
+
188
209
  /**
189
210
  * Count the number of times a choice has been selected in categories.
190
211
  * @param {*} choice
191
212
  * @param {*} categories
192
213
  */
193
-
194
-
195
214
  exports.countInChoices = countInChoices;
196
-
197
215
  var countChosen = function countChosen(choice, categories) {
198
216
  if (!choice || !choice.id) {
199
217
  return 0;
200
218
  }
201
-
202
219
  if (!Array.isArray(categories)) {
203
220
  return 0;
204
221
  }
205
-
206
222
  return categories.reduce(function (acc, c) {
207
223
  var count = (c.choices || []).filter(function (h) {
208
224
  return h.id === choice.id;
@@ -210,28 +226,24 @@ var countChosen = function countChosen(choice, categories) {
210
226
  return acc + count;
211
227
  }, 0);
212
228
  };
229
+
213
230
  /**
214
231
  * @param {string?} categoryId
215
232
  * @param {{category:string, choices: string[]}} answers
216
233
  */
217
-
218
-
219
234
  exports.countChosen = countChosen;
220
-
221
235
  var removeCategory = function removeCategory(categoryId, answers) {
222
236
  return answers.filter(function (a) {
223
237
  return a.category !== categoryId;
224
238
  });
225
239
  };
240
+
226
241
  /**
227
242
  * @param {string} choiceId
228
243
  * @param {{category:string, choices: string[]}} answers
229
244
  * @param {string?} categoryId - optional categegory id
230
245
  */
231
-
232
-
233
246
  exports.removeCategory = removeCategory;
234
-
235
247
  var removeAllChoices = function removeAllChoices(choiceId, answers, categoryId) {
236
248
  return answers.map(function (a) {
237
249
  if (!categoryId || a.category === categoryId) {
@@ -247,9 +259,41 @@ var removeAllChoices = function removeAllChoices(choiceId, answers, categoryId)
247
259
  }
248
260
  });
249
261
  };
250
-
251
262
  exports.removeAllChoices = removeAllChoices;
252
-
263
+ var rearrangeChoices = function rearrangeChoices(choices, indexFrom, indexTo) {
264
+ if (choices.length === 0) {
265
+ return choices;
266
+ }
267
+ choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);
268
+ return choices;
269
+ };
270
+ exports.rearrangeChoices = rearrangeChoices;
271
+ var verifyAllowMultiplePlacements = function verifyAllowMultiplePlacements(choice, categoryId, answers) {
272
+ return answers.map(function (a) {
273
+ if (a.category !== categoryId) {
274
+ a.choices = (a.choices || []).filter(function (c) {
275
+ return c !== choice.id;
276
+ });
277
+ return a;
278
+ } else {
279
+ a.choices = a.choices.reduce(function (acc, currentValue) {
280
+ if (currentValue.id === choice.id) {
281
+ var foundIndex = acc.findIndex(function (c) {
282
+ return c.id === choice.id;
283
+ });
284
+ if (foundIndex === -1) {
285
+ acc.push(currentValue);
286
+ }
287
+ } else {
288
+ acc.push(currentValue);
289
+ }
290
+ return acc;
291
+ }, []);
292
+ return a;
293
+ }
294
+ });
295
+ };
296
+ exports.verifyAllowMultiplePlacements = verifyAllowMultiplePlacements;
253
297
  var removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categoryId, choiceIndex, answers) {
254
298
  log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);
255
299
  return answers.map(function (a) {
@@ -258,11 +302,9 @@ var removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categ
258
302
  var index = cloned.findIndex(function (v, index) {
259
303
  return v === choiceId && index >= choiceIndex;
260
304
  });
261
-
262
305
  if (index !== -1) {
263
306
  cloned.splice(index, 1);
264
307
  }
265
-
266
308
  return _objectSpread(_objectSpread({}, a), {}, {
267
309
  choices: cloned
268
310
  });
@@ -271,24 +313,18 @@ var removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categ
271
313
  }
272
314
  });
273
315
  };
274
-
275
316
  exports.removeChoiceFromCategory = removeChoiceFromCategory;
276
-
277
317
  var moveChoiceToCategory = function moveChoiceToCategory(choiceId, from, to, choiceIndex, answers) {
278
318
  log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);
279
-
280
319
  if (from === to) {
281
320
  return answers;
282
321
  }
283
-
284
322
  if (from) {
285
323
  answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);
286
324
  }
287
-
288
325
  var index = answers.findIndex(function (a) {
289
326
  return a.category === to;
290
327
  });
291
-
292
328
  if (index === -1) {
293
329
  answers.push({
294
330
  category: to,
@@ -302,44 +338,38 @@ var moveChoiceToCategory = function moveChoiceToCategory(choiceId, from, to, cho
302
338
  a.choices.push(choiceId);
303
339
  return a;
304
340
  }
305
-
306
341
  return a;
307
342
  });
308
343
  }
309
344
  };
310
-
311
345
  exports.moveChoiceToCategory = moveChoiceToCategory;
312
-
313
346
  var moveChoiceToAlternate = function moveChoiceToAlternate(choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) {
314
347
  log('[moveChoiceToAlternate] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers, 'chocieIndex: ', choiceIndex);
315
-
316
348
  if (from === to) {
317
349
  return answers;
318
350
  }
319
-
320
351
  return answers.map(function (a) {
321
352
  if (a.category === to) {
322
- if (categoryCount !== 0) {
323
- a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter(function (resp) {
353
+ if (categoryCount !== 0 && a.alternateResponses) {
354
+ a.alternateResponses[alternateIndex] = (a.alternateResponses[alternateIndex] || []).filter(function (resp) {
324
355
  return resp !== choiceId;
325
356
  });
326
357
  }
327
-
358
+ if (!a.alternateResponses) {
359
+ a.alternateResponses = [];
360
+ a.alternateResponses[alternateIndex] = [];
361
+ }
328
362
  a.alternateResponses[alternateIndex].push(choiceId);
329
363
  }
330
-
331
- if (a.category === from && categoryCount !== 0) {
364
+ if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {
332
365
  a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter(function (resp) {
333
366
  return resp !== choiceId;
334
367
  });
335
368
  }
336
-
337
369
  return a;
338
370
  });
339
371
  };
340
-
341
372
  exports.moveChoiceToAlternate = moveChoiceToAlternate;
342
-
343
373
  var stillSelectable = function stillSelectable(h, builtCategories) {
344
374
  if (h.categoryCount > 0) {
345
375
  var count = countChosen(h, builtCategories);
@@ -348,6 +378,7 @@ var stillSelectable = function stillSelectable(h, builtCategories) {
348
378
  return true;
349
379
  }
350
380
  };
381
+
351
382
  /**
352
383
  * returns all choices with property 'correct' set to boolean
353
384
  * @param {string[]} possibleResponseChoices
@@ -356,18 +387,15 @@ var stillSelectable = function stillSelectable(h, builtCategories) {
356
387
  * @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean
357
388
  * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
358
389
  */
359
-
360
-
361
390
  exports.stillSelectable = stillSelectable;
362
-
363
391
  var buildChoices = function buildChoices(possibleResponseChoices, builtCategoryChoices) {
364
392
  return builtCategoryChoices.reduce(function (acc, builtChoice) {
365
393
  // set correct value on each choice that was selected by user
366
394
  var index = acc.copyOfPossibleResponse.findIndex(function (cRC) {
367
395
  return cRC === builtChoice.id;
368
- }); // if the choice exists in the correct response
396
+ });
397
+ // if the choice exists in the correct response
369
398
  // set the correct: true
370
-
371
399
  if (index >= 0) {
372
400
  acc.builtChoices.push(_objectSpread(_objectSpread({}, builtChoice), {}, {
373
401
  correct: true
@@ -379,7 +407,6 @@ var buildChoices = function buildChoices(possibleResponseChoices, builtCategoryC
379
407
  }));
380
408
  acc.allChoicesAreCorrect = false;
381
409
  }
382
-
383
410
  return acc;
384
411
  }, {
385
412
  builtChoices: [],
@@ -387,6 +414,7 @@ var buildChoices = function buildChoices(possibleResponseChoices, builtCategoryC
387
414
  allChoicesAreCorrect: true
388
415
  });
389
416
  };
417
+
390
418
  /**
391
419
  * returns corrected answer using this possible correct response
392
420
  * @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }
@@ -396,20 +424,15 @@ var buildChoices = function buildChoices(possibleResponseChoices, builtCategoryC
396
424
  * BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }
397
425
  * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
398
426
  */
399
-
400
-
401
427
  exports.buildChoices = buildChoices;
402
-
403
428
  var getBuiltCategories = function getBuiltCategories(possibleResponse, builtCategories) {
404
429
  return builtCategories.reduce(function (acc, builtCategory) {
405
430
  var possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category
406
-
407
431
  var builtCategoryChoices = builtCategory.choices || []; // the choices in the answer
408
432
 
409
433
  var _buildChoices = buildChoices(possibleResponseChoices, builtCategoryChoices),
410
- builtChoices = _buildChoices.builtChoices,
411
- allChoicesAreCorrect = _buildChoices.allChoicesAreCorrect;
412
-
434
+ builtChoices = _buildChoices.builtChoices,
435
+ allChoicesAreCorrect = _buildChoices.allChoicesAreCorrect;
413
436
  var allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;
414
437
  acc.builtCategories.push(_objectSpread(_objectSpread({}, builtCategory), {}, {
415
438
  correct: allChoicesAreCorrect && allChoicesAreInAnswer,
@@ -422,6 +445,7 @@ var getBuiltCategories = function getBuiltCategories(possibleResponse, builtCate
422
445
  correct: true
423
446
  });
424
447
  };
448
+
425
449
  /**
426
450
  * returns all the possible responses by combining the proper alternate responses
427
451
  * @param {Object[]} correctResponse
@@ -429,24 +453,20 @@ var getBuiltCategories = function getBuiltCategories(possibleResponse, builtCate
429
453
  * @returns {Object[]}, returns Response[]
430
454
  * Response = { CategoryId: ChoiceId[] },
431
455
  */
432
-
433
-
434
456
  exports.getBuiltCategories = getBuiltCategories;
435
-
436
457
  var getAllPossibleResponses = function getAllPossibleResponses(correctResponse) {
437
458
  if (!correctResponse) {
438
459
  return [];
439
460
  }
440
-
441
461
  return correctResponse.reduce(function (acc, cR) {
442
462
  // main response
443
463
  if (acc[0]) {
444
464
  acc[0][cR.category] = cR.choices;
445
465
  } else {
446
466
  acc.push((0, _defineProperty2["default"])({}, cR.category, cR.choices));
447
- } // alternate responses
448
-
467
+ }
449
468
 
469
+ // alternate responses
450
470
  if (cR.alternateResponses) {
451
471
  cR.alternateResponses.forEach(function (aR, index) {
452
472
  if (acc[index + 1]) {
@@ -456,10 +476,10 @@ var getAllPossibleResponses = function getAllPossibleResponses(correctResponse)
456
476
  }
457
477
  });
458
478
  }
459
-
460
479
  return acc;
461
480
  }, []);
462
481
  };
482
+
463
483
  /**
464
484
  * build the categories to be displayed, where each category has its own list of choices
465
485
  * @param {Object[]} categories
@@ -470,10 +490,7 @@ var getAllPossibleResponses = function getAllPossibleResponses(correctResponse)
470
490
  * BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},
471
491
  * BuiltChoice = { id: choiceId, content: choiceContent }
472
492
  */
473
-
474
-
475
493
  exports.getAllPossibleResponses = getAllPossibleResponses;
476
-
477
494
  var buildCategories = function buildCategories(categories, choices, answers) {
478
495
  categories = categories || [];
479
496
  answers = answers || [];
@@ -482,11 +499,9 @@ var buildCategories = function buildCategories(categories, choices, answers) {
482
499
  var answer = answers.find(function (answer) {
483
500
  return answer.category === category.id;
484
501
  });
485
-
486
502
  var _ref = answer || {},
487
- _ref$choices = _ref.choices,
488
- answerChoices = _ref$choices === void 0 ? [] : _ref$choices;
489
-
503
+ _ref$choices = _ref.choices,
504
+ answerChoices = _ref$choices === void 0 ? [] : _ref$choices;
490
505
  return _objectSpread(_objectSpread({}, category), {}, {
491
506
  choices: answerChoices.map(function (chId) {
492
507
  return choices.find(function (ch) {
@@ -496,6 +511,7 @@ var buildCategories = function buildCategories(categories, choices, answers) {
496
511
  });
497
512
  });
498
513
  };
514
+
499
515
  /**
500
516
  * build the choice and category state
501
517
  * @param {Object[]} categories
@@ -505,10 +521,7 @@ var buildCategories = function buildCategories(categories, choices, answers) {
505
521
  * @param correctResponse
506
522
  * @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }
507
523
  */
508
-
509
-
510
524
  exports.buildCategories = buildCategories;
511
-
512
525
  var buildState = function buildState(categories, choices, answers, correctResponse) {
513
526
  categories = categories || [];
514
527
  choices = choices || [];
@@ -516,16 +529,17 @@ var buildState = function buildState(categories, choices, answers, correctRespon
516
529
  var allResponses = getAllPossibleResponses(correctResponse) || [];
517
530
  var builtCategories = buildCategories(categories, choices, answers);
518
531
  var bestResponse;
519
- var entirelyCorrect; // at least one defined correct response
532
+ var entirelyCorrect;
520
533
 
534
+ // at least one defined correct response
521
535
  if (allResponses.length) {
522
536
  var builtData = allResponses.reduce(function (acc, possibleResponse) {
523
537
  // set correctness for each possible response
524
538
  var _getBuiltCategories = getBuiltCategories(possibleResponse, builtCategories),
525
- categoriesWithChoices = _getBuiltCategories.builtCategories,
526
- correct = _getBuiltCategories.correct; // if bestResponse not found yet OR no correct response found yet and this one is the correct one
527
-
539
+ categoriesWithChoices = _getBuiltCategories.builtCategories,
540
+ correct = _getBuiltCategories.correct;
528
541
 
542
+ // if bestResponse not found yet OR no correct response found yet and this one is the correct one
529
543
  if (acc.bestResponse === null || !acc.entirelyCorrect && correct) {
530
544
  return {
531
545
  bestResponse: possibleResponse,
@@ -533,7 +547,6 @@ var buildState = function buildState(categories, choices, answers, correctRespon
533
547
  entirelyCorrect: correct
534
548
  };
535
549
  }
536
-
537
550
  return acc;
538
551
  }, {
539
552
  bestResponse: null,
@@ -544,7 +557,6 @@ var buildState = function buildState(categories, choices, answers, correctRespon
544
557
  bestResponse = builtData.bestResponse;
545
558
  entirelyCorrect = builtData.entirelyCorrect;
546
559
  }
547
-
548
560
  var filteredChoices = choices.map(function (ch) {
549
561
  return stillSelectable(ch, builtCategories) ? ch : {
550
562
  empty: true
@@ -557,6 +569,5 @@ var buildState = function buildState(categories, choices, answers, correctRespon
557
569
  bestResponse: bestResponse
558
570
  };
559
571
  };
560
-
561
572
  exports.buildState = buildState;
562
573
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["FooTwo","log","limitChoices","choiceId","count","choices","out","reduce","acc","id","foundCount","countInChoices","push","limitInArrays","arrays","limit","result","array","l","limitInArray","arr","stripped","filter","v","length","ensureNoExtraChoicesInAnswer","answer","answerArray","choice","categoryCount","undefined","map","a","updatedArray","r","index","category","alternateResponses","countInAnswer","c","countChosen","categories","Array","isArray","h","removeCategory","categoryId","answers","removeAllChoices","cloned","removeChoiceFromCategory","choiceIndex","findIndex","splice","moveChoiceToCategory","from","to","moveChoiceToAlternate","alternateIndex","resp","stillSelectable","builtCategories","buildChoices","possibleResponseChoices","builtCategoryChoices","builtChoice","copyOfPossibleResponse","cRC","builtChoices","correct","slice","allChoicesAreCorrect","getBuiltCategories","possibleResponse","builtCategory","allChoicesAreInAnswer","getAllPossibleResponses","correctResponse","cR","forEach","aR","buildCategories","find","answerChoices","chId","ch","buildState","allResponses","bestResponse","entirelyCorrect","builtData","categoriesWithChoices","filteredChoices","empty"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;A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KAAqB,IAArB,IAA8B,CAAChF,GAAG,CAACiF,eAAL,IAAwBpB,OAA1D,EAAoE;AAClE,eAAO;AACLmB,UAAAA,YAAY,EAAEf,gBADT;AAELZ,UAAAA,eAAe,EAAE8B,qBAFZ;AAGLF,UAAAA,eAAe,EAAEpB;AAHZ,SAAP;AAKD;;AAED,aAAO7D,GAAP;AACD,KAlBe,EAmBhB;AACEgF,MAAAA,YAAY,EAAE,IADhB;AAEE3B,MAAAA,eAAe,EAAE,EAFnB;AAGE4B,MAAAA,eAAe,EAAE;AAHnB,KAnBgB,CAAlB;AA0BA5B,IAAAA,eAAe,GAAG6B,SAAS,CAAC7B,eAA5B;AACA2B,IAAAA,YAAY,GAAGE,SAAS,CAACF,YAAzB;AACAC,IAAAA,eAAe,GAAGC,SAAS,CAACD,eAA5B;AACD;;AAED,MAAMG,eAAe,GAAGvF,OAAO,CAAC0B,GAAR,CAAY,UAACsD,EAAD;AAAA,WAASzB,eAAe,CAACyB,EAAD,EAAKxB,eAAL,CAAf,GAAuCwB,EAAvC,GAA4C;AAAEQ,MAAAA,KAAK,EAAE;AAAT,KAArD;AAAA,GAAZ,CAAxB;AAEA,SAAO;AACLxF,IAAAA,OAAO,EAAEuF,eADJ;AAELnD,IAAAA,UAAU,EAAEoB,eAFP;AAGLQ,IAAAA,OAAO,EAAEoB,eAHJ;AAILD,IAAAA,YAAY,EAAZA;AAJK,GAAP;AAMD,CApDM","sourcesContent":["import compact from 'lodash/compact';\nimport debug from 'debug';\nimport clone from 'lodash/clone';\nimport cloneDeep from 'lodash/cloneDeep';\nimport remove from 'lodash/remove';\nimport every from 'lodash/every';\nimport isEqual from 'lodash/isEqual';\nimport isUndefined from 'lodash/isUndefined';\nimport { score } from './scoring';\n\nexport { score };\n\nexport const FooTwo = 'foo-two';\n\nconst log = debug('@pie-lib:categorize');\nexport const limitChoices = (choiceId, count, choices) => {\n const out = choices.reduce(\n (acc, id) => {\n const foundCount = countInChoices(choiceId, acc.choices);\n // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);\n if (id !== choiceId || foundCount < count) {\n acc.choices.push(id);\n }\n return acc;\n },\n { choices: [] },\n );\n\n return out.choices;\n};\n\n/**\n * Limit in an array of arrays.\n * So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]\n * @param {*} id\n * @param {*} arrays\n * @param {*} limit\n */\nexport const limitInArrays = (id, arrays, limit) => {\n arrays = arrays || [];\n\n const result = arrays.reduce(\n (acc, array) => {\n const l = limit - acc.count;\n const result = limitInArray(id, array, l);\n acc.out.push(result.array);\n acc.count = acc.count + (result.count || 0);\n return acc;\n },\n { out: [], count: 0 },\n );\n\n return result.out;\n};\n\n/**\n * Limit the id in the array to the limit set.\n * So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]\n * @param {string} id\n * @param {string[]} arr\n * @param {number} limit\n */\nexport const limitInArray = (id, arr, limit) => {\n arr = arr || [];\n\n if (limit === 0) {\n const stripped = arr.filter((v) => v !== id);\n return { array: stripped, count: arr.length - stripped.length };\n } else {\n const result = arr.reduce(\n (acc, v) => {\n if (v === id) {\n if (acc.count < limit) {\n acc.count += 1;\n acc.out.push(v);\n }\n } else {\n acc.out.push(v);\n }\n return acc;\n },\n { out: [], count: 0 },\n );\n\n return { array: result.out, count: result.count };\n }\n};\n\n/**\n * Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.\n * @param {{category: string, choices: string[]}[]} answer\n * @param {{id:string,categoryCount:number}} choices\n */\nexport const ensureNoExtraChoicesInAnswer = (answer, choices) => {\n choices = choices || [];\n\n const out = choices.reduce((answerArray, choice) => {\n log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);\n // log('answer array: ', answerArray);\n if (choice.categoryCount === undefined || choice.categoryCount === 0) {\n return answerArray;\n } else {\n const choices = answerArray.map((a) => a.choices);\n const result = limitInArrays(choice.id, choices, choice.categoryCount);\n const updatedArray = result.map((r, index) => {\n return {\n category: answerArray[index].category,\n alternateResponses: answerArray[index].alternateResponses,\n choices: r,\n };\n });\n return updatedArray;\n }\n }, answer);\n return out;\n};\n\n/**\n * Count the number of choice ids in a given answer array\n * @param {string} choiceId\n * @param {{category: string, choices: string[]}[]} answer\n */\nexport const countInAnswer = (choiceId, answer) => {\n const out = answer.reduce((acc, a) => acc + countInChoices(choiceId, a.choices), 0);\n log('[countInAnswer] choiceId:', choiceId, answer);\n return out;\n};\n\nexport const countInChoices = (choiceId, choices) => (choices || []).filter((c) => c === choiceId).length;\n\n/**\n * Count the number of times a choice has been selected in categories.\n * @param {*} choice\n * @param {*} categories\n */\nexport const countChosen = (choice, categories) => {\n if (!choice || !choice.id) {\n return 0;\n }\n\n if (!Array.isArray(categories)) {\n return 0;\n }\n\n return categories.reduce((acc, c) => {\n const count = (c.choices || []).filter((h) => h.id === choice.id).length;\n return acc + count;\n }, 0);\n};\n\n/**\n * @param {string?} categoryId\n * @param {{category:string, choices: string[]}} answers\n */\nexport const removeCategory = (categoryId, answers) => answers.filter((a) => a.category !== categoryId);\n\n/**\n * @param {string} choiceId\n * @param {{category:string, choices: string[]}} answers\n * @param {string?} categoryId - optional categegory id\n */\nexport const removeAllChoices = (choiceId, answers, categoryId) => {\n return answers.map((a) => {\n if (!categoryId || a.category === categoryId) {\n const cloned = clone(a.choices);\n remove(cloned, (v) => v === choiceId);\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const removeChoiceFromCategory = (choiceId, categoryId, choiceIndex, answers) => {\n log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);\n\n return answers.map((a) => {\n if (a.category === categoryId) {\n const cloned = clone(a.choices);\n const index = cloned.findIndex((v, index) => {\n return v === choiceId && index >= choiceIndex;\n });\n if (index !== -1) {\n cloned.splice(index, 1);\n }\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const moveChoiceToCategory = (choiceId, from, to, choiceIndex, answers) => {\n log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);\n\n if (from === to) {\n return answers;\n }\n\n if (from) {\n answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);\n }\n\n const index = answers.findIndex((a) => a.category === to);\n if (index === -1) {\n answers.push({ category: to, choices: [choiceId] });\n return answers;\n } else {\n return answers.map((a) => {\n if (a.category === to) {\n a.choices = a.choices || [];\n a.choices.push(choiceId);\n return a;\n }\n return a;\n });\n }\n};\n\nexport const moveChoiceToAlternate = (choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) => {\n log(\n '[moveChoiceToAlternate] choice: ',\n choiceId,\n 'from: ',\n from,\n 'to: ',\n to,\n 'answers: ',\n answers,\n 'chocieIndex: ',\n choiceIndex,\n );\n\n if (from === to) {\n return answers;\n }\n\n return answers.map((a) => {\n if (a.category === to) {\n if (categoryCount !== 0) {\n a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter((resp) => resp !== choiceId);\n }\n a.alternateResponses[alternateIndex].push(choiceId);\n }\n\n if (a.category === from && categoryCount !== 0) {\n a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter((resp) => resp !== choiceId);\n }\n\n return a;\n });\n};\n\nexport const stillSelectable = (h, builtCategories) => {\n if (h.categoryCount > 0) {\n const count = countChosen(h, builtCategories);\n return count < h.categoryCount;\n } else {\n return true;\n }\n};\n\n/**\n * returns all choices with property 'correct' set to boolean\n * @param {string[]} possibleResponseChoices\n * @param {Object[]} builtCategoryChoices\n *\n * @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean\n * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }\n */\nexport const buildChoices = (possibleResponseChoices, builtCategoryChoices) => {\n return builtCategoryChoices.reduce(\n (acc, builtChoice) => {\n // set correct value on each choice that was selected by user\n const index = acc.copyOfPossibleResponse.findIndex((cRC) => cRC === builtChoice.id);\n // if the choice exists in the correct response\n // set the correct: true\n if (index >= 0) {\n acc.builtChoices.push({\n ...builtChoice,\n correct: true,\n });\n acc.copyOfPossibleResponse = [\n ...acc.copyOfPossibleResponse.slice(0, index),\n ...acc.copyOfPossibleResponse.slice(index + 1),\n ];\n } else {\n acc.builtChoices.push({\n ...builtChoice,\n correct: false,\n });\n acc.allChoicesAreCorrect = false;\n }\n\n return acc;\n },\n {\n builtChoices: [],\n copyOfPossibleResponse: [...possibleResponseChoices],\n allChoicesAreCorrect: true,\n },\n );\n};\n\n/**\n * returns corrected answer using this possible correct response\n * @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }\n * @param {Object[]} builtCategories\n *\n * @returns {Object}, returns builtCategories: BuiltCategory[] and correct: boolean\n * BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }\n * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }\n */\nexport const getBuiltCategories = (possibleResponse, builtCategories) =>\n builtCategories.reduce(\n (acc, builtCategory) => {\n const possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category\n const builtCategoryChoices = builtCategory.choices || []; // the choices in the answer\n\n const { builtChoices, allChoicesAreCorrect } = buildChoices(possibleResponseChoices, builtCategoryChoices);\n const allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;\n\n acc.builtCategories.push({\n ...builtCategory,\n correct: allChoicesAreCorrect && allChoicesAreInAnswer,\n choices: builtChoices,\n });\n acc.correct = acc.correct && allChoicesAreCorrect && allChoicesAreInAnswer;\n\n return acc;\n },\n { builtCategories: [], correct: true },\n );\n\n/**\n * returns all the possible responses by combining the proper alternate responses\n * @param {Object[]} correctResponse\n *\n * @returns {Object[]}, returns Response[]\n * Response = { CategoryId: ChoiceId[] },\n */\nexport const getAllPossibleResponses = (correctResponse) => {\n if (!correctResponse) {\n return [];\n }\n\n return correctResponse.reduce((acc, cR) => {\n // main response\n if (acc[0]) {\n acc[0][cR.category] = cR.choices;\n } else {\n acc.push({ [cR.category]: cR.choices });\n }\n\n // alternate responses\n if (cR.alternateResponses) {\n cR.alternateResponses.forEach((aR, index) => {\n if (acc[index + 1]) {\n acc[index + 1][cR.category] = aR;\n } else {\n acc.push({ [cR.category]: aR });\n }\n });\n }\n\n return acc;\n }, []);\n};\n\n/**\n * build the categories to be displayed, where each category has its own list of choices\n * @param {Object[]} categories\n * @param {{id:string}[]} choices\n * @param {{category: string, choices:string[]}[]} answers\n *\n * @returns {Object[]}, returns BuiltCategory[]\n * BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},\n * BuiltChoice = { id: choiceId, content: choiceContent }\n */\nexport const buildCategories = (categories, choices, answers) => {\n categories = categories || [];\n answers = answers || [];\n choices = choices || [];\n\n return categories.map((category) => {\n const answer = answers.find((answer) => answer.category === category.id);\n const { choices: answerChoices = [] } = answer || {};\n\n return {\n ...category,\n choices: answerChoices.map((chId) => choices.find((ch) => ch.id === chId)),\n };\n });\n};\n\n/**\n * build the choice and category state\n * @param {Object[]} categories\n * @param {{id:string}[]} choices\n * @param {{category: string, choices:string[]}[]} answers\n *\n * @param correctResponse\n * @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }\n */\nexport const buildState = (categories, choices, answers, correctResponse) => {\n categories = categories || [];\n choices = choices || [];\n answers = answers || [];\n\n const allResponses = getAllPossibleResponses(correctResponse) || [];\n\n let builtCategories = buildCategories(categories, choices, answers);\n let bestResponse;\n let entirelyCorrect;\n\n // at least one defined correct response\n if (allResponses.length) {\n const builtData = allResponses.reduce(\n (acc, possibleResponse) => {\n // set correctness for each possible response\n const { builtCategories: categoriesWithChoices, correct } = getBuiltCategories(\n possibleResponse,\n builtCategories,\n );\n\n // if bestResponse not found yet OR no correct response found yet and this one is the correct one\n if (acc.bestResponse === null || (!acc.entirelyCorrect && correct)) {\n return {\n bestResponse: possibleResponse,\n builtCategories: categoriesWithChoices,\n entirelyCorrect: correct,\n };\n }\n\n return acc;\n },\n {\n bestResponse: null,\n builtCategories: [],\n entirelyCorrect: false,\n },\n );\n\n builtCategories = builtData.builtCategories;\n bestResponse = builtData.bestResponse;\n entirelyCorrect = builtData.entirelyCorrect;\n }\n\n const filteredChoices = choices.map((ch) => (stillSelectable(ch, builtCategories) ? ch : { empty: true }));\n\n return {\n choices: filteredChoices,\n categories: builtCategories,\n correct: entirelyCorrect,\n bestResponse,\n };\n};\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":["FooTwo","log","debug","limitChoices","choiceId","count","choices","out","reduce","acc","id","foundCount","countInChoices","push","limitInArrays","arrays","limit","result","array","l","limitInArray","arr","stripped","filter","v","length","ensureNoExtraChoicesInAnswer","answer","answerArray","choice","categoryCount","undefined","map","a","updatedArray","r","index","category","alternateResponses","ensureNoExtraChoicesInAlternate","alternatePair","forEach","alternate","recreatedAlternate","Object","keys","k","limitAlternate","item","countInAnswer","c","countChosen","categories","Array","isArray","h","removeCategory","categoryId","answers","removeAllChoices","cloned","clone","remove","rearrangeChoices","indexFrom","indexTo","splice","verifyAllowMultiplePlacements","currentValue","foundIndex","findIndex","removeChoiceFromCategory","choiceIndex","moveChoiceToCategory","from","to","moveChoiceToAlternate","alternateIndex","resp","stillSelectable","builtCategories","buildChoices","possibleResponseChoices","builtCategoryChoices","builtChoice","copyOfPossibleResponse","cRC","builtChoices","correct","slice","allChoicesAreCorrect","getBuiltCategories","possibleResponse","builtCategory","allChoicesAreInAnswer","getAllPossibleResponses","correctResponse","cR","aR","buildCategories","find","answerChoices","chId","ch","buildState","allResponses","bestResponse","entirelyCorrect","builtData","categoriesWithChoices","filteredChoices","empty"],"sources":["../src/index.js"],"sourcesContent":["import compact from 'lodash/compact';\nimport debug from 'debug';\nimport clone from 'lodash/clone';\nimport cloneDeep from 'lodash/cloneDeep';\nimport remove from 'lodash/remove';\nimport every from 'lodash/every';\nimport isEqual from 'lodash/isEqual';\nimport isUndefined from 'lodash/isUndefined';\nimport { score } from './scoring';\n\nexport { score };\n\nexport const FooTwo = 'foo-two';\n\nconst log = debug('@pie-lib:categorize');\nexport const limitChoices = (choiceId, count, choices) => {\n const out = choices.reduce(\n (acc, id) => {\n const foundCount = countInChoices(choiceId, acc.choices);\n // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);\n if (id !== choiceId || foundCount < count) {\n acc.choices.push(id);\n }\n return acc;\n },\n { choices: [] },\n );\n\n return out.choices;\n};\n\n/**\n * Limit in an array of arrays.\n * So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]\n * @param {*} id\n * @param {*} arrays\n * @param {*} limit\n */\nexport const limitInArrays = (id, arrays, limit) => {\n arrays = arrays || [];\n\n const result = arrays.reduce(\n (acc, array) => {\n const l = limit - acc.count;\n const result = limitInArray(id, array, l);\n acc.out.push(result.array);\n acc.count = acc.count + (result.count || 0);\n return acc;\n },\n { out: [], count: 0 },\n );\n\n return result.out;\n};\n\n/**\n * Limit the id in the array to the limit set.\n * So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]\n * @param {string} id\n * @param {string[]} arr\n * @param {number} limit\n */\nexport const limitInArray = (id, arr, limit) => {\n arr = arr || [];\n\n if (limit === 0) {\n const stripped = arr.filter((v) => v !== id);\n return { array: stripped, count: arr.length - stripped.length };\n } else {\n const result = arr.reduce(\n (acc, v) => {\n if (v === id) {\n if (acc.count < limit) {\n acc.count += 1;\n acc.out.push(v);\n }\n } else {\n acc.out.push(v);\n }\n return acc;\n },\n { out: [], count: 0 },\n );\n\n return { array: result.out, count: result.count };\n }\n};\n\n/**\n * Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.\n * @param {{category: string, choices: string[]}[]} answer\n * @param {{id:string,categoryCount:number}} choices\n */\nexport const ensureNoExtraChoicesInAnswer = (answer, choices) => {\n choices = choices || [];\n\n const out = choices.reduce((answerArray, choice) => {\n log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);\n // log('answer array: ', answerArray);\n if (choice.categoryCount === undefined || choice.categoryCount === 0) {\n return answerArray;\n } else {\n const choices = answerArray.map((a) => a.choices);\n const result = limitInArrays(choice.id, choices, choice.categoryCount);\n const updatedArray = result.map((r, index) => {\n return {\n category: answerArray[index].category,\n alternateResponses: answerArray[index].alternateResponses,\n choices: r,\n };\n });\n return updatedArray;\n }\n }, answer);\n return out;\n};\n\n/**\n * Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.\n * @param {{category: string, choices: string[]}[]} answer\n * @param {{id:string,categoryCount:number}} choices\n */\n\nexport const ensureNoExtraChoicesInAlternate = (answer, choices) => {\n choices = choices || [];\n\n const out = choices.reduce((answerArray, choice) => {\n log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);\n // log('answer array: ', answerArray);\n if (choice.categoryCount === undefined || choice.categoryCount === 0) {\n return answerArray;\n } else {\n let alternatePair = {};\n answerArray.forEach((answer) =>\n (answer.alternateResponses || []).forEach((alternate, index) => {\n if (index in alternatePair) {\n alternatePair[index].push(alternate);\n } else {\n alternatePair[index] = [];\n alternatePair[index].push(alternate);\n }\n }),\n );\n\n const recreatedAlternate = [];\n Object.keys(alternatePair).forEach((k) => {\n const limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);\n alternatePair[k] = limitAlternate;\n alternatePair[k].forEach((item, index) => {\n if (!recreatedAlternate[index]) {\n recreatedAlternate[index] = [];\n recreatedAlternate[index].push(item);\n } else {\n recreatedAlternate[index].push(item);\n }\n });\n });\n\n const updatedArray = answerArray.map((answer, index) => {\n return {\n category: answer.category,\n alternateResponses: recreatedAlternate[index] || answer.alternateResponses,\n choices: answer.choices,\n };\n });\n return updatedArray;\n }\n }, answer);\n return out;\n};\n/**\n * Count the number of choice ids in a given answer array\n * @param {string} choiceId\n * @param {{category: string, choices: string[]}[]} answer\n */\nexport const countInAnswer = (choiceId, answer) => {\n const out = answer.reduce((acc, a) => acc + countInChoices(choiceId, a.choices), 0);\n log('[countInAnswer] choiceId:', choiceId, answer);\n return out;\n};\n\nexport const countInChoices = (choiceId, choices) => (choices || []).filter((c) => c === choiceId).length;\n\n/**\n * Count the number of times a choice has been selected in categories.\n * @param {*} choice\n * @param {*} categories\n */\nexport const countChosen = (choice, categories) => {\n if (!choice || !choice.id) {\n return 0;\n }\n\n if (!Array.isArray(categories)) {\n return 0;\n }\n\n return categories.reduce((acc, c) => {\n const count = (c.choices || []).filter((h) => h.id === choice.id).length;\n return acc + count;\n }, 0);\n};\n\n/**\n * @param {string?} categoryId\n * @param {{category:string, choices: string[]}} answers\n */\nexport const removeCategory = (categoryId, answers) => answers.filter((a) => a.category !== categoryId);\n\n/**\n * @param {string} choiceId\n * @param {{category:string, choices: string[]}} answers\n * @param {string?} categoryId - optional categegory id\n */\nexport const removeAllChoices = (choiceId, answers, categoryId) => {\n return answers.map((a) => {\n if (!categoryId || a.category === categoryId) {\n const cloned = clone(a.choices);\n remove(cloned, (v) => v === choiceId);\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const rearrangeChoices = (choices, indexFrom, indexTo) => {\n if (choices.length === 0) {\n return choices;\n }\n choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);\n return choices;\n};\n\nexport const verifyAllowMultiplePlacements = (choice, categoryId, answers) => {\n return answers.map((a) => {\n if (a.category !== categoryId) {\n a.choices = (a.choices || []).filter((c) => c !== choice.id);\n return a;\n } else {\n a.choices = a.choices.reduce((acc, currentValue) => {\n if (currentValue.id === choice.id) {\n const foundIndex = acc.findIndex((c) => c.id === choice.id);\n if (foundIndex === -1) {\n acc.push(currentValue);\n }\n } else {\n acc.push(currentValue);\n }\n\n return acc;\n }, []);\n return a;\n }\n });\n};\n\nexport const removeChoiceFromCategory = (choiceId, categoryId, choiceIndex, answers) => {\n log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);\n\n return answers.map((a) => {\n if (a.category === categoryId) {\n const cloned = clone(a.choices);\n const index = cloned.findIndex((v, index) => {\n return v === choiceId && index >= choiceIndex;\n });\n if (index !== -1) {\n cloned.splice(index, 1);\n }\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const moveChoiceToCategory = (choiceId, from, to, choiceIndex, answers) => {\n log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);\n\n if (from === to) {\n return answers;\n }\n\n if (from) {\n answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);\n }\n\n const index = answers.findIndex((a) => a.category === to);\n if (index === -1) {\n answers.push({ category: to, choices: [choiceId] });\n return answers;\n } else {\n return answers.map((a) => {\n if (a.category === to) {\n a.choices = a.choices || [];\n a.choices.push(choiceId);\n return a;\n }\n return a;\n });\n }\n};\n\nexport const moveChoiceToAlternate = (choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) => {\n log(\n '[moveChoiceToAlternate] choice: ',\n choiceId,\n 'from: ',\n from,\n 'to: ',\n to,\n 'answers: ',\n answers,\n 'chocieIndex: ',\n choiceIndex,\n );\n\n if (from === to) {\n return answers;\n }\n\n return answers.map((a) => {\n if (a.category === to) {\n if (categoryCount !== 0 && a.alternateResponses) {\n a.alternateResponses[alternateIndex] = (a.alternateResponses[alternateIndex] || []).filter(\n (resp) => resp !== choiceId,\n );\n }\n if (!a.alternateResponses) {\n a.alternateResponses = [];\n a.alternateResponses[alternateIndex] = [];\n }\n a.alternateResponses[alternateIndex].push(choiceId);\n }\n\n if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {\n a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter((resp) => resp !== choiceId);\n }\n\n return a;\n });\n};\n\nexport const stillSelectable = (h, builtCategories) => {\n if (h.categoryCount > 0) {\n const count = countChosen(h, builtCategories);\n return count < h.categoryCount;\n } else {\n return true;\n }\n};\n\n/**\n * returns all choices with property 'correct' set to boolean\n * @param {string[]} possibleResponseChoices\n * @param {Object[]} builtCategoryChoices\n *\n * @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean\n * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }\n */\nexport const buildChoices = (possibleResponseChoices, builtCategoryChoices) => {\n return builtCategoryChoices.reduce(\n (acc, builtChoice) => {\n // set correct value on each choice that was selected by user\n const index = acc.copyOfPossibleResponse.findIndex((cRC) => cRC === builtChoice.id);\n // if the choice exists in the correct response\n // set the correct: true\n if (index >= 0) {\n acc.builtChoices.push({\n ...builtChoice,\n correct: true,\n });\n acc.copyOfPossibleResponse = [\n ...acc.copyOfPossibleResponse.slice(0, index),\n ...acc.copyOfPossibleResponse.slice(index + 1),\n ];\n } else {\n acc.builtChoices.push({\n ...builtChoice,\n correct: false,\n });\n acc.allChoicesAreCorrect = false;\n }\n\n return acc;\n },\n {\n builtChoices: [],\n copyOfPossibleResponse: [...possibleResponseChoices],\n allChoicesAreCorrect: true,\n },\n );\n};\n\n/**\n * returns corrected answer using this possible correct response\n * @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }\n * @param {Object[]} builtCategories\n *\n * @returns {Object}, returns builtCategories: BuiltCategory[] and correct: boolean\n * BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }\n * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }\n */\nexport const getBuiltCategories = (possibleResponse, builtCategories) =>\n builtCategories.reduce(\n (acc, builtCategory) => {\n const possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category\n const builtCategoryChoices = builtCategory.choices || []; // the choices in the answer\n\n const { builtChoices, allChoicesAreCorrect } = buildChoices(possibleResponseChoices, builtCategoryChoices);\n const allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;\n\n acc.builtCategories.push({\n ...builtCategory,\n correct: allChoicesAreCorrect && allChoicesAreInAnswer,\n choices: builtChoices,\n });\n acc.correct = acc.correct && allChoicesAreCorrect && allChoicesAreInAnswer;\n\n return acc;\n },\n { builtCategories: [], correct: true },\n );\n\n/**\n * returns all the possible responses by combining the proper alternate responses\n * @param {Object[]} correctResponse\n *\n * @returns {Object[]}, returns Response[]\n * Response = { CategoryId: ChoiceId[] },\n */\nexport const getAllPossibleResponses = (correctResponse) => {\n if (!correctResponse) {\n return [];\n }\n\n return correctResponse.reduce((acc, cR) => {\n // main response\n if (acc[0]) {\n acc[0][cR.category] = cR.choices;\n } else {\n acc.push({ [cR.category]: cR.choices });\n }\n\n // alternate responses\n if (cR.alternateResponses) {\n cR.alternateResponses.forEach((aR, index) => {\n if (acc[index + 1]) {\n acc[index + 1][cR.category] = aR;\n } else {\n acc.push({ [cR.category]: aR });\n }\n });\n }\n\n return acc;\n }, []);\n};\n\n/**\n * build the categories to be displayed, where each category has its own list of choices\n * @param {Object[]} categories\n * @param {{id:string}[]} choices\n * @param {{category: string, choices:string[]}[]} answers\n *\n * @returns {Object[]}, returns BuiltCategory[]\n * BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},\n * BuiltChoice = { id: choiceId, content: choiceContent }\n */\nexport const buildCategories = (categories, choices, answers) => {\n categories = categories || [];\n answers = answers || [];\n choices = choices || [];\n\n return categories.map((category) => {\n const answer = answers.find((answer) => answer.category === category.id);\n const { choices: answerChoices = [] } = answer || {};\n\n return {\n ...category,\n choices: answerChoices.map((chId) => choices.find((ch) => ch.id === chId)),\n };\n });\n};\n\n/**\n * build the choice and category state\n * @param {Object[]} categories\n * @param {{id:string}[]} choices\n * @param {{category: string, choices:string[]}[]} answers\n *\n * @param correctResponse\n * @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }\n */\nexport const buildState = (categories, choices, answers, correctResponse) => {\n categories = categories || [];\n choices = choices || [];\n answers = answers || [];\n\n const allResponses = getAllPossibleResponses(correctResponse) || [];\n\n let builtCategories = buildCategories(categories, choices, answers);\n let bestResponse;\n let entirelyCorrect;\n\n // at least one defined correct response\n if (allResponses.length) {\n const builtData = allResponses.reduce(\n (acc, possibleResponse) => {\n // set correctness for each possible response\n const { builtCategories: categoriesWithChoices, correct } = getBuiltCategories(\n possibleResponse,\n builtCategories,\n );\n\n // if bestResponse not found yet OR no correct response found yet and this one is the correct one\n if (acc.bestResponse === null || (!acc.entirelyCorrect && correct)) {\n return {\n bestResponse: possibleResponse,\n builtCategories: categoriesWithChoices,\n entirelyCorrect: correct,\n };\n }\n\n return acc;\n },\n {\n bestResponse: null,\n builtCategories: [],\n entirelyCorrect: false,\n },\n );\n\n builtCategories = builtData.builtCategories;\n bestResponse = builtData.bestResponse;\n entirelyCorrect = builtData.entirelyCorrect;\n }\n\n const filteredChoices = choices.map((ch) => (stillSelectable(ch, builtCategories) ? ch : { empty: true }));\n\n return {\n choices: filteredChoices,\n categories: builtCategories,\n correct: entirelyCorrect,\n bestResponse,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAkC;AAAA;AAI3B,IAAMA,MAAM,GAAG,SAAS;AAAC;AAEhC,IAAMC,GAAG,GAAG,IAAAC,iBAAK,EAAC,qBAAqB,CAAC;AACjC,IAAMC,YAAY,GAAG,SAAfA,YAAY,CAAIC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAK;EACxD,IAAMC,GAAG,GAAGD,OAAO,CAACE,MAAM,CACxB,UAACC,GAAG,EAAEC,EAAE,EAAK;IACX,IAAMC,UAAU,GAAGC,cAAc,CAACR,QAAQ,EAAEK,GAAG,CAACH,OAAO,CAAC;IACxD;IACA,IAAII,EAAE,KAAKN,QAAQ,IAAIO,UAAU,GAAGN,KAAK,EAAE;MACzCI,GAAG,CAACH,OAAO,CAACO,IAAI,CAACH,EAAE,CAAC;IACtB;IACA,OAAOD,GAAG;EACZ,CAAC,EACD;IAAEH,OAAO,EAAE;EAAG,CAAC,CAChB;EAED,OAAOC,GAAG,CAACD,OAAO;AACpB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AANA;AAOO,IAAMQ,aAAa,GAAG,SAAhBA,aAAa,CAAIJ,EAAE,EAAE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ACD;MACEiG,YAAY,EAAE,IAAI;MAClB1B,eAAe,EAAE,EAAE;MACnB2B,eAAe,EAAE;IACnB,CAAC,CACF;IAED3B,eAAe,GAAG4B,SAAS,CAAC5B,eAAe;IAC3C0B,YAAY,GAAGE,SAAS,CAACF,YAAY;IACrCC,eAAe,GAAGC,SAAS,CAACD,eAAe;EAC7C;EAEA,IAAMG,eAAe,GAAGxG,OAAO,CAAC0B,GAAG,CAAC,UAACuE,EAAE;IAAA,OAAMxB,eAAe,CAACwB,EAAE,EAAEvB,eAAe,CAAC,GAAGuB,EAAE,GAAG;MAAEQ,KAAK,EAAE;IAAK,CAAC;EAAA,CAAC,CAAC;EAE1G,OAAO;IACLzG,OAAO,EAAEwG,eAAe;IACxB1D,UAAU,EAAE4B,eAAe;IAC3BQ,OAAO,EAAEmB,eAAe;IACxBD,YAAY,EAAZA;EACF,CAAC;AACH,CAAC;AAAC"}
package/lib/scoring.js CHANGED
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.score = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _debug = _interopRequireDefault(require("debug"));
13
-
14
10
  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; }
15
-
16
11
  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; }
17
-
18
12
  var log = (0, _debug["default"])('@pie-lib:categorize:scoring');
19
-
20
13
  var getWeightingRules = function getWeightingRules(scoring) {
21
14
  if (!scoring || !scoring.weighting) {
22
15
  return [];
@@ -29,10 +22,8 @@ var getWeightingRules = function getWeightingRules(scoring) {
29
22
  }
30
23
  }
31
24
  };
32
-
33
25
  var getPartialRulesForCategory = function getPartialRulesForCategory(partial, categoryId) {
34
26
  log('partial? ', partial);
35
-
36
27
  if (!partial || !partial.enabled) {
37
28
  return;
38
29
  } else {
@@ -42,6 +33,7 @@ var getPartialRulesForCategory = function getPartialRulesForCategory(partial, ca
42
33
  return pr ? pr.rules || [] : [];
43
34
  }
44
35
  };
36
+
45
37
  /**
46
38
  *
47
39
  * Calculate score based on the categories model generated from `buildState` and the partial scoring rules.
@@ -50,7 +42,6 @@ var getPartialRulesForCategory = function getPartialRulesForCategory(partial, ca
50
42
  * @see ../index#buildState
51
43
  */
52
44
 
53
-
54
45
  var score = function score(categories, scoring) {
55
46
  return new Promise(function (resolve) {
56
47
  log('categories: ', categories, 'scoring: ', scoring);
@@ -78,7 +69,6 @@ var score = function score(categories, scoring) {
78
69
  return r.category === c.id;
79
70
  }).points;
80
71
  log('category: ', c);
81
-
82
72
  if (c.correct === true) {
83
73
  return {
84
74
  category: c.id,
@@ -88,7 +78,6 @@ var score = function score(categories, scoring) {
88
78
  } else {
89
79
  var rules = getPartialRulesForCategory(scoring.partial, c.id);
90
80
  log('partial rules for category: ', rules);
91
-
92
81
  if (!rules) {
93
82
  return {
94
83
  category: c.id,
@@ -108,9 +97,7 @@ var score = function score(categories, scoring) {
108
97
  percent: 0,
109
98
  count: correctCount
110
99
  };
111
-
112
100
  var _score = w * (rule.percent / 100);
113
-
114
101
  return {
115
102
  category: c.id,
116
103
  score: _score,
@@ -140,6 +127,5 @@ var score = function score(categories, scoring) {
140
127
  });
141
128
  });
142
129
  };
143
-
144
130
  exports.score = score;
145
131
  //# sourceMappingURL=scoring.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/scoring.js"],"names":["log","getWeightingRules","scoring","weighting","enabled","rules","getPartialRulesForCategory","partial","categoryId","pr","find","category","score","categories","Promise","resolve","weightingRules","weights","map","c","r","id","points","weightTotal","reduce","total","withScore","w","correct","correctCount","choices","filter","h","length","rule","u","count","percent","correctChoices","weightedScore","sum","parseFloat","toFixed","details","weighted"],"mappings":";;;;;;;;;;;AAAA;;;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,6BAAN,CAAZ;;AACA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,OAAD,EAAa;AACrC,MAAI,CAACA,OAAD,IAAY,CAACA,OAAO,CAACC,SAAzB,EAAoC;AAClC,WAAO,EAAP;AACD,GAFD,MAEO;AACL,QAAI,CAACD,OAAO,CAACC,SAAR,CAAkBC,OAAvB,EAAgC;AAC9B,aAAO,EAAP;AACD,KAFD,MAEO;AACL,UAAMC,KAAK,GAAGH,OAAO,CAACC,SAAR,GAAoBD,OAAO,CAACC,SAAR,CAAkBE,KAAlB,IAA2B,EAA/C,GAAoD,EAAlE;AACA,aAAOA,KAAP;AACD;AACF;AACF,CAXD;;AAaA,IAAMC,0BAA0B,GAAG,SAA7BA,0BAA6B,CAACC,OAAD,EAAUC,UAAV,EAAyB;AAC1DR,EAAAA,GAAG,CAAC,WAAD,EAAcO,OAAd,CAAH;;AACA,MAAI,CAACA,OAAD,IAAY,CAACA,OAAO,CAACH,OAAzB,EAAkC;AAChC;AACD,GAFD,MAEO;AACL,QAAMK,EAAE,GAAGF,OAAO,CAACF,KAAR,CAAcK,IAAd,CAAmB,UAACD,EAAD;AAAA,aAAQA,EAAE,CAACE,QAAH,KAAgBH,UAAxB;AAAA,KAAnB,CAAX;AACA,WAAOC,EAAE,GAAGA,EAAE,CAACJ,KAAH,IAAY,EAAf,GAAoB,EAA7B;AACD;AACF,C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Q,EAAEQ,CAAC,CAACE,EADP;AAELT,YAAAA,KAAK,EAALA,MAFK;AAGLU,YAAAA,MAAM,EAAEK,CAHH;AAILpB,YAAAA,OAAO,EAAE;AACP+B,cAAAA,cAAc,EAAET,YADT;AAEPK,cAAAA,IAAI,EAAEA;AAFC;AAJJ,WAAP;AASD;AACF;AACF,KA7BiB,CAAlB;AA+BA,QAAMK,aAAa,GAAGb,SAAS,CAACF,MAAV,CAAiB,UAACgB,GAAD,EAAMrB,CAAN,EAAY;AACjD,aAAQqB,GAAG,IAAIrB,CAAC,CAACP,KAAjB;AACD,KAFqB,EAEnB,CAFmB,CAAtB;AAIAZ,IAAAA,GAAG,CAAC,iBAAD,EAAoBuC,aAApB,CAAH;AAEA,QAAM3B,KAAK,GAAG6B,UAAU,CAAC,CAACF,aAAa,GAAGhB,WAAjB,EAA8BmB,OAA9B,CAAsC,CAAtC,CAAD,EAA2C,EAA3C,CAAxB;AACA3B,IAAAA,OAAO,CAAC;AACNH,MAAAA,KAAK,EAALA,KADM;AAEN+B,MAAAA,OAAO,EAAE;AACPC,QAAAA,QAAQ,EAAE;AACRnB,UAAAA,KAAK,EAAEF,WADC;AAERX,UAAAA,KAAK,EAAE2B;AAFC,SADH;AAKP1B,QAAAA,UAAU,EAAEa;AALL;AAFH,KAAD,CAAP;AAUD,GAlED,CADmB;AAAA,CAAd","sourcesContent":["import debug from 'debug';\nconst log = debug('@pie-lib:categorize:scoring');\nconst getWeightingRules = (scoring) => {\n if (!scoring || !scoring.weighting) {\n return [];\n } else {\n if (!scoring.weighting.enabled) {\n return [];\n } else {\n const rules = scoring.weighting ? scoring.weighting.rules || [] : [];\n return rules;\n }\n }\n};\n\nconst getPartialRulesForCategory = (partial, categoryId) => {\n log('partial? ', partial);\n if (!partial || !partial.enabled) {\n return;\n } else {\n const pr = partial.rules.find((pr) => pr.category === categoryId);\n return pr ? pr.rules || [] : [];\n }\n};\n\n/**\n *\n * Calculate score based on the categories model generated from `buildState` and the partial scoring rules.\n * @param {*} categories - this is the categories that you get from `buildState`.\n * @param {*} scoring - scoring config.\n * @see ../index#buildState\n */\n\nexport const score = (categories, scoring) =>\n new Promise((resolve) => {\n log('categories: ', categories, 'scoring: ', scoring);\n const weightingRules = getWeightingRules(scoring);\n\n const weights = categories.map((c) => {\n const r = weightingRules.find((r) => r.category === c.id) || { points: 1 };\n return { ...r, category: c.id };\n });\n\n log('weights: ', weights);\n\n const weightTotal = categories.reduce((total, c) => {\n const r = weights.find((r) => r.category === c.id);\n return (total += r.points);\n }, 0);\n\n log('total: ', weightTotal);\n\n const withScore = categories.map((c) => {\n const w = weights.find((r) => r.category === c.id).points;\n\n log('category: ', c);\n if (c.correct === true) {\n return { category: c.id, score: w, points: w };\n } else {\n const rules = getPartialRulesForCategory(scoring.partial, c.id);\n log('partial rules for category: ', rules);\n if (!rules) {\n return { category: c.id, score: 0, points: w };\n } else {\n const correctCount = (c.choices || []).filter((h) => h.correct).length;\n log('correctCount: ', correctCount);\n let rule = rules.find((u) => u.count === correctCount);\n log('rule: ', rule);\n rule = rule || { percent: 0, count: correctCount };\n const score = w * (rule.percent / 100);\n return {\n category: c.id,\n score,\n points: w,\n partial: {\n correctChoices: correctCount,\n rule: rule,\n },\n };\n }\n }\n });\n\n const weightedScore = withScore.reduce((sum, c) => {\n return (sum += c.score);\n }, 0);\n\n log('weightedScore: ', weightedScore);\n\n const score = parseFloat((weightedScore / weightTotal).toFixed(2), 10);\n resolve({\n score,\n details: {\n weighted: {\n total: weightTotal,\n score: weightedScore,\n },\n categories: withScore,\n },\n });\n });\n"],"file":"scoring.js"}
1
+ {"version":3,"file":"scoring.js","names":["log","debug","getWeightingRules","scoring","weighting","enabled","rules","getPartialRulesForCategory","partial","categoryId","pr","find","category","score","categories","Promise","resolve","weightingRules","weights","map","c","r","id","points","weightTotal","reduce","total","withScore","w","correct","correctCount","choices","filter","h","length","rule","u","count","percent","correctChoices","weightedScore","sum","parseFloat","toFixed","details","weighted"],"sources":["../src/scoring.js"],"sourcesContent":["import debug from 'debug';\nconst log = debug('@pie-lib:categorize:scoring');\nconst getWeightingRules = (scoring) => {\n if (!scoring || !scoring.weighting) {\n return [];\n } else {\n if (!scoring.weighting.enabled) {\n return [];\n } else {\n const rules = scoring.weighting ? scoring.weighting.rules || [] : [];\n return rules;\n }\n }\n};\n\nconst getPartialRulesForCategory = (partial, categoryId) => {\n log('partial? ', partial);\n if (!partial || !partial.enabled) {\n return;\n } else {\n const pr = partial.rules.find((pr) => pr.category === categoryId);\n return pr ? pr.rules || [] : [];\n }\n};\n\n/**\n *\n * Calculate score based on the categories model generated from `buildState` and the partial scoring rules.\n * @param {*} categories - this is the categories that you get from `buildState`.\n * @param {*} scoring - scoring config.\n * @see ../index#buildState\n */\n\nexport const score = (categories, scoring) =>\n new Promise((resolve) => {\n log('categories: ', categories, 'scoring: ', scoring);\n const weightingRules = getWeightingRules(scoring);\n\n const weights = categories.map((c) => {\n const r = weightingRules.find((r) => r.category === c.id) || { points: 1 };\n return { ...r, category: c.id };\n });\n\n log('weights: ', weights);\n\n const weightTotal = categories.reduce((total, c) => {\n const r = weights.find((r) => r.category === c.id);\n return (total += r.points);\n }, 0);\n\n log('total: ', weightTotal);\n\n const withScore = categories.map((c) => {\n const w = weights.find((r) => r.category === c.id).points;\n\n log('category: ', c);\n if (c.correct === true) {\n return { category: c.id, score: w, points: w };\n } else {\n const rules = getPartialRulesForCategory(scoring.partial, c.id);\n log('partial rules for category: ', rules);\n if (!rules) {\n return { category: c.id, score: 0, points: w };\n } else {\n const correctCount = (c.choices || []).filter((h) => h.correct).length;\n log('correctCount: ', correctCount);\n let rule = rules.find((u) => u.count === correctCount);\n log('rule: ', rule);\n rule = rule || { percent: 0, count: correctCount };\n const score = w * (rule.percent / 100);\n return {\n category: c.id,\n score,\n points: w,\n partial: {\n correctChoices: correctCount,\n rule: rule,\n },\n };\n }\n }\n });\n\n const weightedScore = withScore.reduce((sum, c) => {\n return (sum += c.score);\n }, 0);\n\n log('weightedScore: ', weightedScore);\n\n const score = parseFloat((weightedScore / weightTotal).toFixed(2), 10);\n resolve({\n score,\n details: {\n weighted: {\n total: weightTotal,\n score: weightedScore,\n },\n categories: withScore,\n },\n });\n });\n"],"mappings":";;;;;;;;AAAA;AAA0B;AAAA;AAC1B,IAAMA,GAAG,GAAG,IAAAC,iBAAK,EAAC,6BAA6B,CAAC;AAChD,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIC,OAAO,EAAK;EACrC,IAAI,CAACA,OAAO,IAAI,CAACA,OAAO,CAACC,SAAS,EAAE;IAClC,OAAO,EAAE;EACX,CAAC,MAAM;IACL,IAAI,CAACD,OAAO,CAACC,SAAS,CAACC,OAAO,EAAE;MAC9B,OAAO,EAAE;IACX,CAAC,MAAM;MACL,IAAMC,KAAK,GAAGH,OAAO,CAACC,SAAS,GAAGD,OAAO,CAACC,SAAS,CAACE,KAAK,IAAI,EAAE,GAAG,EAAE;MACpE,OAAOA,KAAK;IACd;EACF;AACF,CAAC;AAED,IAAMC,0BAA0B,GAAG,SAA7BA,0BAA0B,CAAIC,OAAO,EAAEC,UAAU,EAAK;EAC1DT,GAAG,CAAC,WAAW,EAAEQ,OAAO,CAAC;EACzB,IAAI,CAACA,OAAO,IAAI,CAACA,OAAO,CAACH,OAAO,EAAE;IAChC;EACF,CAAC,MAAM;IACL,IAAMK,EAAE,GAAGF,OAAO,CAACF,KAAK,CAACK,IAAI,CAAC,UAACD,EAAE;MAAA,OAAKA,EAAE,CAACE,QAAQ,KAAKH,UAAU;IAAA,EAAC;IACjE,OAAOC,EAAE,GAAGA,EAAE,CAACJ,KAAK,IAAI,EAAE,GAAG,EAAE;EACjC;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,IAAMO,KAAK,GAAG,SAARA,KAAK,CAAIC,UAAU,EAAEX,OAAO;EAAA,OACvC,IAAIY,OAAO,CAAC,UAACC,OAAO,EAAK;IACvBhB,GAAG,CAAC,cAAc,EAAEc,UAAU,E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AEwC,aAAa,CAAC;IAErC,IAAM3B,KAAK,GAAG6B,UAAU,CAAC,CAACF,aAAa,GAAGhB,WAAW,EAAEmB,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACtE3B,OAAO,CAAC;MACNH,KAAK,EAALA,KAAK;MACL+B,OAAO,EAAE;QACPC,QAAQ,EAAE;UACRnB,KAAK,EAAEF,WAAW;UAClBX,KAAK,EAAE2B;QACT,CAAC;QACD1B,UAAU,EAAEa;MACd;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;AAAA;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/categorize",
3
- "version": "0.6.27-next.36+6e067df5",
3
+ "version": "0.6.27-next.53+cbb2d706",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -14,5 +14,5 @@
14
14
  "scripts": {},
15
15
  "author": "",
16
16
  "license": "ISC",
17
- "gitHead": "6e067df50305f6ef2bbf69df5373b75596dac6d4"
17
+ "gitHead": "cbb2d70637263fd7d0bf2a0a7d0b4b75e2a7370c"
18
18
  }
package/src/index.js CHANGED
@@ -115,6 +115,59 @@ export const ensureNoExtraChoicesInAnswer = (answer, choices) => {
115
115
  return out;
116
116
  };
117
117
 
118
+ /**
119
+ * Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.
120
+ * @param {{category: string, choices: string[]}[]} answer
121
+ * @param {{id:string,categoryCount:number}} choices
122
+ */
123
+
124
+ export const ensureNoExtraChoicesInAlternate = (answer, choices) => {
125
+ choices = choices || [];
126
+
127
+ const out = choices.reduce((answerArray, choice) => {
128
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
129
+ // log('answer array: ', answerArray);
130
+ if (choice.categoryCount === undefined || choice.categoryCount === 0) {
131
+ return answerArray;
132
+ } else {
133
+ let alternatePair = {};
134
+ answerArray.forEach((answer) =>
135
+ (answer.alternateResponses || []).forEach((alternate, index) => {
136
+ if (index in alternatePair) {
137
+ alternatePair[index].push(alternate);
138
+ } else {
139
+ alternatePair[index] = [];
140
+ alternatePair[index].push(alternate);
141
+ }
142
+ }),
143
+ );
144
+
145
+ const recreatedAlternate = [];
146
+ Object.keys(alternatePair).forEach((k) => {
147
+ const limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);
148
+ alternatePair[k] = limitAlternate;
149
+ alternatePair[k].forEach((item, index) => {
150
+ if (!recreatedAlternate[index]) {
151
+ recreatedAlternate[index] = [];
152
+ recreatedAlternate[index].push(item);
153
+ } else {
154
+ recreatedAlternate[index].push(item);
155
+ }
156
+ });
157
+ });
158
+
159
+ const updatedArray = answerArray.map((answer, index) => {
160
+ return {
161
+ category: answer.category,
162
+ alternateResponses: recreatedAlternate[index] || answer.alternateResponses,
163
+ choices: answer.choices,
164
+ };
165
+ });
166
+ return updatedArray;
167
+ }
168
+ }, answer);
169
+ return out;
170
+ };
118
171
  /**
119
172
  * Count the number of choice ids in a given answer array
120
173
  * @param {string} choiceId
@@ -171,6 +224,37 @@ export const removeAllChoices = (choiceId, answers, categoryId) => {
171
224
  });
172
225
  };
173
226
 
227
+ export const rearrangeChoices = (choices, indexFrom, indexTo) => {
228
+ if (choices.length === 0) {
229
+ return choices;
230
+ }
231
+ choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);
232
+ return choices;
233
+ };
234
+
235
+ export const verifyAllowMultiplePlacements = (choice, categoryId, answers) => {
236
+ return answers.map((a) => {
237
+ if (a.category !== categoryId) {
238
+ a.choices = (a.choices || []).filter((c) => c !== choice.id);
239
+ return a;
240
+ } else {
241
+ a.choices = a.choices.reduce((acc, currentValue) => {
242
+ if (currentValue.id === choice.id) {
243
+ const foundIndex = acc.findIndex((c) => c.id === choice.id);
244
+ if (foundIndex === -1) {
245
+ acc.push(currentValue);
246
+ }
247
+ } else {
248
+ acc.push(currentValue);
249
+ }
250
+
251
+ return acc;
252
+ }, []);
253
+ return a;
254
+ }
255
+ });
256
+ };
257
+
174
258
  export const removeChoiceFromCategory = (choiceId, categoryId, choiceIndex, answers) => {
175
259
  log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);
176
260
 
@@ -237,13 +321,19 @@ export const moveChoiceToAlternate = (choiceId, from, to, choiceIndex, answers,
237
321
 
238
322
  return answers.map((a) => {
239
323
  if (a.category === to) {
240
- if (categoryCount !== 0) {
241
- a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter((resp) => resp !== choiceId);
324
+ if (categoryCount !== 0 && a.alternateResponses) {
325
+ a.alternateResponses[alternateIndex] = (a.alternateResponses[alternateIndex] || []).filter(
326
+ (resp) => resp !== choiceId,
327
+ );
328
+ }
329
+ if (!a.alternateResponses) {
330
+ a.alternateResponses = [];
331
+ a.alternateResponses[alternateIndex] = [];
242
332
  }
243
333
  a.alternateResponses[alternateIndex].push(choiceId);
244
334
  }
245
335
 
246
- if (a.category === from && categoryCount !== 0) {
336
+ if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {
247
337
  a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter((resp) => resp !== choiceId);
248
338
  }
249
339