@pie-lib/categorize 0.7.0 → 0.7.1-next.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -18,22 +18,12 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
18
18
 
19
19
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
20
 
21
- var _compact = _interopRequireDefault(require("lodash/compact"));
22
-
23
21
  var _debug = _interopRequireDefault(require("debug"));
24
22
 
25
23
  var _clone = _interopRequireDefault(require("lodash/clone"));
26
24
 
27
- var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
28
-
29
25
  var _remove = _interopRequireDefault(require("lodash/remove"));
30
26
 
31
- var _every = _interopRequireDefault(require("lodash/every"));
32
-
33
- var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
34
-
35
- var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
36
-
37
27
  var _scoring = require("./scoring");
38
28
 
39
29
  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; }
@@ -46,7 +36,7 @@ var log = (0, _debug["default"])('@pie-lib:categorize');
46
36
 
47
37
  var limitChoices = function limitChoices(choiceId, count, choices) {
48
38
  var out = choices.reduce(function (acc, id) {
49
- var foundCount = countInChoices(choiceId, acc.choices); // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);
39
+ var foundCount = countInChoices(choiceId, acc.choices);
50
40
 
51
41
  if (id !== choiceId || foundCount < count) {
52
42
  acc.choices.push(id);
@@ -139,7 +129,7 @@ exports.limitInArray = limitInArray;
139
129
  var ensureNoExtraChoicesInAnswer = function ensureNoExtraChoicesInAnswer(answer, choices) {
140
130
  choices = choices || [];
141
131
  var out = choices.reduce(function (answerArray, choice) {
142
- log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount); // log('answer array: ', answerArray);
132
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
143
133
 
144
134
  if (choice.categoryCount === undefined || choice.categoryCount === 0) {
145
135
  return answerArray;
@@ -173,7 +163,7 @@ exports.ensureNoExtraChoicesInAnswer = ensureNoExtraChoicesInAnswer;
173
163
  var ensureNoExtraChoicesInAlternate = function ensureNoExtraChoicesInAlternate(answer, choices) {
174
164
  choices = choices || [];
175
165
  var out = choices.reduce(function (answerArray, choice) {
176
- log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount); // log('answer array: ', answerArray);
166
+ log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
177
167
 
178
168
  if (choice.categoryCount === undefined || choice.categoryCount === 0) {
179
169
  return answerArray;
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;;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;AACD,GARS,EASV;AAAEH,IAAAA,OAAO,EAAE;AAAX,GATU,CAAZ;AAYA,SAAOC,GAAG,CAACD,OAAX;AACD,CAdM;AAgBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,IAAMQ,aAAa,GAAG,SAAhBA,aAAgB,CAACJ,EAAD,EAAKK,MAAL,EAAaC,KAAb,EAAuB;AAClDD,EAAAA,MAAM,GAAGA,MAAM,IAAI,EAAnB;AAEA,MAAME,MAAM,GAAGF,MAAM,CAACP,MAAP,CACb,UAACC,GAAD,EAAMS,KAAN,EAAgB;AACd,QAAMC,CAAC,GAAGH,KAAK,GAAGP,GAAG,CAACJ,KAAtB;AACA,QAAMY,MAAM,GAAGG,YAAY,CAACV,EAAD,EAAKQ,KAAL,EAAYC,CAAZ,CAA3B;AACAV,IAAAA,GAAG,CAACF,GAAJ,CAAQM,IAAR,CAAaI,MAAM,CAACC,KAAp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ug 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"}
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,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;;AAEA,QAAII,EAAE,KAAKN,QAAP,IAAmBO,UAAU,GAAGN,KAApC,EAA2C;AACzCI,MAAAA,GAAG,CAACH,OAAJ,CAAYO,IAAZ,CAAiBH,EAAjB;AACD;;AAED,WAAOD,GAAP;AACD,GATS,EAUV;AAAEH,IAAAA,OAAO,EAAE;AAAX,GAVU,CAAZ;AAaA,SAAOC,GAAG,CAACD,OAAX;AACD,CAfM;AAiBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,IAAMQ,aAAa,GAAG,SAAhBA,aAAgB,CAACJ,EAAD,EAAKK,MAAL,EAAaC,KAAb,EAAuB;AAClDD,EAAAA,MAAM,GAAGA,MAAM,IAAI,EAAnB;AAEA,MAAME,MAAM,GAAGF,MAAM,CAACP,MAAP,CACb,UAACC,GAAD,EAAMS,KAAN,EAAgB;AACd,QAAMC,CAAC,GAAGH,KAAK,GAAGP,GAAG,CAACJ,KAAtB;AACA,QAAMY,MAAM,GAAGG,YAAY,CAACV,EAAD,EAAKQ,KAAL,EAAYC,CAAZ,CAA3B;AA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AA,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.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) => 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 +1 @@
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,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A,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"}
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;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,6BAAN,CAAZ;;AAEA,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;AAEA,aAAOA,KAAP;AACD;AACF;AACF,CAZD;;AAcA,IAAMC,0BAA0B,GAAG,SAA7BA,0BAA6B,CAACC,OAAD,EAAUC,UAAV,EAAyB;AAC1DR,EAAAA,GAAG,CAAC,WAAD,EAAcO,OAAd,CAAH;;AAEA,MAAI,CAACA,OAAD,IAAY,CAACA,OAAO,CAAC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;AAEA7B,UAAAA,GAAG,CAAC,QAAD,EAAWkC,IAAX,CAAH;AAEAA,UAAAA,IAAI,GAAGA,IAAI,IAAI;AAAEG,YAAAA,OAAO,EAAE,CAAX;AAAcD,YAAAA,KAAK,EAAEP;AAArB,WAAf;;AAEA,cAAMjB,MAAK,GAAGe,CAAC,IAAIO,IAAI,CAACG,OAAL,GAAe,GAAnB,CAAf;;AAEA,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,KArCiB,CAAlB;AAuCA,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;AAEA3B,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,GA9ED,CADmB;AAAA,CAAd","sourcesContent":["import debug from 'debug';\n\nconst log = debug('@pie-lib:categorize:scoring');\n\nconst getWeightingRules = (scoring) => {\n if (!scoring || !scoring.weighting) {\n return [];\n } else {\n if (!scoring.weighting.enabled) {\n return [];\n } else {\n const rules = scoring.weighting ? scoring.weighting.rules || [] : [];\n\n return rules;\n }\n }\n};\n\nconst getPartialRulesForCategory = (partial, categoryId) => {\n log('partial? ', partial);\n\n if (!partial || !partial.enabled) {\n return;\n } else {\n const pr = partial.rules.find((pr) => pr.category === categoryId);\n\n return pr ? pr.rules || [] : [];\n }\n};\n\n/**\n *\n * Calculate score based on the categories model generated from `buildState` and the partial scoring rules.\n * @param {*} categories - this is the categories that you get from `buildState`.\n * @param {*} scoring - scoring config.\n * @see ../index#buildState\n */\n\nexport const score = (categories, scoring) =>\n new Promise((resolve) => {\n log('categories: ', categories, 'scoring: ', scoring);\n\n const weightingRules = getWeightingRules(scoring);\n\n const weights = categories.map((c) => {\n const r = weightingRules.find((r) => r.category === c.id) || { points: 1 };\n\n return { ...r, category: c.id };\n });\n\n log('weights: ', weights);\n\n const weightTotal = categories.reduce((total, c) => {\n const r = weights.find((r) => r.category === c.id);\n\n return (total += r.points);\n }, 0);\n\n log('total: ', weightTotal);\n\n const withScore = categories.map((c) => {\n const w = weights.find((r) => r.category === c.id).points;\n\n log('category: ', c);\n if (c.correct === true) {\n return { category: c.id, score: w, points: w };\n } else {\n const rules = getPartialRulesForCategory(scoring.partial, c.id);\n\n log('partial rules for category: ', rules);\n\n if (!rules) {\n return { category: c.id, score: 0, points: w };\n } else {\n const correctCount = (c.choices || []).filter((h) => h.correct).length;\n\n log('correctCount: ', correctCount);\n\n let rule = rules.find((u) => u.count === correctCount);\n\n log('rule: ', rule);\n\n rule = rule || { percent: 0, count: correctCount };\n\n const score = w * (rule.percent / 100);\n\n return {\n category: c.id,\n score,\n points: w,\n partial: {\n correctChoices: correctCount,\n rule: rule,\n },\n };\n }\n }\n });\n\n const weightedScore = withScore.reduce((sum, c) => {\n return (sum += c.score);\n }, 0);\n\n log('weightedScore: ', weightedScore);\n\n const score = parseFloat((weightedScore / weightTotal).toFixed(2), 10);\n\n resolve({\n score,\n details: {\n weighted: {\n total: weightTotal,\n score: weightedScore,\n },\n categories: withScore,\n },\n });\n });\n"],"file":"scoring.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/categorize",
3
- "version": "0.7.0",
3
+ "version": "0.7.1-next.30+09f0e9b2",
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": "252c387e845b7f3b5887d10ae458cefb76ad3fa5"
17
+ "gitHead": "09f0e9b2bec807d6f6bc26d210181b7d49048726"
18
18
  }
package/src/index.js CHANGED
@@ -1,11 +1,6 @@
1
- import compact from 'lodash/compact';
2
1
  import debug from 'debug';
3
2
  import clone from 'lodash/clone';
4
- import cloneDeep from 'lodash/cloneDeep';
5
3
  import remove from 'lodash/remove';
6
- import every from 'lodash/every';
7
- import isEqual from 'lodash/isEqual';
8
- import isUndefined from 'lodash/isUndefined';
9
4
  import { score } from './scoring';
10
5
 
11
6
  export { score };
@@ -13,14 +8,16 @@ export { score };
13
8
  export const FooTwo = 'foo-two';
14
9
 
15
10
  const log = debug('@pie-lib:categorize');
11
+
16
12
  export const limitChoices = (choiceId, count, choices) => {
17
13
  const out = choices.reduce(
18
14
  (acc, id) => {
19
15
  const foundCount = countInChoices(choiceId, acc.choices);
20
- // log('[limitChoices] choiceId: ', choiceId, ' foundCount: ', foundCount);
16
+
21
17
  if (id !== choiceId || foundCount < count) {
22
18
  acc.choices.push(id);
23
19
  }
20
+
24
21
  return acc;
25
22
  },
26
23
  { choices: [] },
@@ -43,8 +40,10 @@ export const limitInArrays = (id, arrays, limit) => {
43
40
  (acc, array) => {
44
41
  const l = limit - acc.count;
45
42
  const result = limitInArray(id, array, l);
43
+
46
44
  acc.out.push(result.array);
47
45
  acc.count = acc.count + (result.count || 0);
46
+
48
47
  return acc;
49
48
  },
50
49
  { out: [], count: 0 },
@@ -65,6 +64,7 @@ export const limitInArray = (id, arr, limit) => {
65
64
 
66
65
  if (limit === 0) {
67
66
  const stripped = arr.filter((v) => v !== id);
67
+
68
68
  return { array: stripped, count: arr.length - stripped.length };
69
69
  } else {
70
70
  const result = arr.reduce(
@@ -77,6 +77,7 @@ export const limitInArray = (id, arr, limit) => {
77
77
  } else {
78
78
  acc.out.push(v);
79
79
  }
80
+
80
81
  return acc;
81
82
  },
82
83
  { out: [], count: 0 },
@@ -96,12 +97,13 @@ export const ensureNoExtraChoicesInAnswer = (answer, choices) => {
96
97
 
97
98
  const out = choices.reduce((answerArray, choice) => {
98
99
  log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
99
- // log('answer array: ', answerArray);
100
+
100
101
  if (choice.categoryCount === undefined || choice.categoryCount === 0) {
101
102
  return answerArray;
102
103
  } else {
103
104
  const choices = answerArray.map((a) => a.choices);
104
105
  const result = limitInArrays(choice.id, choices, choice.categoryCount);
106
+
105
107
  const updatedArray = result.map((r, index) => {
106
108
  return {
107
109
  category: answerArray[index].category,
@@ -109,6 +111,7 @@ export const ensureNoExtraChoicesInAnswer = (answer, choices) => {
109
111
  choices: r,
110
112
  };
111
113
  });
114
+
112
115
  return updatedArray;
113
116
  }
114
117
  }, answer);
@@ -126,11 +129,12 @@ export const ensureNoExtraChoicesInAlternate = (answer, choices) => {
126
129
 
127
130
  const out = choices.reduce((answerArray, choice) => {
128
131
  log('choice: ----> ', choice.id, 'categoryCount: ', choice.categoryCount);
129
- // log('answer array: ', answerArray);
132
+
130
133
  if (choice.categoryCount === undefined || choice.categoryCount === 0) {
131
134
  return answerArray;
132
135
  } else {
133
136
  let alternatePair = {};
137
+
134
138
  answerArray.forEach((answer) =>
135
139
  (answer.alternateResponses || []).forEach((alternate, index) => {
136
140
  if (index in alternatePair) {
@@ -143,9 +147,11 @@ export const ensureNoExtraChoicesInAlternate = (answer, choices) => {
143
147
  );
144
148
 
145
149
  const recreatedAlternate = [];
150
+
146
151
  Object.keys(alternatePair).forEach((k) => {
147
152
  const limitAlternate = limitInArrays(choice.id, alternatePair[k], choice.categoryCount);
148
153
  alternatePair[k] = limitAlternate;
154
+
149
155
  alternatePair[k].forEach((item, index) => {
150
156
  if (!recreatedAlternate[index]) {
151
157
  recreatedAlternate[index] = [];
@@ -166,6 +172,7 @@ export const ensureNoExtraChoicesInAlternate = (answer, choices) => {
166
172
  return updatedArray;
167
173
  }
168
174
  }, answer);
175
+
169
176
  return out;
170
177
  };
171
178
  /**
@@ -175,7 +182,9 @@ export const ensureNoExtraChoicesInAlternate = (answer, choices) => {
175
182
  */
176
183
  export const countInAnswer = (choiceId, answer) => {
177
184
  const out = answer.reduce((acc, a) => acc + countInChoices(choiceId, a.choices), 0);
185
+
178
186
  log('[countInAnswer] choiceId:', choiceId, answer);
187
+
179
188
  return out;
180
189
  };
181
190
 
@@ -197,6 +206,7 @@ export const countChosen = (choice, categories) => {
197
206
 
198
207
  return categories.reduce((acc, c) => {
199
208
  const count = (c.choices || []).filter((h) => h.id === choice.id).length;
209
+
200
210
  return acc + count;
201
211
  }, 0);
202
212
  };
@@ -216,7 +226,9 @@ export const removeAllChoices = (choiceId, answers, categoryId) => {
216
226
  return answers.map((a) => {
217
227
  if (!categoryId || a.category === categoryId) {
218
228
  const cloned = clone(a.choices);
229
+
219
230
  remove(cloned, (v) => v === choiceId);
231
+
220
232
  return { ...a, choices: cloned };
221
233
  } else {
222
234
  return a;
@@ -228,7 +240,9 @@ export const rearrangeChoices = (choices, indexFrom, indexTo) => {
228
240
  if (choices.length === 0) {
229
241
  return choices;
230
242
  }
243
+
231
244
  choices.splice(indexFrom, 1, choices.splice(indexTo, 1, choices[indexFrom])[0]);
245
+
232
246
  return choices;
233
247
  };
234
248
 
@@ -236,11 +250,13 @@ export const verifyAllowMultiplePlacements = (choice, categoryId, answers) => {
236
250
  return answers.map((a) => {
237
251
  if (a.category !== categoryId) {
238
252
  a.choices = (a.choices || []).filter((c) => c !== choice.id);
253
+
239
254
  return a;
240
255
  } else {
241
256
  a.choices = a.choices.reduce((acc, currentValue) => {
242
257
  if (currentValue.id === choice.id) {
243
258
  const foundIndex = acc.findIndex((c) => c.id === choice.id);
259
+
244
260
  if (foundIndex === -1) {
245
261
  acc.push(currentValue);
246
262
  }
@@ -250,6 +266,7 @@ export const verifyAllowMultiplePlacements = (choice, categoryId, answers) => {
250
266
 
251
267
  return acc;
252
268
  }, []);
269
+
253
270
  return a;
254
271
  }
255
272
  });
@@ -264,9 +281,11 @@ export const removeChoiceFromCategory = (choiceId, categoryId, choiceIndex, answ
264
281
  const index = cloned.findIndex((v, index) => {
265
282
  return v === choiceId && index >= choiceIndex;
266
283
  });
284
+
267
285
  if (index !== -1) {
268
286
  cloned.splice(index, 1);
269
287
  }
288
+
270
289
  return { ...a, choices: cloned };
271
290
  } else {
272
291
  return a;
@@ -288,14 +307,17 @@ export const moveChoiceToCategory = (choiceId, from, to, choiceIndex, answers) =
288
307
  const index = answers.findIndex((a) => a.category === to);
289
308
  if (index === -1) {
290
309
  answers.push({ category: to, choices: [choiceId] });
310
+
291
311
  return answers;
292
312
  } else {
293
313
  return answers.map((a) => {
294
314
  if (a.category === to) {
295
315
  a.choices = a.choices || [];
296
316
  a.choices.push(choiceId);
317
+
297
318
  return a;
298
319
  }
320
+
299
321
  return a;
300
322
  });
301
323
  }
@@ -326,10 +348,12 @@ export const moveChoiceToAlternate = (choiceId, from, to, choiceIndex, answers,
326
348
  (resp) => resp !== choiceId,
327
349
  );
328
350
  }
351
+
329
352
  if (!a.alternateResponses) {
330
353
  a.alternateResponses = [];
331
354
  a.alternateResponses[alternateIndex] = [];
332
355
  }
356
+
333
357
  a.alternateResponses[alternateIndex].push(choiceId);
334
358
  }
335
359
 
@@ -344,6 +368,7 @@ export const moveChoiceToAlternate = (choiceId, from, to, choiceIndex, answers,
344
368
  export const stillSelectable = (h, builtCategories) => {
345
369
  if (h.categoryCount > 0) {
346
370
  const count = countChosen(h, builtCategories);
371
+
347
372
  return count < h.categoryCount;
348
373
  } else {
349
374
  return true;
@@ -363,6 +388,7 @@ export const buildChoices = (possibleResponseChoices, builtCategoryChoices) => {
363
388
  (acc, builtChoice) => {
364
389
  // set correct value on each choice that was selected by user
365
390
  const index = acc.copyOfPossibleResponse.findIndex((cRC) => cRC === builtChoice.id);
391
+
366
392
  // if the choice exists in the correct response
367
393
  // set the correct: true
368
394
  if (index >= 0) {
package/src/scoring.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import debug from 'debug';
2
+
2
3
  const log = debug('@pie-lib:categorize:scoring');
4
+
3
5
  const getWeightingRules = (scoring) => {
4
6
  if (!scoring || !scoring.weighting) {
5
7
  return [];
@@ -8,6 +10,7 @@ const getWeightingRules = (scoring) => {
8
10
  return [];
9
11
  } else {
10
12
  const rules = scoring.weighting ? scoring.weighting.rules || [] : [];
13
+
11
14
  return rules;
12
15
  }
13
16
  }
@@ -15,10 +18,12 @@ const getWeightingRules = (scoring) => {
15
18
 
16
19
  const getPartialRulesForCategory = (partial, categoryId) => {
17
20
  log('partial? ', partial);
21
+
18
22
  if (!partial || !partial.enabled) {
19
23
  return;
20
24
  } else {
21
25
  const pr = partial.rules.find((pr) => pr.category === categoryId);
26
+
22
27
  return pr ? pr.rules || [] : [];
23
28
  }
24
29
  };
@@ -34,10 +39,12 @@ const getPartialRulesForCategory = (partial, categoryId) => {
34
39
  export const score = (categories, scoring) =>
35
40
  new Promise((resolve) => {
36
41
  log('categories: ', categories, 'scoring: ', scoring);
42
+
37
43
  const weightingRules = getWeightingRules(scoring);
38
44
 
39
45
  const weights = categories.map((c) => {
40
46
  const r = weightingRules.find((r) => r.category === c.id) || { points: 1 };
47
+
41
48
  return { ...r, category: c.id };
42
49
  });
43
50
 
@@ -45,6 +52,7 @@ export const score = (categories, scoring) =>
45
52
 
46
53
  const weightTotal = categories.reduce((total, c) => {
47
54
  const r = weights.find((r) => r.category === c.id);
55
+
48
56
  return (total += r.points);
49
57
  }, 0);
50
58
 
@@ -58,16 +66,24 @@ export const score = (categories, scoring) =>
58
66
  return { category: c.id, score: w, points: w };
59
67
  } else {
60
68
  const rules = getPartialRulesForCategory(scoring.partial, c.id);
69
+
61
70
  log('partial rules for category: ', rules);
71
+
62
72
  if (!rules) {
63
73
  return { category: c.id, score: 0, points: w };
64
74
  } else {
65
75
  const correctCount = (c.choices || []).filter((h) => h.correct).length;
76
+
66
77
  log('correctCount: ', correctCount);
78
+
67
79
  let rule = rules.find((u) => u.count === correctCount);
80
+
68
81
  log('rule: ', rule);
82
+
69
83
  rule = rule || { percent: 0, count: correctCount };
84
+
70
85
  const score = w * (rule.percent / 100);
86
+
71
87
  return {
72
88
  category: c.id,
73
89
  score,
@@ -88,6 +104,7 @@ export const score = (categories, scoring) =>
88
104
  log('weightedScore: ', weightedScore);
89
105
 
90
106
  const score = parseFloat((weightedScore / weightTotal).toFixed(2), 10);
107
+
91
108
  resolve({
92
109
  score,
93
110
  details: {