@pie-element/ebsr 14.2.1-next.2 → 14.2.1-next.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +1547 -0
- package/CHANGELOG.md +2281 -0
- package/LICENSE.md +5 -0
- package/README.md +62 -0
- package/configure/CHANGELOG.json +992 -0
- package/configure/CHANGELOG.md +2144 -0
- package/configure/lib/defaults.js +229 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/index.js +154 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/main.js +222 -0
- package/configure/lib/main.js.map +1 -0
- package/configure/package.json +23 -0
- package/configure/src/__tests__/index.test.js +492 -0
- package/configure/src/defaults.js +173 -0
- package/configure/src/index.js +174 -0
- package/configure/src/main.jsx +235 -0
- package/controller/CHANGELOG.json +552 -0
- package/controller/CHANGELOG.md +1282 -0
- package/controller/lib/defaults.js +31 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +448 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/utils.js +18 -0
- package/controller/lib/utils.js.map +1 -0
- package/controller/package.json +18 -0
- package/controller/src/__tests__/index.test.js +591 -0
- package/controller/src/__tests__/utils.test.js +48 -0
- package/controller/src/defaults.js +25 -0
- package/controller/src/index.js +442 -0
- package/controller/src/utils.js +18 -0
- package/docs/config-schema.json +5787 -0
- package/docs/config-schema.json.md +4278 -0
- package/docs/demo/config.js +8 -0
- package/docs/demo/generate.js +52 -0
- package/docs/demo/index.html +2 -0
- package/docs/demo/session.js +14 -0
- package/docs/pie-schema.json +2911 -0
- package/docs/pie-schema.json.md +2142 -0
- package/ebsr.png +0 -0
- package/lib/index.js +207 -0
- package/lib/index.js.map +1 -0
- package/lib/print.js +186 -0
- package/lib/print.js.map +1 -0
- package/module/configure.js +1 -0
- package/module/controller.js +5664 -0
- package/module/demo.js +77 -0
- package/module/element.js +1 -0
- package/module/index.html +21 -0
- package/module/manifest.json +14 -0
- package/module/print-demo.js +115 -0
- package/module/print.html +18 -0
- package/module/print.js +1 -0
- package/package.json +17 -56
- package/src/__tests__/index.test.js +129 -0
- package/src/index.js +222 -0
- package/src/print.js +207 -0
- package/dist/author/defaults.d.ts +0 -66
- package/dist/author/defaults.js +0 -161
- package/dist/author/index.d.ts +0 -34
- package/dist/author/index.js +0 -78
- package/dist/author/main.d.ts +0 -22
- package/dist/author/main.js +0 -121
- package/dist/controller/defaults.d.ts +0 -15
- package/dist/controller/defaults.js +0 -26
- package/dist/controller/index.d.ts +0 -42
- package/dist/controller/index.js +0 -186
- package/dist/controller/utils.d.ts +0 -10
- package/dist/controller/utils.js +0 -8
- package/dist/delivery/index.d.ts +0 -26
- package/dist/delivery/index.js +0 -132
- package/dist/index.d.ts +0 -1
- package/dist/index.iife.d.ts +0 -8
- package/dist/index.iife.js +0 -165
- package/dist/index.js +0 -2
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_DataView.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Hash.js +0 -16
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_ListCache.js +0 -16
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Map.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_MapCache.js +0 -16
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Promise.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Set.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_SetCache.js +0 -11
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Stack.js +0 -14
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Symbol.js +0 -5
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Uint8Array.js +0 -5
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_WeakMap.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_apply.js +0 -12
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayEach.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayFilter.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayLikeKeys.js +0 -15
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayMap.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayPush.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arraySome.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_assignValue.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_assocIndexOf.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssign.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssignIn.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssignValue.js +0 -12
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseClone.js +0 -57
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseCreate.js +0 -14
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGet.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetAllKeys.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetTag.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsArguments.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsEqual.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsEqualDeep.js +0 -30
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsMap.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsNative.js +0 -11
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsSet.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsTypedArray.js +0 -11
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseKeys.js +0 -12
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseKeysIn.js +0 -13
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseRest.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseSetToString.js +0 -14
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseTimes.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseToString.js +0 -15
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseUnary.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cacheHas.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_castPath.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneArrayBuffer.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneBuffer.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneDataView.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneRegExp.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneSymbol.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneTypedArray.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copyArray.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copyObject.js +0 -14
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copySymbols.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copySymbolsIn.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_coreJsData.js +0 -5
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_defineProperty.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_equalArrays.js +0 -35
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_equalByTag.js +0 -35
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_equalObjects.js +0 -32
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_freeGlobal.js +0 -4
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getAllKeys.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getAllKeysIn.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getMapData.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getNative.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getPrototype.js +0 -5
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getRawTag.js +0 -14
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getSymbols.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getSymbolsIn.js +0 -11
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getTag.js +0 -23
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getValue.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashClear.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashDelete.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashGet.js +0 -13
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashHas.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashSet.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneArray.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneByTag.js +0 -33
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneObject.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isIndex.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isIterateeCall.js +0 -12
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isKey.js +0 -11
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isKeyable.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isMasked.js +0 -11
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isPrototype.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheClear.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheDelete.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheGet.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheHas.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheSet.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheClear.js +0 -13
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheDelete.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheGet.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheHas.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheSet.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapToArray.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_memoizeCapped.js +0 -11
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeCreate.js +0 -5
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeys.js +0 -5
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeysIn.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nodeUtil.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_objectToString.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_overArg.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_overRest.js +0 -13
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_root.js +0 -5
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_setCacheAdd.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_setCacheHas.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_setToArray.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_setToString.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_shortOut.js +0 -14
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackClear.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackDelete.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackGet.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackHas.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackSet.js +0 -16
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stringToPath.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_toKey.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_toSource.js +0 -15
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/cloneDeep.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/constant.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/defaults.js +0 -16
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/eq.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/get.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/identity.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArguments.js +0 -10
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArray.js +0 -4
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArrayLike.js +0 -8
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isBuffer.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isEmpty.js +0 -21
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isEqual.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isFunction.js +0 -11
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isLength.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isMap.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObject.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObjectLike.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isSet.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isSymbol.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isTypedArray.js +0 -7
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/keys.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/keysIn.js +0 -9
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/memoize.js +0 -16
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/stubArray.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/stubFalse.js +0 -6
- package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/toString.js +0 -7
- package/dist/print/index.d.ts +0 -25
- package/dist/print/index.js +0 -107
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import defaults from './defaults';
|
|
2
|
+
import { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';
|
|
3
|
+
import { isResponseCorrect } from './utils';
|
|
4
|
+
import { get, isEmpty } from 'lodash-es';
|
|
5
|
+
import Translator from '@pie-lib/translator';
|
|
6
|
+
|
|
7
|
+
const { translator } = Translator;
|
|
8
|
+
|
|
9
|
+
const prepareChoice = (model, env, defaultFeedback) => (choice) => {
|
|
10
|
+
const out = {
|
|
11
|
+
label: choice.label,
|
|
12
|
+
value: choice.value,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
16
|
+
out.rationale = model.rationaleEnabled ? choice.rationale : null;
|
|
17
|
+
} else {
|
|
18
|
+
out.rationale = null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (env.mode === 'evaluate') {
|
|
22
|
+
out.correct = !!choice.correct;
|
|
23
|
+
|
|
24
|
+
if (model.feedbackEnabled) {
|
|
25
|
+
const feedbackType = (choice.feedback && choice.feedback.type) || 'none';
|
|
26
|
+
|
|
27
|
+
if (feedbackType === 'default') {
|
|
28
|
+
out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
|
|
29
|
+
} else if (feedbackType === 'custom') {
|
|
30
|
+
out.feedback = choice.feedback.value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const parsePart = (part, key, session, env) => {
|
|
39
|
+
const defaultFeedback = Object.assign({ correct: 'Correct', incorrect: 'Incorrect' }, part.defaultFeedback);
|
|
40
|
+
|
|
41
|
+
let choices = part.choices ? part.choices.map(prepareChoice(part, env, defaultFeedback)) : [];
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
...part,
|
|
45
|
+
choices,
|
|
46
|
+
disabled: env.mode !== 'gather',
|
|
47
|
+
complete: {
|
|
48
|
+
min: part.choices.filter((c) => c.correct).length,
|
|
49
|
+
},
|
|
50
|
+
responseCorrect: env.mode === 'evaluate' ? isResponseCorrect(part, key, session) : undefined,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const normalizePart = (model, base) => ({
|
|
55
|
+
...base,
|
|
56
|
+
...model,
|
|
57
|
+
choicesLayout: model.choicesLayout || (model.verticalMode === false && 'horizontal') || 'vertical',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const normalize = ({ partA = {}, partB = {}, language, ...question }) => ({
|
|
61
|
+
...defaults,
|
|
62
|
+
...question,
|
|
63
|
+
partA: normalizePart(partA, { ...defaults.partA, language }),
|
|
64
|
+
partB: normalizePart(partB, { ...defaults.partB, language }),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param {*} question
|
|
70
|
+
* @param {*} session
|
|
71
|
+
* @param {*} env
|
|
72
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
73
|
+
*/
|
|
74
|
+
export async function model(question, session, env, updateSession) {
|
|
75
|
+
const normalizedQuestion = normalize(question);
|
|
76
|
+
const partA = parsePart(normalizedQuestion.partA, 'partA', session, env);
|
|
77
|
+
const partB = parsePart(normalizedQuestion.partB, 'partB', session, env);
|
|
78
|
+
|
|
79
|
+
const shuffledValues = {};
|
|
80
|
+
|
|
81
|
+
const us = (part) => (id, element, update) =>
|
|
82
|
+
new Promise((resolve) => {
|
|
83
|
+
shuffledValues[part] = update.shuffledValues;
|
|
84
|
+
resolve();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const partASession = get(session, 'value.partA');
|
|
88
|
+
const partALockChoiceOrder = lockChoices(normalizedQuestion.partA, partASession, env);
|
|
89
|
+
|
|
90
|
+
const { choices: partAChoices } = partA || {};
|
|
91
|
+
const { choices: partBChoices } = partB || {};
|
|
92
|
+
|
|
93
|
+
if (!partALockChoiceOrder && partAChoices && partAChoices.length) {
|
|
94
|
+
partA.choices = await getShuffledChoices(
|
|
95
|
+
partAChoices,
|
|
96
|
+
{ shuffledValues: (session.shuffledValues || {}).partA },
|
|
97
|
+
us('partA'),
|
|
98
|
+
'value',
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const partBSession = get(session, 'value.partB');
|
|
103
|
+
const partBLockChoiceOrder = lockChoices(normalizedQuestion.partB, partBSession, env);
|
|
104
|
+
|
|
105
|
+
if (!partBLockChoiceOrder && partBChoices && partBChoices.length) {
|
|
106
|
+
partB.choices = await getShuffledChoices(
|
|
107
|
+
partBChoices,
|
|
108
|
+
{ shuffledValues: (session.shuffledValues || {}).partB },
|
|
109
|
+
us('partB'),
|
|
110
|
+
'value',
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!isEmpty(shuffledValues)) {
|
|
115
|
+
if (updateSession && typeof updateSession === 'function') {
|
|
116
|
+
updateSession(session.id, session.element, {
|
|
117
|
+
shuffledValues,
|
|
118
|
+
}).catch((e) => {
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
120
|
+
console.error('update session failed', e);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (normalizedQuestion.partLabels) {
|
|
126
|
+
const language = normalizedQuestion.language;
|
|
127
|
+
partA.partLabel = translator.t('ebsr.part', {
|
|
128
|
+
lng: language,
|
|
129
|
+
index: normalizedQuestion.partLabelType === 'Letters' ? 'A' : '1',
|
|
130
|
+
});
|
|
131
|
+
partB.partLabel = translator.t('ebsr.part', {
|
|
132
|
+
lng: language,
|
|
133
|
+
index: normalizedQuestion.partLabelType === 'Letters' ? 'B' : '2',
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
partA.partLabel = undefined;
|
|
137
|
+
partB.partLabel = undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
141
|
+
partA.teacherInstructions = normalizedQuestion.partA.teacherInstructionsEnabled
|
|
142
|
+
? normalizedQuestion.partA.teacherInstructions
|
|
143
|
+
: null;
|
|
144
|
+
partB.teacherInstructions = normalizedQuestion.partB.teacherInstructionsEnabled
|
|
145
|
+
? normalizedQuestion.partB.teacherInstructions
|
|
146
|
+
: null;
|
|
147
|
+
} else {
|
|
148
|
+
partA.teacherInstructions = null;
|
|
149
|
+
partB.teacherInstructions = null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
partA.prompt = normalizedQuestion.partA.promptEnabled ? normalizedQuestion.partA.prompt : null;
|
|
153
|
+
partB.prompt = normalizedQuestion.partB.promptEnabled ? normalizedQuestion.partB.prompt : null;
|
|
154
|
+
|
|
155
|
+
return new Promise((resolve) => {
|
|
156
|
+
resolve({
|
|
157
|
+
disabled: env.mode !== 'gather',
|
|
158
|
+
mode: env.mode,
|
|
159
|
+
extraCSSRules: normalizedQuestion.extraCSSRules,
|
|
160
|
+
partA,
|
|
161
|
+
partB,
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export const createDefaultModel = (model = {}) =>
|
|
167
|
+
new Promise((resolve) => {
|
|
168
|
+
resolve({
|
|
169
|
+
...defaults,
|
|
170
|
+
...model,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const isCorrect = (c) => c.correct === true;
|
|
175
|
+
|
|
176
|
+
const getScore = (config, sessionPart, key, partialScoringEnabled) => {
|
|
177
|
+
const { choices = [] } = (config && config[key]) || {};
|
|
178
|
+
const maxScore = choices.length;
|
|
179
|
+
const { value: sessionPartValue } = sessionPart || {};
|
|
180
|
+
|
|
181
|
+
const chosen = (c) => !!(sessionPartValue || []).find((v) => v === c.value);
|
|
182
|
+
const correctAndNotChosen = (c) => isCorrect(c) && !chosen(c);
|
|
183
|
+
const incorrectAndChosen = (c) => !isCorrect(c) && chosen(c);
|
|
184
|
+
const correctChoices = choices.reduce((total, choice) => {
|
|
185
|
+
if (correctAndNotChosen(choice) || incorrectAndChosen(choice)) {
|
|
186
|
+
return total - 1;
|
|
187
|
+
} else {
|
|
188
|
+
return total;
|
|
189
|
+
}
|
|
190
|
+
}, choices.length);
|
|
191
|
+
|
|
192
|
+
// determine score for a part
|
|
193
|
+
if (!partialScoringEnabled && correctChoices < maxScore) {
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return parseFloat(maxScore ? (correctChoices / maxScore).toFixed(2) : 0);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Generates detailed trace log for math-templated scoring evaluation
|
|
202
|
+
* @param {Object} question
|
|
203
|
+
* @param {Object} session
|
|
204
|
+
* @param {Object} env
|
|
205
|
+
* @returns {Array<string>} traceLog
|
|
206
|
+
*/
|
|
207
|
+
export const getLogTrace = (question, session, env) => {
|
|
208
|
+
const traceLog = [];
|
|
209
|
+
|
|
210
|
+
if (!session || !session.value) {
|
|
211
|
+
traceLog.push('Student did not answer the question.');
|
|
212
|
+
return traceLog;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const { value } = session;
|
|
216
|
+
const { partA, partB } = value;
|
|
217
|
+
|
|
218
|
+
const partialScoringEnabled = partialScoring.enabled(question, env);
|
|
219
|
+
|
|
220
|
+
traceLog.push(
|
|
221
|
+
`Scoring method: ${partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring'}.`
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const partAquestionType =
|
|
225
|
+
question.partA.choiceMode === 'radio'
|
|
226
|
+
? 'multiple-choice (radio)'
|
|
227
|
+
: 'multiple-select (checkbox)';
|
|
228
|
+
traceLog.push(`Part A question type: ${partAquestionType}.`);
|
|
229
|
+
|
|
230
|
+
const partASelections = partA?.value || [];
|
|
231
|
+
const partACorrectChoices = (question.partA.choices || []).filter((c) => c.correct);
|
|
232
|
+
const partACorrectValues = partACorrectChoices.map((c) => c.value);
|
|
233
|
+
const partACorrectSelected = partASelections.filter((v) => partACorrectValues.includes(v));
|
|
234
|
+
const partAIncorrectSelected = partASelections.filter((v) => !partACorrectValues.includes(v));
|
|
235
|
+
|
|
236
|
+
if (partASelections.length) {
|
|
237
|
+
traceLog.push(
|
|
238
|
+
`Part A: student selected ${partASelections.length} choice(s) (${partACorrectSelected.length} correct, ${partAIncorrectSelected.length} incorrect).`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const scoreA = getScore(question, partA, 'partA', partialScoringEnabled);
|
|
243
|
+
traceLog.push(`Part A score: ${scoreA}.`);
|
|
244
|
+
|
|
245
|
+
const partBquestionType =
|
|
246
|
+
question.partB.choiceMode === 'radio'
|
|
247
|
+
? 'multiple-choice (radio)'
|
|
248
|
+
: 'multiple-select (checkbox)';
|
|
249
|
+
traceLog.push(`Part B question type: ${partBquestionType}.`);
|
|
250
|
+
|
|
251
|
+
const partBSelections = partB?.value || [];
|
|
252
|
+
const partBCorrectChoices = (question.partB.choices || []).filter((c) => c.correct);
|
|
253
|
+
const partBCorrectValues = partBCorrectChoices.map((c) => c.value);
|
|
254
|
+
const correctSelected = partBSelections.filter((v) => partBCorrectValues.includes(v));
|
|
255
|
+
const incorrectSelected = partBSelections.filter((v) => !partBCorrectValues.includes(v));
|
|
256
|
+
|
|
257
|
+
if (partBSelections.length) {
|
|
258
|
+
traceLog.push(
|
|
259
|
+
`Part B: student selected ${partBSelections.length} choice(s) (${correctSelected.length} correct, ${incorrectSelected.length} incorrect).`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const scoreB = getScore(question, partB, 'partB', partialScoringEnabled);
|
|
264
|
+
traceLog.push(`Part B score: ${scoreB}.`);
|
|
265
|
+
|
|
266
|
+
if (!partialScoringEnabled) {
|
|
267
|
+
traceLog.push(
|
|
268
|
+
'Final score is awarded only if both Part A and Part B are completely correct.'
|
|
269
|
+
);
|
|
270
|
+
traceLog.push(`Final score: ${scoreA === 1 && scoreB === 1 ? 1 : 0}.`);
|
|
271
|
+
} else {
|
|
272
|
+
traceLog.push(
|
|
273
|
+
'With partial scoring enabled, Part A must be correct to earn any credit.'
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
let finalScore = 0;
|
|
277
|
+
if (scoreA === 1 && scoreB === 1) {
|
|
278
|
+
finalScore = 2;
|
|
279
|
+
} else if (scoreA === 1 && scoreB < 1) {
|
|
280
|
+
finalScore = 1;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
traceLog.push(`Final score: ${finalScore}.`);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return traceLog;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export function outcome(config, session, env) {
|
|
290
|
+
return new Promise((resolve) => {
|
|
291
|
+
const { value } = session || {};
|
|
292
|
+
|
|
293
|
+
if (!session || !value) {
|
|
294
|
+
resolve({ score: 0, scoreA: 0, scoreB: 0, empty: true, logTrace: ['Student did not answer the question.'] });
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (value) {
|
|
298
|
+
const { partA, partB } = value || {};
|
|
299
|
+
|
|
300
|
+
const partialScoringEnabled = partialScoring.enabled(config, env);
|
|
301
|
+
|
|
302
|
+
const scoreA = getScore(config, partA, 'partA', partialScoringEnabled);
|
|
303
|
+
const scoreB = getScore(config, partB, 'partB', partialScoringEnabled);
|
|
304
|
+
const logTrace = getLogTrace(config, session, env);
|
|
305
|
+
|
|
306
|
+
if (!partialScoringEnabled) {
|
|
307
|
+
// The EBSR item is worth 1 point
|
|
308
|
+
// That point is awarded if and only if both parts are fully correct, otherwise no points are awarded
|
|
309
|
+
resolve({ score: scoreA === 1 && scoreB === 1 ? 1 : 0, scoreA, scoreB, max: 1, logTrace });
|
|
310
|
+
} else {
|
|
311
|
+
// The EBSR item is worth 2 points
|
|
312
|
+
if (scoreA === 1) {
|
|
313
|
+
if (scoreB === 1) {
|
|
314
|
+
// If Part A and Part B are both correct, 2 points are awarded
|
|
315
|
+
resolve({ score: 2, scoreA, scoreB, max: 2, logTrace });
|
|
316
|
+
} else {
|
|
317
|
+
// If Part A is correct and part B is incorrect, 1 point is awarded
|
|
318
|
+
resolve({ score: 1, scoreA, scoreB, max: 2, logTrace });
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
// For all other combinations, no points are awarded
|
|
322
|
+
resolve({ score: 0, scoreA, scoreB, max: 2, logTrace });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const returnPartCorrect = (choices) => {
|
|
330
|
+
let answers = [];
|
|
331
|
+
|
|
332
|
+
choices.forEach((i) => {
|
|
333
|
+
const { correct, value } = i;
|
|
334
|
+
if (correct) {
|
|
335
|
+
answers.push(value);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
return answers;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export const createCorrectResponseSession = (question, env) => {
|
|
342
|
+
return new Promise((resolve) => {
|
|
343
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
344
|
+
const { partA, partB } = question;
|
|
345
|
+
|
|
346
|
+
const partACorrect = returnPartCorrect(partA.choices);
|
|
347
|
+
const partBCorrect = returnPartCorrect(partB.choices);
|
|
348
|
+
|
|
349
|
+
resolve({
|
|
350
|
+
value: {
|
|
351
|
+
partA: {
|
|
352
|
+
id: 'partA',
|
|
353
|
+
value: partACorrect,
|
|
354
|
+
},
|
|
355
|
+
partB: {
|
|
356
|
+
id: 'partB',
|
|
357
|
+
value: partBCorrect,
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
id: '1',
|
|
361
|
+
});
|
|
362
|
+
} else {
|
|
363
|
+
resolve(null);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
// remove all html tags
|
|
369
|
+
const getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
370
|
+
|
|
371
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
372
|
+
const getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
373
|
+
|
|
374
|
+
const validatePart = (model = {}, config = {}) => {
|
|
375
|
+
const { choices } = model;
|
|
376
|
+
const { minAnswerChoices = 2, maxAnswerChoices } = config;
|
|
377
|
+
const reversedChoices = [...(choices || [])].reverse();
|
|
378
|
+
const errors = {};
|
|
379
|
+
const choicesErrors = {};
|
|
380
|
+
const rationaleErrors = {};
|
|
381
|
+
let hasCorrectResponse = false;
|
|
382
|
+
|
|
383
|
+
['teacherInstructions', 'prompt'].forEach((field) => {
|
|
384
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
385
|
+
errors[field] = 'This field is required.';
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
reversedChoices.forEach((choice, index) => {
|
|
390
|
+
const { correct, value, label, rationale } = choice;
|
|
391
|
+
|
|
392
|
+
if (correct) {
|
|
393
|
+
hasCorrectResponse = true;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (!getContent(label)) {
|
|
397
|
+
choicesErrors[value] = 'Content should not be empty.';
|
|
398
|
+
} else {
|
|
399
|
+
const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);
|
|
400
|
+
|
|
401
|
+
if (identicalAnswer) {
|
|
402
|
+
choicesErrors[value] = 'Content should be unique.';
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (config.rationale?.required && !getContent(rationale)) {
|
|
407
|
+
rationaleErrors[value] = 'This field is required.';
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const nbOfChoices = (choices || []).length;
|
|
412
|
+
|
|
413
|
+
if (nbOfChoices < minAnswerChoices) {
|
|
414
|
+
errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;
|
|
415
|
+
} else if (nbOfChoices > maxAnswerChoices) {
|
|
416
|
+
errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (!hasCorrectResponse) {
|
|
420
|
+
errors.correctResponse = 'No correct response defined.';
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (!isEmpty(choicesErrors)) {
|
|
424
|
+
errors.choices = choicesErrors;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (!isEmpty(rationaleErrors)) {
|
|
428
|
+
errors.rationale = rationaleErrors;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return errors;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
export const validate = (model = {}, config = {}) => {
|
|
435
|
+
const { partA, partB } = model || {};
|
|
436
|
+
const { partA: partAConfig, partB: partBConfig } = config || {};
|
|
437
|
+
|
|
438
|
+
const partAErrors = validatePart(partA, partAConfig);
|
|
439
|
+
const partBErrors = validatePart(partB, partBConfig);
|
|
440
|
+
|
|
441
|
+
return { partA: partAErrors, partB: partBErrors };
|
|
442
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
|
|
3
|
+
export const getCorrectResponse = (choices) =>
|
|
4
|
+
choices &&
|
|
5
|
+
choices
|
|
6
|
+
.filter((c) => c.correct)
|
|
7
|
+
.map((c) => c.value)
|
|
8
|
+
.sort();
|
|
9
|
+
|
|
10
|
+
export const isResponseCorrect = (question, key, session) => {
|
|
11
|
+
let correctResponse = getCorrectResponse(question.choices);
|
|
12
|
+
|
|
13
|
+
if (session && session.value) {
|
|
14
|
+
return isEqual((session.value[key].value || []).sort(), correctResponse);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return false;
|
|
18
|
+
};
|