@pie-element/image-cloze-association 9.1.2-next.4 → 9.2.0-next.0
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 +16 -0
- package/configure/CHANGELOG.md +6 -0
- package/configure/package.json +3 -3
- package/controller/CHANGELOG.md +10 -0
- package/controller/lib/index.js +68 -6
- package/controller/lib/index.js.map +1 -1
- package/controller/package.json +1 -1
- package/controller/src/__tests__/index.test.js +1 -1
- package/controller/src/index.js +80 -7
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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
|
+
# [9.2.0-next.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/image-cloze-association@9.1.2-next.5...@pie-element/image-cloze-association@9.2.0-next.0) (2026-03-18)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- test - include trace log in score response for empty placements ([4a46588](https://github.com/pie-framework/pie-elements/commit/4a46588819250b6efb11b458ed415c6346e70c94))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **image-cloze-association:** add trace log for scoring in outcome function PD-5437 ([c9e8e27](https://github.com/pie-framework/pie-elements/commit/c9e8e279113f144b9f316b2de833dbf9264884fd))
|
|
15
|
+
|
|
16
|
+
## [9.1.2-next.5](https://github.com/pie-framework/pie-elements/compare/@pie-element/image-cloze-association@9.1.2-next.4...@pie-element/image-cloze-association@9.1.2-next.5) (2026-03-12)
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
- bump libs, update mathquill, switch interface PD-5791 ([686a7c0](https://github.com/pie-framework/pie-elements/commit/686a7c0d41ff82f5ddad7cecd93cc0c18324a81b))
|
|
21
|
+
|
|
6
22
|
## [9.1.2-next.4](https://github.com/pie-framework/pie-elements/compare/@pie-element/image-cloze-association@9.1.2-next.3...@pie-element/image-cloze-association@9.1.2-next.4) (2026-03-09)
|
|
7
23
|
|
|
8
24
|
### Bug Fixes
|
package/configure/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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
|
+
## [8.1.1-next.4](https://github.com/pie-framework/pie-elements/compare/@pie-element/image-cloze-association-configure@8.1.1-next.3...@pie-element/image-cloze-association-configure@8.1.1-next.4) (2026-03-12)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- bump libs, update mathquill, switch interface PD-5791 ([686a7c0](https://github.com/pie-framework/pie-elements/commit/686a7c0d41ff82f5ddad7cecd93cc0c18324a81b))
|
|
11
|
+
|
|
6
12
|
## [8.1.1-next.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/image-cloze-association-configure@8.1.1-next.2...@pie-element/image-cloze-association-configure@8.1.1-next.3) (2026-03-06)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @pie-element/image-cloze-association-configure
|
package/configure/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/image-cloze-association-configure",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "8.1.1-next.
|
|
4
|
+
"version": "8.1.1-next.4",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "src/index.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"@mui/icons-material": "^7.3.4",
|
|
13
13
|
"@mui/material": "^7.3.4",
|
|
14
14
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
15
|
-
"@pie-lib/config-ui": "12.2.0-next.
|
|
16
|
-
"@pie-lib/editable-html-tip-tap": "1.2.0-next.
|
|
15
|
+
"@pie-lib/config-ui": "12.2.0-next.17",
|
|
16
|
+
"@pie-lib/editable-html-tip-tap": "1.2.0-next.16",
|
|
17
17
|
"debug": "^4.1.1",
|
|
18
18
|
"prop-types": "^15.8.1",
|
|
19
19
|
"react": "18.3.1",
|
package/controller/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.2.0-next.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/image-cloze-association-controller@7.1.1-next.1...@pie-element/image-cloze-association-controller@7.2.0-next.0) (2026-03-18)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- test - include trace log in score response for empty placements ([4a46588](https://github.com/pie-framework/pie-elements/commit/4a46588819250b6efb11b458ed415c6346e70c94))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **image-cloze-association:** add trace log for scoring in outcome function PD-5437 ([c9e8e27](https://github.com/pie-framework/pie-elements/commit/c9e8e279113f144b9f316b2de833dbf9264884fd))
|
|
15
|
+
|
|
6
16
|
## [7.1.1-next.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/image-cloze-association-controller@7.1.0-next.1...@pie-element/image-cloze-association-controller@7.1.1-next.1) (2026-02-26)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @pie-element/image-cloze-association-controller
|
package/controller/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.validate = exports.outcome = exports.normalize = exports.model = exports.isResponseCorrect = exports.getPartialScore = exports.createCorrectResponseSession = void 0;
|
|
7
|
+
exports.validate = exports.outcome = exports.normalize = exports.model = exports.isResponseCorrect = exports.getPartialScore = exports.getLogTrace = exports.createCorrectResponseSession = void 0;
|
|
8
8
|
var _debug = _interopRequireDefault(require("debug"));
|
|
9
9
|
var _humps = require("humps");
|
|
10
10
|
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
@@ -173,20 +173,82 @@ const getScore = (config, session, env = {}) => {
|
|
|
173
173
|
const correct = isDefaultOrAltResponseCorrect(config, session);
|
|
174
174
|
return isPartialScoring ? getPartialScore(config, session) : correct ? 1 : 0;
|
|
175
175
|
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Generates detailed trace log for scoring evaluation
|
|
179
|
+
* @param {Object} model - the question model
|
|
180
|
+
* @param {Object} session - the student session
|
|
181
|
+
* @param {Object} env - the environment
|
|
182
|
+
* @returns {Array} traceLog - array of trace messages
|
|
183
|
+
*/
|
|
184
|
+
const getLogTrace = (model, session, env) => {
|
|
185
|
+
const traceLog = [];
|
|
186
|
+
const {
|
|
187
|
+
answers
|
|
188
|
+
} = session || {};
|
|
189
|
+
const validResponse = model.validation?.validResponse?.value || [];
|
|
190
|
+
const totalContainers = validResponse.length;
|
|
191
|
+
traceLog.push(`${totalContainers} placement container(s) defined in this question.`);
|
|
192
|
+
if (answers && answers.length > 0) {
|
|
193
|
+
traceLog.push(`Student placed ${answers.length} image(s) into placement containers.`);
|
|
194
|
+
const answersByContainer = {};
|
|
195
|
+
answers.forEach(answer => {
|
|
196
|
+
if (!answersByContainer[answer.containerIndex]) {
|
|
197
|
+
answersByContainer[answer.containerIndex] = [];
|
|
198
|
+
}
|
|
199
|
+
answersByContainer[answer.containerIndex].push(answer.value);
|
|
200
|
+
});
|
|
201
|
+
validResponse.forEach((container, containerIndex) => {
|
|
202
|
+
const correctImages = container.images || [];
|
|
203
|
+
const studentImages = answersByContainer[containerIndex] || [];
|
|
204
|
+
if (correctImages.length > 0) {
|
|
205
|
+
if (studentImages.length === 0) {
|
|
206
|
+
traceLog.push(`Container ${containerIndex + 1}: student left empty (should contain ${correctImages.length} image(s)).`);
|
|
207
|
+
} else {
|
|
208
|
+
const correctCount = studentImages.filter(img => correctImages.includes(img)).length;
|
|
209
|
+
const incorrectCount = studentImages.length - correctCount;
|
|
210
|
+
if (correctCount > 0 && incorrectCount === 0) {
|
|
211
|
+
traceLog.push(`Container ${containerIndex + 1}: student placed ${correctCount} correct image(s).`);
|
|
212
|
+
} else if (correctCount === 0 && incorrectCount > 0) {
|
|
213
|
+
traceLog.push(`Container ${containerIndex + 1}: student placed ${incorrectCount} incorrect image(s).`);
|
|
214
|
+
} else {
|
|
215
|
+
traceLog.push(`Container ${containerIndex + 1}: student placed ${correctCount} correct and ${incorrectCount} incorrect image(s).`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
traceLog.push('Student did not place any images into placement containers.');
|
|
222
|
+
}
|
|
223
|
+
const altResponses = model.validation?.altResponses || [];
|
|
224
|
+
if (altResponses.length > 0) {
|
|
225
|
+
traceLog.push(`${altResponses.length} alternate response combination(s) are accepted for this question.`);
|
|
226
|
+
}
|
|
227
|
+
const partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env);
|
|
228
|
+
const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';
|
|
229
|
+
traceLog.push(`Score calculated using ${scoringMethod}.`);
|
|
230
|
+
const score = getScore(model, session, env);
|
|
231
|
+
traceLog.push(`Final score: ${score}.`);
|
|
232
|
+
return traceLog;
|
|
233
|
+
};
|
|
234
|
+
exports.getLogTrace = getLogTrace;
|
|
176
235
|
const outcome = (config, session, env = {}) => {
|
|
177
236
|
return new Promise(resolve => {
|
|
178
237
|
log('outcome...');
|
|
179
238
|
if (!session || (0, _lodashEs.isEmpty)(session)) {
|
|
180
239
|
resolve({
|
|
181
240
|
score: 0,
|
|
182
|
-
empty: true
|
|
241
|
+
empty: true,
|
|
242
|
+
traceLog: ['Student did not place any images into placement containers. Score is 0.']
|
|
183
243
|
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
244
|
+
} else {
|
|
245
|
+
const configCamelized = (0, _humps.camelizeKeys)(config);
|
|
246
|
+
const traceLog = getLogTrace(configCamelized, session, env);
|
|
187
247
|
const score = getScore(configCamelized, session, env);
|
|
188
248
|
resolve({
|
|
189
|
-
score
|
|
249
|
+
score,
|
|
250
|
+
empty: false,
|
|
251
|
+
traceLog
|
|
190
252
|
});
|
|
191
253
|
}
|
|
192
254
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_humps","_controllerUtils","_lodashEs","_defaults","_utils","log","debug","normalize","question","defaults","exports","model","session","env","questionNormalized","questionCamelized","camelizeKeys","Promise","resolve","shouldIncludeCorrectResponse","mode","responseAreasToBeFilled","possibleResponses","completeResponses","hasUnplacedChoices","getCompleteResponseDetails","validation","out","disabled","responseCorrect","getScore","undefined","shuffle","possible_responses","role","teacherInstructions","teacherInstructionsEnabled","rationale","isResponseCorrect","correctResponses","responses","cloneDeep","isCorrect","totalValidResponses","isEmpty","forEach","value","images","length","answers","answer","index","containerIndex","indexOf","splice","keepNonEmptyResponses","filtered","filter","response","isDefaultOrAltResponseCorrect","altResponses","validResponse","altResponse","getDeductionPerContainer","valid","totalStack","item","incorrectStack","maxValid","ignored","slice","getPartialScore","maxResponsePerZone","correctAnswers","incorrectAnswers","all","getAllUniqueCorrectness","deductionList","id","nonEmptyResponses","denominator","str","toFixed","parseFloat","config","isPartialScoring","partialScoring","enabled","correct","outcome","score","empty","configCamelized","createCorrectResponseSession","valid_response","container","i","v","push","getInnerText","html","replaceAll","getContent","replace","validate","errors","field","required"],"sources":["../src/index.js"],"sourcesContent":["import debug from 'debug';\nimport { camelizeKeys } from 'humps';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport { cloneDeep, isEmpty, shuffle } from 'lodash-es';\n\nimport defaults from './defaults';\nimport { getAllUniqueCorrectness, getCompleteResponseDetails } from './utils';\n\nconst log = debug('pie-elements:image-cloze-association:controller');\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\nexport const model = (question, session, env) => {\n const questionNormalized = normalize(question);\n const questionCamelized = camelizeKeys(questionNormalized);\n\n return new Promise((resolve) => {\n const shouldIncludeCorrectResponse = env.mode === 'evaluate';\n\n const {\n responseAreasToBeFilled,\n possibleResponses: completeResponses,\n hasUnplacedChoices,\n } = getCompleteResponseDetails(questionCamelized.validation, questionCamelized.possibleResponses);\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n ...questionCamelized,\n responseCorrect: shouldIncludeCorrectResponse ? getScore(questionCamelized, session) === 1 : undefined,\n validation: shouldIncludeCorrectResponse ? questionCamelized.validation : undefined,\n responseAreasToBeFilled,\n completeResponses,\n hasUnplacedChoices,\n };\n\n if (questionNormalized.shuffle) {\n out.possibleResponses = shuffle(questionNormalized.possible_responses);\n }\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.teacherInstructions = questionCamelized.teacherInstructionsEnabled\n ? questionCamelized.teacherInstructions\n : null;\n out.rationale = questionCamelized.rationale ? questionCamelized.rationale : null;\n } else {\n out.teacherInstructions = null;\n out.rationale = null;\n }\n\n resolve(out);\n });\n};\n\nexport const isResponseCorrect = (correctResponses, session) => {\n const responses = cloneDeep(correctResponses);\n let isCorrect = true;\n let totalValidResponses = 0;\n\n if (!session || isEmpty(session)) {\n return false;\n }\n\n responses.forEach((value) => (totalValidResponses += (value.images || []).length));\n\n if (session.answers && totalValidResponses === session.answers.length) {\n session.answers.forEach((answer) => {\n const index = (responses[answer.containerIndex]?.images || []).indexOf(answer.value);\n\n if (index >= 0) {\n // remove response from correct responses array to ensure that duplicates are evaluated correctly\n responses[answer.containerIndex].images.splice(index, 1);\n } else {\n isCorrect = false;\n }\n });\n } else {\n isCorrect = false;\n }\n\n return isCorrect;\n};\n\n// This applies for correct responses that have empty values\nconst keepNonEmptyResponses = (responses) => {\n const filtered = responses.filter((response) => response.images && response.images.length);\n return cloneDeep(filtered);\n};\n\n// This applies for items that don't support partial scoring.\nconst isDefaultOrAltResponseCorrect = (question, session) => {\n const {\n validation: { altResponses },\n } = question;\n let {\n validation: {\n validResponse: { value },\n },\n } = question;\n\n let isCorrect = isResponseCorrect(value, session);\n\n // Look for correct answers in alternate responses.\n if (!isCorrect && altResponses && altResponses.length) {\n altResponses.forEach((altResponse) => {\n if (isResponseCorrect(altResponse.value, session)) {\n isCorrect = true;\n }\n });\n }\n return isCorrect;\n};\n\n// Deduct only the items that exceeded the maximum valid response per container.\nconst getDeductionPerContainer = (containerIndex, answers, valid) => {\n const totalStack = answers.filter((item) => item.containerIndex === containerIndex);\n const incorrectStack = totalStack.filter((item) => !item.isCorrect);\n const maxValid = (valid.value[containerIndex].images || []).length;\n\n if (totalStack.length > maxValid) {\n const ignored = totalStack.length - maxValid;\n return incorrectStack.slice(-ignored);\n }\n return [];\n};\n\nexport const getPartialScore = (question, session) => {\n const {\n validation: { validResponse },\n maxResponsePerZone,\n } = question;\n let correctAnswers = 0;\n let incorrectAnswers = 0;\n let possibleResponses = 0;\n\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n validResponse.value.forEach((value) => (possibleResponses += (value.images || []).length));\n\n if (session.answers && session.answers.length) {\n const all = getAllUniqueCorrectness(session.answers, validResponse.value);\n correctAnswers = all.filter((item) => item.isCorrect).length;\n incorrectAnswers = all.filter((item) => !item.isCorrect).length;\n\n // deduction rules: https://docs.google.com/document/d/1Oprm8Qs5fg_Dwoj2pNpsfu4D63QgCZgvcqTgeaVel7I/edit\n session.answers.forEach((answer) => {\n if (maxResponsePerZone > 1) {\n const deductionList = getDeductionPerContainer(answer.containerIndex, all, validResponse);\n\n if (deductionList.length) {\n deductionList.forEach((item) => {\n if (item.id === answer.id) {\n correctAnswers -= 1;\n }\n });\n }\n }\n });\n\n if (!maxResponsePerZone || maxResponsePerZone <= 1) {\n correctAnswers -= incorrectAnswers;\n }\n } else {\n correctAnswers = 0;\n }\n // negative values will implicitly make the score equal to zero\n correctAnswers = correctAnswers < 0 ? 0 : correctAnswers;\n\n // use length of validResponse since some containers can be left empty\n const nonEmptyResponses = keepNonEmptyResponses(validResponse.value);\n const denominator = maxResponsePerZone > 1 ? possibleResponses : (nonEmptyResponses || []).length;\n const str = (correctAnswers / denominator).toFixed(2);\n\n return parseFloat(str);\n};\n\nconst getScore = (config, session, env = {}) => {\n const isPartialScoring = partialScoring.enabled(config, env);\n const correct = isDefaultOrAltResponseCorrect(config, session);\n\n return isPartialScoring ? getPartialScore(config, session) : correct ? 1 : 0;\n};\n\nexport const outcome = (config, session, env = {}) => {\n return new Promise((resolve) => {\n log('outcome...');\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n const configCamelized = camelizeKeys(config);\n\n if (session.answers || []) {\n const score = getScore(configCamelized, session, env);\n resolve({ score });\n }\n });\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const {\n validation: {\n valid_response: { value },\n },\n } = question;\n const answers = [];\n\n if (value) {\n value.forEach((container, i) => {\n (container.images || []).forEach((v) => {\n answers.push({\n value: v,\n containerIndex: i,\n });\n });\n });\n }\n\n resolve({\n answers,\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const errors = {};\n\n ['teacherInstructions'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n return errors;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GA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OAAA,CAAA8F,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_humps","_controllerUtils","_lodashEs","_defaults","_utils","log","debug","normalize","question","defaults","exports","model","session","env","questionNormalized","questionCamelized","camelizeKeys","Promise","resolve","shouldIncludeCorrectResponse","mode","responseAreasToBeFilled","possibleResponses","completeResponses","hasUnplacedChoices","getCompleteResponseDetails","validation","out","disabled","responseCorrect","getScore","undefined","shuffle","possible_responses","role","teacherInstructions","teacherInstructionsEnabled","rationale","isResponseCorrect","correctResponses","responses","cloneDeep","isCorrect","totalValidResponses","isEmpty","forEach","value","images","length","answers","answer","index","containerIndex","indexOf","splice","keepNonEmptyResponses","filtered","filter","response","isDefaultOrAltResponseCorrect","altResponses","validResponse","altResponse","getDeductionPerContainer","valid","totalStack","item","incorrectStack","maxValid","ignored","slice","getPartialScore","maxResponsePerZone","correctAnswers","incorrectAnswers","all","getAllUniqueCorrectness","deductionList","id","nonEmptyResponses","denominator","str","toFixed","parseFloat","config","isPartialScoring","partialScoring","enabled","correct","getLogTrace","traceLog","totalContainers","push","answersByContainer","container","correctImages","studentImages","correctCount","img","includes","incorrectCount","partialScoringEnabled","scoringMethod","score","outcome","empty","configCamelized","createCorrectResponseSession","valid_response","i","v","getInnerText","html","replaceAll","getContent","replace","validate","errors","field","required"],"sources":["../src/index.js"],"sourcesContent":["import debug from 'debug';\nimport { camelizeKeys } from 'humps';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport { cloneDeep, isEmpty, shuffle } from 'lodash-es';\n\nimport defaults from './defaults';\nimport { getAllUniqueCorrectness, getCompleteResponseDetails } from './utils';\n\nconst log = debug('pie-elements:image-cloze-association:controller');\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\nexport const model = (question, session, env) => {\n const questionNormalized = normalize(question);\n const questionCamelized = camelizeKeys(questionNormalized);\n\n return new Promise((resolve) => {\n const shouldIncludeCorrectResponse = env.mode === 'evaluate';\n\n const {\n responseAreasToBeFilled,\n possibleResponses: completeResponses,\n hasUnplacedChoices,\n } = getCompleteResponseDetails(questionCamelized.validation, questionCamelized.possibleResponses);\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n ...questionCamelized,\n responseCorrect: shouldIncludeCorrectResponse ? getScore(questionCamelized, session) === 1 : undefined,\n validation: shouldIncludeCorrectResponse ? questionCamelized.validation : undefined,\n responseAreasToBeFilled,\n completeResponses,\n hasUnplacedChoices,\n };\n\n if (questionNormalized.shuffle) {\n out.possibleResponses = shuffle(questionNormalized.possible_responses);\n }\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.teacherInstructions = questionCamelized.teacherInstructionsEnabled\n ? questionCamelized.teacherInstructions\n : null;\n out.rationale = questionCamelized.rationale ? questionCamelized.rationale : null;\n } else {\n out.teacherInstructions = null;\n out.rationale = null;\n }\n\n resolve(out);\n });\n};\n\nexport const isResponseCorrect = (correctResponses, session) => {\n const responses = cloneDeep(correctResponses);\n let isCorrect = true;\n let totalValidResponses = 0;\n\n if (!session || isEmpty(session)) {\n return false;\n }\n\n responses.forEach((value) => (totalValidResponses += (value.images || []).length));\n\n if (session.answers && totalValidResponses === session.answers.length) {\n session.answers.forEach((answer) => {\n const index = (responses[answer.containerIndex]?.images || []).indexOf(answer.value);\n\n if (index >= 0) {\n // remove response from correct responses array to ensure that duplicates are evaluated correctly\n responses[answer.containerIndex].images.splice(index, 1);\n } else {\n isCorrect = false;\n }\n });\n } else {\n isCorrect = false;\n }\n\n return isCorrect;\n};\n\n// This applies for correct responses that have empty values\nconst keepNonEmptyResponses = (responses) => {\n const filtered = responses.filter((response) => response.images && response.images.length);\n return cloneDeep(filtered);\n};\n\n// This applies for items that don't support partial scoring.\nconst isDefaultOrAltResponseCorrect = (question, session) => {\n const {\n validation: { altResponses },\n } = question;\n let {\n validation: {\n validResponse: { value },\n },\n } = question;\n\n let isCorrect = isResponseCorrect(value, session);\n\n // Look for correct answers in alternate responses.\n if (!isCorrect && altResponses && altResponses.length) {\n altResponses.forEach((altResponse) => {\n if (isResponseCorrect(altResponse.value, session)) {\n isCorrect = true;\n }\n });\n }\n return isCorrect;\n};\n\n// Deduct only the items that exceeded the maximum valid response per container.\nconst getDeductionPerContainer = (containerIndex, answers, valid) => {\n const totalStack = answers.filter((item) => item.containerIndex === containerIndex);\n const incorrectStack = totalStack.filter((item) => !item.isCorrect);\n const maxValid = (valid.value[containerIndex].images || []).length;\n\n if (totalStack.length > maxValid) {\n const ignored = totalStack.length - maxValid;\n return incorrectStack.slice(-ignored);\n }\n return [];\n};\n\nexport const getPartialScore = (question, session) => {\n const {\n validation: { validResponse },\n maxResponsePerZone,\n } = question;\n let correctAnswers = 0;\n let incorrectAnswers = 0;\n let possibleResponses = 0;\n\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n validResponse.value.forEach((value) => (possibleResponses += (value.images || []).length));\n\n if (session.answers && session.answers.length) {\n const all = getAllUniqueCorrectness(session.answers, validResponse.value);\n correctAnswers = all.filter((item) => item.isCorrect).length;\n incorrectAnswers = all.filter((item) => !item.isCorrect).length;\n\n // deduction rules: https://docs.google.com/document/d/1Oprm8Qs5fg_Dwoj2pNpsfu4D63QgCZgvcqTgeaVel7I/edit\n session.answers.forEach((answer) => {\n if (maxResponsePerZone > 1) {\n const deductionList = getDeductionPerContainer(answer.containerIndex, all, validResponse);\n\n if (deductionList.length) {\n deductionList.forEach((item) => {\n if (item.id === answer.id) {\n correctAnswers -= 1;\n }\n });\n }\n }\n });\n\n if (!maxResponsePerZone || maxResponsePerZone <= 1) {\n correctAnswers -= incorrectAnswers;\n }\n } else {\n correctAnswers = 0;\n }\n // negative values will implicitly make the score equal to zero\n correctAnswers = correctAnswers < 0 ? 0 : correctAnswers;\n\n // use length of validResponse since some containers can be left empty\n const nonEmptyResponses = keepNonEmptyResponses(validResponse.value);\n const denominator = maxResponsePerZone > 1 ? possibleResponses : (nonEmptyResponses || []).length;\n const str = (correctAnswers / denominator).toFixed(2);\n\n return parseFloat(str);\n};\n\nconst getScore = (config, session, env = {}) => {\n const isPartialScoring = partialScoring.enabled(config, env);\n const correct = isDefaultOrAltResponseCorrect(config, session);\n\n return isPartialScoring ? getPartialScore(config, session) : correct ? 1 : 0;\n};\n\n/**\n * Generates detailed trace log for scoring evaluation\n * @param {Object} model - the question model\n * @param {Object} session - the student session\n * @param {Object} env - the environment\n * @returns {Array} traceLog - array of trace messages\n */\nexport const getLogTrace = (model, session, env) => {\n const traceLog = [];\n const { answers } = session || {};\n \n const validResponse = model.validation?.validResponse?.value || [];\n const totalContainers = validResponse.length;\n traceLog.push(`${totalContainers} placement container(s) defined in this question.`);\n\n if (answers && answers.length > 0) {\n traceLog.push(`Student placed ${answers.length} image(s) into placement containers.`);\n \n const answersByContainer = {};\n answers.forEach((answer) => {\n if (!answersByContainer[answer.containerIndex]) {\n answersByContainer[answer.containerIndex] = [];\n }\n answersByContainer[answer.containerIndex].push(answer.value);\n });\n \n validResponse.forEach((container, containerIndex) => {\n const correctImages = container.images || [];\n const studentImages = answersByContainer[containerIndex] || [];\n \n if (correctImages.length > 0) {\n if (studentImages.length === 0) {\n traceLog.push(`Container ${containerIndex + 1}: student left empty (should contain ${correctImages.length} image(s)).`);\n } else {\n const correctCount = studentImages.filter(img => correctImages.includes(img)).length;\n const incorrectCount = studentImages.length - correctCount;\n \n if (correctCount > 0 && incorrectCount === 0) {\n traceLog.push(`Container ${containerIndex + 1}: student placed ${correctCount} correct image(s).`);\n } else if (correctCount === 0 && incorrectCount > 0) {\n traceLog.push(`Container ${containerIndex + 1}: student placed ${incorrectCount} incorrect image(s).`);\n } else {\n traceLog.push(`Container ${containerIndex + 1}: student placed ${correctCount} correct and ${incorrectCount} incorrect image(s).`);\n }\n }\n }\n });\n } else {\n traceLog.push('Student did not place any images into placement containers.');\n }\n\n const altResponses = model.validation?.altResponses || [];\n if (altResponses.length > 0) {\n traceLog.push(`${altResponses.length} alternate response combination(s) are accepted for this question.`);\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env);\n const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';\n traceLog.push(`Score calculated using ${scoringMethod}.`);\n\n const score = getScore(model, session, env);\n traceLog.push(`Final score: ${score}.`);\n\n return traceLog;\n}\n\nexport const outcome = (config, session, env = {}) => {\n return new Promise((resolve) => {\n log('outcome...');\n if (!session || isEmpty(session)) {\n resolve({ \n score: 0, \n empty: true, \n traceLog: ['Student did not place any images into placement containers. Score is 0.'] \n });\n } else {\n const configCamelized = camelizeKeys(config);\n const traceLog = getLogTrace(configCamelized, session, env);\n const score = getScore(configCamelized, session, env);\n \n resolve({ \n score, \n empty: false,\n traceLog \n });\n }\n });\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const {\n validation: {\n valid_response: { value },\n },\n } = question;\n const answers = [];\n\n if (value) {\n value.forEach((container, i) => {\n (container.images || []).forEach((v) => {\n answers.push({\n value: v,\n containerIndex: i,\n });\n });\n });\n }\n\n resolve({\n answers,\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const errors = {};\n\n ['teacherInstructions'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n return errors;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,MAAA,GAA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,IAAIlC,MAAM,CAACkC,KAAK,CAAC,EAAEC,QAAQ,IAAI,CAACL,UAAU,CAACvG,KAAK,CAAC2G,KAAK,CAAC,CAAC,EAAE;MACxDD,MAAM,CAACC,KAAK,CAAC,GAAG,yBAAyB;IAC3C;EACF,CAAC,CAAC;EAEF,OAAOD,MAAM;AACf,CAAC;AAAC3G,OAAA,CAAA0G,QAAA,GAAAA,QAAA","ignoreList":[]}
|
package/controller/package.json
CHANGED
|
@@ -135,7 +135,7 @@ describe('controller', () => {
|
|
|
135
135
|
const returnOutcome = (session) => {
|
|
136
136
|
it(`returns score of 0 and empty: true if session is ${JSON.stringify(session)}`, async () => {
|
|
137
137
|
const result = await outcome(question, session);
|
|
138
|
-
expect(result).toEqual({ score: 0, empty: true });
|
|
138
|
+
expect(result).toEqual({ score: 0, empty: true, traceLog: ['Student did not place any images into placement containers. Score is 0.'] });
|
|
139
139
|
});
|
|
140
140
|
};
|
|
141
141
|
|
package/controller/src/index.js
CHANGED
|
@@ -183,18 +183,91 @@ const getScore = (config, session, env = {}) => {
|
|
|
183
183
|
return isPartialScoring ? getPartialScore(config, session) : correct ? 1 : 0;
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Generates detailed trace log for scoring evaluation
|
|
188
|
+
* @param {Object} model - the question model
|
|
189
|
+
* @param {Object} session - the student session
|
|
190
|
+
* @param {Object} env - the environment
|
|
191
|
+
* @returns {Array} traceLog - array of trace messages
|
|
192
|
+
*/
|
|
193
|
+
export const getLogTrace = (model, session, env) => {
|
|
194
|
+
const traceLog = [];
|
|
195
|
+
const { answers } = session || {};
|
|
196
|
+
|
|
197
|
+
const validResponse = model.validation?.validResponse?.value || [];
|
|
198
|
+
const totalContainers = validResponse.length;
|
|
199
|
+
traceLog.push(`${totalContainers} placement container(s) defined in this question.`);
|
|
200
|
+
|
|
201
|
+
if (answers && answers.length > 0) {
|
|
202
|
+
traceLog.push(`Student placed ${answers.length} image(s) into placement containers.`);
|
|
203
|
+
|
|
204
|
+
const answersByContainer = {};
|
|
205
|
+
answers.forEach((answer) => {
|
|
206
|
+
if (!answersByContainer[answer.containerIndex]) {
|
|
207
|
+
answersByContainer[answer.containerIndex] = [];
|
|
208
|
+
}
|
|
209
|
+
answersByContainer[answer.containerIndex].push(answer.value);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
validResponse.forEach((container, containerIndex) => {
|
|
213
|
+
const correctImages = container.images || [];
|
|
214
|
+
const studentImages = answersByContainer[containerIndex] || [];
|
|
215
|
+
|
|
216
|
+
if (correctImages.length > 0) {
|
|
217
|
+
if (studentImages.length === 0) {
|
|
218
|
+
traceLog.push(`Container ${containerIndex + 1}: student left empty (should contain ${correctImages.length} image(s)).`);
|
|
219
|
+
} else {
|
|
220
|
+
const correctCount = studentImages.filter(img => correctImages.includes(img)).length;
|
|
221
|
+
const incorrectCount = studentImages.length - correctCount;
|
|
222
|
+
|
|
223
|
+
if (correctCount > 0 && incorrectCount === 0) {
|
|
224
|
+
traceLog.push(`Container ${containerIndex + 1}: student placed ${correctCount} correct image(s).`);
|
|
225
|
+
} else if (correctCount === 0 && incorrectCount > 0) {
|
|
226
|
+
traceLog.push(`Container ${containerIndex + 1}: student placed ${incorrectCount} incorrect image(s).`);
|
|
227
|
+
} else {
|
|
228
|
+
traceLog.push(`Container ${containerIndex + 1}: student placed ${correctCount} correct and ${incorrectCount} incorrect image(s).`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
traceLog.push('Student did not place any images into placement containers.');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const altResponses = model.validation?.altResponses || [];
|
|
238
|
+
if (altResponses.length > 0) {
|
|
239
|
+
traceLog.push(`${altResponses.length} alternate response combination(s) are accepted for this question.`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const partialScoringEnabled = partialScoring.enabled(model, env);
|
|
243
|
+
const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';
|
|
244
|
+
traceLog.push(`Score calculated using ${scoringMethod}.`);
|
|
245
|
+
|
|
246
|
+
const score = getScore(model, session, env);
|
|
247
|
+
traceLog.push(`Final score: ${score}.`);
|
|
248
|
+
|
|
249
|
+
return traceLog;
|
|
250
|
+
}
|
|
251
|
+
|
|
186
252
|
export const outcome = (config, session, env = {}) => {
|
|
187
253
|
return new Promise((resolve) => {
|
|
188
254
|
log('outcome...');
|
|
189
255
|
if (!session || isEmpty(session)) {
|
|
190
|
-
resolve({
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
256
|
+
resolve({
|
|
257
|
+
score: 0,
|
|
258
|
+
empty: true,
|
|
259
|
+
traceLog: ['Student did not place any images into placement containers. Score is 0.']
|
|
260
|
+
});
|
|
261
|
+
} else {
|
|
262
|
+
const configCamelized = camelizeKeys(config);
|
|
263
|
+
const traceLog = getLogTrace(configCamelized, session, env);
|
|
196
264
|
const score = getScore(configCamelized, session, env);
|
|
197
|
-
|
|
265
|
+
|
|
266
|
+
resolve({
|
|
267
|
+
score,
|
|
268
|
+
empty: false,
|
|
269
|
+
traceLog
|
|
270
|
+
});
|
|
198
271
|
}
|
|
199
272
|
});
|
|
200
273
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/image-cloze-association",
|
|
3
3
|
"repository": "pie-framework/pie-elements",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.2.0-next.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"author": "pie framework developers",
|
|
28
28
|
"license": "ISC",
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "c4198b2dfd0bfa1847c515a0c95c39147398395c",
|
|
30
30
|
"scripts": {
|
|
31
31
|
"postpublish": "../../scripts/postpublish"
|
|
32
32
|
},
|