@pie-lib/categorize 0.24.1-next.0 → 0.25.2

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/esm/index.js ADDED
@@ -0,0 +1,667 @@
1
+ import debug from 'debug';
2
+ import clone from 'lodash/clone';
3
+ import remove from 'lodash/remove';
4
+
5
+ function _extends() {
6
+ _extends = Object.assign || function (target) {
7
+ for (var i = 1; i < arguments.length; i++) {
8
+ var source = arguments[i];
9
+
10
+ for (var key in source) {
11
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
12
+ target[key] = source[key];
13
+ }
14
+ }
15
+ }
16
+
17
+ return target;
18
+ };
19
+
20
+ return _extends.apply(this, arguments);
21
+ }
22
+
23
+ const log$1 = debug('@pie-lib:categorize:scoring');
24
+
25
+ const getWeightingRules = scoring => {
26
+ if (!scoring || !scoring.weighting) {
27
+ return [];
28
+ } else {
29
+ if (!scoring.weighting.enabled) {
30
+ return [];
31
+ } else {
32
+ const rules = scoring.weighting ? scoring.weighting.rules || [] : [];
33
+ return rules;
34
+ }
35
+ }
36
+ };
37
+
38
+ const getPartialRulesForCategory = (partial, categoryId) => {
39
+ log$1('partial? ', partial);
40
+
41
+ if (!partial || !partial.enabled) {
42
+ return;
43
+ } else {
44
+ const pr = partial.rules.find(pr => pr.category === categoryId);
45
+ return pr ? pr.rules || [] : [];
46
+ }
47
+ };
48
+ /**
49
+ *
50
+ * Calculate score based on the categories model generated from `buildState` and the partial scoring rules.
51
+ * @param {*} categories - this is the categories that you get from `buildState`.
52
+ * @param {*} scoring - scoring config.
53
+ * @see ../index#buildState
54
+ */
55
+
56
+
57
+ const score = (categories, scoring) => new Promise(resolve => {
58
+ log$1('categories: ', categories, 'scoring: ', scoring);
59
+ const weightingRules = getWeightingRules(scoring);
60
+ const weights = categories.map(c => {
61
+ const r = weightingRules.find(r => r.category === c.id) || {
62
+ points: 1
63
+ };
64
+ return _extends({}, r, {
65
+ category: c.id
66
+ });
67
+ });
68
+ log$1('weights: ', weights);
69
+ const weightTotal = categories.reduce((total, c) => {
70
+ const r = weights.find(r => r.category === c.id);
71
+ return total += r.points;
72
+ }, 0);
73
+ log$1('total: ', weightTotal);
74
+ const withScore = categories.map(c => {
75
+ const w = weights.find(r => r.category === c.id).points;
76
+ log$1('category: ', c);
77
+
78
+ if (c.correct === true) {
79
+ return {
80
+ category: c.id,
81
+ score: w,
82
+ points: w
83
+ };
84
+ } else {
85
+ const rules = getPartialRulesForCategory(scoring.partial, c.id);
86
+ log$1('partial rules for category: ', rules);
87
+
88
+ if (!rules) {
89
+ return {
90
+ category: c.id,
91
+ score: 0,
92
+ points: w
93
+ };
94
+ } else {
95
+ const correctCount = (c.choices || []).filter(h => h.correct).length;
96
+ log$1('correctCount: ', correctCount);
97
+ let rule = rules.find(u => u.count === correctCount);
98
+ log$1('rule: ', rule);
99
+ rule = rule || {
100
+ percent: 0,
101
+ count: correctCount
102
+ };
103
+ const score = w * (rule.percent / 100);
104
+ return {
105
+ category: c.id,
106
+ score,
107
+ points: w,
108
+ partial: {
109
+ correctChoices: correctCount,
110
+ rule: rule
111
+ }
112
+ };
113
+ }
114
+ }
115
+ });
116
+ const weightedScore = withScore.reduce((sum, c) => {
117
+ return sum += c.score;
118
+ }, 0);
119
+ log$1('weightedScore: ', weightedScore);
120
+ const score = parseFloat((weightedScore / weightTotal).toFixed(2), 10);
121
+ resolve({
122
+ score,
123
+ details: {
124
+ weighted: {
125
+ total: weightTotal,
126
+ score: weightedScore
127
+ },
128
+ categories: withScore
129
+ }
130
+ });
131
+ });
132
+
133
+ const FooTwo = 'foo-two';
134
+ const log = debug('@pie-lib:categorize');
135
+ const limitChoices = (choiceId, count, choices) => {
136
+ const out = choices.reduce((acc, id) => {
137
+ const foundCount = countInChoices(choiceId, acc.choices);
138
+
139
+ if (id !== choiceId || foundCount < count) {
140
+ acc.choices.push(id);
141
+ }
142
+
143
+ return acc;
144
+ }, {
145
+ choices: []
146
+ });
147
+ return out.choices;
148
+ };
149
+ /**
150
+ * Limit in an array of arrays.
151
+ * So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]
152
+ * @param {*} id
153
+ * @param {*} arrays
154
+ * @param {*} limit
155
+ */
156
+
157
+ const limitInArrays = (id, arrays, limit) => {
158
+ arrays = arrays || [];
159
+ const result = arrays.reduce((acc, array) => {
160
+ const l = limit - acc.count;
161
+ const result = limitInArray(id, array, l);
162
+ acc.out.push(result.array);
163
+ acc.count = acc.count + (result.count || 0);
164
+ return acc;
165
+ }, {
166
+ out: [],
167
+ count: 0
168
+ });
169
+ return result.out;
170
+ };
171
+ /**
172
+ * Limit the id in the array to the limit set.
173
+ * So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]
174
+ * @param {string} id
175
+ * @param {string[]} arr
176
+ * @param {number} limit
177
+ */
178
+
179
+ const limitInArray = (id, arr, limit) => {
180
+ arr = arr || [];
181
+
182
+ if (limit === 0) {
183
+ const stripped = arr.filter(v => v !== id);
184
+ return {
185
+ array: stripped,
186
+ count: arr.length - stripped.length
187
+ };
188
+ } else {
189
+ const result = arr.reduce((acc, v) => {
190
+ if (v === id) {
191
+ if (acc.count < limit) {
192
+ acc.count += 1;
193
+ acc.out.push(v);
194
+ }
195
+ } else {
196
+ acc.out.push(v);
197
+ }
198
+
199
+ return acc;
200
+ }, {
201
+ out: [],
202
+ count: 0
203
+ });
204
+ return {
205
+ array: result.out,
206
+ count: result.count
207
+ };
208
+ }
209
+ };
210
+ /**
211
+ * Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.
212
+ * @param {{category: string, choices: string[]}[]} answer
213
+ * @param {{id:string,categoryCount:number}} choices
214
+ */
215
+
216
+ const ensureNoExtraChoicesInAnswer = (answer, choices) => {
217
+ choices = choices || [];
218
+ const out = choices.reduce((answerArray, choice) => {
219
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
220
+
221
+ if (choice.categoryCount === undefined || choice.categoryCount === 0) {
222
+ return answerArray;
223
+ } else {
224
+ const choices = answerArray.map(a => a.choices);
225
+ const result = limitInArrays(choice.id, choices, choice.categoryCount);
226
+ const updatedArray = result.map((r, index) => {
227
+ return {
228
+ category: answerArray[index].category,
229
+ alternateResponses: answerArray[index].alternateResponses,
230
+ choices: r
231
+ };
232
+ });
233
+ return updatedArray;
234
+ }
235
+ }, answer);
236
+ return out;
237
+ };
238
+ /**
239
+ * Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.
240
+ * @param {{category: string, choices: string[]}[]} answer
241
+ * @param {{id:string,categoryCount:number}} choices
242
+ */
243
+
244
+ const ensureNoExtraChoicesInAlternate = (answer, choices) => {
245
+ choices = choices || [];
246
+ const out = choices.reduce((answerArray, choice) => {
247
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
248
+
249
+ if (choice.categoryCount === undefined || choice.categoryCount === 0) {
250
+ return answerArray;
251
+ } else {
252
+ let alternatePair = {};
253
+ answerArray.forEach(answer => (answer.alternateResponses || []).forEach((alternate, index) => {
254
+ if (index in alternatePair) {
255
+ alternatePair[index].push(alternate);
256
+ } else {
257
+ alternatePair[index] = [];
258
+ alternatePair[index].push(alternate);
259
+ }
260
+ }));
261
+ const recreatedAlternate = [];
262
+ Object.keys(alternatePair).forEach(k => {
263
+ const limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);
264
+ alternatePair[k] = limitAlternate;
265
+ alternatePair[k].forEach((item, index) => {
266
+ if (!recreatedAlternate[index]) {
267
+ recreatedAlternate[index] = [];
268
+ recreatedAlternate[index].push(item);
269
+ } else {
270
+ recreatedAlternate[index].push(item);
271
+ }
272
+ });
273
+ });
274
+ const updatedArray = answerArray.map((answer, index) => {
275
+ return {
276
+ category: answer.category,
277
+ alternateResponses: recreatedAlternate[index] || answer.alternateResponses,
278
+ choices: answer.choices
279
+ };
280
+ });
281
+ return updatedArray;
282
+ }
283
+ }, answer);
284
+ return out;
285
+ };
286
+ /**
287
+ * Count the number of choice ids in a given answer array
288
+ * @param {string} choiceId
289
+ * @param {{category: string, choices: string[]}[]} answer
290
+ */
291
+
292
+ const countInAnswer = (choiceId, answer) => {
293
+ const out = answer.reduce((acc, a) => acc + countInChoices(choiceId, a.choices), 0);
294
+ log('[countInAnswer] choiceId:', choiceId, answer);
295
+ return out;
296
+ };
297
+ const countInChoices = (choiceId, choices) => (choices || []).filter(c => c === choiceId).length;
298
+ /**
299
+ * Count the number of times a choice has been selected in categories.
300
+ * @param {*} choice
301
+ * @param {*} categories
302
+ */
303
+
304
+ const countChosen = (choice, categories) => {
305
+ if (!choice || !choice.id) {
306
+ return 0;
307
+ }
308
+
309
+ if (!Array.isArray(categories)) {
310
+ return 0;
311
+ }
312
+
313
+ return categories.reduce((acc, c) => {
314
+ const count = (c.choices || []).filter(h => h && h.id === choice.id).length;
315
+ return acc + count;
316
+ }, 0);
317
+ };
318
+ /**
319
+ * @param {string?} categoryId
320
+ * @param {{category:string, choices: string[]}} answers
321
+ */
322
+
323
+ const removeCategory = (categoryId, answers) => answers.filter(a => a.category !== categoryId);
324
+ /**
325
+ * @param {string} choiceId
326
+ * @param {{category:string, choices: string[]}} answers
327
+ * @param {string?} categoryId - optional categegory id
328
+ */
329
+
330
+ const removeAllChoices = (choiceId, answers, categoryId) => {
331
+ return answers.map(a => {
332
+ if (!categoryId || a.category === categoryId) {
333
+ const cloned = clone(a.choices);
334
+ remove(cloned, v => v === choiceId);
335
+ return _extends({}, a, {
336
+ choices: cloned
337
+ });
338
+ } else {
339
+ return a;
340
+ }
341
+ });
342
+ };
343
+ const rearrangeChoices = (choices, indexFrom, indexTo) => {
344
+ if (choices.length === 0) {
345
+ return choices;
346
+ }
347
+
348
+ choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);
349
+ return choices;
350
+ };
351
+ const verifyAllowMultiplePlacements = (choice, categoryId, answers) => {
352
+ return answers.map(a => {
353
+ if (a.category !== categoryId) {
354
+ a.choices = (a.choices || []).filter(c => c !== choice.id);
355
+ return a;
356
+ } else {
357
+ a.choices = a.choices.reduce((acc, currentValue) => {
358
+ if (currentValue.id === choice.id) {
359
+ const foundIndex = acc.findIndex(c => c.id === choice.id);
360
+
361
+ if (foundIndex === -1) {
362
+ acc.push(currentValue);
363
+ }
364
+ } else {
365
+ acc.push(currentValue);
366
+ }
367
+
368
+ return acc;
369
+ }, []);
370
+ return a;
371
+ }
372
+ });
373
+ };
374
+ const removeChoiceFromCategory = (choiceId, categoryId, choiceIndex, answers) => {
375
+ log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);
376
+ return answers.map(a => {
377
+ if (a.category === categoryId) {
378
+ const cloned = clone(a.choices);
379
+ const index = cloned.findIndex((v, index) => {
380
+ return v === choiceId && index >= choiceIndex;
381
+ });
382
+
383
+ if (index !== -1) {
384
+ cloned.splice(index, 1);
385
+ }
386
+
387
+ return _extends({}, a, {
388
+ choices: cloned
389
+ });
390
+ } else {
391
+ return a;
392
+ }
393
+ });
394
+ };
395
+ const removeChoiceFromAlternate = (choiceId, categoryId, choiceIndex, altIndex, answers) => {
396
+ return (answers || []).map(a => {
397
+ if ((a == null ? void 0 : a.category) === categoryId) {
398
+ const newAlternates = ((a == null ? void 0 : a.alternateResponses) || []).map((altArray, idx) => {
399
+ if (idx === altIndex) {
400
+ (altArray || []).splice(choiceIndex, 1);
401
+ return altArray;
402
+ }
403
+
404
+ return altArray;
405
+ });
406
+ return _extends({}, a, {
407
+ alternateResponses: newAlternates
408
+ });
409
+ }
410
+
411
+ return a;
412
+ });
413
+ };
414
+ const moveChoiceToCategory = (choiceId, from, to, choiceIndex, answers) => {
415
+ log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);
416
+
417
+ if (from === to) {
418
+ return answers;
419
+ }
420
+
421
+ if (from) {
422
+ answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);
423
+ }
424
+
425
+ const index = answers.findIndex(a => a.category === to);
426
+
427
+ if (index === -1) {
428
+ answers.push({
429
+ category: to,
430
+ choices: [choiceId]
431
+ });
432
+ return answers;
433
+ } else {
434
+ return answers.map(a => {
435
+ if (a.category === to) {
436
+ a.choices = a.choices || [];
437
+ a.choices.push(choiceId);
438
+ return a;
439
+ }
440
+
441
+ return a;
442
+ });
443
+ }
444
+ };
445
+ const moveChoiceToAlternate = (choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) => {
446
+ log('[moveChoiceToAlternate] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers, 'chocieIndex: ', choiceIndex);
447
+
448
+ if (from === to) {
449
+ return answers;
450
+ }
451
+
452
+ return answers.map(a => {
453
+ if (a.category === to) {
454
+ if (categoryCount !== 0 && a.alternateResponses) {
455
+ a.alternateResponses[alternateIndex] = (a.alternateResponses[alternateIndex] || []).filter(resp => resp !== choiceId);
456
+ }
457
+
458
+ if (!a.alternateResponses) {
459
+ a.alternateResponses = [];
460
+ a.alternateResponses[alternateIndex] = [];
461
+ }
462
+
463
+ a.alternateResponses[alternateIndex].push(choiceId);
464
+ }
465
+
466
+ if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {
467
+ a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter(resp => resp !== choiceId);
468
+ }
469
+
470
+ return a;
471
+ });
472
+ };
473
+ const stillSelectable = (h, builtCategories) => {
474
+ if (h.categoryCount > 0) {
475
+ const count = countChosen(h, builtCategories);
476
+ return count < h.categoryCount;
477
+ } else {
478
+ return true;
479
+ }
480
+ };
481
+ /**
482
+ * returns all choices with property 'correct' set to boolean
483
+ * @param {string[]} possibleResponseChoices
484
+ * @param {Object[]} builtCategoryChoices
485
+ *
486
+ * @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean
487
+ * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
488
+ */
489
+
490
+ const buildChoices = (possibleResponseChoices, builtCategoryChoices) => {
491
+ return builtCategoryChoices.reduce((acc, builtChoice) => {
492
+ // set correct value on each choice that was selected by user
493
+ const index = acc.copyOfPossibleResponse.findIndex(cRC => builtChoice && cRC === builtChoice.id); // if the choice exists in the correct response
494
+ // set the correct: true
495
+
496
+ if (index >= 0) {
497
+ acc.builtChoices.push(_extends({}, builtChoice, {
498
+ correct: true
499
+ }));
500
+ acc.copyOfPossibleResponse = [...acc.copyOfPossibleResponse.slice(0, index), ...acc.copyOfPossibleResponse.slice(index + 1)];
501
+ } else {
502
+ acc.builtChoices.push(_extends({}, builtChoice, {
503
+ correct: false
504
+ }));
505
+ acc.allChoicesAreCorrect = false;
506
+ }
507
+
508
+ return acc;
509
+ }, {
510
+ builtChoices: [],
511
+ copyOfPossibleResponse: [...possibleResponseChoices],
512
+ allChoicesAreCorrect: true
513
+ });
514
+ };
515
+ /**
516
+ * returns corrected answer using this possible correct response
517
+ * @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }
518
+ * @param {Object[]} builtCategories
519
+ *
520
+ * @returns {Object}, returns builtCategories: BuiltCategory[] and correct: boolean
521
+ * BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }
522
+ * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
523
+ */
524
+
525
+ const getBuiltCategories = (possibleResponse, builtCategories) => builtCategories.reduce((acc, builtCategory) => {
526
+ const possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category
527
+
528
+ const builtCategoryChoices = builtCategory.choices || []; // the choices in the answer
529
+
530
+ const {
531
+ builtChoices,
532
+ allChoicesAreCorrect
533
+ } = buildChoices(possibleResponseChoices, builtCategoryChoices);
534
+ const allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;
535
+ acc.builtCategories.push(_extends({}, builtCategory, {
536
+ correct: allChoicesAreCorrect && allChoicesAreInAnswer,
537
+ choices: builtChoices
538
+ }));
539
+ acc.correct = acc.correct && allChoicesAreCorrect && allChoicesAreInAnswer;
540
+ return acc;
541
+ }, {
542
+ builtCategories: [],
543
+ correct: true
544
+ });
545
+ /**
546
+ * returns all the possible responses by combining the proper alternate responses
547
+ * @param {Object[]} correctResponse
548
+ *
549
+ * @returns {Object[]}, returns Response[]
550
+ * Response = { CategoryId: ChoiceId[] },
551
+ */
552
+
553
+ const getAllPossibleResponses = correctResponse => {
554
+ if (!correctResponse) {
555
+ return [];
556
+ }
557
+
558
+ return correctResponse.reduce((acc, cR) => {
559
+ // main response
560
+ if (acc[0]) {
561
+ acc[0][cR.category] = cR.choices;
562
+ } else {
563
+ acc.push({
564
+ [cR.category]: cR.choices
565
+ });
566
+ } // alternate responses
567
+
568
+
569
+ if (cR.alternateResponses) {
570
+ cR.alternateResponses.forEach((aR, index) => {
571
+ if (acc[index + 1]) {
572
+ acc[index + 1][cR.category] = aR;
573
+ } else {
574
+ acc.push({
575
+ [cR.category]: aR
576
+ });
577
+ }
578
+ });
579
+ }
580
+
581
+ return acc;
582
+ }, []);
583
+ };
584
+ /**
585
+ * build the categories to be displayed, where each category has its own list of choices
586
+ * @param {Object[]} categories
587
+ * @param {{id:string}[]} choices
588
+ * @param {{category: string, choices:string[]}[]} answers
589
+ *
590
+ * @returns {Object[]}, returns BuiltCategory[]
591
+ * BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},
592
+ * BuiltChoice = { id: choiceId, content: choiceContent }
593
+ */
594
+
595
+ const buildCategories = (categories, choices, answers) => {
596
+ categories = categories || [];
597
+ answers = answers || [];
598
+ choices = choices || [];
599
+ return categories.map(category => {
600
+ const answer = answers.find(answer => answer.category === category.id);
601
+ const {
602
+ choices: answerChoices = []
603
+ } = answer || {};
604
+ return _extends({}, category, {
605
+ choices: answerChoices.map(chId => choices.find(ch => ch.id === chId))
606
+ });
607
+ });
608
+ };
609
+ /**
610
+ * build the choice and category state
611
+ * @param {Object[]} categories
612
+ * @param {{id:string}[]} choices
613
+ * @param {{category: string, choices:string[]}[]} answers
614
+ *
615
+ * @param correctResponse
616
+ * @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }
617
+ */
618
+
619
+ const buildState = (categories, choices, answers, correctResponse) => {
620
+ categories = categories || [];
621
+ choices = choices || [];
622
+ answers = answers || [];
623
+ const allResponses = getAllPossibleResponses(correctResponse) || [];
624
+ let builtCategories = buildCategories(categories, choices, answers);
625
+ let bestResponse;
626
+ let entirelyCorrect; // at least one defined correct response
627
+
628
+ if (allResponses.length) {
629
+ const builtData = allResponses.reduce((acc, possibleResponse) => {
630
+ // set correctness for each possible response
631
+ const {
632
+ builtCategories: categoriesWithChoices,
633
+ correct
634
+ } = getBuiltCategories(possibleResponse, builtCategories); // if bestResponse not found yet OR no correct response found yet and this one is the correct one
635
+
636
+ if (acc.bestResponse === null || !acc.entirelyCorrect && correct) {
637
+ return {
638
+ bestResponse: possibleResponse,
639
+ builtCategories: categoriesWithChoices,
640
+ entirelyCorrect: correct
641
+ };
642
+ }
643
+
644
+ return acc;
645
+ }, {
646
+ bestResponse: null,
647
+ builtCategories: [],
648
+ entirelyCorrect: false
649
+ });
650
+ builtCategories = builtData.builtCategories;
651
+ bestResponse = builtData.bestResponse;
652
+ entirelyCorrect = builtData.entirelyCorrect;
653
+ }
654
+
655
+ const filteredChoices = choices.map(ch => stillSelectable(ch, builtCategories) ? ch : {
656
+ empty: true
657
+ });
658
+ return {
659
+ choices: filteredChoices,
660
+ categories: builtCategories,
661
+ correct: entirelyCorrect,
662
+ bestResponse
663
+ };
664
+ };
665
+
666
+ export { FooTwo, buildCategories, buildChoices, buildState, countChosen, countInAnswer, countInChoices, ensureNoExtraChoicesInAlternate, ensureNoExtraChoicesInAnswer, getAllPossibleResponses, getBuiltCategories, limitChoices, limitInArray, limitInArrays, moveChoiceToAlternate, moveChoiceToCategory, rearrangeChoices, removeAllChoices, removeCategory, removeChoiceFromAlternate, removeChoiceFromCategory, score, stillSelectable, verifyAllowMultiplePlacements };
667
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/scoring.js","../src/index.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","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\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\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"],"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","FooTwo","limitChoices","choiceId","out","acc","foundCount","countInChoices","push","limitInArrays","arrays","limit","result","array","l","limitInArray","arr","stripped","v","ensureNoExtraChoicesInAnswer","answer","answerArray","choice","categoryCount","undefined","a","updatedArray","index","alternateResponses","ensureNoExtraChoicesInAlternate","alternatePair","forEach","alternate","recreatedAlternate","Object","keys","k","limitAlternate","item","countInAnswer","countChosen","Array","isArray","removeCategory","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","slice","allChoicesAreCorrect","getBuiltCategories","possibleResponse","builtCategory","allChoicesAreInAnswer","getAllPossibleResponses","correctResponse","cR","aR","buildCategories","answerChoices","chId","ch","buildState","allResponses","bestResponse","entirelyCorrect","builtData","categoriesWithChoices","filteredChoices","empty"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,MAAMA,KAAG,GAAGC,KAAK,CAAC,6BAAD,CAAjB;;AAEA,MAAMC,iBAAiB,GAAIC,OAAD,IAAa;AACrC,EAAA,IAAI,CAACA,OAAD,IAAY,CAACA,OAAO,CAACC,SAAzB,EAAoC;AAClC,IAAA,OAAO,EAAP;AACD,EAAA,CAFD,MAEO;AACL,IAAA,IAAI,CAACD,OAAO,CAACC,SAAR,CAAkBC,OAAvB,EAAgC;AAC9B,MAAA,OAAO,EAAP;AACD,IAAA,CAFD,MAEO;AACL,MAAA,MAAMC,KAAK,GAAGH,OAAO,CAACC,SAAR,GAAoBD,OAAO,CAACC,SAAR,CAAkBE,KAAlB,IAA2B,EAA/C,GAAoD,EAAlE;AAEA,MAAA,OAAOA,KAAP;A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UAAU,EAAEsG,eAFP;AAGLvF,IAAAA,OAAO,EAAEgH,eAHJ;AAILD,IAAAA;AAJK,GAAP;AAMD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/categorize",
3
- "version": "0.24.1-next.0+a5d1550f",
3
+ "version": "0.25.2",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -14,5 +14,12 @@
14
14
  "scripts": {},
15
15
  "author": "",
16
16
  "license": "ISC",
17
- "gitHead": "a5d1550faec7e27c8824e5aa4b4ef29ad4ee525a"
17
+ "gitHead": "8a327571bd64249e4c88c0c8e750d16d6213f535",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./esm/index.js",
21
+ "require": "./lib/index.js",
22
+ "default": "./esm/index.js"
23
+ }
24
+ }
18
25
  }
package/LICENSE.md DELETED
@@ -1,5 +0,0 @@
1
- Copyright 2019 CoreSpring Inc
2
-
3
- Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
-
5
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.