@pie-element/ebsr 7.0.21 → 7.0.24-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,395 +0,0 @@
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
-
13
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
-
15
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
-
17
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
18
-
19
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
-
21
- var _defaults = _interopRequireDefault(require("./defaults"));
22
-
23
- var _controllerUtils = require("@pie-lib/controller-utils");
24
-
25
- var _utils = require("./utils");
26
-
27
- var _get = _interopRequireDefault(require("lodash/get"));
28
-
29
- var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
30
-
31
- var _excluded = ["partA", "partB"];
32
-
33
- 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; }
34
-
35
- 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; }
36
-
37
- var prepareChoice = function prepareChoice(model, env, defaultFeedback) {
38
- return function (choice) {
39
- var out = {
40
- label: choice.label,
41
- value: choice.value
42
- };
43
-
44
- if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
45
- out.rationale = model.rationaleEnabled ? choice.rationale : null;
46
- } else {
47
- out.rationale = null;
48
- }
49
-
50
- if (env.mode === 'evaluate') {
51
- out.correct = !!choice.correct;
52
-
53
- if (model.feedbackEnabled) {
54
- var feedbackType = choice.feedback && choice.feedback.type || 'none';
55
-
56
- if (feedbackType === 'default') {
57
- out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
58
- } else if (feedbackType === 'custom') {
59
- out.feedback = choice.feedback.value;
60
- }
61
- }
62
- }
63
-
64
- return out;
65
- };
66
- };
67
-
68
- var parsePart = function parsePart(part, key, session, env) {
69
- var defaultFeedback = Object.assign({
70
- correct: 'Correct',
71
- incorrect: 'Incorrect'
72
- }, part.defaultFeedback);
73
- var choices = part.choices ? part.choices.map(prepareChoice(part, env, defaultFeedback)) : [];
74
- return _objectSpread(_objectSpread({}, part), {}, {
75
- choices: choices,
76
- disabled: env.mode !== 'gather',
77
- complete: {
78
- min: part.choices.filter(function (c) {
79
- return c.correct;
80
- }).length
81
- },
82
- responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(part, key, session) : undefined
83
- });
84
- };
85
-
86
- var normalize = function normalize(_ref) {
87
- var _ref$partA = _ref.partA,
88
- partA = _ref$partA === void 0 ? {} : _ref$partA,
89
- _ref$partB = _ref.partB,
90
- partB = _ref$partB === void 0 ? {} : _ref$partB,
91
- question = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
92
- return _objectSpread(_objectSpread({
93
- partLabels: true,
94
- partLabelType: 'Letters'
95
- }, question), {}, {
96
- partA: _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"].partA), {}, {
97
- rationaleEnabled: true,
98
- feedbackEnabled: true,
99
- promptEnabled: true,
100
- teacherInstructionsEnabled: true,
101
- studentInstructionsEnabled: true,
102
- gridColumns: '2'
103
- }, partA), {}, {
104
- choicesLayout: partA.choicesLayout || partA.verticalMode === false && 'horizontal' || 'vertical'
105
- }),
106
- partB: _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"].partB), {}, {
107
- rationaleEnabled: true,
108
- promptEnabled: true,
109
- feedbackEnabled: true,
110
- teacherInstructionsEnabled: true,
111
- studentInstructionsEnabled: true,
112
- gridColumns: '2'
113
- }, partB), {}, {
114
- choicesLayout: partB.choicesLayout || partB.verticalMode === false && 'horizontal' || 'vertical'
115
- })
116
- });
117
- };
118
- /**
119
- *
120
- * @param {*} question
121
- * @param {*} session
122
- * @param {*} env
123
- * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
124
- */
125
-
126
-
127
- exports.normalize = normalize;
128
-
129
- function model(_x, _x2, _x3, _x4) {
130
- return _model.apply(this, arguments);
131
- }
132
-
133
- function _model() {
134
- _model = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(question, session, env, updateSession) {
135
- var normalizedQuestion, partA, partB, shuffledValues, us, partASession, partALockChoiceOrder, _ref6, partAChoices, _ref7, partBChoices, partBSession, partBLockChoiceOrder;
136
-
137
- return _regenerator["default"].wrap(function _callee$(_context) {
138
- while (1) {
139
- switch (_context.prev = _context.next) {
140
- case 0:
141
- normalizedQuestion = normalize(question);
142
- partA = parsePart(normalizedQuestion.partA, 'partA', session, env);
143
- partB = parsePart(normalizedQuestion.partB, 'partB', session, env);
144
- shuffledValues = {};
145
-
146
- us = function us(part) {
147
- return function (id, element, update) {
148
- return new Promise(function (resolve) {
149
- shuffledValues[part] = update.shuffledValues;
150
- resolve();
151
- });
152
- };
153
- };
154
-
155
- partASession = (0, _get["default"])(session, 'value.partA');
156
- partALockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion.partA, partASession, env);
157
- _ref6 = partA || {}, partAChoices = _ref6.choices;
158
- _ref7 = partB || {}, partBChoices = _ref7.choices;
159
-
160
- if (!(!partALockChoiceOrder && partAChoices && partAChoices.length)) {
161
- _context.next = 13;
162
- break;
163
- }
164
-
165
- _context.next = 12;
166
- return (0, _controllerUtils.getShuffledChoices)(partAChoices, {
167
- shuffledValues: (session.shuffledValues || {}).partA
168
- }, us('partA'), 'value');
169
-
170
- case 12:
171
- partA.choices = _context.sent;
172
-
173
- case 13:
174
- partBSession = (0, _get["default"])(session, 'value.partB');
175
- partBLockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion.partB, partBSession, env);
176
-
177
- if (!(!partBLockChoiceOrder && partBChoices && partBChoices.length)) {
178
- _context.next = 19;
179
- break;
180
- }
181
-
182
- _context.next = 18;
183
- return (0, _controllerUtils.getShuffledChoices)(partBChoices, {
184
- shuffledValues: (session.shuffledValues || {}).partB
185
- }, us('partB'), 'value');
186
-
187
- case 18:
188
- partB.choices = _context.sent;
189
-
190
- case 19:
191
- if (!(0, _isEmpty["default"])(shuffledValues)) {
192
- if (updateSession && typeof updateSession === 'function') {
193
- updateSession(session.id, session.element, {
194
- shuffledValues: shuffledValues
195
- })["catch"](function (e) {
196
- console.error('update session failed', e);
197
- });
198
- }
199
- }
200
-
201
- if (normalizedQuestion.partLabels) {
202
- partA.partLabel = normalizedQuestion.partLabelType === 'Letters' ? 'Part A' : 'Part 1';
203
- partB.partLabel = normalizedQuestion.partLabelType === 'Letters' ? 'Part B' : 'Part 2';
204
- } else {
205
- partA.partLabel = undefined;
206
- partB.partLabel = undefined;
207
- }
208
-
209
- if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
210
- partA.teacherInstructions = normalizedQuestion.partA.teacherInstructionsEnabled ? normalizedQuestion.partA.teacherInstructions : null;
211
- partB.teacherInstructions = normalizedQuestion.partB.teacherInstructionsEnabled ? normalizedQuestion.partB.teacherInstructions : null;
212
- } else {
213
- partA.teacherInstructions = null;
214
- partB.teacherInstructions = null;
215
- }
216
-
217
- partA.prompt = normalizedQuestion.partA.promptEnabled ? normalizedQuestion.partA.prompt : null;
218
- partB.prompt = normalizedQuestion.partB.promptEnabled ? normalizedQuestion.partB.prompt : null;
219
- return _context.abrupt("return", new Promise(function (resolve) {
220
- resolve({
221
- disabled: env.mode !== 'gather',
222
- mode: env.mode,
223
- partA: partA,
224
- partB: partB
225
- });
226
- }));
227
-
228
- case 25:
229
- case "end":
230
- return _context.stop();
231
- }
232
- }
233
- }, _callee);
234
- }));
235
- return _model.apply(this, arguments);
236
- }
237
-
238
- var createDefaultModel = function createDefaultModel() {
239
- var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
240
- return new Promise(function (resolve) {
241
- resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
242
- });
243
- };
244
-
245
- exports.createDefaultModel = createDefaultModel;
246
-
247
- var isCorrect = function isCorrect(c) {
248
- return c.correct === true;
249
- };
250
-
251
- var getScore = function getScore(config, sessionPart, key) {
252
- var _ref2 = config && config[key] || {},
253
- _ref2$choices = _ref2.choices,
254
- choices = _ref2$choices === void 0 ? [] : _ref2$choices;
255
-
256
- var maxScore = choices.length;
257
-
258
- var _ref3 = sessionPart || {},
259
- sessionPartValue = _ref3.value;
260
-
261
- var chosen = function chosen(c) {
262
- return !!(sessionPartValue || []).find(function (v) {
263
- return v === c.value;
264
- });
265
- };
266
-
267
- var correctAndNotChosen = function correctAndNotChosen(c) {
268
- return isCorrect(c) && !chosen(c);
269
- };
270
-
271
- var incorrectAndChosen = function incorrectAndChosen(c) {
272
- return !isCorrect(c) && chosen(c);
273
- };
274
-
275
- var correctChoices = choices.reduce(function (total, choice) {
276
- if (correctAndNotChosen(choice) || incorrectAndChosen(choice)) {
277
- return total - 1;
278
- } else {
279
- return total;
280
- }
281
- }, choices.length); // determine score for a part
282
-
283
- if (!config.partialScoring && correctChoices < maxScore) {
284
- return 0;
285
- }
286
-
287
- return parseFloat(maxScore ? (correctChoices / maxScore).toFixed(2) : 0);
288
- };
289
-
290
- function outcome(config, session) {
291
- return new Promise(function (resolve) {
292
- var _ref4 = session || {},
293
- value = _ref4.value;
294
-
295
- if (!session || !value) {
296
- resolve({
297
- score: 0,
298
- scoreA: 0,
299
- scoreB: 0,
300
- empty: true
301
- });
302
- }
303
-
304
- if (value) {
305
- var _ref5 = value || {},
306
- partA = _ref5.partA,
307
- partB = _ref5.partB;
308
-
309
- var scoreA = getScore(config, partA, 'partA');
310
- var scoreB = getScore(config, partB, 'partB');
311
-
312
- if (!config.partialScoring) {
313
- // The EBSR item is worth 1 point
314
- // That point is awarded if and only if both parts are fully correct, otherwise no points are awarded
315
- resolve({
316
- score: scoreA === 1 && scoreB === 1 ? 1 : 0,
317
- scoreA: scoreA,
318
- scoreB: scoreB,
319
- max: 1
320
- });
321
- } else {
322
- // The EBSR item is worth 2 points
323
- if (scoreA === 1) {
324
- if (scoreB === 1) {
325
- // If Part A and Part B are both correct, 2 points are awarded
326
- resolve({
327
- score: 2,
328
- scoreA: scoreA,
329
- scoreB: scoreB,
330
- max: 2
331
- });
332
- } else {
333
- // If Part A is correct and part B is incorrect, 1 point is awarded
334
- resolve({
335
- score: 1,
336
- scoreA: scoreA,
337
- scoreB: scoreB,
338
- max: 2
339
- });
340
- }
341
- } else {
342
- // For all other combinations, no points are awarded
343
- resolve({
344
- score: 0,
345
- scoreA: scoreA,
346
- scoreB: scoreB,
347
- max: 2
348
- });
349
- }
350
- }
351
- }
352
- });
353
- }
354
-
355
- var returnPartCorrect = function returnPartCorrect(choices) {
356
- var answers = [];
357
- choices.forEach(function (i) {
358
- var correct = i.correct,
359
- value = i.value;
360
-
361
- if (correct) {
362
- answers.push(value);
363
- }
364
- });
365
- return answers;
366
- };
367
-
368
- var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
369
- return new Promise(function (resolve) {
370
- if (env.mode !== 'evaluate' && env.role === 'instructor') {
371
- var partA = question.partA,
372
- partB = question.partB;
373
- var partACorrect = returnPartCorrect(partA.choices);
374
- var partBCorrect = returnPartCorrect(partB.choices);
375
- resolve({
376
- value: {
377
- partA: {
378
- id: 'partA',
379
- value: partACorrect
380
- },
381
- partB: {
382
- id: 'partB',
383
- value: partBCorrect
384
- }
385
- },
386
- id: '1'
387
- });
388
- } else {
389
- resolve(null);
390
- }
391
- });
392
- };
393
-
394
- exports.createCorrectResponseSession = createCorrectResponseSession;
395
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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"],"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,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YAAAA,KAAK,EAAE4F;AAFF;AALF,SADD;AAWNhD,QAAAA,EAAE,EAAE;AAXE,OAAD,CAAP;AAaD,KAnBD,MAmBO;AACLI,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAvBM,CAAP;AAwBD,CAzBM","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"],"file":"index.js"}
@@ -1,33 +0,0 @@
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
@@ -1 +0,0 @@
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"}
package/lib/index.js DELETED
@@ -1,202 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.isSessionComplete = exports["default"] = void 0;
9
-
10
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
11
-
12
- var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
13
-
14
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
19
-
20
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
-
22
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
23
-
24
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
25
-
26
- var _piePlayerEvents = require("@pie-framework/pie-player-events");
27
-
28
- var _multipleChoice = _interopRequireDefault(require("@pie-element/multiple-choice"));
29
-
30
- var _get = _interopRequireDefault(require("lodash/get"));
31
-
32
- var _debug = _interopRequireDefault(require("debug"));
33
-
34
- 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; }
35
-
36
- 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; }
37
-
38
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
39
-
40
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
41
-
42
- var SESSION_CHANGED = _piePlayerEvents.SessionChangedEvent.TYPE;
43
- var MC_TAG_NAME = 'ebsr-multiple-choice';
44
- var log = (0, _debug["default"])('pie-elements:ebsr');
45
-
46
- var EbsrMC = /*#__PURE__*/function (_MultipleChoice) {
47
- (0, _inherits2["default"])(EbsrMC, _MultipleChoice);
48
-
49
- var _super = _createSuper(EbsrMC);
50
-
51
- function EbsrMC() {
52
- (0, _classCallCheck2["default"])(this, EbsrMC);
53
- return _super.apply(this, arguments);
54
- }
55
-
56
- return (0, _createClass2["default"])(EbsrMC);
57
- }(_multipleChoice["default"]);
58
-
59
- var defineMultipleChoice = function defineMultipleChoice() {
60
- if (!customElements.get(MC_TAG_NAME)) {
61
- customElements.define(MC_TAG_NAME, EbsrMC);
62
- }
63
- };
64
-
65
- defineMultipleChoice();
66
-
67
- var isNonEmptyArray = function isNonEmptyArray(a) {
68
- return Array.isArray(a) && a.length > 0;
69
- };
70
-
71
- var isSessionComplete = function isSessionComplete(session) {
72
- var a = (0, _get["default"])(session, 'value.partA.value');
73
- var b = (0, _get["default"])(session, 'value.partB.value');
74
- return isNonEmptyArray(a) && isNonEmptyArray(b);
75
- };
76
-
77
- exports.isSessionComplete = isSessionComplete;
78
-
79
- var Ebsr = /*#__PURE__*/function (_HTMLElement) {
80
- (0, _inherits2["default"])(Ebsr, _HTMLElement);
81
-
82
- var _super2 = _createSuper(Ebsr);
83
-
84
- function Ebsr() {
85
- var _this;
86
-
87
- (0, _classCallCheck2["default"])(this, Ebsr);
88
- _this = _super2.call(this);
89
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSessionUpdated", function (e) {
90
- if (e.target === (0, _assertThisInitialized2["default"])(_this)) {
91
- return;
92
- }
93
-
94
- e.preventDefault();
95
- e.stopImmediatePropagation();
96
- var id = e.target.getAttribute('id');
97
-
98
- if (id) {
99
- var key = "part".concat(id.toUpperCase());
100
-
101
- if (e.update) {
102
- _this._model[key] = e.update;
103
- } //TODO: accessing a private property here. The session event should contain the update in future to prevent this.
104
-
105
-
106
- _this.dispatchSessionChanged(e.srcElement._session, key);
107
- }
108
- });
109
- _this._model = {};
110
- _this._session = {};
111
- return _this;
112
- }
113
-
114
- (0, _createClass2["default"])(Ebsr, [{
115
- key: "model",
116
- set: function set(m) {
117
- var _this2 = this;
118
-
119
- this._model = m;
120
- customElements.whenDefined(MC_TAG_NAME).then(function () {
121
- _this2.setPartModel(_this2.partA, 'partA');
122
-
123
- _this2.setPartModel(_this2.partB, 'partB');
124
- });
125
- }
126
- }, {
127
- key: "session",
128
- get: function get() {
129
- return this._session;
130
- },
131
- set: function set(s) {
132
- var _this3 = this;
133
-
134
- this._session = s;
135
- customElements.whenDefined(MC_TAG_NAME).then(function () {
136
- _this3.setPartSession(_this3.partA, 'partA');
137
-
138
- _this3.setPartSession(_this3.partB, 'partB');
139
- });
140
- }
141
- }, {
142
- key: "setPartModel",
143
- value: function setPartModel(part, key) {
144
- if (this._model && this._model[key]) {
145
- var mode = this._model.mode;
146
- part.model = _objectSpread(_objectSpread({}, this._model[key]), {}, {
147
- mode: mode,
148
- keyMode: this._model[key].choicePrefix
149
- });
150
- }
151
- }
152
- }, {
153
- key: "setPartSession",
154
- value: function setPartSession(part, key) {
155
- if (this._session && this._model) {
156
- var value = this._session.value;
157
- part.session = value && value[key] ? value[key] : {
158
- id: key
159
- };
160
- }
161
- }
162
- }, {
163
- key: "dispatchSessionChanged",
164
- value: function dispatchSessionChanged(partSession, key) {
165
- this._session.value = _objectSpread(_objectSpread({}, this._session.value), {}, (0, _defineProperty2["default"])({}, key, partSession));
166
- log('[onSessionChanged] session: ', this._session);
167
- var complete = isSessionComplete(this._session);
168
- this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), complete));
169
- }
170
- }, {
171
- key: "partA",
172
- get: function get() {
173
- return this.querySelector("".concat(MC_TAG_NAME, "#a"));
174
- }
175
- }, {
176
- key: "partB",
177
- get: function get() {
178
- return this.querySelector("".concat(MC_TAG_NAME, "#b"));
179
- }
180
- }, {
181
- key: "connectedCallback",
182
- value: function connectedCallback() {
183
- this._render();
184
-
185
- this.addEventListener(SESSION_CHANGED, this.onSessionUpdated);
186
- }
187
- }, {
188
- key: "disconnectedCallback",
189
- value: function disconnectedCallback() {
190
- this.removeEventListener(SESSION_CHANGED, this.onSessionUpdated);
191
- }
192
- }, {
193
- key: "_render",
194
- value: function _render() {
195
- this.innerHTML = "\n <div>\n <".concat(MC_TAG_NAME, " id=\"a\"></").concat(MC_TAG_NAME, ">\n <").concat(MC_TAG_NAME, " id=\"b\"></").concat(MC_TAG_NAME, ">\n </div>\n ");
196
- }
197
- }]);
198
- return Ebsr;
199
- }( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
200
-
201
- exports["default"] = Ebsr;
202
- //# sourceMappingURL=index.js.map