@pie-lib/categorize 2.0.3-next.1 → 3.0.0-next.20261002100925

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 DELETED
@@ -1,561 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.removeChoiceFromCategory = exports.removeChoiceFromAlternate = 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;
8
- Object.defineProperty(exports, "score", {
9
- enumerable: true,
10
- get: function get() {
11
- return _scoring.score;
12
- }
13
- });
14
- exports.verifyAllowMultiplePlacements = exports.stillSelectable = void 0;
15
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
16
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
- var _debug = _interopRequireDefault(require("debug"));
18
- var _lodashEs = require("lodash-es");
19
- var _scoring = require("./scoring");
20
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
22
- var FooTwo = exports.FooTwo = 'foo-two';
23
- var log = (0, _debug["default"])('@pie-lib:categorize');
24
- var limitChoices = exports.limitChoices = function limitChoices(choiceId, count, choices) {
25
- var out = choices.reduce(function (acc, id) {
26
- var foundCount = countInChoices(choiceId, acc.choices);
27
- if (id !== choiceId || foundCount < count) {
28
- acc.choices.push(id);
29
- }
30
- return acc;
31
- }, {
32
- choices: []
33
- });
34
- return out.choices;
35
- };
36
-
37
- /**
38
- * Limit in an array of arrays.
39
- * So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]
40
- * @param {*} id
41
- * @param {*} arrays
42
- * @param {*} limit
43
- */
44
- var limitInArrays = exports.limitInArrays = function limitInArrays(id, arrays, limit) {
45
- arrays = arrays || [];
46
- var result = arrays.reduce(function (acc, array) {
47
- var l = limit - acc.count;
48
- var result = limitInArray(id, array, l);
49
- acc.out.push(result.array);
50
- acc.count = acc.count + (result.count || 0);
51
- return acc;
52
- }, {
53
- out: [],
54
- count: 0
55
- });
56
- return result.out;
57
- };
58
-
59
- /**
60
- * Limit the id in the array to the limit set.
61
- * So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]
62
- * @param {string} id
63
- * @param {string[]} arr
64
- * @param {number} limit
65
- */
66
- var limitInArray = exports.limitInArray = function limitInArray(id, arr, limit) {
67
- arr = arr || [];
68
- if (limit === 0) {
69
- var stripped = arr.filter(function (v) {
70
- return v !== id;
71
- });
72
- return {
73
- array: stripped,
74
- count: arr.length - stripped.length
75
- };
76
- } else {
77
- var result = arr.reduce(function (acc, v) {
78
- if (v === id) {
79
- if (acc.count < limit) {
80
- acc.count += 1;
81
- acc.out.push(v);
82
- }
83
- } else {
84
- acc.out.push(v);
85
- }
86
- return acc;
87
- }, {
88
- out: [],
89
- count: 0
90
- });
91
- return {
92
- array: result.out,
93
- count: result.count
94
- };
95
- }
96
- };
97
-
98
- /**
99
- * Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.
100
- * @param {{category: string, choices: string[]}[]} answer
101
- * @param {{id:string,categoryCount:number}} choices
102
- */
103
- var ensureNoExtraChoicesInAnswer = exports.ensureNoExtraChoicesInAnswer = function ensureNoExtraChoicesInAnswer(answer, choices) {
104
- choices = choices || [];
105
- var out = choices.reduce(function (answerArray, choice) {
106
- log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
107
- if (choice.categoryCount === undefined || choice.categoryCount === 0) {
108
- return answerArray;
109
- } else {
110
- var _choices = answerArray.map(function (a) {
111
- return a.choices;
112
- });
113
- var result = limitInArrays(choice.id, _choices, choice.categoryCount);
114
- var updatedArray = result.map(function (r, index) {
115
- return {
116
- category: answerArray[index].category,
117
- alternateResponses: answerArray[index].alternateResponses,
118
- choices: r
119
- };
120
- });
121
- return updatedArray;
122
- }
123
- }, answer);
124
- return out;
125
- };
126
-
127
- /**
128
- * Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.
129
- * @param {{category: string, choices: string[]}[]} answer
130
- * @param {{id:string,categoryCount:number}} choices
131
- */
132
-
133
- var ensureNoExtraChoicesInAlternate = exports.ensureNoExtraChoicesInAlternate = function ensureNoExtraChoicesInAlternate(answer, choices) {
134
- choices = choices || [];
135
- var out = choices.reduce(function (answerArray, choice) {
136
- log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
137
- if (choice.categoryCount === undefined || choice.categoryCount === 0) {
138
- return answerArray;
139
- } else {
140
- var alternatePair = {};
141
- answerArray.forEach(function (answer) {
142
- return (answer.alternateResponses || []).forEach(function (alternate, index) {
143
- if (index in alternatePair) {
144
- alternatePair[index].push(alternate);
145
- } else {
146
- alternatePair[index] = [];
147
- alternatePair[index].push(alternate);
148
- }
149
- });
150
- });
151
- var recreatedAlternate = [];
152
- Object.keys(alternatePair).forEach(function (k) {
153
- var limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);
154
- alternatePair[k] = limitAlternate;
155
- alternatePair[k].forEach(function (item, index) {
156
- if (!recreatedAlternate[index]) {
157
- recreatedAlternate[index] = [];
158
- recreatedAlternate[index].push(item);
159
- } else {
160
- recreatedAlternate[index].push(item);
161
- }
162
- });
163
- });
164
- var updatedArray = answerArray.map(function (answer, index) {
165
- return {
166
- category: answer.category,
167
- alternateResponses: recreatedAlternate[index] || answer.alternateResponses,
168
- choices: answer.choices
169
- };
170
- });
171
- return updatedArray;
172
- }
173
- }, answer);
174
- return out;
175
- };
176
- /**
177
- * Count the number of choice ids in a given answer array
178
- * @param {string} choiceId
179
- * @param {{category: string, choices: string[]}[]} answer
180
- */
181
- var countInAnswer = exports.countInAnswer = function countInAnswer(choiceId, answer) {
182
- var out = answer.reduce(function (acc, a) {
183
- return acc + countInChoices(choiceId, a.choices);
184
- }, 0);
185
- log('[countInAnswer] choiceId:', choiceId, answer);
186
- return out;
187
- };
188
- var countInChoices = exports.countInChoices = function countInChoices(choiceId, choices) {
189
- return (choices || []).filter(function (c) {
190
- return c === choiceId;
191
- }).length;
192
- };
193
-
194
- /**
195
- * Count the number of times a choice has been selected in categories.
196
- * @param {*} choice
197
- * @param {*} categories
198
- */
199
- var countChosen = exports.countChosen = function countChosen(choice, categories) {
200
- if (!choice || !choice.id) {
201
- return 0;
202
- }
203
- if (!Array.isArray(categories)) {
204
- return 0;
205
- }
206
- return categories.reduce(function (acc, c) {
207
- var count = (c.choices || []).filter(function (h) {
208
- return h && h.id === choice.id;
209
- }).length;
210
- return acc + count;
211
- }, 0);
212
- };
213
-
214
- /**
215
- * @param {string?} categoryId
216
- * @param {{category:string, choices: string[]}} answers
217
- */
218
- var removeCategory = exports.removeCategory = function removeCategory(categoryId, answers) {
219
- return answers.filter(function (a) {
220
- return a.category !== categoryId;
221
- });
222
- };
223
-
224
- /**
225
- * @param {string} choiceId
226
- * @param {{category:string, choices: string[]}} answers
227
- * @param {string?} categoryId - optional categegory id
228
- */
229
- var removeAllChoices = exports.removeAllChoices = function removeAllChoices(choiceId, answers, categoryId) {
230
- return answers.map(function (a) {
231
- if (!categoryId || a.category === categoryId) {
232
- var cloned = (0, _lodashEs.clone)(a.choices);
233
- (0, _lodashEs.remove)(cloned, function (v) {
234
- return v === choiceId;
235
- });
236
- return _objectSpread(_objectSpread({}, a), {}, {
237
- choices: cloned
238
- });
239
- } else {
240
- return a;
241
- }
242
- });
243
- };
244
- var rearrangeChoices = exports.rearrangeChoices = function rearrangeChoices(choices, indexFrom, indexTo) {
245
- if (choices.length === 0) {
246
- return choices;
247
- }
248
- choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);
249
- return choices;
250
- };
251
- var verifyAllowMultiplePlacements = exports.verifyAllowMultiplePlacements = function verifyAllowMultiplePlacements(choice, categoryId, answers) {
252
- return answers.map(function (a) {
253
- if (a.category !== categoryId) {
254
- a.choices = (a.choices || []).filter(function (c) {
255
- return c !== choice.id;
256
- });
257
- return a;
258
- } else {
259
- a.choices = a.choices.reduce(function (acc, currentValue) {
260
- if (currentValue.id === choice.id) {
261
- var foundIndex = acc.findIndex(function (c) {
262
- return c.id === choice.id;
263
- });
264
- if (foundIndex === -1) {
265
- acc.push(currentValue);
266
- }
267
- } else {
268
- acc.push(currentValue);
269
- }
270
- return acc;
271
- }, []);
272
- return a;
273
- }
274
- });
275
- };
276
- var removeChoiceFromCategory = exports.removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categoryId, choiceIndex, answers) {
277
- log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);
278
- return answers.map(function (a) {
279
- if (a.category === categoryId) {
280
- var cloned = (0, _lodashEs.clone)(a.choices);
281
- var index = cloned.findIndex(function (v, index) {
282
- return v === choiceId && index >= choiceIndex;
283
- });
284
- if (index !== -1) {
285
- cloned.splice(index, 1);
286
- }
287
- return _objectSpread(_objectSpread({}, a), {}, {
288
- choices: cloned
289
- });
290
- } else {
291
- return a;
292
- }
293
- });
294
- };
295
- var removeChoiceFromAlternate = exports.removeChoiceFromAlternate = function removeChoiceFromAlternate(choiceId, categoryId, choiceIndex, altIndex, answers) {
296
- return (answers || []).map(function (a) {
297
- if ((a === null || a === void 0 ? void 0 : a.category) === categoryId) {
298
- var newAlternates = ((a === null || a === void 0 ? void 0 : a.alternateResponses) || []).map(function (altArray, idx) {
299
- if (idx === altIndex) {
300
- (altArray || []).splice(choiceIndex, 1);
301
- return altArray;
302
- }
303
- return altArray;
304
- });
305
- return _objectSpread(_objectSpread({}, a), {}, {
306
- alternateResponses: newAlternates
307
- });
308
- }
309
- return a;
310
- });
311
- };
312
- var moveChoiceToCategory = exports.moveChoiceToCategory = function moveChoiceToCategory(choiceId, from, to, choiceIndex, answers) {
313
- log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);
314
- if (from === to) {
315
- return answers;
316
- }
317
- if (from) {
318
- answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);
319
- }
320
- var index = answers.findIndex(function (a) {
321
- return a.category === to;
322
- });
323
- if (index === -1) {
324
- answers.push({
325
- category: to,
326
- choices: [choiceId]
327
- });
328
- return answers;
329
- } else {
330
- return answers.map(function (a) {
331
- if (a.category === to) {
332
- a.choices = a.choices || [];
333
- a.choices.push(choiceId);
334
- return a;
335
- }
336
- return a;
337
- });
338
- }
339
- };
340
- var moveChoiceToAlternate = exports.moveChoiceToAlternate = function moveChoiceToAlternate(choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) {
341
- log('[moveChoiceToAlternate] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers, 'chocieIndex: ', choiceIndex);
342
- if (from === to) {
343
- return answers;
344
- }
345
- return answers.map(function (a) {
346
- if (a.category === to) {
347
- if (categoryCount !== 0 && a.alternateResponses) {
348
- a.alternateResponses[alternateIndex] = (a.alternateResponses[alternateIndex] || []).filter(function (resp) {
349
- return resp !== choiceId;
350
- });
351
- }
352
- if (!a.alternateResponses) {
353
- a.alternateResponses = [];
354
- a.alternateResponses[alternateIndex] = [];
355
- }
356
- a.alternateResponses[alternateIndex].push(choiceId);
357
- }
358
- if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {
359
- a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter(function (resp) {
360
- return resp !== choiceId;
361
- });
362
- }
363
- return a;
364
- });
365
- };
366
- var stillSelectable = exports.stillSelectable = function stillSelectable(h, builtCategories) {
367
- if (h.categoryCount > 0) {
368
- var count = countChosen(h, builtCategories);
369
- return count < h.categoryCount;
370
- } else {
371
- return true;
372
- }
373
- };
374
-
375
- /**
376
- * returns all choices with property 'correct' set to boolean
377
- * @param {string[]} possibleResponseChoices
378
- * @param {Object[]} builtCategoryChoices
379
- *
380
- * @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean
381
- * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
382
- */
383
- var buildChoices = exports.buildChoices = function buildChoices(possibleResponseChoices, builtCategoryChoices) {
384
- return builtCategoryChoices.reduce(function (acc, builtChoice) {
385
- // set correct value on each choice that was selected by user
386
- var index = acc.copyOfPossibleResponse.findIndex(function (cRC) {
387
- return builtChoice && cRC === builtChoice.id;
388
- });
389
-
390
- // if the choice exists in the correct response
391
- // set the correct: true
392
- if (index >= 0) {
393
- acc.builtChoices.push(_objectSpread(_objectSpread({}, builtChoice), {}, {
394
- correct: true
395
- }));
396
- acc.copyOfPossibleResponse = [].concat((0, _toConsumableArray2["default"])(acc.copyOfPossibleResponse.slice(0, index)), (0, _toConsumableArray2["default"])(acc.copyOfPossibleResponse.slice(index + 1)));
397
- } else {
398
- acc.builtChoices.push(_objectSpread(_objectSpread({}, builtChoice), {}, {
399
- correct: false
400
- }));
401
- acc.allChoicesAreCorrect = false;
402
- }
403
- return acc;
404
- }, {
405
- builtChoices: [],
406
- copyOfPossibleResponse: (0, _toConsumableArray2["default"])(possibleResponseChoices),
407
- allChoicesAreCorrect: true
408
- });
409
- };
410
-
411
- /**
412
- * returns corrected answer using this possible correct response
413
- * @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }
414
- * @param {Object[]} builtCategories
415
- *
416
- * @returns {Object}, returns builtCategories: BuiltCategory[] and correct: boolean
417
- * BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }
418
- * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
419
- */
420
- var getBuiltCategories = exports.getBuiltCategories = function getBuiltCategories(possibleResponse, builtCategories) {
421
- return builtCategories.reduce(function (acc, builtCategory) {
422
- var possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category
423
- var builtCategoryChoices = builtCategory.choices || []; // the choices in the answer
424
-
425
- var _buildChoices = buildChoices(possibleResponseChoices, builtCategoryChoices),
426
- builtChoices = _buildChoices.builtChoices,
427
- allChoicesAreCorrect = _buildChoices.allChoicesAreCorrect;
428
- var allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;
429
- acc.builtCategories.push(_objectSpread(_objectSpread({}, builtCategory), {}, {
430
- correct: allChoicesAreCorrect && allChoicesAreInAnswer,
431
- choices: builtChoices
432
- }));
433
- acc.correct = acc.correct && allChoicesAreCorrect && allChoicesAreInAnswer;
434
- return acc;
435
- }, {
436
- builtCategories: [],
437
- correct: true
438
- });
439
- };
440
-
441
- /**
442
- * returns all the possible responses by combining the proper alternate responses
443
- * @param {Object[]} correctResponse
444
- *
445
- * @returns {Object[]}, returns Response[]
446
- * Response = { CategoryId: ChoiceId[] },
447
- */
448
- var getAllPossibleResponses = exports.getAllPossibleResponses = function getAllPossibleResponses(correctResponse) {
449
- if (!correctResponse) {
450
- return [];
451
- }
452
- return correctResponse.reduce(function (acc, cR) {
453
- // main response
454
- if (acc[0]) {
455
- acc[0][cR.category] = cR.choices;
456
- } else {
457
- acc.push((0, _defineProperty2["default"])({}, cR.category, cR.choices));
458
- }
459
-
460
- // alternate responses
461
- if (cR.alternateResponses) {
462
- cR.alternateResponses.forEach(function (aR, index) {
463
- if (acc[index + 1]) {
464
- acc[index + 1][cR.category] = aR;
465
- } else {
466
- acc.push((0, _defineProperty2["default"])({}, cR.category, aR));
467
- }
468
- });
469
- }
470
- return acc;
471
- }, []);
472
- };
473
-
474
- /**
475
- * build the categories to be displayed, where each category has its own list of choices
476
- * @param {Object[]} categories
477
- * @param {{id:string}[]} choices
478
- * @param {{category: string, choices:string[]}[]} answers
479
- *
480
- * @returns {Object[]}, returns BuiltCategory[]
481
- * BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},
482
- * BuiltChoice = { id: choiceId, content: choiceContent }
483
- */
484
- var buildCategories = exports.buildCategories = function buildCategories(categories, choices, answers) {
485
- categories = categories || [];
486
- answers = answers || [];
487
- choices = choices || [];
488
- return categories.map(function (category) {
489
- var answer = answers.find(function (answer) {
490
- return answer.category === category.id;
491
- });
492
- var _ref = answer || {},
493
- _ref$choices = _ref.choices,
494
- answerChoices = _ref$choices === void 0 ? [] : _ref$choices;
495
- return _objectSpread(_objectSpread({}, category), {}, {
496
- choices: answerChoices.map(function (chId) {
497
- return choices.find(function (ch) {
498
- return ch.id === chId;
499
- });
500
- })
501
- });
502
- });
503
- };
504
-
505
- /**
506
- * build the choice and category state
507
- * @param {Object[]} categories
508
- * @param {{id:string}[]} choices
509
- * @param {{category: string, choices:string[]}[]} answers
510
- *
511
- * @param correctResponse
512
- * @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }
513
- */
514
- var buildState = exports.buildState = function buildState(categories, choices, answers, correctResponse) {
515
- categories = categories || [];
516
- choices = choices || [];
517
- answers = answers || [];
518
- var allResponses = getAllPossibleResponses(correctResponse) || [];
519
- var builtCategories = buildCategories(categories, choices, answers);
520
- var bestResponse;
521
- var entirelyCorrect;
522
-
523
- // at least one defined correct response
524
- if (allResponses.length) {
525
- var builtData = allResponses.reduce(function (acc, possibleResponse) {
526
- // set correctness for each possible response
527
- var _getBuiltCategories = getBuiltCategories(possibleResponse, builtCategories),
528
- categoriesWithChoices = _getBuiltCategories.builtCategories,
529
- correct = _getBuiltCategories.correct;
530
-
531
- // if bestResponse not found yet OR no correct response found yet and this one is the correct one
532
- if (acc.bestResponse === null || !acc.entirelyCorrect && correct) {
533
- return {
534
- bestResponse: possibleResponse,
535
- builtCategories: categoriesWithChoices,
536
- entirelyCorrect: correct
537
- };
538
- }
539
- return acc;
540
- }, {
541
- bestResponse: null,
542
- builtCategories: [],
543
- entirelyCorrect: false
544
- });
545
- builtCategories = builtData.builtCategories;
546
- bestResponse = builtData.bestResponse;
547
- entirelyCorrect = builtData.entirelyCorrect;
548
- }
549
- var filteredChoices = choices.map(function (ch) {
550
- return stillSelectable(ch, builtCategories) ? ch : {
551
- empty: true
552
- };
553
- });
554
- return {
555
- choices: filteredChoices,
556
- categories: builtCategories,
557
- correct: entirelyCorrect,
558
- bestResponse: bestResponse
559
- };
560
- };
561
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_lodashEs","_scoring","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","FooTwo","exports","log","debug","limitChoices","choiceId","count","choices","out","reduce","acc","id","foundCount","countInChoices","limitInArrays","arrays","limit","result","array","l","limitInArray","arr","stripped","v","ensureNoExtraChoicesInAnswer","answer","answerArray","choice","categoryCount","undefined","map","a","updatedArray","index","category","alternateResponses","ensureNoExtraChoicesInAlternate","alternatePair","alternate","recreatedAlternate","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","removeChoiceFromAlternate","altIndex","newAlternates","altArray","idx","moveChoiceToCategory","from","to","moveChoiceToAlternate","alternateIndex","resp","stillSelectable","builtCategories","buildChoices","possibleResponseChoices","builtCategoryChoices","builtChoice","copyOfPossibleResponse","cRC","builtChoices","correct","concat","_toConsumableArray2","slice","allChoicesAreCorrect","getBuiltCategories","possibleResponse","builtCategory","_buildChoices","allChoicesAreInAnswer","getAllPossibleResponses","correctResponse","cR","aR","buildCategories","find","_ref","_ref$choices","answerChoices","chId","ch","buildState","allResponses","bestResponse","entirelyCorrect","builtData","_getBuiltCategories","categoriesWithChoices","filteredChoices","empty"],"sources":["../src/index.js"],"sourcesContent":["import debug from 'debug';\nimport { clone, remove } from 'lodash-es';\nimport { score } from './scoring';\n\nexport { score };\n\nexport const FooTwo = 'foo-two';\n\nconst log = debug('@pie-lib:categorize');\n\nexport const limitChoices = (choiceId, count, choices) => {\n const out = choices.reduce(\n (acc, id) => {\n const foundCount = countInChoices(choiceId, acc.choices);\n\n if (id !== choiceId || foundCount < count) {\n acc.choices.push(id);\n }\n return acc;\n },\n { choices: [] },\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\n acc.out.push(result.array);\n acc.count = acc.count + (result.count || 0);\n\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\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\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\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\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\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\n if (choice.categoryCount === undefined || choice.categoryCount === 0) {\n return answerArray;\n } else {\n let alternatePair = {};\n\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\n Object.keys(alternatePair).forEach((k) => {\n const limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);\n alternatePair[k] = limitAlternate;\n\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\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\n log('[countInAnswer] choiceId:', choiceId, answer);\n\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 && h.id === choice.id).length;\n\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\n remove(cloned, (v) => v === choiceId);\n\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\n choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);\n\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\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\n if (foundIndex === -1) {\n acc.push(currentValue);\n }\n } else {\n acc.push(currentValue);\n }\n\n return acc;\n }, []);\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\n if (index !== -1) {\n cloned.splice(index, 1);\n }\n\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const removeChoiceFromAlternate = (choiceId, categoryId, choiceIndex, altIndex, answers) => {\n return (answers || []).map((a) => {\n if (a?.category === categoryId) {\n const newAlternates = (a?.alternateResponses || []).map((altArray, idx) => {\n if (idx === altIndex) {\n (altArray || []).splice(choiceIndex, 1);\n return altArray;\n }\n return altArray;\n });\n return { ...a, alternateResponses: newAlternates };\n }\n return a;\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\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\n return a;\n }\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\n if (!a.alternateResponses) {\n a.alternateResponses = [];\n a.alternateResponses[alternateIndex] = [];\n }\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\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) => builtChoice && cRC === builtChoice.id);\n\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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