@pie-element/ebsr 7.0.24-next.1 → 7.0.24-next.2
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/configure/lib/defaults.js +125 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/index.js +207 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/main.js +284 -0
- package/configure/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +1793 -0
- package/configure/node_modules/@pie-element/multiple-choice/LICENSE.md +5 -0
- package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
- package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
- package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +1334 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +104 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +198 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +599 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +20 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +768 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +305 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +36 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +353 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +277 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +52 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +338 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +274 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +298 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +157 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +174 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +151 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +97 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +254 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +129 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +35 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/configure.js +843 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/controller.js +20686 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/demo.js +77 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/element.js +2019 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/index.html +21 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/manifest.json +14 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print-demo.js +115 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print.html +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print.js +1983 -0
- package/configure/node_modules/@pie-element/multiple-choice/package.json +34 -0
- package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.json +672 -0
- package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.md +427 -0
- package/configure/node_modules/@pie-lib/math-rendering/LICENSE.md +5 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/index.js +30 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js +316 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js +23 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js +123 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js +103 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js +275 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/package.json +19 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/demo.html +872 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/demo.js +108 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/main.html +156 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/main.js +16 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/webpack.config.js +29 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/index.js +4 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/chtml.js +215 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/index.js +13 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/mml.js +24 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/normalization.js +69 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/render-math.js +234 -0
- package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.json +937 -0
- package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.md +602 -0
- package/configure/node_modules/@pie-lib/render-ui/LICENSE.md +5 -0
- package/configure/node_modules/@pie-lib/render-ui/README.md +33 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js +146 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/color.js +134 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/color.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js +160 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js +24 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js +102 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/index.js +104 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js +60 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js +133 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js +162 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js +28 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/readable.js +28 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/readable.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js +160 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js +206 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/package.json +30 -0
- package/configure/node_modules/@pie-lib/render-ui/src/collapsible/index.jsx +68 -0
- package/configure/node_modules/@pie-lib/render-ui/src/color.js +48 -0
- package/configure/node_modules/@pie-lib/render-ui/src/feedback.jsx +100 -0
- package/configure/node_modules/@pie-lib/render-ui/src/has-text.js +14 -0
- package/configure/node_modules/@pie-lib/render-ui/src/html-and-math.js +40 -0
- package/configure/node_modules/@pie-lib/render-ui/src/index.js +27 -0
- package/configure/node_modules/@pie-lib/render-ui/src/input-container.jsx +41 -0
- package/configure/node_modules/@pie-lib/render-ui/src/preview-layout.jsx +77 -0
- package/configure/node_modules/@pie-lib/render-ui/src/preview-prompt.jsx +90 -0
- package/configure/node_modules/@pie-lib/render-ui/src/purpose.jsx +19 -0
- package/configure/node_modules/@pie-lib/render-ui/src/readable.jsx +19 -0
- package/configure/node_modules/@pie-lib/render-ui/src/response-indicators.jsx +89 -0
- package/configure/node_modules/@pie-lib/render-ui/src/withUndoReset.jsx +118 -0
- package/controller/lib/defaults.js +28 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +471 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/utils.js +33 -0
- package/controller/lib/utils.js.map +1 -0
- package/lib/index.js +202 -0
- package/lib/index.js.map +1 -0
- package/lib/print.js +243 -0
- package/lib/print.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
|
|
9
|
+
exports.model = model;
|
|
10
|
+
exports.normalize = void 0;
|
|
11
|
+
exports.outcome = outcome;
|
|
12
|
+
exports.validate = void 0;
|
|
13
|
+
|
|
14
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
15
|
+
|
|
16
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
17
|
+
|
|
18
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
19
|
+
|
|
20
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
21
|
+
|
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
+
|
|
24
|
+
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
25
|
+
|
|
26
|
+
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
27
|
+
|
|
28
|
+
var _utils = require("./utils");
|
|
29
|
+
|
|
30
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
31
|
+
|
|
32
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
33
|
+
|
|
34
|
+
var _excluded = ["partA", "partB"];
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
39
|
+
|
|
40
|
+
var prepareChoice = function prepareChoice(model, env, defaultFeedback) {
|
|
41
|
+
return function (choice) {
|
|
42
|
+
var out = {
|
|
43
|
+
label: choice.label,
|
|
44
|
+
value: choice.value
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
48
|
+
out.rationale = model.rationaleEnabled ? choice.rationale : null;
|
|
49
|
+
} else {
|
|
50
|
+
out.rationale = null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (env.mode === 'evaluate') {
|
|
54
|
+
out.correct = !!choice.correct;
|
|
55
|
+
|
|
56
|
+
if (model.feedbackEnabled) {
|
|
57
|
+
var feedbackType = choice.feedback && choice.feedback.type || 'none';
|
|
58
|
+
|
|
59
|
+
if (feedbackType === 'default') {
|
|
60
|
+
out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
|
|
61
|
+
} else if (feedbackType === 'custom') {
|
|
62
|
+
out.feedback = choice.feedback.value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return out;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var parsePart = function parsePart(part, key, session, env) {
|
|
72
|
+
var defaultFeedback = Object.assign({
|
|
73
|
+
correct: 'Correct',
|
|
74
|
+
incorrect: 'Incorrect'
|
|
75
|
+
}, part.defaultFeedback);
|
|
76
|
+
var choices = part.choices ? part.choices.map(prepareChoice(part, env, defaultFeedback)) : [];
|
|
77
|
+
return _objectSpread(_objectSpread({}, part), {}, {
|
|
78
|
+
choices: choices,
|
|
79
|
+
disabled: env.mode !== 'gather',
|
|
80
|
+
complete: {
|
|
81
|
+
min: part.choices.filter(function (c) {
|
|
82
|
+
return c.correct;
|
|
83
|
+
}).length
|
|
84
|
+
},
|
|
85
|
+
responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(part, key, session) : undefined
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var normalize = function normalize(_ref) {
|
|
90
|
+
var _ref$partA = _ref.partA,
|
|
91
|
+
partA = _ref$partA === void 0 ? {} : _ref$partA,
|
|
92
|
+
_ref$partB = _ref.partB,
|
|
93
|
+
partB = _ref$partB === void 0 ? {} : _ref$partB,
|
|
94
|
+
question = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
95
|
+
return _objectSpread(_objectSpread({
|
|
96
|
+
partLabels: true,
|
|
97
|
+
partLabelType: 'Letters'
|
|
98
|
+
}, question), {}, {
|
|
99
|
+
partA: _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"].partA), {}, {
|
|
100
|
+
rationaleEnabled: true,
|
|
101
|
+
feedbackEnabled: true,
|
|
102
|
+
promptEnabled: true,
|
|
103
|
+
teacherInstructionsEnabled: true,
|
|
104
|
+
studentInstructionsEnabled: true,
|
|
105
|
+
gridColumns: '2'
|
|
106
|
+
}, partA), {}, {
|
|
107
|
+
choicesLayout: partA.choicesLayout || partA.verticalMode === false && 'horizontal' || 'vertical'
|
|
108
|
+
}),
|
|
109
|
+
partB: _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"].partB), {}, {
|
|
110
|
+
rationaleEnabled: true,
|
|
111
|
+
promptEnabled: true,
|
|
112
|
+
feedbackEnabled: true,
|
|
113
|
+
teacherInstructionsEnabled: true,
|
|
114
|
+
studentInstructionsEnabled: true,
|
|
115
|
+
gridColumns: '2'
|
|
116
|
+
}, partB), {}, {
|
|
117
|
+
choicesLayout: partB.choicesLayout || partB.verticalMode === false && 'horizontal' || 'vertical'
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* @param {*} question
|
|
124
|
+
* @param {*} session
|
|
125
|
+
* @param {*} env
|
|
126
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
exports.normalize = normalize;
|
|
131
|
+
|
|
132
|
+
function model(_x, _x2, _x3, _x4) {
|
|
133
|
+
return _model.apply(this, arguments);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function _model() {
|
|
137
|
+
_model = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(question, session, env, updateSession) {
|
|
138
|
+
var normalizedQuestion, partA, partB, shuffledValues, us, partASession, partALockChoiceOrder, _ref8, partAChoices, _ref9, partBChoices, partBSession, partBLockChoiceOrder;
|
|
139
|
+
|
|
140
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
141
|
+
while (1) {
|
|
142
|
+
switch (_context.prev = _context.next) {
|
|
143
|
+
case 0:
|
|
144
|
+
normalizedQuestion = normalize(question);
|
|
145
|
+
partA = parsePart(normalizedQuestion.partA, 'partA', session, env);
|
|
146
|
+
partB = parsePart(normalizedQuestion.partB, 'partB', session, env);
|
|
147
|
+
shuffledValues = {};
|
|
148
|
+
|
|
149
|
+
us = function us(part) {
|
|
150
|
+
return function (id, element, update) {
|
|
151
|
+
return new Promise(function (resolve) {
|
|
152
|
+
shuffledValues[part] = update.shuffledValues;
|
|
153
|
+
resolve();
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
partASession = (0, _get["default"])(session, 'value.partA');
|
|
159
|
+
partALockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion.partA, partASession, env);
|
|
160
|
+
_ref8 = partA || {}, partAChoices = _ref8.choices;
|
|
161
|
+
_ref9 = partB || {}, partBChoices = _ref9.choices;
|
|
162
|
+
|
|
163
|
+
if (!(!partALockChoiceOrder && partAChoices && partAChoices.length)) {
|
|
164
|
+
_context.next = 13;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
_context.next = 12;
|
|
169
|
+
return (0, _controllerUtils.getShuffledChoices)(partAChoices, {
|
|
170
|
+
shuffledValues: (session.shuffledValues || {}).partA
|
|
171
|
+
}, us('partA'), 'value');
|
|
172
|
+
|
|
173
|
+
case 12:
|
|
174
|
+
partA.choices = _context.sent;
|
|
175
|
+
|
|
176
|
+
case 13:
|
|
177
|
+
partBSession = (0, _get["default"])(session, 'value.partB');
|
|
178
|
+
partBLockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion.partB, partBSession, env);
|
|
179
|
+
|
|
180
|
+
if (!(!partBLockChoiceOrder && partBChoices && partBChoices.length)) {
|
|
181
|
+
_context.next = 19;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
_context.next = 18;
|
|
186
|
+
return (0, _controllerUtils.getShuffledChoices)(partBChoices, {
|
|
187
|
+
shuffledValues: (session.shuffledValues || {}).partB
|
|
188
|
+
}, us('partB'), 'value');
|
|
189
|
+
|
|
190
|
+
case 18:
|
|
191
|
+
partB.choices = _context.sent;
|
|
192
|
+
|
|
193
|
+
case 19:
|
|
194
|
+
if (!(0, _isEmpty["default"])(shuffledValues)) {
|
|
195
|
+
if (updateSession && typeof updateSession === 'function') {
|
|
196
|
+
updateSession(session.id, session.element, {
|
|
197
|
+
shuffledValues: shuffledValues
|
|
198
|
+
})["catch"](function (e) {
|
|
199
|
+
console.error('update session failed', e);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (normalizedQuestion.partLabels) {
|
|
205
|
+
partA.partLabel = normalizedQuestion.partLabelType === 'Letters' ? 'Part A' : 'Part 1';
|
|
206
|
+
partB.partLabel = normalizedQuestion.partLabelType === 'Letters' ? 'Part B' : 'Part 2';
|
|
207
|
+
} else {
|
|
208
|
+
partA.partLabel = undefined;
|
|
209
|
+
partB.partLabel = undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
213
|
+
partA.teacherInstructions = normalizedQuestion.partA.teacherInstructionsEnabled ? normalizedQuestion.partA.teacherInstructions : null;
|
|
214
|
+
partB.teacherInstructions = normalizedQuestion.partB.teacherInstructionsEnabled ? normalizedQuestion.partB.teacherInstructions : null;
|
|
215
|
+
} else {
|
|
216
|
+
partA.teacherInstructions = null;
|
|
217
|
+
partB.teacherInstructions = null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
partA.prompt = normalizedQuestion.partA.promptEnabled ? normalizedQuestion.partA.prompt : null;
|
|
221
|
+
partB.prompt = normalizedQuestion.partB.promptEnabled ? normalizedQuestion.partB.prompt : null;
|
|
222
|
+
return _context.abrupt("return", new Promise(function (resolve) {
|
|
223
|
+
resolve({
|
|
224
|
+
disabled: env.mode !== 'gather',
|
|
225
|
+
mode: env.mode,
|
|
226
|
+
partA: partA,
|
|
227
|
+
partB: partB
|
|
228
|
+
});
|
|
229
|
+
}));
|
|
230
|
+
|
|
231
|
+
case 25:
|
|
232
|
+
case "end":
|
|
233
|
+
return _context.stop();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}, _callee);
|
|
237
|
+
}));
|
|
238
|
+
return _model.apply(this, arguments);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
var createDefaultModel = function createDefaultModel() {
|
|
242
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
243
|
+
return new Promise(function (resolve) {
|
|
244
|
+
resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
exports.createDefaultModel = createDefaultModel;
|
|
249
|
+
|
|
250
|
+
var isCorrect = function isCorrect(c) {
|
|
251
|
+
return c.correct === true;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
var getScore = function getScore(config, sessionPart, key) {
|
|
255
|
+
var _ref2 = config && config[key] || {},
|
|
256
|
+
_ref2$choices = _ref2.choices,
|
|
257
|
+
choices = _ref2$choices === void 0 ? [] : _ref2$choices;
|
|
258
|
+
|
|
259
|
+
var maxScore = choices.length;
|
|
260
|
+
|
|
261
|
+
var _ref3 = sessionPart || {},
|
|
262
|
+
sessionPartValue = _ref3.value;
|
|
263
|
+
|
|
264
|
+
var chosen = function chosen(c) {
|
|
265
|
+
return !!(sessionPartValue || []).find(function (v) {
|
|
266
|
+
return v === c.value;
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
var correctAndNotChosen = function correctAndNotChosen(c) {
|
|
271
|
+
return isCorrect(c) && !chosen(c);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
var incorrectAndChosen = function incorrectAndChosen(c) {
|
|
275
|
+
return !isCorrect(c) && chosen(c);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
var correctChoices = choices.reduce(function (total, choice) {
|
|
279
|
+
if (correctAndNotChosen(choice) || incorrectAndChosen(choice)) {
|
|
280
|
+
return total - 1;
|
|
281
|
+
} else {
|
|
282
|
+
return total;
|
|
283
|
+
}
|
|
284
|
+
}, choices.length); // determine score for a part
|
|
285
|
+
|
|
286
|
+
if (!config.partialScoring && correctChoices < maxScore) {
|
|
287
|
+
return 0;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return parseFloat(maxScore ? (correctChoices / maxScore).toFixed(2) : 0);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
function outcome(config, session) {
|
|
294
|
+
return new Promise(function (resolve) {
|
|
295
|
+
var _ref4 = session || {},
|
|
296
|
+
value = _ref4.value;
|
|
297
|
+
|
|
298
|
+
if (!session || !value) {
|
|
299
|
+
resolve({
|
|
300
|
+
score: 0,
|
|
301
|
+
scoreA: 0,
|
|
302
|
+
scoreB: 0,
|
|
303
|
+
empty: true
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (value) {
|
|
308
|
+
var _ref5 = value || {},
|
|
309
|
+
partA = _ref5.partA,
|
|
310
|
+
partB = _ref5.partB;
|
|
311
|
+
|
|
312
|
+
var scoreA = getScore(config, partA, 'partA');
|
|
313
|
+
var scoreB = getScore(config, partB, 'partB');
|
|
314
|
+
|
|
315
|
+
if (!config.partialScoring) {
|
|
316
|
+
// The EBSR item is worth 1 point
|
|
317
|
+
// That point is awarded if and only if both parts are fully correct, otherwise no points are awarded
|
|
318
|
+
resolve({
|
|
319
|
+
score: scoreA === 1 && scoreB === 1 ? 1 : 0,
|
|
320
|
+
scoreA: scoreA,
|
|
321
|
+
scoreB: scoreB,
|
|
322
|
+
max: 1
|
|
323
|
+
});
|
|
324
|
+
} else {
|
|
325
|
+
// The EBSR item is worth 2 points
|
|
326
|
+
if (scoreA === 1) {
|
|
327
|
+
if (scoreB === 1) {
|
|
328
|
+
// If Part A and Part B are both correct, 2 points are awarded
|
|
329
|
+
resolve({
|
|
330
|
+
score: 2,
|
|
331
|
+
scoreA: scoreA,
|
|
332
|
+
scoreB: scoreB,
|
|
333
|
+
max: 2
|
|
334
|
+
});
|
|
335
|
+
} else {
|
|
336
|
+
// If Part A is correct and part B is incorrect, 1 point is awarded
|
|
337
|
+
resolve({
|
|
338
|
+
score: 1,
|
|
339
|
+
scoreA: scoreA,
|
|
340
|
+
scoreB: scoreB,
|
|
341
|
+
max: 2
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
// For all other combinations, no points are awarded
|
|
346
|
+
resolve({
|
|
347
|
+
score: 0,
|
|
348
|
+
scoreA: scoreA,
|
|
349
|
+
scoreB: scoreB,
|
|
350
|
+
max: 2
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
var returnPartCorrect = function returnPartCorrect(choices) {
|
|
359
|
+
var answers = [];
|
|
360
|
+
choices.forEach(function (i) {
|
|
361
|
+
var correct = i.correct,
|
|
362
|
+
value = i.value;
|
|
363
|
+
|
|
364
|
+
if (correct) {
|
|
365
|
+
answers.push(value);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
return answers;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
|
|
372
|
+
return new Promise(function (resolve) {
|
|
373
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
374
|
+
var partA = question.partA,
|
|
375
|
+
partB = question.partB;
|
|
376
|
+
var partACorrect = returnPartCorrect(partA.choices);
|
|
377
|
+
var partBCorrect = returnPartCorrect(partB.choices);
|
|
378
|
+
resolve({
|
|
379
|
+
value: {
|
|
380
|
+
partA: {
|
|
381
|
+
id: 'partA',
|
|
382
|
+
value: partACorrect
|
|
383
|
+
},
|
|
384
|
+
partB: {
|
|
385
|
+
id: 'partB',
|
|
386
|
+
value: partBCorrect
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
id: '1'
|
|
390
|
+
});
|
|
391
|
+
} else {
|
|
392
|
+
resolve(null);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
398
|
+
|
|
399
|
+
var validatePart = function validatePart() {
|
|
400
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
401
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
402
|
+
var choices = model.choices;
|
|
403
|
+
var _config$minAnswerChoi = config.minAnswerChoices,
|
|
404
|
+
minAnswerChoices = _config$minAnswerChoi === void 0 ? 2 : _config$minAnswerChoi,
|
|
405
|
+
maxAnswerChoices = config.maxAnswerChoices;
|
|
406
|
+
var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
|
|
407
|
+
var choicesErrors = {};
|
|
408
|
+
var hasCorrectResponse = false;
|
|
409
|
+
reversedChoices.forEach(function (choice, index) {
|
|
410
|
+
var correct = choice.correct,
|
|
411
|
+
value = choice.value,
|
|
412
|
+
label = choice.label;
|
|
413
|
+
|
|
414
|
+
if (correct) {
|
|
415
|
+
hasCorrectResponse = true;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (label === '' || label === '<div></div>') {
|
|
419
|
+
choicesErrors[value] = 'Content should not be empty.';
|
|
420
|
+
} else {
|
|
421
|
+
var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
|
|
422
|
+
return c.label === label;
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
if (identicalAnswer) {
|
|
426
|
+
choicesErrors[value] = 'Content should be unique.';
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
var errors = {};
|
|
431
|
+
var nbOfChoices = (choices || []).length;
|
|
432
|
+
|
|
433
|
+
if (nbOfChoices < minAnswerChoices) {
|
|
434
|
+
errors.answerChoicesError = "There should be at least ".concat(minAnswerChoices, " choices defined.");
|
|
435
|
+
} else if (nbOfChoices > maxAnswerChoices) {
|
|
436
|
+
errors.answerChoicesError = "No more than ".concat(maxAnswerChoices, " choices should be defined.");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (!hasCorrectResponse) {
|
|
440
|
+
errors.correctResponseError = 'No correct response defined.';
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (!(0, _isEmpty["default"])(choicesErrors)) {
|
|
444
|
+
errors.choicesErrors = choicesErrors;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return errors;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
var validate = function validate() {
|
|
451
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
452
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
453
|
+
|
|
454
|
+
var _ref6 = model || {},
|
|
455
|
+
partA = _ref6.partA,
|
|
456
|
+
partB = _ref6.partB;
|
|
457
|
+
|
|
458
|
+
var _ref7 = config || {},
|
|
459
|
+
partAConfig = _ref7.partA,
|
|
460
|
+
partBConfig = _ref7.partB;
|
|
461
|
+
|
|
462
|
+
var partAErrors = validatePart(partA, partAConfig);
|
|
463
|
+
var partBErrors = validatePart(partB, partBConfig);
|
|
464
|
+
return {
|
|
465
|
+
partA: partAErrors,
|
|
466
|
+
partB: partBErrors
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
exports.validate = validate;
|
|
471
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["prepareChoice","model","env","defaultFeedback","choice","out","label","value","role","mode","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","parsePart","part","key","session","Object","assign","incorrect","choices","map","disabled","complete","min","filter","c","length","responseCorrect","undefined","normalize","partA","partB","question","partLabels","partLabelType","defaults","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","gridColumns","choicesLayout","verticalMode","updateSession","normalizedQuestion","shuffledValues","us","id","element","update","Promise","resolve","partASession","partALockChoiceOrder","partAChoices","partBChoices","partBSession","partBLockChoiceOrder","e","console","error","partLabel","teacherInstructions","prompt","createDefaultModel","isCorrect","getScore","config","sessionPart","maxScore","sessionPartValue","chosen","find","v","correctAndNotChosen","incorrectAndChosen","correctChoices","reduce","total","partialScoring","parseFloat","toFixed","outcome","score","scoreA","scoreB","empty","max","returnPartCorrect","answers","forEach","i","push","createCorrectResponseSession","partACorrect","partBCorrect","validatePart","minAnswerChoices","maxAnswerChoices","reversedChoices","reverse","choicesErrors","hasCorrectResponse","index","identicalAnswer","slice","some","errors","nbOfChoices","answerChoicesError","correctResponseError","validate","partAConfig","partBConfig","partAErrors","partBErrors"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAQC,GAAR,EAAaC,eAAb;AAAA,SAAiC,UAAAC,MAAM,EAAI;AAC/D,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEF,MAAM,CAACE,KADJ;AAEVC,MAAAA,KAAK,EAAEH,MAAM,CAACG;AAFJ,KAAZ;;AAKA,QACEL,GAAG,CAACM,IAAJ,KAAa,YAAb,KACCN,GAAG,CAACO,IAAJ,KAAa,MAAb,IAAuBP,GAAG,CAACO,IAAJ,KAAa,UADrC,CADF,EAGE;AACAJ,MAAAA,GAAG,CAACK,SAAJ,GAAgBT,KAAK,CAACU,gBAAN,GAAyBP,MAAM,CAACM,SAAhC,GAA4C,IAA5D;AACD,KALD,MAKO;AACLL,MAAAA,GAAG,CAACK,SAAJ,GAAgB,IAAhB;AACD;;AAED,QAAIR,GAAG,CAACO,IAAJ,KAAa,UAAjB,EAA6B;AAC3BJ,MAAAA,GAAG,CAACO,OAAJ,GAAc,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FD,MAEO,IAAIW,WAAW,GAAGV,gBAAlB,EAAoC;AACzCS,IAAAA,MAAM,CAACE,kBAAP,0BAA4CX,gBAA5C;AACD;;AAED,MAAI,CAACI,kBAAL,EAAyB;AACvBK,IAAAA,MAAM,CAACG,oBAAP,GAA8B,8BAA9B;AACD;;AAED,MAAI,CAAC,yBAAQT,aAAR,CAAL,EAA6B;AAC3BM,IAAAA,MAAM,CAACN,aAAP,GAAuBA,aAAvB;AACD;;AAED,SAAOM,MAAP;AACD,CA3CD;;AA6CO,IAAMI,QAAQ,GAAG,SAAXA,QAAW,GAA6B;AAAA,MAA5BlH,KAA4B,uEAApB,EAAoB;AAAA,MAAhBsE,MAAgB,uEAAP,EAAO;;AACnD,cAAyBtE,KAAK,IAAI,EAAlC;AAAA,MAAQkC,KAAR,SAAQA,KAAR;AAAA,MAAeC,KAAf,SAAeA,KAAf;;AACA,cAAmDmC,MAAM,IAAI,EAA7D;AAAA,MAAe6C,WAAf,SAAQjF,KAAR;AAAA,MAAmCkF,WAAnC,SAA4BjF,KAA5B;;AAEA,MAAMkF,WAAW,GAAGlB,YAAY,CAACjE,KAAD,EAAQiF,WAAR,CAAhC;AACA,MAAMG,WAAW,GAAGnB,YAAY,CAAChE,KAAD,EAAQiF,WAAR,CAAhC;AAEA,SAAO;AAAElF,IAAAA,KAAK,EAAEmF,WAAT;AAAsBlF,IAAAA,KAAK,EAAEmF;AAA7B,GAAP;AACD,CARM","sourcesContent":["import defaults from './defaults';\nimport { lockChoices, getShuffledChoices } from '@pie-lib/controller-utils';\nimport { isResponseCorrect } from './utils';\nimport get from 'lodash/get';\nimport isEmpty from 'lodash/isEmpty';\n\nconst prepareChoice = (model, env, defaultFeedback) => choice => {\n const out = {\n label: choice.label,\n value: choice.value\n };\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n out.rationale = model.rationaleEnabled ? choice.rationale : null;\n } else {\n out.rationale = null;\n }\n\n if (env.mode === 'evaluate') {\n out.correct = !!choice.correct;\n\n if (model.feedbackEnabled) {\n const feedbackType = (choice.feedback && choice.feedback.type) || 'none';\n\n if (feedbackType === 'default') {\n out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];\n } else if (feedbackType === 'custom') {\n out.feedback = choice.feedback.value;\n }\n }\n }\n\n return out;\n};\n\nconst parsePart = (part, key, session, env) => {\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n part.defaultFeedback\n );\n\n let choices = part.choices\n ? part.choices.map(prepareChoice(part, env, defaultFeedback))\n : [];\n\n return {\n ...part,\n choices,\n disabled: env.mode !== 'gather',\n complete: {\n min: part.choices.filter(c => c.correct).length\n },\n responseCorrect:\n env.mode === 'evaluate'\n ? isResponseCorrect(part, key, session)\n : undefined\n };\n};\n\nexport const normalize = ({ partA = {}, partB = {}, ...question }) => ({\n partLabels: true,\n partLabelType: 'Letters',\n ...question,\n partA: {\n ...defaults.partA,\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n gridColumns: '2',\n ...partA,\n choicesLayout: partA.choicesLayout || (partA.verticalMode === false && 'horizontal') || 'vertical'\n },\n partB: {\n ...defaults.partB,\n rationaleEnabled: true,\n promptEnabled: true,\n feedbackEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n gridColumns: '2',\n ...partB,\n choicesLayout: partB.choicesLayout || (partB.verticalMode === false && 'horizontal') || 'vertical'\n }\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n const normalizedQuestion = normalize(question);\n const partA = parsePart(normalizedQuestion.partA, 'partA', session, env);\n const partB = parsePart(normalizedQuestion.partB, 'partB', session, env);\n\n const shuffledValues = {};\n\n const us = part => (id, element, update) =>\n new Promise(resolve => {\n shuffledValues[part] = update.shuffledValues;\n resolve();\n });\n\n const partASession = get(session, 'value.partA');\n const partALockChoiceOrder = lockChoices(normalizedQuestion.partA, partASession, env);\n\n const { choices: partAChoices } = partA || {};\n const { choices: partBChoices } = partB || {};\n\n if (!partALockChoiceOrder && partAChoices && partAChoices.length) {\n partA.choices = await getShuffledChoices(\n partAChoices,\n { shuffledValues: (session.shuffledValues || {}).partA },\n us('partA'),\n 'value'\n );\n }\n\n const partBSession = get(session, 'value.partB');\n const partBLockChoiceOrder = lockChoices(normalizedQuestion.partB, partBSession, env);\n\n if (!partBLockChoiceOrder && partBChoices && partBChoices.length) {\n partB.choices = await getShuffledChoices(\n partBChoices,\n { shuffledValues: (session.shuffledValues || {}).partB },\n us('partB'),\n 'value'\n );\n }\n\n if (!isEmpty(shuffledValues)) {\n if (updateSession && typeof updateSession === 'function') {\n updateSession(session.id, session.element, {\n shuffledValues\n }).catch(e => {\n console.error('update session failed', e);\n });\n }\n }\n\n if (normalizedQuestion.partLabels) {\n partA.partLabel =\n normalizedQuestion.partLabelType === 'Letters' ? 'Part A' : 'Part 1';\n partB.partLabel =\n normalizedQuestion.partLabelType === 'Letters' ? 'Part B' : 'Part 2';\n } else {\n partA.partLabel = undefined;\n partB.partLabel = undefined;\n }\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n partA.teacherInstructions = normalizedQuestion.partA\n .teacherInstructionsEnabled\n ? normalizedQuestion.partA.teacherInstructions\n : null;\n partB.teacherInstructions = normalizedQuestion.partB\n .teacherInstructionsEnabled\n ? normalizedQuestion.partB.teacherInstructions\n : null;\n } else {\n partA.teacherInstructions = null;\n partB.teacherInstructions = null;\n }\n\n partA.prompt = normalizedQuestion.partA.promptEnabled\n ? normalizedQuestion.partA.prompt\n : null;\n partB.prompt = normalizedQuestion.partB.promptEnabled\n ? normalizedQuestion.partB.prompt\n : null;\n\n return new Promise(resolve => {\n resolve({\n disabled: env.mode !== 'gather',\n mode: env.mode,\n partA,\n partB\n });\n });\n}\n\nexport const createDefaultModel = (model = {}) =>\n new Promise(resolve => {\n resolve({\n ...defaults,\n ...model\n });\n });\n\nconst isCorrect = c => c.correct === true;\n\nconst getScore = (config, sessionPart, key) => {\n const { choices = [] } = (config && config[key]) || {};\n const maxScore = choices.length;\n const { value: sessionPartValue } = sessionPart || {};\n\n const chosen = c => !!(sessionPartValue || []).find(v => v === c.value);\n const correctAndNotChosen = c => isCorrect(c) && !chosen(c);\n const incorrectAndChosen = c => !isCorrect(c) && chosen(c);\n const correctChoices = choices.reduce((total, choice) => {\n if (correctAndNotChosen(choice) || incorrectAndChosen(choice)) {\n return total - 1;\n } else {\n return total;\n }\n }, choices.length);\n\n // determine score for a part\n if (!config.partialScoring && correctChoices < maxScore) {\n return 0;\n }\n\n return parseFloat(maxScore ? (correctChoices / maxScore).toFixed(2) : 0);\n};\n\nexport function outcome(config, session) {\n return new Promise(resolve => {\n const { value } = session || {};\n\n if (!session || !value) {\n resolve({ score: 0, scoreA: 0, scoreB: 0, empty: true });\n }\n\n if (value) {\n const { partA, partB } = value || {};\n\n const scoreA = getScore(config, partA, 'partA');\n const scoreB = getScore(config, partB, 'partB');\n\n if (!config.partialScoring) {\n // The EBSR item is worth 1 point\n // That point is awarded if and only if both parts are fully correct, otherwise no points are awarded\n resolve({ score: (scoreA === 1 && scoreB === 1) ? 1 : 0, scoreA, scoreB, max: 1 });\n } else {\n // The EBSR item is worth 2 points\n if (scoreA === 1) {\n if (scoreB === 1) {\n // If Part A and Part B are both correct, 2 points are awarded\n resolve({ score: 2, scoreA, scoreB, max: 2 });\n } else {\n // If Part A is correct and part B is incorrect, 1 point is awarded\n resolve({ score: 1, scoreA, scoreB, max: 2 });\n }\n } else {\n // For all other combinations, no points are awarded\n resolve({ score: 0, scoreA, scoreB, max: 2 });\n }\n }\n }\n });\n}\n\nconst returnPartCorrect = choices => {\n let answers = [];\n\n choices.forEach(i => {\n const { correct, value } = i;\n if (correct) {\n answers.push(value);\n }\n });\n return answers;\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { partA, partB } = question;\n\n const partACorrect = returnPartCorrect(partA.choices);\n const partBCorrect = returnPartCorrect(partB.choices);\n\n resolve({\n value: {\n partA: {\n id: 'partA',\n value: partACorrect\n },\n partB: {\n id: 'partB',\n value: partBCorrect\n }\n },\n id: '1'\n });\n } else {\n resolve(null);\n }\n });\n};\n\nconst validatePart = (model = {}, config = {}) => {\n const { choices } = model;\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n const reversedChoices = [...choices || []].reverse();\n const choicesErrors = {};\n let hasCorrectResponse = false;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n }\n\n if (label === '' || label === '<div></div>') {\n choicesErrors[value] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[value] = 'Content should be unique.';\n }\n }\n });\n\n const errors = {};\n const nbOfChoices = (choices || []).length;\n\n if (nbOfChoices < minAnswerChoices) {\n errors.answerChoicesError = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.answerChoicesError = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (!hasCorrectResponse) {\n errors.correctResponseError = 'No correct response defined.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n return errors;\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { partA, partB } = model || {};\n const { partA: partAConfig, partB: partBConfig } = config || {};\n\n const partAErrors = validatePart(partA, partAConfig);\n const partBErrors = validatePart(partB, partBConfig);\n\n return { partA: partAErrors, partB: partBErrors };\n};\n"],"file":"index.js"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.isResponseCorrect = exports.getCorrectResponse = void 0;
|
|
9
|
+
|
|
10
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
11
|
+
|
|
12
|
+
var getCorrectResponse = function getCorrectResponse(choices) {
|
|
13
|
+
return choices && choices.filter(function (c) {
|
|
14
|
+
return c.correct;
|
|
15
|
+
}).map(function (c) {
|
|
16
|
+
return c.value;
|
|
17
|
+
}).sort();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.getCorrectResponse = getCorrectResponse;
|
|
21
|
+
|
|
22
|
+
var isResponseCorrect = function isResponseCorrect(question, key, session) {
|
|
23
|
+
var correctResponse = getCorrectResponse(question.choices);
|
|
24
|
+
|
|
25
|
+
if (session && session.value) {
|
|
26
|
+
return (0, _isEqual["default"])((session.value[key].value || []).sort(), correctResponse);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.isResponseCorrect = isResponseCorrect;
|
|
33
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","value","sort","isResponseCorrect","question","key","session","correctResponse"],"mappings":";;;;;;;;;AAAA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAAaA,OAAO,IAAIA,OAAO,CAC9DC,MADuD,CAChD,UAAAC,CAAC;AAAA,WAAIA,CAAC,CAACC,OAAN;AAAA,GAD+C,EAEvDC,GAFuD,CAEnD,UAAAF,CAAC;AAAA,WAAIA,CAAC,CAACG,KAAN;AAAA,GAFkD,EAGvDC,IAHuD,EAAxB;AAAA,CAA3B;;;;AAKA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,GAAX,EAAgBC,OAAhB,EAA4B;AAC3D,MAAIC,eAAe,GAAGZ,kBAAkB,CAACS,QAAQ,CAACR,OAAV,CAAxC;;AAEA,MAAIU,OAAO,IAAIA,OAAO,CAACL,KAAvB,EAA8B;AAC5B,WAAO,yBAAQ,CAACK,OAAO,CAACL,KAAR,CAAcI,GAAd,EAAmBJ,KAAnB,IAA4B,EAA7B,EAAiCC,IAAjC,EAAR,EAAiDK,eAAjD,CAAP;AACD;;AAED,SAAO,KAAP;AACD,CARM","sourcesContent":["import isEqual from 'lodash/isEqual';\n\nexport const getCorrectResponse = (choices) => choices && choices\n .filter(c => c.correct)\n .map(c => c.value)\n .sort();\n\nexport const isResponseCorrect = (question, key, session) => {\n let correctResponse = getCorrectResponse(question.choices);\n\n if (session && session.value) {\n return isEqual((session.value[key].value || []).sort(), correctResponse);\n }\n\n return false;\n};\n"],"file":"utils.js"}
|