@pie-lib/categorize 1.1.0-next.3 → 1.1.0-next.37

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 ADDED
@@ -0,0 +1,580 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.js");
4
+ require("core-js/modules/es.object.define-properties.js");
5
+ require("core-js/modules/es.object.define-property.js");
6
+ require("core-js/modules/es.object.get-own-property-descriptor.js");
7
+ require("core-js/modules/es.object.get-own-property-descriptors.js");
8
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ 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;
13
+ Object.defineProperty(exports, "score", {
14
+ enumerable: true,
15
+ get: function get() {
16
+ return _scoring.score;
17
+ }
18
+ });
19
+ exports.verifyAllowMultiplePlacements = exports.stillSelectable = void 0;
20
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
21
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
22
+ require("core-js/modules/es.array.concat.js");
23
+ require("core-js/modules/es.array.filter.js");
24
+ require("core-js/modules/es.array.find.js");
25
+ require("core-js/modules/es.array.find-index.js");
26
+ require("core-js/modules/es.array.for-each.js");
27
+ require("core-js/modules/es.array.is-array.js");
28
+ require("core-js/modules/es.array.map.js");
29
+ require("core-js/modules/es.array.reduce.js");
30
+ require("core-js/modules/es.array.slice.js");
31
+ require("core-js/modules/es.array.splice.js");
32
+ require("core-js/modules/es.object.keys.js");
33
+ require("core-js/modules/es.object.to-string.js");
34
+ require("core-js/modules/web.dom-collections.for-each.js");
35
+ var _debug = _interopRequireDefault(require("debug"));
36
+ var _clone = _interopRequireDefault(require("lodash/clone"));
37
+ var _remove = _interopRequireDefault(require("lodash/remove"));
38
+ var _scoring = require("./scoring");
39
+ 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; }
40
+ 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; }
41
+ var FooTwo = exports.FooTwo = 'foo-two';
42
+ var log = (0, _debug["default"])('@pie-lib:categorize');
43
+ var limitChoices = exports.limitChoices = function limitChoices(choiceId, count, choices) {
44
+ var out = choices.reduce(function (acc, id) {
45
+ var foundCount = countInChoices(choiceId, acc.choices);
46
+ if (id !== choiceId || foundCount < count) {
47
+ acc.choices.push(id);
48
+ }
49
+ return acc;
50
+ }, {
51
+ choices: []
52
+ });
53
+ return out.choices;
54
+ };
55
+
56
+ /**
57
+ * Limit in an array of arrays.
58
+ * So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]
59
+ * @param {*} id
60
+ * @param {*} arrays
61
+ * @param {*} limit
62
+ */
63
+ var limitInArrays = exports.limitInArrays = function limitInArrays(id, arrays, limit) {
64
+ arrays = arrays || [];
65
+ var result = arrays.reduce(function (acc, array) {
66
+ var l = limit - acc.count;
67
+ var result = limitInArray(id, array, l);
68
+ acc.out.push(result.array);
69
+ acc.count = acc.count + (result.count || 0);
70
+ return acc;
71
+ }, {
72
+ out: [],
73
+ count: 0
74
+ });
75
+ return result.out;
76
+ };
77
+
78
+ /**
79
+ * Limit the id in the array to the limit set.
80
+ * So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]
81
+ * @param {string} id
82
+ * @param {string[]} arr
83
+ * @param {number} limit
84
+ */
85
+ var limitInArray = exports.limitInArray = function limitInArray(id, arr, limit) {
86
+ arr = arr || [];
87
+ if (limit === 0) {
88
+ var stripped = arr.filter(function (v) {
89
+ return v !== id;
90
+ });
91
+ return {
92
+ array: stripped,
93
+ count: arr.length - stripped.length
94
+ };
95
+ } else {
96
+ var result = arr.reduce(function (acc, v) {
97
+ if (v === id) {
98
+ if (acc.count < limit) {
99
+ acc.count += 1;
100
+ acc.out.push(v);
101
+ }
102
+ } else {
103
+ acc.out.push(v);
104
+ }
105
+ return acc;
106
+ }, {
107
+ out: [],
108
+ count: 0
109
+ });
110
+ return {
111
+ array: result.out,
112
+ count: result.count
113
+ };
114
+ }
115
+ };
116
+
117
+ /**
118
+ * Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.
119
+ * @param {{category: string, choices: string[]}[]} answer
120
+ * @param {{id:string,categoryCount:number}} choices
121
+ */
122
+ var ensureNoExtraChoicesInAnswer = exports.ensureNoExtraChoicesInAnswer = function ensureNoExtraChoicesInAnswer(answer, choices) {
123
+ choices = choices || [];
124
+ var out = choices.reduce(function (answerArray, choice) {
125
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
126
+ if (choice.categoryCount === undefined || choice.categoryCount === 0) {
127
+ return answerArray;
128
+ } else {
129
+ var _choices = answerArray.map(function (a) {
130
+ return a.choices;
131
+ });
132
+ var result = limitInArrays(choice.id, _choices, choice.categoryCount);
133
+ var updatedArray = result.map(function (r, index) {
134
+ return {
135
+ category: answerArray[index].category,
136
+ alternateResponses: answerArray[index].alternateResponses,
137
+ choices: r
138
+ };
139
+ });
140
+ return updatedArray;
141
+ }
142
+ }, answer);
143
+ return out;
144
+ };
145
+
146
+ /**
147
+ * Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.
148
+ * @param {{category: string, choices: string[]}[]} answer
149
+ * @param {{id:string,categoryCount:number}} choices
150
+ */
151
+
152
+ var ensureNoExtraChoicesInAlternate = exports.ensureNoExtraChoicesInAlternate = function ensureNoExtraChoicesInAlternate(answer, choices) {
153
+ choices = choices || [];
154
+ var out = choices.reduce(function (answerArray, choice) {
155
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
156
+ if (choice.categoryCount === undefined || choice.categoryCount === 0) {
157
+ return answerArray;
158
+ } else {
159
+ var alternatePair = {};
160
+ answerArray.forEach(function (answer) {
161
+ return (answer.alternateResponses || []).forEach(function (alternate, index) {
162
+ if (index in alternatePair) {
163
+ alternatePair[index].push(alternate);
164
+ } else {
165
+ alternatePair[index] = [];
166
+ alternatePair[index].push(alternate);
167
+ }
168
+ });
169
+ });
170
+ var recreatedAlternate = [];
171
+ Object.keys(alternatePair).forEach(function (k) {
172
+ var limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);
173
+ alternatePair[k] = limitAlternate;
174
+ alternatePair[k].forEach(function (item, index) {
175
+ if (!recreatedAlternate[index]) {
176
+ recreatedAlternate[index] = [];
177
+ recreatedAlternate[index].push(item);
178
+ } else {
179
+ recreatedAlternate[index].push(item);
180
+ }
181
+ });
182
+ });
183
+ var updatedArray = answerArray.map(function (answer, index) {
184
+ return {
185
+ category: answer.category,
186
+ alternateResponses: recreatedAlternate[index] || answer.alternateResponses,
187
+ choices: answer.choices
188
+ };
189
+ });
190
+ return updatedArray;
191
+ }
192
+ }, answer);
193
+ return out;
194
+ };
195
+ /**
196
+ * Count the number of choice ids in a given answer array
197
+ * @param {string} choiceId
198
+ * @param {{category: string, choices: string[]}[]} answer
199
+ */
200
+ var countInAnswer = exports.countInAnswer = function countInAnswer(choiceId, answer) {
201
+ var out = answer.reduce(function (acc, a) {
202
+ return acc + countInChoices(choiceId, a.choices);
203
+ }, 0);
204
+ log('[countInAnswer] choiceId:', choiceId, answer);
205
+ return out;
206
+ };
207
+ var countInChoices = exports.countInChoices = function countInChoices(choiceId, choices) {
208
+ return (choices || []).filter(function (c) {
209
+ return c === choiceId;
210
+ }).length;
211
+ };
212
+
213
+ /**
214
+ * Count the number of times a choice has been selected in categories.
215
+ * @param {*} choice
216
+ * @param {*} categories
217
+ */
218
+ var countChosen = exports.countChosen = function countChosen(choice, categories) {
219
+ if (!choice || !choice.id) {
220
+ return 0;
221
+ }
222
+ if (!Array.isArray(categories)) {
223
+ return 0;
224
+ }
225
+ return categories.reduce(function (acc, c) {
226
+ var count = (c.choices || []).filter(function (h) {
227
+ return h && h.id === choice.id;
228
+ }).length;
229
+ return acc + count;
230
+ }, 0);
231
+ };
232
+
233
+ /**
234
+ * @param {string?} categoryId
235
+ * @param {{category:string, choices: string[]}} answers
236
+ */
237
+ var removeCategory = exports.removeCategory = function removeCategory(categoryId, answers) {
238
+ return answers.filter(function (a) {
239
+ return a.category !== categoryId;
240
+ });
241
+ };
242
+
243
+ /**
244
+ * @param {string} choiceId
245
+ * @param {{category:string, choices: string[]}} answers
246
+ * @param {string?} categoryId - optional categegory id
247
+ */
248
+ var removeAllChoices = exports.removeAllChoices = function removeAllChoices(choiceId, answers, categoryId) {
249
+ return answers.map(function (a) {
250
+ if (!categoryId || a.category === categoryId) {
251
+ var cloned = (0, _clone["default"])(a.choices);
252
+ (0, _remove["default"])(cloned, function (v) {
253
+ return v === choiceId;
254
+ });
255
+ return _objectSpread(_objectSpread({}, a), {}, {
256
+ choices: cloned
257
+ });
258
+ } else {
259
+ return a;
260
+ }
261
+ });
262
+ };
263
+ var rearrangeChoices = exports.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
+ var verifyAllowMultiplePlacements = exports.verifyAllowMultiplePlacements = function verifyAllowMultiplePlacements(choice, categoryId, answers) {
271
+ return answers.map(function (a) {
272
+ if (a.category !== categoryId) {
273
+ a.choices = (a.choices || []).filter(function (c) {
274
+ return c !== choice.id;
275
+ });
276
+ return a;
277
+ } else {
278
+ a.choices = a.choices.reduce(function (acc, currentValue) {
279
+ if (currentValue.id === choice.id) {
280
+ var foundIndex = acc.findIndex(function (c) {
281
+ return c.id === choice.id;
282
+ });
283
+ if (foundIndex === -1) {
284
+ acc.push(currentValue);
285
+ }
286
+ } else {
287
+ acc.push(currentValue);
288
+ }
289
+ return acc;
290
+ }, []);
291
+ return a;
292
+ }
293
+ });
294
+ };
295
+ var removeChoiceFromCategory = exports.removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categoryId, choiceIndex, answers) {
296
+ log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);
297
+ return answers.map(function (a) {
298
+ if (a.category === categoryId) {
299
+ var cloned = (0, _clone["default"])(a.choices);
300
+ var index = cloned.findIndex(function (v, index) {
301
+ return v === choiceId && index >= choiceIndex;
302
+ });
303
+ if (index !== -1) {
304
+ cloned.splice(index, 1);
305
+ }
306
+ return _objectSpread(_objectSpread({}, a), {}, {
307
+ choices: cloned
308
+ });
309
+ } else {
310
+ return a;
311
+ }
312
+ });
313
+ };
314
+ var removeChoiceFromAlternate = exports.removeChoiceFromAlternate = function removeChoiceFromAlternate(choiceId, categoryId, choiceIndex, altIndex, answers) {
315
+ return (answers || []).map(function (a) {
316
+ if ((a === null || a === void 0 ? void 0 : a.category) === categoryId) {
317
+ var newAlternates = ((a === null || a === void 0 ? void 0 : a.alternateResponses) || []).map(function (altArray, idx) {
318
+ if (idx === altIndex) {
319
+ (altArray || []).splice(choiceIndex, 1);
320
+ return altArray;
321
+ }
322
+ return altArray;
323
+ });
324
+ return _objectSpread(_objectSpread({}, a), {}, {
325
+ alternateResponses: newAlternates
326
+ });
327
+ }
328
+ return a;
329
+ });
330
+ };
331
+ var moveChoiceToCategory = exports.moveChoiceToCategory = function moveChoiceToCategory(choiceId, from, to, choiceIndex, answers) {
332
+ log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);
333
+ if (from === to) {
334
+ return answers;
335
+ }
336
+ if (from) {
337
+ answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);
338
+ }
339
+ var index = answers.findIndex(function (a) {
340
+ return a.category === to;
341
+ });
342
+ if (index === -1) {
343
+ answers.push({
344
+ category: to,
345
+ choices: [choiceId]
346
+ });
347
+ return answers;
348
+ } else {
349
+ return answers.map(function (a) {
350
+ if (a.category === to) {
351
+ a.choices = a.choices || [];
352
+ a.choices.push(choiceId);
353
+ return a;
354
+ }
355
+ return a;
356
+ });
357
+ }
358
+ };
359
+ var moveChoiceToAlternate = exports.moveChoiceToAlternate = function moveChoiceToAlternate(choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) {
360
+ log('[moveChoiceToAlternate] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers, 'chocieIndex: ', choiceIndex);
361
+ if (from === to) {
362
+ return answers;
363
+ }
364
+ return answers.map(function (a) {
365
+ if (a.category === to) {
366
+ if (categoryCount !== 0 && a.alternateResponses) {
367
+ a.alternateResponses[alternateIndex] = (a.alternateResponses[alternateIndex] || []).filter(function (resp) {
368
+ return resp !== choiceId;
369
+ });
370
+ }
371
+ if (!a.alternateResponses) {
372
+ a.alternateResponses = [];
373
+ a.alternateResponses[alternateIndex] = [];
374
+ }
375
+ a.alternateResponses[alternateIndex].push(choiceId);
376
+ }
377
+ if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {
378
+ a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter(function (resp) {
379
+ return resp !== choiceId;
380
+ });
381
+ }
382
+ return a;
383
+ });
384
+ };
385
+ var stillSelectable = exports.stillSelectable = function stillSelectable(h, builtCategories) {
386
+ if (h.categoryCount > 0) {
387
+ var count = countChosen(h, builtCategories);
388
+ return count < h.categoryCount;
389
+ } else {
390
+ return true;
391
+ }
392
+ };
393
+
394
+ /**
395
+ * returns all choices with property 'correct' set to boolean
396
+ * @param {string[]} possibleResponseChoices
397
+ * @param {Object[]} builtCategoryChoices
398
+ *
399
+ * @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean
400
+ * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
401
+ */
402
+ var buildChoices = exports.buildChoices = function buildChoices(possibleResponseChoices, builtCategoryChoices) {
403
+ return builtCategoryChoices.reduce(function (acc, builtChoice) {
404
+ // set correct value on each choice that was selected by user
405
+ var index = acc.copyOfPossibleResponse.findIndex(function (cRC) {
406
+ return builtChoice && cRC === builtChoice.id;
407
+ });
408
+
409
+ // if the choice exists in the correct response
410
+ // set the correct: true
411
+ if (index >= 0) {
412
+ acc.builtChoices.push(_objectSpread(_objectSpread({}, builtChoice), {}, {
413
+ correct: true
414
+ }));
415
+ acc.copyOfPossibleResponse = [].concat((0, _toConsumableArray2["default"])(acc.copyOfPossibleResponse.slice(0, index)), (0, _toConsumableArray2["default"])(acc.copyOfPossibleResponse.slice(index + 1)));
416
+ } else {
417
+ acc.builtChoices.push(_objectSpread(_objectSpread({}, builtChoice), {}, {
418
+ correct: false
419
+ }));
420
+ acc.allChoicesAreCorrect = false;
421
+ }
422
+ return acc;
423
+ }, {
424
+ builtChoices: [],
425
+ copyOfPossibleResponse: (0, _toConsumableArray2["default"])(possibleResponseChoices),
426
+ allChoicesAreCorrect: true
427
+ });
428
+ };
429
+
430
+ /**
431
+ * returns corrected answer using this possible correct response
432
+ * @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }
433
+ * @param {Object[]} builtCategories
434
+ *
435
+ * @returns {Object}, returns builtCategories: BuiltCategory[] and correct: boolean
436
+ * BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }
437
+ * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
438
+ */
439
+ var getBuiltCategories = exports.getBuiltCategories = function getBuiltCategories(possibleResponse, builtCategories) {
440
+ return builtCategories.reduce(function (acc, builtCategory) {
441
+ var possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category
442
+ var builtCategoryChoices = builtCategory.choices || []; // the choices in the answer
443
+
444
+ var _buildChoices = buildChoices(possibleResponseChoices, builtCategoryChoices),
445
+ builtChoices = _buildChoices.builtChoices,
446
+ allChoicesAreCorrect = _buildChoices.allChoicesAreCorrect;
447
+ var allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;
448
+ acc.builtCategories.push(_objectSpread(_objectSpread({}, builtCategory), {}, {
449
+ correct: allChoicesAreCorrect && allChoicesAreInAnswer,
450
+ choices: builtChoices
451
+ }));
452
+ acc.correct = acc.correct && allChoicesAreCorrect && allChoicesAreInAnswer;
453
+ return acc;
454
+ }, {
455
+ builtCategories: [],
456
+ correct: true
457
+ });
458
+ };
459
+
460
+ /**
461
+ * returns all the possible responses by combining the proper alternate responses
462
+ * @param {Object[]} correctResponse
463
+ *
464
+ * @returns {Object[]}, returns Response[]
465
+ * Response = { CategoryId: ChoiceId[] },
466
+ */
467
+ var getAllPossibleResponses = exports.getAllPossibleResponses = function getAllPossibleResponses(correctResponse) {
468
+ if (!correctResponse) {
469
+ return [];
470
+ }
471
+ return correctResponse.reduce(function (acc, cR) {
472
+ // main response
473
+ if (acc[0]) {
474
+ acc[0][cR.category] = cR.choices;
475
+ } else {
476
+ acc.push((0, _defineProperty2["default"])({}, cR.category, cR.choices));
477
+ }
478
+
479
+ // alternate responses
480
+ if (cR.alternateResponses) {
481
+ cR.alternateResponses.forEach(function (aR, index) {
482
+ if (acc[index + 1]) {
483
+ acc[index + 1][cR.category] = aR;
484
+ } else {
485
+ acc.push((0, _defineProperty2["default"])({}, cR.category, aR));
486
+ }
487
+ });
488
+ }
489
+ return acc;
490
+ }, []);
491
+ };
492
+
493
+ /**
494
+ * build the categories to be displayed, where each category has its own list of choices
495
+ * @param {Object[]} categories
496
+ * @param {{id:string}[]} choices
497
+ * @param {{category: string, choices:string[]}[]} answers
498
+ *
499
+ * @returns {Object[]}, returns BuiltCategory[]
500
+ * BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},
501
+ * BuiltChoice = { id: choiceId, content: choiceContent }
502
+ */
503
+ var buildCategories = exports.buildCategories = function buildCategories(categories, choices, answers) {
504
+ categories = categories || [];
505
+ answers = answers || [];
506
+ choices = choices || [];
507
+ return categories.map(function (category) {
508
+ var answer = answers.find(function (answer) {
509
+ return answer.category === category.id;
510
+ });
511
+ var _ref = answer || {},
512
+ _ref$choices = _ref.choices,
513
+ answerChoices = _ref$choices === void 0 ? [] : _ref$choices;
514
+ return _objectSpread(_objectSpread({}, category), {}, {
515
+ choices: answerChoices.map(function (chId) {
516
+ return choices.find(function (ch) {
517
+ return ch.id === chId;
518
+ });
519
+ })
520
+ });
521
+ });
522
+ };
523
+
524
+ /**
525
+ * build the choice and category state
526
+ * @param {Object[]} categories
527
+ * @param {{id:string}[]} choices
528
+ * @param {{category: string, choices:string[]}[]} answers
529
+ *
530
+ * @param correctResponse
531
+ * @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }
532
+ */
533
+ var buildState = exports.buildState = function buildState(categories, choices, answers, correctResponse) {
534
+ categories = categories || [];
535
+ choices = choices || [];
536
+ answers = answers || [];
537
+ var allResponses = getAllPossibleResponses(correctResponse) || [];
538
+ var builtCategories = buildCategories(categories, choices, answers);
539
+ var bestResponse;
540
+ var entirelyCorrect;
541
+
542
+ // at least one defined correct response
543
+ if (allResponses.length) {
544
+ var builtData = allResponses.reduce(function (acc, possibleResponse) {
545
+ // set correctness for each possible response
546
+ var _getBuiltCategories = getBuiltCategories(possibleResponse, builtCategories),
547
+ categoriesWithChoices = _getBuiltCategories.builtCategories,
548
+ correct = _getBuiltCategories.correct;
549
+
550
+ // if bestResponse not found yet OR no correct response found yet and this one is the correct one
551
+ if (acc.bestResponse === null || !acc.entirelyCorrect && correct) {
552
+ return {
553
+ bestResponse: possibleResponse,
554
+ builtCategories: categoriesWithChoices,
555
+ entirelyCorrect: correct
556
+ };
557
+ }
558
+ return acc;
559
+ }, {
560
+ bestResponse: null,
561
+ builtCategories: [],
562
+ entirelyCorrect: false
563
+ });
564
+ builtCategories = builtData.builtCategories;
565
+ bestResponse = builtData.bestResponse;
566
+ entirelyCorrect = builtData.entirelyCorrect;
567
+ }
568
+ var filteredChoices = choices.map(function (ch) {
569
+ return stillSelectable(ch, builtCategories) ? ch : {
570
+ empty: true
571
+ };
572
+ });
573
+ return {
574
+ choices: filteredChoices,
575
+ categories: builtCategories,
576
+ correct: entirelyCorrect,
577
+ bestResponse: bestResponse
578
+ };
579
+ };
580
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_clone","_remove","_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 from 'lodash/clone';\nimport remove from 'lodash/remove';\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 };\n};\n"],"mappings":";;;;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,eAAe,EAAE,EAAE;MACnBgC,eAAe,EAAE;IACnB,CACF,CAAC;IAEDhC,eAAe,GAAGiC,SAAS,CAACjC,eAAe;IAC3C+B,YAAY,GAAGE,SAAS,CAACF,YAAY;IACrCC,eAAe,GAAGC,SAAS,CAACD,eAAe;EAC7C;EAEA,IAAMI,eAAe,GAAG5G,OAAO,CAACuB,GAAG,CAAC,UAAC6E,EAAE;IAAA,OAAM7B,eAAe,CAAC6B,EAAE,EAAE5B,eAAe,CAAC,GAAG4B,EAAE,GAAG;MAAES,KAAK,EAAE;IAAK,CAAC;EAAA,CAAC,CAAC;EAE1G,OAAO;IACL7G,OAAO,EAAE4G,eAAe;IACxBrE,UAAU,EAAEiC,eAAe;IAC3BQ,OAAO,EAAEwB,eAAe;IACxBD,YAAY,EAAZA;EACF,CAAC;AACH,CAAC","ignoreList":[]}
package/lib/scoring.js ADDED
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.js");
4
+ require("core-js/modules/es.array.for-each.js");
5
+ require("core-js/modules/es.object.define-properties.js");
6
+ require("core-js/modules/es.object.define-property.js");
7
+ require("core-js/modules/es.object.get-own-property-descriptor.js");
8
+ require("core-js/modules/es.object.get-own-property-descriptors.js");
9
+ require("core-js/modules/es.object.keys.js");
10
+ require("core-js/modules/web.dom-collections.for-each.js");
11
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
12
+ Object.defineProperty(exports, "__esModule", {
13
+ value: true
14
+ });
15
+ exports.score = void 0;
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+ require("core-js/modules/es.array.filter.js");
18
+ require("core-js/modules/es.array.find.js");
19
+ require("core-js/modules/es.array.map.js");
20
+ require("core-js/modules/es.array.reduce.js");
21
+ require("core-js/modules/es.number.to-fixed.js");
22
+ require("core-js/modules/es.object.to-string.js");
23
+ require("core-js/modules/es.parse-float.js");
24
+ require("core-js/modules/es.promise.js");
25
+ var _debug = _interopRequireDefault(require("debug"));
26
+ 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; }
27
+ 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; }
28
+ var log = (0, _debug["default"])('@pie-lib:categorize:scoring');
29
+ var getWeightingRules = function getWeightingRules(scoring) {
30
+ if (!scoring || !scoring.weighting) {
31
+ return [];
32
+ } else {
33
+ if (!scoring.weighting.enabled) {
34
+ return [];
35
+ } else {
36
+ var rules = scoring.weighting ? scoring.weighting.rules || [] : [];
37
+ return rules;
38
+ }
39
+ }
40
+ };
41
+ var getPartialRulesForCategory = function getPartialRulesForCategory(partial, categoryId) {
42
+ log('partial? ', partial);
43
+ if (!partial || !partial.enabled) {
44
+ return;
45
+ } else {
46
+ var pr = partial.rules.find(function (pr) {
47
+ return pr.category === categoryId;
48
+ });
49
+ return pr ? pr.rules || [] : [];
50
+ }
51
+ };
52
+
53
+ /**
54
+ *
55
+ * Calculate score based on the categories model generated from `buildState` and the partial scoring rules.
56
+ * @param {*} categories - this is the categories that you get from `buildState`.
57
+ * @param {*} scoring - scoring config.
58
+ * @see ../index#buildState
59
+ */
60
+
61
+ var score = exports.score = function score(categories, scoring) {
62
+ return new Promise(function (resolve) {
63
+ log('categories: ', categories, 'scoring: ', scoring);
64
+ var weightingRules = getWeightingRules(scoring);
65
+ var weights = categories.map(function (c) {
66
+ var r = weightingRules.find(function (r) {
67
+ return r.category === c.id;
68
+ }) || {
69
+ points: 1
70
+ };
71
+ return _objectSpread(_objectSpread({}, r), {}, {
72
+ category: c.id
73
+ });
74
+ });
75
+ log('weights: ', weights);
76
+ var weightTotal = categories.reduce(function (total, c) {
77
+ var r = weights.find(function (r) {
78
+ return r.category === c.id;
79
+ });
80
+ return total += r.points;
81
+ }, 0);
82
+ log('total: ', weightTotal);
83
+ var withScore = categories.map(function (c) {
84
+ var w = weights.find(function (r) {
85
+ return r.category === c.id;
86
+ }).points;
87
+ log('category: ', c);
88
+ if (c.correct === true) {
89
+ return {
90
+ category: c.id,
91
+ score: w,
92
+ points: w
93
+ };
94
+ } else {
95
+ var rules = getPartialRulesForCategory(scoring.partial, c.id);
96
+ log('partial rules for category: ', rules);
97
+ if (!rules) {
98
+ return {
99
+ category: c.id,
100
+ score: 0,
101
+ points: w
102
+ };
103
+ } else {
104
+ var correctCount = (c.choices || []).filter(function (h) {
105
+ return h.correct;
106
+ }).length;
107
+ log('correctCount: ', correctCount);
108
+ var rule = rules.find(function (u) {
109
+ return u.count === correctCount;
110
+ });
111
+ log('rule: ', rule);
112
+ rule = rule || {
113
+ percent: 0,
114
+ count: correctCount
115
+ };
116
+ var _score = w * (rule.percent / 100);
117
+ return {
118
+ category: c.id,
119
+ score: _score,
120
+ points: w,
121
+ partial: {
122
+ correctChoices: correctCount,
123
+ rule: rule
124
+ }
125
+ };
126
+ }
127
+ }
128
+ });
129
+ var weightedScore = withScore.reduce(function (sum, c) {
130
+ return sum += c.score;
131
+ }, 0);
132
+ log('weightedScore: ', weightedScore);
133
+ var score = parseFloat((weightedScore / weightTotal).toFixed(2), 10);
134
+ resolve({
135
+ score: score,
136
+ details: {
137
+ weighted: {
138
+ total: weightTotal,
139
+ score: weightedScore
140
+ },
141
+ categories: withScore
142
+ }
143
+ });
144
+ });
145
+ };
146
+ //# sourceMappingURL=scoring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring.js","names":["_debug","_interopRequireDefault","require","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","log","debug","getWeightingRules","scoring","weighting","enabled","rules","getPartialRulesForCategory","partial","categoryId","pr","find","category","score","exports","categories","Promise","resolve","weightingRules","weights","map","c","id","points","weightTotal","reduce","total","withScore","w","correct","correctCount","choices","h","rule","u","count","percent","correctChoices","weightedScore","sum","parseFloat","toFixed","details","weighted"],"sources":["../src/scoring.js"],"sourcesContent":["import debug from 'debug';\n\nconst log = debug('@pie-lib:categorize:scoring');\n\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\n return rules;\n }\n }\n};\n\nconst getPartialRulesForCategory = (partial, categoryId) => {\n log('partial? ', partial);\n\n if (!partial || !partial.enabled) {\n return;\n } else {\n const pr = partial.rules.find((pr) => pr.category === categoryId);\n\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\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\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\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\n log('partial rules for category: ', rules);\n\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\n log('correctCount: ', correctCount);\n\n let rule = rules.find((u) => u.count === correctCount);\n\n log('rule: ', rule);\n\n rule = rule || { percent: 0, count: correctCount };\n\n const score = w * (rule.percent / 100);\n\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\n resolve({\n score,\n details: {\n weighted: {\n total: weightTotal,\n score: weightedScore,\n },\n categories: withScore,\n },\n });\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,SAAAC,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,aAAAhB,CAA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,EAAEP,YAAY;cAC5BG,IAAI,EAAEA;YACR;UACF,CAAC;QACH;MACF;IACF,CAAC,CAAC;IAEF,IAAMK,aAAa,GAAGX,SAAS,CAACF,MAAM,CAAC,UAACc,GAAG,EAAElB,CAAC,EAAK;MACjD,OAAQkB,GAAG,IAAIlB,CAAC,CAACR,KAAK;IACxB,CAAC,EAAE,CAAC,CAAC;IAELb,GAAG,CAAC,iBAAiB,EAAEsC,aAAa,CAAC;IAErC,IAAMzB,KAAK,GAAG2B,UAAU,CAAC,CAACF,aAAa,GAAGd,WAAW,EAAEiB,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAEtExB,OAAO,CAAC;MACNJ,KAAK,EAALA,KAAK;MACL6B,OAAO,EAAE;QACPC,QAAQ,EAAE;UACRjB,KAAK,EAAEF,WAAW;UAClBX,KAAK,EAAEyB;QACT,CAAC;QACDvB,UAAU,EAAEY;MACd;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;AAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pie-lib/categorize",
3
- "version": "1.1.0-next.3",
3
+ "version": "1.1.0-next.37+283de799",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
7
7
  "dependencies": {
8
8
  "debug": "^4.1.1",
9
- "lodash": "^4.17.11"
9
+ "lodash": "^4.17.23"
10
10
  },
11
11
  "publishConfig": {
12
12
  "access": "public"
@@ -14,5 +14,5 @@
14
14
  "scripts": {},
15
15
  "author": "",
16
16
  "license": "ISC",
17
- "gitHead": "8ea41592c5553487014f2694f91b657c4f62d131"
17
+ "gitHead": "283de799c8e7a14e255287a8e22c4b76d837198f"
18
18
  }
package/src/index.js CHANGED
@@ -17,12 +17,10 @@ export const limitChoices = (choiceId, count, choices) => {
17
17
  if (id !== choiceId || foundCount < count) {
18
18
  acc.choices.push(id);
19
19
  }
20
-
21
20
  return acc;
22
21
  },
23
22
  { choices: [] },
24
23
  );
25
-
26
24
  return out.choices;
27
25
  };
28
26