@pie-lib/categorize 0.6.27-next.53 → 0.7.1-next.1
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/CHANGELOG.json +15 -0
- package/CHANGELOG.md +19 -0
- package/lib/index.js +119 -31
- package/lib/index.js.map +1 -1
- package/lib/scoring.js +15 -1
- package/lib/scoring.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.json
CHANGED
|
@@ -328,5 +328,20 @@
|
|
|
328
328
|
"committerDate": "2021-02-02 16:17:48 +0200",
|
|
329
329
|
"isTagged": true,
|
|
330
330
|
"tag": "@pie-lib/categorize@0.6.19"
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
"type": "feat",
|
|
334
|
+
"scope": "categorize",
|
|
335
|
+
"subject": "conclude merge",
|
|
336
|
+
"merge": null,
|
|
337
|
+
"header": "feat(categorize): conclude merge",
|
|
338
|
+
"body": null,
|
|
339
|
+
"footer": null,
|
|
340
|
+
"notes": [],
|
|
341
|
+
"hash": "da8b33228705490c504be56d250f61e14ca5530d",
|
|
342
|
+
"gitTags": "",
|
|
343
|
+
"committerDate": "2023-01-03 11:36:51 +0200",
|
|
344
|
+
"isTagged": true,
|
|
345
|
+
"tag": "@pie-lib/categorize@0.7.0"
|
|
331
346
|
}
|
|
332
347
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.7.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.6.26...@pie-lib/categorize@0.7.0) (2023-01-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **categorize:** add test for addChoiceToAlternate-PD-1995 ([153ada3](https://github.com/pie-framework/pie-lib/commit/153ada3ce0a27189ca1fecb5839c2843e35487d5))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **categorize:** add method to swap teo choices-PD-1967 ([4660fcf](https://github.com/pie-framework/pie-lib/commit/4660fcfe8cd47c0d02707651812c7897182baeea))
|
|
17
|
+
* **categorize:** conclude merge ([da8b332](https://github.com/pie-framework/pie-lib/commit/da8b33228705490c504be56d250f61e14ca5530d))
|
|
18
|
+
* **categorize:** ensure no extra choices in alternate + sanity checks-PD-1967 ([a574028](https://github.com/pie-framework/pie-lib/commit/a5740285469691e89bc2255045f129989861892b))
|
|
19
|
+
* **categorzie:** Ensure that there are no extra choices after moving and adding new choices: PD-1967 ([a2f0ebd](https://github.com/pie-framework/pie-lib/commit/a2f0ebd1dd5e0f86a255727207182a29db7e8ce0))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.6.26](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.6.25...@pie-lib/categorize@0.6.26) (2022-12-19)
|
|
7
26
|
|
|
8
27
|
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
@@ -12,36 +13,51 @@ Object.defineProperty(exports, "score", {
|
|
|
12
13
|
}
|
|
13
14
|
});
|
|
14
15
|
exports.verifyAllowMultiplePlacements = exports.stillSelectable = void 0;
|
|
16
|
+
|
|
15
17
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
|
+
|
|
16
19
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
20
|
+
|
|
17
21
|
var _compact = _interopRequireDefault(require("lodash/compact"));
|
|
22
|
+
|
|
18
23
|
var _debug = _interopRequireDefault(require("debug"));
|
|
24
|
+
|
|
19
25
|
var _clone = _interopRequireDefault(require("lodash/clone"));
|
|
26
|
+
|
|
20
27
|
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
28
|
+
|
|
21
29
|
var _remove = _interopRequireDefault(require("lodash/remove"));
|
|
30
|
+
|
|
22
31
|
var _every = _interopRequireDefault(require("lodash/every"));
|
|
32
|
+
|
|
23
33
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
34
|
+
|
|
24
35
|
var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
|
|
36
|
+
|
|
25
37
|
var _scoring = require("./scoring");
|
|
38
|
+
|
|
26
39
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
40
|
+
|
|
27
41
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
42
|
+
|
|
28
43
|
var FooTwo = 'foo-two';
|
|
29
44
|
exports.FooTwo = FooTwo;
|
|
30
45
|
var log = (0, _debug["default"])('@pie-lib:categorize');
|
|
46
|
+
|
|
31
47
|
var limitChoices = function limitChoices(choiceId, count, choices) {
|
|
32
48
|
var out = choices.reduce(function (acc, id) {
|
|
33
|
-
var foundCount = countInChoices(choiceId, acc.choices);
|
|
34
|
-
|
|
49
|
+
var foundCount = countInChoices(choiceId, acc.choices); // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);
|
|
50
|
+
|
|
35
51
|
if (id !== choiceId || foundCount < count) {
|
|
36
52
|
acc.choices.push(id);
|
|
37
53
|
}
|
|
54
|
+
|
|
38
55
|
return acc;
|
|
39
56
|
}, {
|
|
40
57
|
choices: []
|
|
41
58
|
});
|
|
42
59
|
return out.choices;
|
|
43
60
|
};
|
|
44
|
-
|
|
45
61
|
/**
|
|
46
62
|
* Limit in an array of arrays.
|
|
47
63
|
* So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]
|
|
@@ -49,7 +65,10 @@ var limitChoices = function limitChoices(choiceId, count, choices) {
|
|
|
49
65
|
* @param {*} arrays
|
|
50
66
|
* @param {*} limit
|
|
51
67
|
*/
|
|
68
|
+
|
|
69
|
+
|
|
52
70
|
exports.limitChoices = limitChoices;
|
|
71
|
+
|
|
53
72
|
var limitInArrays = function limitInArrays(id, arrays, limit) {
|
|
54
73
|
arrays = arrays || [];
|
|
55
74
|
var result = arrays.reduce(function (acc, array) {
|
|
@@ -64,7 +83,6 @@ var limitInArrays = function limitInArrays(id, arrays, limit) {
|
|
|
64
83
|
});
|
|
65
84
|
return result.out;
|
|
66
85
|
};
|
|
67
|
-
|
|
68
86
|
/**
|
|
69
87
|
* Limit the id in the array to the limit set.
|
|
70
88
|
* So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]
|
|
@@ -72,9 +90,13 @@ var limitInArrays = function limitInArrays(id, arrays, limit) {
|
|
|
72
90
|
* @param {string[]} arr
|
|
73
91
|
* @param {number} limit
|
|
74
92
|
*/
|
|
93
|
+
|
|
94
|
+
|
|
75
95
|
exports.limitInArrays = limitInArrays;
|
|
96
|
+
|
|
76
97
|
var limitInArray = function limitInArray(id, arr, limit) {
|
|
77
98
|
arr = arr || [];
|
|
99
|
+
|
|
78
100
|
if (limit === 0) {
|
|
79
101
|
var stripped = arr.filter(function (v) {
|
|
80
102
|
return v !== id;
|
|
@@ -93,6 +115,7 @@ var limitInArray = function limitInArray(id, arr, limit) {
|
|
|
93
115
|
} else {
|
|
94
116
|
acc.out.push(v);
|
|
95
117
|
}
|
|
118
|
+
|
|
96
119
|
return acc;
|
|
97
120
|
}, {
|
|
98
121
|
out: [],
|
|
@@ -104,24 +127,27 @@ var limitInArray = function limitInArray(id, arr, limit) {
|
|
|
104
127
|
};
|
|
105
128
|
}
|
|
106
129
|
};
|
|
107
|
-
|
|
108
130
|
/**
|
|
109
131
|
* Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.
|
|
110
132
|
* @param {{category: string, choices: string[]}[]} answer
|
|
111
133
|
* @param {{id:string,categoryCount:number}} choices
|
|
112
134
|
*/
|
|
135
|
+
|
|
136
|
+
|
|
113
137
|
exports.limitInArray = limitInArray;
|
|
138
|
+
|
|
114
139
|
var ensureNoExtraChoicesInAnswer = function ensureNoExtraChoicesInAnswer(answer, choices) {
|
|
115
140
|
choices = choices || [];
|
|
116
141
|
var out = choices.reduce(function (answerArray, choice) {
|
|
117
|
-
log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
|
|
118
|
-
|
|
142
|
+
log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount); // log('answer array: ', answerArray);
|
|
143
|
+
|
|
119
144
|
if (choice.categoryCount === undefined || choice.categoryCount === 0) {
|
|
120
145
|
return answerArray;
|
|
121
146
|
} else {
|
|
122
147
|
var _choices = answerArray.map(function (a) {
|
|
123
148
|
return a.choices;
|
|
124
149
|
});
|
|
150
|
+
|
|
125
151
|
var result = limitInArrays(choice.id, _choices, choice.categoryCount);
|
|
126
152
|
var updatedArray = result.map(function (r, index) {
|
|
127
153
|
return {
|
|
@@ -135,18 +161,20 @@ var ensureNoExtraChoicesInAnswer = function ensureNoExtraChoicesInAnswer(answer,
|
|
|
135
161
|
}, answer);
|
|
136
162
|
return out;
|
|
137
163
|
};
|
|
138
|
-
|
|
139
164
|
/**
|
|
140
165
|
* Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.
|
|
141
166
|
* @param {{category: string, choices: string[]}[]} answer
|
|
142
167
|
* @param {{id:string,categoryCount:number}} choices
|
|
143
168
|
*/
|
|
169
|
+
|
|
170
|
+
|
|
144
171
|
exports.ensureNoExtraChoicesInAnswer = ensureNoExtraChoicesInAnswer;
|
|
172
|
+
|
|
145
173
|
var ensureNoExtraChoicesInAlternate = function ensureNoExtraChoicesInAlternate(answer, choices) {
|
|
146
174
|
choices = choices || [];
|
|
147
175
|
var out = choices.reduce(function (answerArray, choice) {
|
|
148
|
-
log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
|
|
149
|
-
|
|
176
|
+
log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount); // log('answer array: ', answerArray);
|
|
177
|
+
|
|
150
178
|
if (choice.categoryCount === undefined || choice.categoryCount === 0) {
|
|
151
179
|
return answerArray;
|
|
152
180
|
} else {
|
|
@@ -191,7 +219,10 @@ var ensureNoExtraChoicesInAlternate = function ensureNoExtraChoicesInAlternate(a
|
|
|
191
219
|
* @param {string} choiceId
|
|
192
220
|
* @param {{category: string, choices: string[]}[]} answer
|
|
193
221
|
*/
|
|
222
|
+
|
|
223
|
+
|
|
194
224
|
exports.ensureNoExtraChoicesInAlternate = ensureNoExtraChoicesInAlternate;
|
|
225
|
+
|
|
195
226
|
var countInAnswer = function countInAnswer(choiceId, answer) {
|
|
196
227
|
var out = answer.reduce(function (acc, a) {
|
|
197
228
|
return acc + countInChoices(choiceId, a.choices);
|
|
@@ -199,26 +230,32 @@ var countInAnswer = function countInAnswer(choiceId, answer) {
|
|
|
199
230
|
log('[countInAnswer] choiceId:', choiceId, answer);
|
|
200
231
|
return out;
|
|
201
232
|
};
|
|
233
|
+
|
|
202
234
|
exports.countInAnswer = countInAnswer;
|
|
235
|
+
|
|
203
236
|
var countInChoices = function countInChoices(choiceId, choices) {
|
|
204
237
|
return (choices || []).filter(function (c) {
|
|
205
238
|
return c === choiceId;
|
|
206
239
|
}).length;
|
|
207
240
|
};
|
|
208
|
-
|
|
209
241
|
/**
|
|
210
242
|
* Count the number of times a choice has been selected in categories.
|
|
211
243
|
* @param {*} choice
|
|
212
244
|
* @param {*} categories
|
|
213
245
|
*/
|
|
246
|
+
|
|
247
|
+
|
|
214
248
|
exports.countInChoices = countInChoices;
|
|
249
|
+
|
|
215
250
|
var countChosen = function countChosen(choice, categories) {
|
|
216
251
|
if (!choice || !choice.id) {
|
|
217
252
|
return 0;
|
|
218
253
|
}
|
|
254
|
+
|
|
219
255
|
if (!Array.isArray(categories)) {
|
|
220
256
|
return 0;
|
|
221
257
|
}
|
|
258
|
+
|
|
222
259
|
return categories.reduce(function (acc, c) {
|
|
223
260
|
var count = (c.choices || []).filter(function (h) {
|
|
224
261
|
return h.id === choice.id;
|
|
@@ -226,24 +263,28 @@ var countChosen = function countChosen(choice, categories) {
|
|
|
226
263
|
return acc + count;
|
|
227
264
|
}, 0);
|
|
228
265
|
};
|
|
229
|
-
|
|
230
266
|
/**
|
|
231
267
|
* @param {string?} categoryId
|
|
232
268
|
* @param {{category:string, choices: string[]}} answers
|
|
233
269
|
*/
|
|
270
|
+
|
|
271
|
+
|
|
234
272
|
exports.countChosen = countChosen;
|
|
273
|
+
|
|
235
274
|
var removeCategory = function removeCategory(categoryId, answers) {
|
|
236
275
|
return answers.filter(function (a) {
|
|
237
276
|
return a.category !== categoryId;
|
|
238
277
|
});
|
|
239
278
|
};
|
|
240
|
-
|
|
241
279
|
/**
|
|
242
280
|
* @param {string} choiceId
|
|
243
281
|
* @param {{category:string, choices: string[]}} answers
|
|
244
282
|
* @param {string?} categoryId - optional categegory id
|
|
245
283
|
*/
|
|
284
|
+
|
|
285
|
+
|
|
246
286
|
exports.removeCategory = removeCategory;
|
|
287
|
+
|
|
247
288
|
var removeAllChoices = function removeAllChoices(choiceId, answers, categoryId) {
|
|
248
289
|
return answers.map(function (a) {
|
|
249
290
|
if (!categoryId || a.category === categoryId) {
|
|
@@ -259,15 +300,20 @@ var removeAllChoices = function removeAllChoices(choiceId, answers, categoryId)
|
|
|
259
300
|
}
|
|
260
301
|
});
|
|
261
302
|
};
|
|
303
|
+
|
|
262
304
|
exports.removeAllChoices = removeAllChoices;
|
|
305
|
+
|
|
263
306
|
var rearrangeChoices = function rearrangeChoices(choices, indexFrom, indexTo) {
|
|
264
307
|
if (choices.length === 0) {
|
|
265
308
|
return choices;
|
|
266
309
|
}
|
|
310
|
+
|
|
267
311
|
choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);
|
|
268
312
|
return choices;
|
|
269
313
|
};
|
|
314
|
+
|
|
270
315
|
exports.rearrangeChoices = rearrangeChoices;
|
|
316
|
+
|
|
271
317
|
var verifyAllowMultiplePlacements = function verifyAllowMultiplePlacements(choice, categoryId, answers) {
|
|
272
318
|
return answers.map(function (a) {
|
|
273
319
|
if (a.category !== categoryId) {
|
|
@@ -281,19 +327,23 @@ var verifyAllowMultiplePlacements = function verifyAllowMultiplePlacements(choic
|
|
|
281
327
|
var foundIndex = acc.findIndex(function (c) {
|
|
282
328
|
return c.id === choice.id;
|
|
283
329
|
});
|
|
330
|
+
|
|
284
331
|
if (foundIndex === -1) {
|
|
285
332
|
acc.push(currentValue);
|
|
286
333
|
}
|
|
287
334
|
} else {
|
|
288
335
|
acc.push(currentValue);
|
|
289
336
|
}
|
|
337
|
+
|
|
290
338
|
return acc;
|
|
291
339
|
}, []);
|
|
292
340
|
return a;
|
|
293
341
|
}
|
|
294
342
|
});
|
|
295
343
|
};
|
|
344
|
+
|
|
296
345
|
exports.verifyAllowMultiplePlacements = verifyAllowMultiplePlacements;
|
|
346
|
+
|
|
297
347
|
var removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categoryId, choiceIndex, answers) {
|
|
298
348
|
log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);
|
|
299
349
|
return answers.map(function (a) {
|
|
@@ -302,9 +352,11 @@ var removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categ
|
|
|
302
352
|
var index = cloned.findIndex(function (v, index) {
|
|
303
353
|
return v === choiceId && index >= choiceIndex;
|
|
304
354
|
});
|
|
355
|
+
|
|
305
356
|
if (index !== -1) {
|
|
306
357
|
cloned.splice(index, 1);
|
|
307
358
|
}
|
|
359
|
+
|
|
308
360
|
return _objectSpread(_objectSpread({}, a), {}, {
|
|
309
361
|
choices: cloned
|
|
310
362
|
});
|
|
@@ -313,18 +365,24 @@ var removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categ
|
|
|
313
365
|
}
|
|
314
366
|
});
|
|
315
367
|
};
|
|
368
|
+
|
|
316
369
|
exports.removeChoiceFromCategory = removeChoiceFromCategory;
|
|
370
|
+
|
|
317
371
|
var moveChoiceToCategory = function moveChoiceToCategory(choiceId, from, to, choiceIndex, answers) {
|
|
318
372
|
log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);
|
|
373
|
+
|
|
319
374
|
if (from === to) {
|
|
320
375
|
return answers;
|
|
321
376
|
}
|
|
377
|
+
|
|
322
378
|
if (from) {
|
|
323
379
|
answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);
|
|
324
380
|
}
|
|
381
|
+
|
|
325
382
|
var index = answers.findIndex(function (a) {
|
|
326
383
|
return a.category === to;
|
|
327
384
|
});
|
|
385
|
+
|
|
328
386
|
if (index === -1) {
|
|
329
387
|
answers.push({
|
|
330
388
|
category: to,
|
|
@@ -338,16 +396,21 @@ var moveChoiceToCategory = function moveChoiceToCategory(choiceId, from, to, cho
|
|
|
338
396
|
a.choices.push(choiceId);
|
|
339
397
|
return a;
|
|
340
398
|
}
|
|
399
|
+
|
|
341
400
|
return a;
|
|
342
401
|
});
|
|
343
402
|
}
|
|
344
403
|
};
|
|
404
|
+
|
|
345
405
|
exports.moveChoiceToCategory = moveChoiceToCategory;
|
|
406
|
+
|
|
346
407
|
var moveChoiceToAlternate = function moveChoiceToAlternate(choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) {
|
|
347
408
|
log('[moveChoiceToAlternate] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers, 'chocieIndex: ', choiceIndex);
|
|
409
|
+
|
|
348
410
|
if (from === to) {
|
|
349
411
|
return answers;
|
|
350
412
|
}
|
|
413
|
+
|
|
351
414
|
return answers.map(function (a) {
|
|
352
415
|
if (a.category === to) {
|
|
353
416
|
if (categoryCount !== 0 && a.alternateResponses) {
|
|
@@ -355,21 +418,27 @@ var moveChoiceToAlternate = function moveChoiceToAlternate(choiceId, from, to, c
|
|
|
355
418
|
return resp !== choiceId;
|
|
356
419
|
});
|
|
357
420
|
}
|
|
421
|
+
|
|
358
422
|
if (!a.alternateResponses) {
|
|
359
423
|
a.alternateResponses = [];
|
|
360
424
|
a.alternateResponses[alternateIndex] = [];
|
|
361
425
|
}
|
|
426
|
+
|
|
362
427
|
a.alternateResponses[alternateIndex].push(choiceId);
|
|
363
428
|
}
|
|
429
|
+
|
|
364
430
|
if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {
|
|
365
431
|
a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter(function (resp) {
|
|
366
432
|
return resp !== choiceId;
|
|
367
433
|
});
|
|
368
434
|
}
|
|
435
|
+
|
|
369
436
|
return a;
|
|
370
437
|
});
|
|
371
438
|
};
|
|
439
|
+
|
|
372
440
|
exports.moveChoiceToAlternate = moveChoiceToAlternate;
|
|
441
|
+
|
|
373
442
|
var stillSelectable = function stillSelectable(h, builtCategories) {
|
|
374
443
|
if (h.categoryCount > 0) {
|
|
375
444
|
var count = countChosen(h, builtCategories);
|
|
@@ -378,7 +447,6 @@ var stillSelectable = function stillSelectable(h, builtCategories) {
|
|
|
378
447
|
return true;
|
|
379
448
|
}
|
|
380
449
|
};
|
|
381
|
-
|
|
382
450
|
/**
|
|
383
451
|
* returns all choices with property 'correct' set to boolean
|
|
384
452
|
* @param {string[]} possibleResponseChoices
|
|
@@ -387,15 +455,18 @@ var stillSelectable = function stillSelectable(h, builtCategories) {
|
|
|
387
455
|
* @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean
|
|
388
456
|
* BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
|
|
389
457
|
*/
|
|
458
|
+
|
|
459
|
+
|
|
390
460
|
exports.stillSelectable = stillSelectable;
|
|
461
|
+
|
|
391
462
|
var buildChoices = function buildChoices(possibleResponseChoices, builtCategoryChoices) {
|
|
392
463
|
return builtCategoryChoices.reduce(function (acc, builtChoice) {
|
|
393
464
|
// set correct value on each choice that was selected by user
|
|
394
465
|
var index = acc.copyOfPossibleResponse.findIndex(function (cRC) {
|
|
395
466
|
return cRC === builtChoice.id;
|
|
396
|
-
});
|
|
397
|
-
// if the choice exists in the correct response
|
|
467
|
+
}); // if the choice exists in the correct response
|
|
398
468
|
// set the correct: true
|
|
469
|
+
|
|
399
470
|
if (index >= 0) {
|
|
400
471
|
acc.builtChoices.push(_objectSpread(_objectSpread({}, builtChoice), {}, {
|
|
401
472
|
correct: true
|
|
@@ -407,6 +478,7 @@ var buildChoices = function buildChoices(possibleResponseChoices, builtCategoryC
|
|
|
407
478
|
}));
|
|
408
479
|
acc.allChoicesAreCorrect = false;
|
|
409
480
|
}
|
|
481
|
+
|
|
410
482
|
return acc;
|
|
411
483
|
}, {
|
|
412
484
|
builtChoices: [],
|
|
@@ -414,7 +486,6 @@ var buildChoices = function buildChoices(possibleResponseChoices, builtCategoryC
|
|
|
414
486
|
allChoicesAreCorrect: true
|
|
415
487
|
});
|
|
416
488
|
};
|
|
417
|
-
|
|
418
489
|
/**
|
|
419
490
|
* returns corrected answer using this possible correct response
|
|
420
491
|
* @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }
|
|
@@ -424,15 +495,20 @@ var buildChoices = function buildChoices(possibleResponseChoices, builtCategoryC
|
|
|
424
495
|
* BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }
|
|
425
496
|
* BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }
|
|
426
497
|
*/
|
|
498
|
+
|
|
499
|
+
|
|
427
500
|
exports.buildChoices = buildChoices;
|
|
501
|
+
|
|
428
502
|
var getBuiltCategories = function getBuiltCategories(possibleResponse, builtCategories) {
|
|
429
503
|
return builtCategories.reduce(function (acc, builtCategory) {
|
|
430
504
|
var possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category
|
|
505
|
+
|
|
431
506
|
var builtCategoryChoices = builtCategory.choices || []; // the choices in the answer
|
|
432
507
|
|
|
433
508
|
var _buildChoices = buildChoices(possibleResponseChoices, builtCategoryChoices),
|
|
434
|
-
|
|
435
|
-
|
|
509
|
+
builtChoices = _buildChoices.builtChoices,
|
|
510
|
+
allChoicesAreCorrect = _buildChoices.allChoicesAreCorrect;
|
|
511
|
+
|
|
436
512
|
var allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;
|
|
437
513
|
acc.builtCategories.push(_objectSpread(_objectSpread({}, builtCategory), {}, {
|
|
438
514
|
correct: allChoicesAreCorrect && allChoicesAreInAnswer,
|
|
@@ -445,7 +521,6 @@ var getBuiltCategories = function getBuiltCategories(possibleResponse, builtCate
|
|
|
445
521
|
correct: true
|
|
446
522
|
});
|
|
447
523
|
};
|
|
448
|
-
|
|
449
524
|
/**
|
|
450
525
|
* returns all the possible responses by combining the proper alternate responses
|
|
451
526
|
* @param {Object[]} correctResponse
|
|
@@ -453,20 +528,24 @@ var getBuiltCategories = function getBuiltCategories(possibleResponse, builtCate
|
|
|
453
528
|
* @returns {Object[]}, returns Response[]
|
|
454
529
|
* Response = { CategoryId: ChoiceId[] },
|
|
455
530
|
*/
|
|
531
|
+
|
|
532
|
+
|
|
456
533
|
exports.getBuiltCategories = getBuiltCategories;
|
|
534
|
+
|
|
457
535
|
var getAllPossibleResponses = function getAllPossibleResponses(correctResponse) {
|
|
458
536
|
if (!correctResponse) {
|
|
459
537
|
return [];
|
|
460
538
|
}
|
|
539
|
+
|
|
461
540
|
return correctResponse.reduce(function (acc, cR) {
|
|
462
541
|
// main response
|
|
463
542
|
if (acc[0]) {
|
|
464
543
|
acc[0][cR.category] = cR.choices;
|
|
465
544
|
} else {
|
|
466
545
|
acc.push((0, _defineProperty2["default"])({}, cR.category, cR.choices));
|
|
467
|
-
}
|
|
546
|
+
} // alternate responses
|
|
547
|
+
|
|
468
548
|
|
|
469
|
-
// alternate responses
|
|
470
549
|
if (cR.alternateResponses) {
|
|
471
550
|
cR.alternateResponses.forEach(function (aR, index) {
|
|
472
551
|
if (acc[index + 1]) {
|
|
@@ -476,10 +555,10 @@ var getAllPossibleResponses = function getAllPossibleResponses(correctResponse)
|
|
|
476
555
|
}
|
|
477
556
|
});
|
|
478
557
|
}
|
|
558
|
+
|
|
479
559
|
return acc;
|
|
480
560
|
}, []);
|
|
481
561
|
};
|
|
482
|
-
|
|
483
562
|
/**
|
|
484
563
|
* build the categories to be displayed, where each category has its own list of choices
|
|
485
564
|
* @param {Object[]} categories
|
|
@@ -490,7 +569,10 @@ var getAllPossibleResponses = function getAllPossibleResponses(correctResponse)
|
|
|
490
569
|
* BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},
|
|
491
570
|
* BuiltChoice = { id: choiceId, content: choiceContent }
|
|
492
571
|
*/
|
|
572
|
+
|
|
573
|
+
|
|
493
574
|
exports.getAllPossibleResponses = getAllPossibleResponses;
|
|
575
|
+
|
|
494
576
|
var buildCategories = function buildCategories(categories, choices, answers) {
|
|
495
577
|
categories = categories || [];
|
|
496
578
|
answers = answers || [];
|
|
@@ -499,9 +581,11 @@ var buildCategories = function buildCategories(categories, choices, answers) {
|
|
|
499
581
|
var answer = answers.find(function (answer) {
|
|
500
582
|
return answer.category === category.id;
|
|
501
583
|
});
|
|
584
|
+
|
|
502
585
|
var _ref = answer || {},
|
|
503
|
-
|
|
504
|
-
|
|
586
|
+
_ref$choices = _ref.choices,
|
|
587
|
+
answerChoices = _ref$choices === void 0 ? [] : _ref$choices;
|
|
588
|
+
|
|
505
589
|
return _objectSpread(_objectSpread({}, category), {}, {
|
|
506
590
|
choices: answerChoices.map(function (chId) {
|
|
507
591
|
return choices.find(function (ch) {
|
|
@@ -511,7 +595,6 @@ var buildCategories = function buildCategories(categories, choices, answers) {
|
|
|
511
595
|
});
|
|
512
596
|
});
|
|
513
597
|
};
|
|
514
|
-
|
|
515
598
|
/**
|
|
516
599
|
* build the choice and category state
|
|
517
600
|
* @param {Object[]} categories
|
|
@@ -521,7 +604,10 @@ var buildCategories = function buildCategories(categories, choices, answers) {
|
|
|
521
604
|
* @param correctResponse
|
|
522
605
|
* @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }
|
|
523
606
|
*/
|
|
607
|
+
|
|
608
|
+
|
|
524
609
|
exports.buildCategories = buildCategories;
|
|
610
|
+
|
|
525
611
|
var buildState = function buildState(categories, choices, answers, correctResponse) {
|
|
526
612
|
categories = categories || [];
|
|
527
613
|
choices = choices || [];
|
|
@@ -529,17 +615,16 @@ var buildState = function buildState(categories, choices, answers, correctRespon
|
|
|
529
615
|
var allResponses = getAllPossibleResponses(correctResponse) || [];
|
|
530
616
|
var builtCategories = buildCategories(categories, choices, answers);
|
|
531
617
|
var bestResponse;
|
|
532
|
-
var entirelyCorrect;
|
|
618
|
+
var entirelyCorrect; // at least one defined correct response
|
|
533
619
|
|
|
534
|
-
// at least one defined correct response
|
|
535
620
|
if (allResponses.length) {
|
|
536
621
|
var builtData = allResponses.reduce(function (acc, possibleResponse) {
|
|
537
622
|
// set correctness for each possible response
|
|
538
623
|
var _getBuiltCategories = getBuiltCategories(possibleResponse, builtCategories),
|
|
539
|
-
|
|
540
|
-
|
|
624
|
+
categoriesWithChoices = _getBuiltCategories.builtCategories,
|
|
625
|
+
correct = _getBuiltCategories.correct; // if bestResponse not found yet OR no correct response found yet and this one is the correct one
|
|
626
|
+
|
|
541
627
|
|
|
542
|
-
// if bestResponse not found yet OR no correct response found yet and this one is the correct one
|
|
543
628
|
if (acc.bestResponse === null || !acc.entirelyCorrect && correct) {
|
|
544
629
|
return {
|
|
545
630
|
bestResponse: possibleResponse,
|
|
@@ -547,6 +632,7 @@ var buildState = function buildState(categories, choices, answers, correctRespon
|
|
|
547
632
|
entirelyCorrect: correct
|
|
548
633
|
};
|
|
549
634
|
}
|
|
635
|
+
|
|
550
636
|
return acc;
|
|
551
637
|
}, {
|
|
552
638
|
bestResponse: null,
|
|
@@ -557,6 +643,7 @@ var buildState = function buildState(categories, choices, answers, correctRespon
|
|
|
557
643
|
bestResponse = builtData.bestResponse;
|
|
558
644
|
entirelyCorrect = builtData.entirelyCorrect;
|
|
559
645
|
}
|
|
646
|
+
|
|
560
647
|
var filteredChoices = choices.map(function (ch) {
|
|
561
648
|
return stillSelectable(ch, builtCategories) ? ch : {
|
|
562
649
|
empty: true
|
|
@@ -569,5 +656,6 @@ var buildState = function buildState(categories, choices, answers, correctRespon
|
|
|
569
656
|
bestResponse: bestResponse
|
|
570
657
|
};
|
|
571
658
|
};
|
|
659
|
+
|
|
572
660
|
exports.buildState = buildState;
|
|
573
661
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["FooTwo","log","debug","limitChoices","choiceId","count","choices","out","reduce","acc","id","foundCount","countInChoices","push","limitInArrays","arrays","limit","result","array","l","limitInArray","arr","stripped","filter","v","length","ensureNoExtraChoicesInAnswer","answer","answerArray","choice","categoryCount","undefined","map","a","updatedArray","r","index","category","alternateResponses","ensureNoExtraChoicesInAlternate","alternatePair","forEach","alternate","recreatedAlternate","Object","keys","k","limitAlternate","item","countInAnswer","c","countChosen","categories","Array","isArray","h","removeCategory","categoryId","answers","removeAllChoices","cloned","clone","remove","rearrangeChoices","indexFrom","indexTo","splice","verifyAllowMultiplePlacements","currentValue","foundIndex","findIndex","removeChoiceFromCategory","choiceIndex","moveChoiceToCategory","from","to","moveChoiceToAlternate","alternateIndex","resp","stillSelectable","builtCategories","buildChoices","possibleResponseChoices","builtCategoryChoices","builtChoice","copyOfPossibleResponse","cRC","builtChoices","correct","slice","allChoicesAreCorrect","getBuiltCategories","possibleResponse","builtCategory","allChoicesAreInAnswer","getAllPossibleResponses","correctResponse","cR","aR","buildCategories","find","answerChoices","chId","ch","buildState","allResponses","bestResponse","entirelyCorrect","builtData","categoriesWithChoices","filteredChoices","empty"],"sources":["../src/index.js"],"sourcesContent":["import compact from 'lodash/compact';\nimport debug from 'debug';\nimport clone from 'lodash/clone';\nimport cloneDeep from 'lodash/cloneDeep';\nimport remove from 'lodash/remove';\nimport every from 'lodash/every';\nimport isEqual from 'lodash/isEqual';\nimport isUndefined from 'lodash/isUndefined';\nimport { score } from './scoring';\n\nexport { score };\n\nexport const FooTwo = 'foo-two';\n\nconst log = debug('@pie-lib:categorize');\nexport const limitChoices = (choiceId, count, choices) => {\n const out = choices.reduce(\n (acc, id) => {\n const foundCount = countInChoices(choiceId, acc.choices);\n // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);\n if (id !== choiceId || foundCount < count) {\n acc.choices.push(id);\n }\n return acc;\n },\n { choices: [] },\n );\n\n return out.choices;\n};\n\n/**\n * Limit in an array of arrays.\n * So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]\n * @param {*} id\n * @param {*} arrays\n * @param {*} limit\n */\nexport const limitInArrays = (id, arrays, limit) => {\n arrays = arrays || [];\n\n const result = arrays.reduce(\n (acc, array) => {\n const l = limit - acc.count;\n const result = limitInArray(id, array, l);\n acc.out.push(result.array);\n acc.count = acc.count + (result.count || 0);\n return acc;\n },\n { out: [], count: 0 },\n );\n\n return result.out;\n};\n\n/**\n * Limit the id in the array to the limit set.\n * So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]\n * @param {string} id\n * @param {string[]} arr\n * @param {number} limit\n */\nexport const limitInArray = (id, arr, limit) => {\n arr = arr || [];\n\n if (limit === 0) {\n const stripped = arr.filter((v) => v !== id);\n return { array: stripped, count: arr.length - stripped.length };\n } else {\n const result = arr.reduce(\n (acc, v) => {\n if (v === id) {\n if (acc.count < limit) {\n acc.count += 1;\n acc.out.push(v);\n }\n } else {\n acc.out.push(v);\n }\n return acc;\n },\n { out: [], count: 0 },\n );\n\n return { array: result.out, count: result.count };\n }\n};\n\n/**\n * Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.\n * @param {{category: string, choices: string[]}[]} answer\n * @param {{id:string,categoryCount:number}} choices\n */\nexport const ensureNoExtraChoicesInAnswer = (answer, choices) => {\n choices = choices || [];\n\n const out = choices.reduce((answerArray, choice) => {\n log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);\n // log('answer array: ', answerArray);\n if (choice.categoryCount === undefined || choice.categoryCount === 0) {\n return answerArray;\n } else {\n const choices = answerArray.map((a) => a.choices);\n const result = limitInArrays(choice.id, choices, choice.categoryCount);\n const updatedArray = result.map((r, index) => {\n return {\n category: answerArray[index].category,\n alternateResponses: answerArray[index].alternateResponses,\n choices: r,\n };\n });\n return updatedArray;\n }\n }, answer);\n return out;\n};\n\n/**\n * Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.\n * @param {{category: string, choices: string[]}[]} answer\n * @param {{id:string,categoryCount:number}} choices\n */\n\nexport const ensureNoExtraChoicesInAlternate = (answer, choices) => {\n choices = choices || [];\n\n const out = choices.reduce((answerArray, choice) => {\n log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);\n // log('answer array: ', answerArray);\n if (choice.categoryCount === undefined || choice.categoryCount === 0) {\n return answerArray;\n } else {\n let alternatePair = {};\n answerArray.forEach((answer) =>\n (answer.alternateResponses || []).forEach((alternate, index) => {\n if (index in alternatePair) {\n alternatePair[index].push(alternate);\n } else {\n alternatePair[index] = [];\n alternatePair[index].push(alternate);\n }\n }),\n );\n\n const recreatedAlternate = [];\n Object.keys(alternatePair).forEach((k) => {\n const limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);\n alternatePair[k] = limitAlternate;\n alternatePair[k].forEach((item, index) => {\n if (!recreatedAlternate[index]) {\n recreatedAlternate[index] = [];\n recreatedAlternate[index].push(item);\n } else {\n recreatedAlternate[index].push(item);\n }\n });\n });\n\n const updatedArray = answerArray.map((answer, index) => {\n return {\n category: answer.category,\n alternateResponses: recreatedAlternate[index] || answer.alternateResponses,\n choices: answer.choices,\n };\n });\n return updatedArray;\n }\n }, answer);\n return out;\n};\n/**\n * Count the number of choice ids in a given answer array\n * @param {string} choiceId\n * @param {{category: string, choices: string[]}[]} answer\n */\nexport const countInAnswer = (choiceId, answer) => {\n const out = answer.reduce((acc, a) => acc + countInChoices(choiceId, a.choices), 0);\n log('[countInAnswer] choiceId:', choiceId, answer);\n return out;\n};\n\nexport const countInChoices = (choiceId, choices) => (choices || []).filter((c) => c === choiceId).length;\n\n/**\n * Count the number of times a choice has been selected in categories.\n * @param {*} choice\n * @param {*} categories\n */\nexport const countChosen = (choice, categories) => {\n if (!choice || !choice.id) {\n return 0;\n }\n\n if (!Array.isArray(categories)) {\n return 0;\n }\n\n return categories.reduce((acc, c) => {\n const count = (c.choices || []).filter((h) => h.id === choice.id).length;\n return acc + count;\n }, 0);\n};\n\n/**\n * @param {string?} categoryId\n * @param {{category:string, choices: string[]}} answers\n */\nexport const removeCategory = (categoryId, answers) => answers.filter((a) => a.category !== categoryId);\n\n/**\n * @param {string} choiceId\n * @param {{category:string, choices: string[]}} answers\n * @param {string?} categoryId - optional categegory id\n */\nexport const removeAllChoices = (choiceId, answers, categoryId) => {\n return answers.map((a) => {\n if (!categoryId || a.category === categoryId) {\n const cloned = clone(a.choices);\n remove(cloned, (v) => v === choiceId);\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const rearrangeChoices = (choices, indexFrom, indexTo) => {\n if (choices.length === 0) {\n return choices;\n }\n choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);\n return choices;\n};\n\nexport const verifyAllowMultiplePlacements = (choice, categoryId, answers) => {\n return answers.map((a) => {\n if (a.category !== categoryId) {\n a.choices = (a.choices || []).filter((c) => c !== choice.id);\n return a;\n } else {\n a.choices = a.choices.reduce((acc, currentValue) => {\n if (currentValue.id === choice.id) {\n const foundIndex = acc.findIndex((c) => c.id === choice.id);\n if (foundIndex === -1) {\n acc.push(currentValue);\n }\n } else {\n acc.push(currentValue);\n }\n\n return acc;\n }, []);\n return a;\n }\n });\n};\n\nexport const removeChoiceFromCategory = (choiceId, categoryId, choiceIndex, answers) => {\n log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);\n\n return answers.map((a) => {\n if (a.category === categoryId) {\n const cloned = clone(a.choices);\n const index = cloned.findIndex((v, index) => {\n return v === choiceId && index >= choiceIndex;\n });\n if (index !== -1) {\n cloned.splice(index, 1);\n }\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const moveChoiceToCategory = (choiceId, from, to, choiceIndex, answers) => {\n log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);\n\n if (from === to) {\n return answers;\n }\n\n if (from) {\n answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);\n }\n\n const index = answers.findIndex((a) => a.category === to);\n if (index === -1) {\n answers.push({ category: to, choices: [choiceId] });\n return answers;\n } else {\n return answers.map((a) => {\n if (a.category === to) {\n a.choices = a.choices || [];\n a.choices.push(choiceId);\n return a;\n }\n return a;\n });\n }\n};\n\nexport const moveChoiceToAlternate = (choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) => {\n log(\n '[moveChoiceToAlternate] choice: ',\n choiceId,\n 'from: ',\n from,\n 'to: ',\n to,\n 'answers: ',\n answers,\n 'chocieIndex: ',\n choiceIndex,\n );\n\n if (from === to) {\n return answers;\n }\n\n return answers.map((a) => {\n if (a.category === to) {\n if (categoryCount !== 0 && a.alternateResponses) {\n a.alternateResponses[alternateIndex] = (a.alternateResponses[alternateIndex] || []).filter(\n (resp) => resp !== choiceId,\n );\n }\n if (!a.alternateResponses) {\n a.alternateResponses = [];\n a.alternateResponses[alternateIndex] = [];\n }\n a.alternateResponses[alternateIndex].push(choiceId);\n }\n\n if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {\n a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter((resp) => resp !== choiceId);\n }\n\n return a;\n });\n};\n\nexport const stillSelectable = (h, builtCategories) => {\n if (h.categoryCount > 0) {\n const count = countChosen(h, builtCategories);\n return count < h.categoryCount;\n } else {\n return true;\n }\n};\n\n/**\n * returns all choices with property 'correct' set to boolean\n * @param {string[]} possibleResponseChoices\n * @param {Object[]} builtCategoryChoices\n *\n * @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean\n * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }\n */\nexport const buildChoices = (possibleResponseChoices, builtCategoryChoices) => {\n return builtCategoryChoices.reduce(\n (acc, builtChoice) => {\n // set correct value on each choice that was selected by user\n const index = acc.copyOfPossibleResponse.findIndex((cRC) => cRC === builtChoice.id);\n // if the choice exists in the correct response\n // set the correct: true\n if (index >= 0) {\n acc.builtChoices.push({\n ...builtChoice,\n correct: true,\n });\n acc.copyOfPossibleResponse = [\n ...acc.copyOfPossibleResponse.slice(0, index),\n ...acc.copyOfPossibleResponse.slice(index + 1),\n ];\n } else {\n acc.builtChoices.push({\n ...builtChoice,\n correct: false,\n });\n acc.allChoicesAreCorrect = false;\n }\n\n return acc;\n },\n {\n builtChoices: [],\n copyOfPossibleResponse: [...possibleResponseChoices],\n allChoicesAreCorrect: true,\n },\n );\n};\n\n/**\n * returns corrected answer using this possible correct response\n * @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }\n * @param {Object[]} builtCategories\n *\n * @returns {Object}, returns builtCategories: BuiltCategory[] and correct: boolean\n * BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }\n * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }\n */\nexport const getBuiltCategories = (possibleResponse, builtCategories) =>\n builtCategories.reduce(\n (acc, builtCategory) => {\n const possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category\n const builtCategoryChoices = builtCategory.choices || []; // the choices in the answer\n\n const { builtChoices, allChoicesAreCorrect } = buildChoices(possibleResponseChoices, builtCategoryChoices);\n const allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;\n\n acc.builtCategories.push({\n ...builtCategory,\n correct: allChoicesAreCorrect && allChoicesAreInAnswer,\n choices: builtChoices,\n });\n acc.correct = acc.correct && allChoicesAreCorrect && allChoicesAreInAnswer;\n\n return acc;\n },\n { builtCategories: [], correct: true },\n );\n\n/**\n * returns all the possible responses by combining the proper alternate responses\n * @param {Object[]} correctResponse\n *\n * @returns {Object[]}, returns Response[]\n * Response = { CategoryId: ChoiceId[] },\n */\nexport const getAllPossibleResponses = (correctResponse) => {\n if (!correctResponse) {\n return [];\n }\n\n return correctResponse.reduce((acc, cR) => {\n // main response\n if (acc[0]) {\n acc[0][cR.category] = cR.choices;\n } else {\n acc.push({ [cR.category]: cR.choices });\n }\n\n // alternate responses\n if (cR.alternateResponses) {\n cR.alternateResponses.forEach((aR, index) => {\n if (acc[index + 1]) {\n acc[index + 1][cR.category] = aR;\n } else {\n acc.push({ [cR.category]: aR });\n }\n });\n }\n\n return acc;\n }, []);\n};\n\n/**\n * build the categories to be displayed, where each category has its own list of choices\n * @param {Object[]} categories\n * @param {{id:string}[]} choices\n * @param {{category: string, choices:string[]}[]} answers\n *\n * @returns {Object[]}, returns BuiltCategory[]\n * BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},\n * BuiltChoice = { id: choiceId, content: choiceContent }\n */\nexport const buildCategories = (categories, choices, answers) => {\n categories = categories || [];\n answers = answers || [];\n choices = choices || [];\n\n return categories.map((category) => {\n const answer = answers.find((answer) => answer.category === category.id);\n const { choices: answerChoices = [] } = answer || {};\n\n return {\n ...category,\n choices: answerChoices.map((chId) => choices.find((ch) => ch.id === chId)),\n };\n });\n};\n\n/**\n * build the choice and category state\n * @param {Object[]} categories\n * @param {{id:string}[]} choices\n * @param {{category: string, choices:string[]}[]} answers\n *\n * @param correctResponse\n * @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }\n */\nexport const buildState = (categories, choices, answers, correctResponse) => {\n categories = categories || [];\n choices = choices || [];\n answers = answers || [];\n\n const allResponses = getAllPossibleResponses(correctResponse) || [];\n\n let builtCategories = buildCategories(categories, choices, answers);\n let bestResponse;\n let entirelyCorrect;\n\n // at least one defined correct response\n if (allResponses.length) {\n const builtData = allResponses.reduce(\n (acc, possibleResponse) => {\n // set correctness for each possible response\n const { builtCategories: categoriesWithChoices, correct } = getBuiltCategories(\n possibleResponse,\n builtCategories,\n );\n\n // if bestResponse not found yet OR no correct response found yet and this one is the correct one\n if (acc.bestResponse === null || (!acc.entirelyCorrect && correct)) {\n return {\n bestResponse: possibleResponse,\n builtCategories: categoriesWithChoices,\n entirelyCorrect: correct,\n };\n }\n\n return acc;\n },\n {\n bestResponse: null,\n builtCategories: [],\n entirelyCorrect: false,\n },\n );\n\n builtCategories = builtData.builtCategories;\n bestResponse = builtData.bestResponse;\n entirelyCorrect = builtData.entirelyCorrect;\n }\n\n const filteredChoices = choices.map((ch) => (stillSelectable(ch, builtCategories) ? ch : { empty: true }));\n\n return {\n choices: filteredChoices,\n categories: builtCategories,\n correct: entirelyCorrect,\n bestResponse,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAkC;AAAA;AAI3B,IAAMA,MAAM,GAAG,SAAS;AAAC;AAEhC,IAAMC,GAAG,GAAG,IAAAC,iBAAK,EAAC,qBAAqB,CAAC;AACjC,IA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AO,EAAEoD,OAAO,CAAC;EACnE,IAAIgD,YAAY;EAChB,IAAIC,eAAe;;EAEnB;EACA,IAAIF,YAAY,CAAChF,MAAM,EAAE;IACvB,IAAMmF,SAAS,GAAGH,YAAY,CAACjG,MAAM,CACnC,UAACC,GAAG,EAAEmF,gBAAgB,EAAK;MACzB;MACA,0BAA4DD,kBAAkB,CAC5EC,gBAAgB,EAChBZ,eAAe,CAChB;QAHwB6B,qBAAqB,uBAAtC7B,eAAe;QAAyBQ,OAAO,uBAAPA,OAAO;;MAKvD;MACA,IAAI/E,GAAG,CAACiG,YAAY,KAAK,IAAI,IAAK,CAACjG,GAAG,CAACkG,eAAe,IAAInB,OAAQ,EAAE;QAClE,OAAO;UACLkB,YAAY,EAAEd,gBAAgB;UAC9BZ,eAAe,EAAE6B,qBAAqB;UACtCF,eAAe,EAAEnB;QACnB,CAAC;MACH;MAEA,OAAO/E,GAAG;IACZ,CAAC,EACD;MACEiG,YAAY,EAAE,IAAI;MAClB1B,eAAe,EAAE,EAAE;MACnB2B,eAAe,EAAE;IACnB,CAAC,CACF;IAED3B,eAAe,GAAG4B,SAAS,CAAC5B,eAAe;IAC3C0B,YAAY,GAAGE,SAAS,CAACF,YAAY;IACrCC,eAAe,GAAGC,SAAS,CAACD,eAAe;EAC7C;EAEA,IAAMG,eAAe,GAAGxG,OAAO,CAAC0B,GAAG,CAAC,UAACuE,EAAE;IAAA,OAAMxB,eAAe,CAACwB,EAAE,EAAEvB,eAAe,CAAC,GAAGuB,EAAE,GAAG;MAAEQ,KAAK,EAAE;IAAK,CAAC;EAAA,CAAC,CAAC;EAE1G,OAAO;IACLzG,OAAO,EAAEwG,eAAe;IACxB1D,UAAU,EAAE4B,eAAe;IAC3BQ,OAAO,EAAEmB,eAAe;IACxBD,YAAY,EAAZA;EACF,CAAC;AACH,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["FooTwo","log","limitChoices","choiceId","count","choices","out","reduce","acc","id","foundCount","countInChoices","push","limitInArrays","arrays","limit","result","array","l","limitInArray","arr","stripped","filter","v","length","ensureNoExtraChoicesInAnswer","answer","answerArray","choice","categoryCount","undefined","map","a","updatedArray","r","index","category","alternateResponses","ensureNoExtraChoicesInAlternate","alternatePair","forEach","alternate","recreatedAlternate","Object","keys","k","limitAlternate","item","countInAnswer","c","countChosen","categories","Array","isArray","h","removeCategory","categoryId","answers","removeAllChoices","cloned","rearrangeChoices","indexFrom","indexTo","splice","verifyAllowMultiplePlacements","currentValue","foundIndex","findIndex","removeChoiceFromCategory","choiceIndex","moveChoiceToCategory","from","to","moveChoiceToAlternate","alternateIndex","resp","stillSelectable","builtCategories","buildChoices","possibleResponseChoices","builtCategoryChoices","builtChoice","copyOfPossibleResponse","cRC","builtChoices","correct","slice","allChoicesAreCorrect","getBuiltCategories","possibleResponse","builtCategory","allChoicesAreInAnswer","getAllPossibleResponses","correctResponse","cR","aR","buildCategories","find","answerChoices","chId","ch","buildState","allResponses","bestResponse","entirelyCorrect","builtData","categoriesWithChoices","filteredChoices","empty"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAIO,IAAMA,MAAM,GAAG,SAAf;;AAEP,IAAMC,GAAG,GAAG,uBAAM,qBAAN,CAAZ;;AACO,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAACC,QAAD,EAAWC,KAAX,EAAkBC,OAAlB,EAA8B;AACxD,MAAMC,GAAG,GAAGD,OAAO,CAACE,MAAR,CACV,UAACC,GAAD,EAAMC,EAAN,EAAa;AACX,QAAMC,UAAU,GAAGC,cAAc,CAACR,QAAD,EAAWK,GAAG,CAACH,OAAf,CAAjC,CADW,CAEX;;AACA,QAAII,EAAE,KAAKN,QAAP,IAAmBO,UAAU,GAAGN,KAApC,EAA2C;AACzCI,MAAAA,GAAG,CAACH,OAAJ,CAAYO,IAAZ,CAAiBH,EAAjB;AACD;;AACD,WAAOD,GAAP;AAC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AAlB;AA0BA3B,IAAAA,eAAe,GAAG4B,SAAS,CAAC5B,eAA5B;AACA0B,IAAAA,YAAY,GAAGE,SAAS,CAACF,YAAzB;AACAC,IAAAA,eAAe,GAAGC,SAAS,CAACD,eAA5B;AACD;;AAED,MAAMG,eAAe,GAAGtG,OAAO,CAAC0B,GAAR,CAAY,UAACqE,EAAD;AAAA,WAASxB,eAAe,CAACwB,EAAD,EAAKvB,eAAL,CAAf,GAAuCuB,EAAvC,GAA4C;AAAEQ,MAAAA,KAAK,EAAE;AAAT,KAArD;AAAA,GAAZ,CAAxB;AAEA,SAAO;AACLvG,IAAAA,OAAO,EAAEsG,eADJ;AAELxD,IAAAA,UAAU,EAAE0B,eAFP;AAGLQ,IAAAA,OAAO,EAAEmB,eAHJ;AAILD,IAAAA,YAAY,EAAZA;AAJK,GAAP;AAMD,CApDM","sourcesContent":["import compact from 'lodash/compact';\nimport debug from 'debug';\nimport clone from 'lodash/clone';\nimport cloneDeep from 'lodash/cloneDeep';\nimport remove from 'lodash/remove';\nimport every from 'lodash/every';\nimport isEqual from 'lodash/isEqual';\nimport isUndefined from 'lodash/isUndefined';\nimport { score } from './scoring';\n\nexport { score };\n\nexport const FooTwo = 'foo-two';\n\nconst log = debug('@pie-lib:categorize');\nexport const limitChoices = (choiceId, count, choices) => {\n const out = choices.reduce(\n (acc, id) => {\n const foundCount = countInChoices(choiceId, acc.choices);\n // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);\n if (id !== choiceId || foundCount < count) {\n acc.choices.push(id);\n }\n return acc;\n },\n { choices: [] },\n );\n\n return out.choices;\n};\n\n/**\n * Limit in an array of arrays.\n * So for an array with [[1,1],[1,1]] if you call limitInArray(1, arr, 3) you'll get: [[1,1], [1]]\n * @param {*} id\n * @param {*} arrays\n * @param {*} limit\n */\nexport const limitInArrays = (id, arrays, limit) => {\n arrays = arrays || [];\n\n const result = arrays.reduce(\n (acc, array) => {\n const l = limit - acc.count;\n const result = limitInArray(id, array, l);\n acc.out.push(result.array);\n acc.count = acc.count + (result.count || 0);\n return acc;\n },\n { out: [], count: 0 },\n );\n\n return result.out;\n};\n\n/**\n * Limit the id in the array to the limit set.\n * So for an array with [1,1,1,1] if you call limitInArray(1, arr, 2) you'll get: [1,1]\n * @param {string} id\n * @param {string[]} arr\n * @param {number} limit\n */\nexport const limitInArray = (id, arr, limit) => {\n arr = arr || [];\n\n if (limit === 0) {\n const stripped = arr.filter((v) => v !== id);\n return { array: stripped, count: arr.length - stripped.length };\n } else {\n const result = arr.reduce(\n (acc, v) => {\n if (v === id) {\n if (acc.count < limit) {\n acc.count += 1;\n acc.out.push(v);\n }\n } else {\n acc.out.push(v);\n }\n return acc;\n },\n { out: [], count: 0 },\n );\n\n return { array: result.out, count: result.count };\n }\n};\n\n/**\n * Ensure that there are no extra choices in answer, if a choice.categoryCount is > 0.\n * @param {{category: string, choices: string[]}[]} answer\n * @param {{id:string,categoryCount:number}} choices\n */\nexport const ensureNoExtraChoicesInAnswer = (answer, choices) => {\n choices = choices || [];\n\n const out = choices.reduce((answerArray, choice) => {\n log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);\n // log('answer array: ', answerArray);\n if (choice.categoryCount === undefined || choice.categoryCount === 0) {\n return answerArray;\n } else {\n const choices = answerArray.map((a) => a.choices);\n const result = limitInArrays(choice.id, choices, choice.categoryCount);\n const updatedArray = result.map((r, index) => {\n return {\n category: answerArray[index].category,\n alternateResponses: answerArray[index].alternateResponses,\n choices: r,\n };\n });\n return updatedArray;\n }\n }, answer);\n return out;\n};\n\n/**\n * Ensure that there are no extra choices in alternate responses, if a choice.categoryCount is > 0.\n * @param {{category: string, choices: string[]}[]} answer\n * @param {{id:string,categoryCount:number}} choices\n */\n\nexport const ensureNoExtraChoicesInAlternate = (answer, choices) => {\n choices = choices || [];\n\n const out = choices.reduce((answerArray, choice) => {\n log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);\n // log('answer array: ', answerArray);\n if (choice.categoryCount === undefined || choice.categoryCount === 0) {\n return answerArray;\n } else {\n let alternatePair = {};\n answerArray.forEach((answer) =>\n (answer.alternateResponses || []).forEach((alternate, index) => {\n if (index in alternatePair) {\n alternatePair[index].push(alternate);\n } else {\n alternatePair[index] = [];\n alternatePair[index].push(alternate);\n }\n }),\n );\n\n const recreatedAlternate = [];\n Object.keys(alternatePair).forEach((k) => {\n const limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);\n alternatePair[k] = limitAlternate;\n alternatePair[k].forEach((item, index) => {\n if (!recreatedAlternate[index]) {\n recreatedAlternate[index] = [];\n recreatedAlternate[index].push(item);\n } else {\n recreatedAlternate[index].push(item);\n }\n });\n });\n\n const updatedArray = answerArray.map((answer, index) => {\n return {\n category: answer.category,\n alternateResponses: recreatedAlternate[index] || answer.alternateResponses,\n choices: answer.choices,\n };\n });\n return updatedArray;\n }\n }, answer);\n return out;\n};\n/**\n * Count the number of choice ids in a given answer array\n * @param {string} choiceId\n * @param {{category: string, choices: string[]}[]} answer\n */\nexport const countInAnswer = (choiceId, answer) => {\n const out = answer.reduce((acc, a) => acc + countInChoices(choiceId, a.choices), 0);\n log('[countInAnswer] choiceId:', choiceId, answer);\n return out;\n};\n\nexport const countInChoices = (choiceId, choices) => (choices || []).filter((c) => c === choiceId).length;\n\n/**\n * Count the number of times a choice has been selected in categories.\n * @param {*} choice\n * @param {*} categories\n */\nexport const countChosen = (choice, categories) => {\n if (!choice || !choice.id) {\n return 0;\n }\n\n if (!Array.isArray(categories)) {\n return 0;\n }\n\n return categories.reduce((acc, c) => {\n const count = (c.choices || []).filter((h) => h.id === choice.id).length;\n return acc + count;\n }, 0);\n};\n\n/**\n * @param {string?} categoryId\n * @param {{category:string, choices: string[]}} answers\n */\nexport const removeCategory = (categoryId, answers) => answers.filter((a) => a.category !== categoryId);\n\n/**\n * @param {string} choiceId\n * @param {{category:string, choices: string[]}} answers\n * @param {string?} categoryId - optional categegory id\n */\nexport const removeAllChoices = (choiceId, answers, categoryId) => {\n return answers.map((a) => {\n if (!categoryId || a.category === categoryId) {\n const cloned = clone(a.choices);\n remove(cloned, (v) => v === choiceId);\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const rearrangeChoices = (choices, indexFrom, indexTo) => {\n if (choices.length === 0) {\n return choices;\n }\n choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);\n return choices;\n};\n\nexport const verifyAllowMultiplePlacements = (choice, categoryId, answers) => {\n return answers.map((a) => {\n if (a.category !== categoryId) {\n a.choices = (a.choices || []).filter((c) => c !== choice.id);\n return a;\n } else {\n a.choices = a.choices.reduce((acc, currentValue) => {\n if (currentValue.id === choice.id) {\n const foundIndex = acc.findIndex((c) => c.id === choice.id);\n if (foundIndex === -1) {\n acc.push(currentValue);\n }\n } else {\n acc.push(currentValue);\n }\n\n return acc;\n }, []);\n return a;\n }\n });\n};\n\nexport const removeChoiceFromCategory = (choiceId, categoryId, choiceIndex, answers) => {\n log('[removeChoiceFromCategory] choiceIndex:', choiceIndex);\n\n return answers.map((a) => {\n if (a.category === categoryId) {\n const cloned = clone(a.choices);\n const index = cloned.findIndex((v, index) => {\n return v === choiceId && index >= choiceIndex;\n });\n if (index !== -1) {\n cloned.splice(index, 1);\n }\n return { ...a, choices: cloned };\n } else {\n return a;\n }\n });\n};\n\nexport const moveChoiceToCategory = (choiceId, from, to, choiceIndex, answers) => {\n log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);\n\n if (from === to) {\n return answers;\n }\n\n if (from) {\n answers = removeChoiceFromCategory(choiceId, from, choiceIndex, answers);\n }\n\n const index = answers.findIndex((a) => a.category === to);\n if (index === -1) {\n answers.push({ category: to, choices: [choiceId] });\n return answers;\n } else {\n return answers.map((a) => {\n if (a.category === to) {\n a.choices = a.choices || [];\n a.choices.push(choiceId);\n return a;\n }\n return a;\n });\n }\n};\n\nexport const moveChoiceToAlternate = (choiceId, from, to, choiceIndex, answers, alternateIndex, categoryCount) => {\n log(\n '[moveChoiceToAlternate] choice: ',\n choiceId,\n 'from: ',\n from,\n 'to: ',\n to,\n 'answers: ',\n answers,\n 'chocieIndex: ',\n choiceIndex,\n );\n\n if (from === to) {\n return answers;\n }\n\n return answers.map((a) => {\n if (a.category === to) {\n if (categoryCount !== 0 && a.alternateResponses) {\n a.alternateResponses[alternateIndex] = (a.alternateResponses[alternateIndex] || []).filter(\n (resp) => resp !== choiceId,\n );\n }\n if (!a.alternateResponses) {\n a.alternateResponses = [];\n a.alternateResponses[alternateIndex] = [];\n }\n a.alternateResponses[alternateIndex].push(choiceId);\n }\n\n if (a.category === from && categoryCount !== 0 && a.alternateResponses && a.alternateResponses[alternateIndex]) {\n a.alternateResponses[alternateIndex] = a.alternateResponses[alternateIndex].filter((resp) => resp !== choiceId);\n }\n\n return a;\n });\n};\n\nexport const stillSelectable = (h, builtCategories) => {\n if (h.categoryCount > 0) {\n const count = countChosen(h, builtCategories);\n return count < h.categoryCount;\n } else {\n return true;\n }\n};\n\n/**\n * returns all choices with property 'correct' set to boolean\n * @param {string[]} possibleResponseChoices\n * @param {Object[]} builtCategoryChoices\n *\n * @returns {Object}, returns builtChoices: BuiltChoice[] and allChoicesAreCorrect: boolean\n * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }\n */\nexport const buildChoices = (possibleResponseChoices, builtCategoryChoices) => {\n return builtCategoryChoices.reduce(\n (acc, builtChoice) => {\n // set correct value on each choice that was selected by user\n const index = acc.copyOfPossibleResponse.findIndex((cRC) => cRC === builtChoice.id);\n // if the choice exists in the correct response\n // set the correct: true\n if (index >= 0) {\n acc.builtChoices.push({\n ...builtChoice,\n correct: true,\n });\n acc.copyOfPossibleResponse = [\n ...acc.copyOfPossibleResponse.slice(0, index),\n ...acc.copyOfPossibleResponse.slice(index + 1),\n ];\n } else {\n acc.builtChoices.push({\n ...builtChoice,\n correct: false,\n });\n acc.allChoicesAreCorrect = false;\n }\n\n return acc;\n },\n {\n builtChoices: [],\n copyOfPossibleResponse: [...possibleResponseChoices],\n allChoicesAreCorrect: true,\n },\n );\n};\n\n/**\n * returns corrected answer using this possible correct response\n * @param {Object} possibleResponse, has form: { CategoryId: ChoiceId[] }\n * @param {Object[]} builtCategories\n *\n * @returns {Object}, returns builtCategories: BuiltCategory[] and correct: boolean\n * BuiltCategory = { id: categoryId, label: categoryLabel, correct: boolean, choices: BuiltChoice[] }\n * BuiltChoice = { id: choiceId, content: choiceContent, correct: boolean }\n */\nexport const getBuiltCategories = (possibleResponse, builtCategories) =>\n builtCategories.reduce(\n (acc, builtCategory) => {\n const possibleResponseChoices = possibleResponse[builtCategory.id] || []; // the correct choices for this category\n const builtCategoryChoices = builtCategory.choices || []; // the choices in the answer\n\n const { builtChoices, allChoicesAreCorrect } = buildChoices(possibleResponseChoices, builtCategoryChoices);\n const allChoicesAreInAnswer = builtCategoryChoices.length === possibleResponseChoices.length;\n\n acc.builtCategories.push({\n ...builtCategory,\n correct: allChoicesAreCorrect && allChoicesAreInAnswer,\n choices: builtChoices,\n });\n acc.correct = acc.correct && allChoicesAreCorrect && allChoicesAreInAnswer;\n\n return acc;\n },\n { builtCategories: [], correct: true },\n );\n\n/**\n * returns all the possible responses by combining the proper alternate responses\n * @param {Object[]} correctResponse\n *\n * @returns {Object[]}, returns Response[]\n * Response = { CategoryId: ChoiceId[] },\n */\nexport const getAllPossibleResponses = (correctResponse) => {\n if (!correctResponse) {\n return [];\n }\n\n return correctResponse.reduce((acc, cR) => {\n // main response\n if (acc[0]) {\n acc[0][cR.category] = cR.choices;\n } else {\n acc.push({ [cR.category]: cR.choices });\n }\n\n // alternate responses\n if (cR.alternateResponses) {\n cR.alternateResponses.forEach((aR, index) => {\n if (acc[index + 1]) {\n acc[index + 1][cR.category] = aR;\n } else {\n acc.push({ [cR.category]: aR });\n }\n });\n }\n\n return acc;\n }, []);\n};\n\n/**\n * build the categories to be displayed, where each category has its own list of choices\n * @param {Object[]} categories\n * @param {{id:string}[]} choices\n * @param {{category: string, choices:string[]}[]} answers\n *\n * @returns {Object[]}, returns BuiltCategory[]\n * BuiltCategory = { id: categoryId, label: categoryLabel, choices: BuiltChoice[]},\n * BuiltChoice = { id: choiceId, content: choiceContent }\n */\nexport const buildCategories = (categories, choices, answers) => {\n categories = categories || [];\n answers = answers || [];\n choices = choices || [];\n\n return categories.map((category) => {\n const answer = answers.find((answer) => answer.category === category.id);\n const { choices: answerChoices = [] } = answer || {};\n\n return {\n ...category,\n choices: answerChoices.map((chId) => choices.find((ch) => ch.id === chId)),\n };\n });\n};\n\n/**\n * build the choice and category state\n * @param {Object[]} categories\n * @param {{id:string}[]} choices\n * @param {{category: string, choices:string[]}[]} answers\n *\n * @param correctResponse\n * @returns { categories: Category[], choices: Choice[], correct: boolean, bestResponse: Response }, where Response: { categoryId: choiceId[] }\n */\nexport const buildState = (categories, choices, answers, correctResponse) => {\n categories = categories || [];\n choices = choices || [];\n answers = answers || [];\n\n const allResponses = getAllPossibleResponses(correctResponse) || [];\n\n let builtCategories = buildCategories(categories, choices, answers);\n let bestResponse;\n let entirelyCorrect;\n\n // at least one defined correct response\n if (allResponses.length) {\n const builtData = allResponses.reduce(\n (acc, possibleResponse) => {\n // set correctness for each possible response\n const { builtCategories: categoriesWithChoices, correct } = getBuiltCategories(\n possibleResponse,\n builtCategories,\n );\n\n // if bestResponse not found yet OR no correct response found yet and this one is the correct one\n if (acc.bestResponse === null || (!acc.entirelyCorrect && correct)) {\n return {\n bestResponse: possibleResponse,\n builtCategories: categoriesWithChoices,\n entirelyCorrect: correct,\n };\n }\n\n return acc;\n },\n {\n bestResponse: null,\n builtCategories: [],\n entirelyCorrect: false,\n },\n );\n\n builtCategories = builtData.builtCategories;\n bestResponse = builtData.bestResponse;\n entirelyCorrect = builtData.entirelyCorrect;\n }\n\n const filteredChoices = choices.map((ch) => (stillSelectable(ch, builtCategories) ? ch : { empty: true }));\n\n return {\n choices: filteredChoices,\n categories: builtCategories,\n correct: entirelyCorrect,\n bestResponse,\n };\n};\n"],"file":"index.js"}
|
package/lib/scoring.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.score = void 0;
|
|
9
|
+
|
|
8
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
9
12
|
var _debug = _interopRequireDefault(require("debug"));
|
|
13
|
+
|
|
10
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
11
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
|
|
12
18
|
var log = (0, _debug["default"])('@pie-lib:categorize:scoring');
|
|
19
|
+
|
|
13
20
|
var getWeightingRules = function getWeightingRules(scoring) {
|
|
14
21
|
if (!scoring || !scoring.weighting) {
|
|
15
22
|
return [];
|
|
@@ -22,8 +29,10 @@ var getWeightingRules = function getWeightingRules(scoring) {
|
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
};
|
|
32
|
+
|
|
25
33
|
var getPartialRulesForCategory = function getPartialRulesForCategory(partial, categoryId) {
|
|
26
34
|
log('partial? ', partial);
|
|
35
|
+
|
|
27
36
|
if (!partial || !partial.enabled) {
|
|
28
37
|
return;
|
|
29
38
|
} else {
|
|
@@ -33,7 +42,6 @@ var getPartialRulesForCategory = function getPartialRulesForCategory(partial, ca
|
|
|
33
42
|
return pr ? pr.rules || [] : [];
|
|
34
43
|
}
|
|
35
44
|
};
|
|
36
|
-
|
|
37
45
|
/**
|
|
38
46
|
*
|
|
39
47
|
* Calculate score based on the categories model generated from `buildState` and the partial scoring rules.
|
|
@@ -42,6 +50,7 @@ var getPartialRulesForCategory = function getPartialRulesForCategory(partial, ca
|
|
|
42
50
|
* @see ../index#buildState
|
|
43
51
|
*/
|
|
44
52
|
|
|
53
|
+
|
|
45
54
|
var score = function score(categories, scoring) {
|
|
46
55
|
return new Promise(function (resolve) {
|
|
47
56
|
log('categories: ', categories, 'scoring: ', scoring);
|
|
@@ -69,6 +78,7 @@ var score = function score(categories, scoring) {
|
|
|
69
78
|
return r.category === c.id;
|
|
70
79
|
}).points;
|
|
71
80
|
log('category: ', c);
|
|
81
|
+
|
|
72
82
|
if (c.correct === true) {
|
|
73
83
|
return {
|
|
74
84
|
category: c.id,
|
|
@@ -78,6 +88,7 @@ var score = function score(categories, scoring) {
|
|
|
78
88
|
} else {
|
|
79
89
|
var rules = getPartialRulesForCategory(scoring.partial, c.id);
|
|
80
90
|
log('partial rules for category: ', rules);
|
|
91
|
+
|
|
81
92
|
if (!rules) {
|
|
82
93
|
return {
|
|
83
94
|
category: c.id,
|
|
@@ -97,7 +108,9 @@ var score = function score(categories, scoring) {
|
|
|
97
108
|
percent: 0,
|
|
98
109
|
count: correctCount
|
|
99
110
|
};
|
|
111
|
+
|
|
100
112
|
var _score = w * (rule.percent / 100);
|
|
113
|
+
|
|
101
114
|
return {
|
|
102
115
|
category: c.id,
|
|
103
116
|
score: _score,
|
|
@@ -127,5 +140,6 @@ var score = function score(categories, scoring) {
|
|
|
127
140
|
});
|
|
128
141
|
});
|
|
129
142
|
};
|
|
143
|
+
|
|
130
144
|
exports.score = score;
|
|
131
145
|
//# sourceMappingURL=scoring.js.map
|
package/lib/scoring.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/scoring.js"],"names":["log","getWeightingRules","scoring","weighting","enabled","rules","getPartialRulesForCategory","partial","categoryId","pr","find","category","score","categories","Promise","resolve","weightingRules","weights","map","c","r","id","points","weightTotal","reduce","total","withScore","w","correct","correctCount","choices","filter","h","length","rule","u","count","percent","correctChoices","weightedScore","sum","parseFloat","toFixed","details","weighted"],"mappings":";;;;;;;;;;;AAAA;;;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,6BAAN,CAAZ;;AACA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,OAAD,EAAa;AACrC,MAAI,CAACA,OAAD,IAAY,CAACA,OAAO,CAACC,SAAzB,EAAoC;AAClC,WAAO,EAAP;AACD,GAFD,MAEO;AACL,QAAI,CAACD,OAAO,CAACC,SAAR,CAAkBC,OAAvB,EAAgC;AAC9B,aAAO,EAAP;AACD,KAFD,MAEO;AACL,UAAMC,KAAK,GAAGH,OAAO,CAACC,SAAR,GAAoBD,OAAO,CAACC,SAAR,CAAkBE,KAAlB,IAA2B,EAA/C,GAAoD,EAAlE;AACA,aAAOA,KAAP;AACD;AACF;AACF,CAXD;;AAaA,IAAMC,0BAA0B,GAAG,SAA7BA,0BAA6B,CAACC,OAAD,EAAUC,UAAV,EAAyB;AAC1DR,EAAAA,GAAG,CAAC,WAAD,EAAcO,OAAd,CAAH;;AACA,MAAI,CAACA,OAAD,IAAY,CAACA,OAAO,CAACH,OAAzB,EAAkC;AAChC;AACD,GAFD,MAEO;AACL,QAAMK,EAAE,GAAGF,OAAO,CAACF,KAAR,CAAcK,IAAd,CAAmB,UAACD,EAAD;AAAA,aAAQA,EAAE,CAACE,QAAH,KAAgBH,UAAxB;AAAA,KAAnB,CAAX;AACA,WAAOC,EAAE,GAAGA,EAAE,CAACJ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,GAAnB,CAAf;;AACA,iBAAO;AACL1B,YAAAA,QAAQ,EAAEQ,CAAC,CAACE,EADP;AAELT,YAAAA,KAAK,EAALA,MAFK;AAGLU,YAAAA,MAAM,EAAEK,CAHH;AAILpB,YAAAA,OAAO,EAAE;AACP+B,cAAAA,cAAc,EAAET,YADT;AAEPK,cAAAA,IAAI,EAAEA;AAFC;AAJJ,WAAP;AASD;AACF;AACF,KA7BiB,CAAlB;AA+BA,QAAMK,aAAa,GAAGb,SAAS,CAACF,MAAV,CAAiB,UAACgB,GAAD,EAAMrB,CAAN,EAAY;AACjD,aAAQqB,GAAG,IAAIrB,CAAC,CAACP,KAAjB;AACD,KAFqB,EAEnB,CAFmB,CAAtB;AAIAZ,IAAAA,GAAG,CAAC,iBAAD,EAAoBuC,aAApB,CAAH;AAEA,QAAM3B,KAAK,GAAG6B,UAAU,CAAC,CAACF,aAAa,GAAGhB,WAAjB,EAA8BmB,OAA9B,CAAsC,CAAtC,CAAD,EAA2C,EAA3C,CAAxB;AACA3B,IAAAA,OAAO,CAAC;AACNH,MAAAA,KAAK,EAALA,KADM;AAEN+B,MAAAA,OAAO,EAAE;AACPC,QAAAA,QAAQ,EAAE;AACRnB,UAAAA,KAAK,EAAEF,WADC;AAERX,UAAAA,KAAK,EAAE2B;AAFC,SADH;AAKP1B,QAAAA,UAAU,EAAEa;AALL;AAFH,KAAD,CAAP;AAUD,GAlED,CADmB;AAAA,CAAd","sourcesContent":["import debug from 'debug';\nconst log = debug('@pie-lib:categorize:scoring');\nconst getWeightingRules = (scoring) => {\n if (!scoring || !scoring.weighting) {\n return [];\n } else {\n if (!scoring.weighting.enabled) {\n return [];\n } else {\n const rules = scoring.weighting ? scoring.weighting.rules || [] : [];\n return rules;\n }\n }\n};\n\nconst getPartialRulesForCategory = (partial, categoryId) => {\n log('partial? ', partial);\n if (!partial || !partial.enabled) {\n return;\n } else {\n const pr = partial.rules.find((pr) => pr.category === categoryId);\n return pr ? pr.rules || [] : [];\n }\n};\n\n/**\n *\n * Calculate score based on the categories model generated from `buildState` and the partial scoring rules.\n * @param {*} categories - this is the categories that you get from `buildState`.\n * @param {*} scoring - scoring config.\n * @see ../index#buildState\n */\n\nexport const score = (categories, scoring) =>\n new Promise((resolve) => {\n log('categories: ', categories, 'scoring: ', scoring);\n const weightingRules = getWeightingRules(scoring);\n\n const weights = categories.map((c) => {\n const r = weightingRules.find((r) => r.category === c.id) || { points: 1 };\n return { ...r, category: c.id };\n });\n\n log('weights: ', weights);\n\n const weightTotal = categories.reduce((total, c) => {\n const r = weights.find((r) => r.category === c.id);\n return (total += r.points);\n }, 0);\n\n log('total: ', weightTotal);\n\n const withScore = categories.map((c) => {\n const w = weights.find((r) => r.category === c.id).points;\n\n log('category: ', c);\n if (c.correct === true) {\n return { category: c.id, score: w, points: w };\n } else {\n const rules = getPartialRulesForCategory(scoring.partial, c.id);\n log('partial rules for category: ', rules);\n if (!rules) {\n return { category: c.id, score: 0, points: w };\n } else {\n const correctCount = (c.choices || []).filter((h) => h.correct).length;\n log('correctCount: ', correctCount);\n let rule = rules.find((u) => u.count === correctCount);\n log('rule: ', rule);\n rule = rule || { percent: 0, count: correctCount };\n const score = w * (rule.percent / 100);\n return {\n category: c.id,\n score,\n points: w,\n partial: {\n correctChoices: correctCount,\n rule: rule,\n },\n };\n }\n }\n });\n\n const weightedScore = withScore.reduce((sum, c) => {\n return (sum += c.score);\n }, 0);\n\n log('weightedScore: ', weightedScore);\n\n const score = parseFloat((weightedScore / weightTotal).toFixed(2), 10);\n resolve({\n score,\n details: {\n weighted: {\n total: weightTotal,\n score: weightedScore,\n },\n categories: withScore,\n },\n });\n });\n"],"file":"scoring.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/categorize",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1-next.1+007708fb",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
"scripts": {},
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "ISC",
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "007708fbd9184f1fd8876fdc2d7c689330ca47e0"
|
|
18
18
|
}
|