@pie-lib/categorize 0.8.17-next.0 → 0.9.0-beta.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.md +28 -63
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/index.js +23 -1
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/index.test.js +953 -0
- package/src/__tests__/scoring.test.js +282 -0
- package/src/__tests__/utils.js +19 -0
- package/src/index.js +16 -0
- package/README.md +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,144 +3,109 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
6
|
+
# [0.9.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.17...@pie-lib/categorize@0.9.0-beta.1) (2025-07-20)
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
**Note:** Version bump only for package @pie-lib/categorize
|
|
10
9
|
|
|
11
|
-
* **categorize:** add sanity check to fix PD-1982 ([9c221b5](https://github.com/pie-framework/pie-lib/commit/9c221b5fb7ef2469d8bc8eb96bce0203ce3d8ff3))
|
|
12
10
|
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
|
|
14
|
+
# [0.9.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.17...@pie-lib/categorize@0.9.0-beta.0) (2025-07-20)
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
**Note:** Version bump only for package @pie-lib/categorize
|
|
18
17
|
|
|
19
18
|
|
|
20
|
-
### Bug Fixes
|
|
21
19
|
|
|
22
|
-
* version bump ([d9280a9](https://github.com/pie-framework/pie-lib/commit/d9280a9aeddab459b6d84ecdbeb62814e1eee965))
|
|
23
20
|
|
|
24
21
|
|
|
22
|
+
# [0.10.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.17...@pie-lib/categorize@0.10.0-beta.0) (2025-07-15)
|
|
25
23
|
|
|
24
|
+
**Note:** Version bump only for package @pie-lib/categorize
|
|
26
25
|
|
|
26
|
+
# [0.9.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.17...@pie-lib/categorize@0.9.0-beta.0) (2025-07-15)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
**Note:** Version bump only for package @pie-lib/categorize
|
|
29
29
|
|
|
30
|
+
## [0.8.17](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.16...@pie-lib/categorize@0.8.17) (2023-06-24)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
**Note:** Version bump only for package @pie-lib/categorize
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
## [0.8.16](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.15...@pie-lib/categorize@0.8.16) (2023-05-08)
|
|
34
35
|
|
|
36
|
+
### Bug Fixes
|
|
35
37
|
|
|
38
|
+
- **categorize:** add sanity check to fix PD-1982 ([9c221b5](https://github.com/pie-framework/pie-lib/commit/9c221b5fb7ef2469d8bc8eb96bce0203ce3d8ff3))
|
|
36
39
|
|
|
40
|
+
## [0.8.15](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.13...@pie-lib/categorize@0.8.15) (2023-02-28)
|
|
37
41
|
|
|
42
|
+
### Bug Fixes
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
- version bump ([d9280a9](https://github.com/pie-framework/pie-lib/commit/d9280a9aeddab459b6d84ecdbeb62814e1eee965))
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
## [0.8.13](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.12...@pie-lib/categorize@0.8.13) (2023-02-28)
|
|
42
47
|
|
|
48
|
+
### Bug Fixes
|
|
43
49
|
|
|
50
|
+
- **categorize:** sanity check for blind session answers in eval mode-PD-2601 ([b974de8](https://github.com/pie-framework/pie-lib/commit/b974de8c4a44d3fead2bcbdf8f523204c83d4846))
|
|
44
51
|
|
|
52
|
+
## [0.8.12](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.10...@pie-lib/categorize@0.8.12) (2023-01-31)
|
|
45
53
|
|
|
54
|
+
**Note:** Version bump only for package @pie-lib/categorize
|
|
46
55
|
|
|
47
56
|
## [0.8.10](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.9...@pie-lib/categorize@0.8.10) (2023-01-31)
|
|
48
57
|
|
|
49
58
|
**Note:** Version bump only for package @pie-lib/categorize
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
60
|
## [0.8.9](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.8...@pie-lib/categorize@0.8.9) (2023-01-31)
|
|
56
61
|
|
|
57
62
|
**Note:** Version bump only for package @pie-lib/categorize
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
64
|
## [0.8.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.7...@pie-lib/categorize@0.8.8) (2023-01-31)
|
|
64
65
|
|
|
65
66
|
**Note:** Version bump only for package @pie-lib/categorize
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
68
|
## [0.8.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.4...@pie-lib/categorize@0.8.7) (2023-01-31)
|
|
72
69
|
|
|
73
70
|
**Note:** Version bump only for package @pie-lib/categorize
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
72
|
## [0.8.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.2...@pie-lib/categorize@0.8.4) (2023-01-31)
|
|
80
73
|
|
|
81
74
|
**Note:** Version bump only for package @pie-lib/categorize
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
76
|
## [0.8.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.8.0...@pie-lib/categorize@0.8.2) (2023-01-31)
|
|
88
77
|
|
|
89
78
|
**Note:** Version bump only for package @pie-lib/categorize
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
80
|
# [0.8.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.7.0...@pie-lib/categorize@0.8.0) (2023-01-16)
|
|
96
81
|
|
|
97
|
-
|
|
98
82
|
### Features
|
|
99
83
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
84
|
+
- added theme naming support + cleanup ([72d562d](https://github.com/pie-framework/pie-lib/commit/72d562d509e5d31d883690eb455a9afea6bf54fc))
|
|
105
85
|
|
|
106
86
|
# [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)
|
|
107
87
|
|
|
108
|
-
|
|
109
88
|
### Bug Fixes
|
|
110
89
|
|
|
111
|
-
|
|
112
|
-
|
|
90
|
+
- **categorize:** add test for addChoiceToAlternate-PD-1995 ([153ada3](https://github.com/pie-framework/pie-lib/commit/153ada3ce0a27189ca1fecb5839c2843e35487d5))
|
|
113
91
|
|
|
114
92
|
### Features
|
|
115
93
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
94
|
+
- **categorize:** add method to swap teo choices-PD-1967 ([4660fcf](https://github.com/pie-framework/pie-lib/commit/4660fcfe8cd47c0d02707651812c7897182baeea))
|
|
95
|
+
- **categorize:** conclude merge ([da8b332](https://github.com/pie-framework/pie-lib/commit/da8b33228705490c504be56d250f61e14ca5530d))
|
|
96
|
+
- **categorize:** ensure no extra choices in alternate + sanity checks-PD-1967 ([a574028](https://github.com/pie-framework/pie-lib/commit/a5740285469691e89bc2255045f129989861892b))
|
|
97
|
+
- **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))
|
|
124
98
|
|
|
125
99
|
## [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)
|
|
126
100
|
|
|
127
|
-
|
|
128
101
|
### Bug Fixes
|
|
129
102
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
103
|
+
- **drag,categorize:** drag an answer choice elsewhere after it has been placed in a category-PD-1995 ([d32015b](https://github.com/pie-framework/pie-lib/commit/d32015b31d50b45851df2f27ad517eeaad8ae511))
|
|
135
104
|
|
|
136
105
|
## [0.6.25](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.6.24...@pie-lib/categorize@0.6.25) (2022-11-23)
|
|
137
106
|
|
|
138
107
|
**Note:** Version bump only for package @pie-lib/categorize
|
|
139
108
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
109
|
## [0.6.24](https://github.com/pie-framework/pie-lib/compare/@pie-lib/categorize@0.6.22...@pie-lib/categorize@0.6.24) (2021-06-25)
|
|
145
110
|
|
|
146
111
|
**Note:** Version bump only for package @pie-lib/categorize
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/lib/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.removeChoiceFromCategory = exports.removeCategory = exports.removeAllChoices = exports.rearrangeChoices = exports.moveChoiceToCategory = exports.moveChoiceToAlternate = exports.limitInArrays = exports.limitInArray = exports.limitChoices = exports.getBuiltCategories = exports.getAllPossibleResponses = exports.ensureNoExtraChoicesInAnswer = exports.ensureNoExtraChoicesInAlternate = exports.countInChoices = exports.countInAnswer = exports.countChosen = exports.buildState = exports.buildChoices = exports.buildCategories = exports.FooTwo = void 0;
|
|
8
|
+
exports.removeChoiceFromCategory = exports.removeChoiceFromAlternate = exports.removeCategory = exports.removeAllChoices = exports.rearrangeChoices = exports.moveChoiceToCategory = exports.moveChoiceToAlternate = exports.limitInArrays = exports.limitInArray = exports.limitChoices = exports.getBuiltCategories = exports.getAllPossibleResponses = exports.ensureNoExtraChoicesInAnswer = exports.ensureNoExtraChoicesInAlternate = exports.countInChoices = exports.countInAnswer = exports.countChosen = exports.buildState = exports.buildChoices = exports.buildCategories = exports.FooTwo = void 0;
|
|
9
9
|
Object.defineProperty(exports, "score", {
|
|
10
10
|
enumerable: true,
|
|
11
11
|
get: function get() {
|
|
@@ -358,6 +358,28 @@ var removeChoiceFromCategory = function removeChoiceFromCategory(choiceId, categ
|
|
|
358
358
|
|
|
359
359
|
exports.removeChoiceFromCategory = removeChoiceFromCategory;
|
|
360
360
|
|
|
361
|
+
var removeChoiceFromAlternate = function removeChoiceFromAlternate(choiceId, categoryId, choiceIndex, altIndex, answers) {
|
|
362
|
+
return (answers || []).map(function (a) {
|
|
363
|
+
if ((a === null || a === void 0 ? void 0 : a.category) === categoryId) {
|
|
364
|
+
var newAlternates = ((a === null || a === void 0 ? void 0 : a.alternateResponses) || []).map(function (altArray, idx) {
|
|
365
|
+
if (idx === altIndex) {
|
|
366
|
+
(altArray || []).splice(choiceIndex, 1);
|
|
367
|
+
return altArray;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return altArray;
|
|
371
|
+
});
|
|
372
|
+
return _objectSpread(_objectSpread({}, a), {}, {
|
|
373
|
+
alternateResponses: newAlternates
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return a;
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
exports.removeChoiceFromAlternate = removeChoiceFromAlternate;
|
|
382
|
+
|
|
361
383
|
var moveChoiceToCategory = function moveChoiceToCategory(choiceId, from, to, choiceIndex, answers) {
|
|
362
384
|
log('[moveChoiceToCategory] choice: ', choiceId, 'from: ', from, 'to: ', to, 'answers: ', answers);
|
|
363
385
|
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["FooTwo","log","limitChoices","choiceId","count","choices","out","reduce","acc","id","foundCount","countInChoices","push","limitInArrays","arrays","limit","result","array","l","limitInArray","arr","stripped","filter","v","length","ensureNoExtraChoicesInAnswer","answer","answerArray","choice","categoryCount","undefined","map","a","updatedArray","r","index","category","alternateResponses","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;;;;;;AAIO,IAAMA,MAAM,GAAG,SAAf;;AAEP,IAAMC,GAAG,GAAG,uBAAM,qBAAN,CAAZ;;AAEO,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAACC,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AACA,UAAI7E,GAAG,CAAC+F,YAAJ,KAAqB,IAArB,IAA8B,CAAC/F,GAAG,CAACgG,eAAL,IAAwBnB,OAA1D,EAAoE;AAClE,eAAO;AACLkB,UAAAA,YAAY,EAAEd,gBADT;AAELZ,UAAAA,eAAe,EAAE6B,qBAFZ;AAGLF,UAAAA,eAAe,EAAEnB;AAHZ,SAAP;AAKD;;AAED,aAAO7E,GAAP;AACD,KAlBe,EAmBhB;AACE+F,MAAAA,YAAY,EAAE,IADhB;AAEE1B,MAAAA,eAAe,EAAE,EAFnB;AAGE2B,MAAAA,eAAe,EAAE;AAHnB,KAnBgB,CAAlB;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 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 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"],"file":"index.js"}
|
|
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","removeChoiceFromAlternate","altIndex","newAlternates","altArray","idx","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;;;;;;AAIO,IAAMA,MAAM,GAAG,SAAf;;AAEP,IAAMC,GAAG,GAAG,uBAAM,qBAAN,CAAZ;;AAEO,IAA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IAAAA,eAAe,GAAG4B,SAAS,CAAC5B,eAA5B;AACA0B,IAAAA,YAAY,GAAGE,SAAS,CAACF,YAAzB;AACAC,IAAAA,eAAe,GAAGC,SAAS,CAACD,eAA5B;AACD;;AAED,MAAMG,eAAe,GAAG3G,OAAO,CAAC0B,GAAR,CAAY,UAAC0E,EAAD;AAAA,WAASxB,eAAe,CAACwB,EAAD,EAAKvB,eAAL,CAAf,GAAuCuB,EAAvC,GAA4C;AAAEQ,MAAAA,KAAK,EAAE;AAAT,KAArD;AAAA,GAAZ,CAAxB;AAEA,SAAO;AACL5G,IAAAA,OAAO,EAAE2G,eADJ;AAEL7D,IAAAA,UAAU,EAAE+B,eAFP;AAGLQ,IAAAA,OAAO,EAAEmB,eAHJ;AAILD,IAAAA,YAAY,EAAZA;AAJK,GAAP;AAMD,CApDM","sourcesContent":["import debug from 'debug';\nimport clone from 'lodash/clone';\nimport remove from 'lodash/remove';\nimport { score } from './scoring';\n\nexport { score };\n\nexport const FooTwo = 'foo-two';\n\nconst log = debug('@pie-lib:categorize');\n\nexport const limitChoices = (choiceId, count, choices) => {\n const out = choices.reduce(\n (acc, id) => {\n const foundCount = countInChoices(choiceId, acc.choices);\n\n if (id !== choiceId || foundCount < count) {\n acc.choices.push(id);\n }\n\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"],"file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/categorize",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-beta.1",
|
|
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": "e2aa3ddac60f49bcb8c2562370f496323642f453"
|
|
18
18
|
}
|