@pie-element/graphing 8.1.0 → 8.2.0-mui-update.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/configure/CHANGELOG.md +11 -0
- package/configure/lib/configure.js +303 -403
- package/configure/lib/configure.js.map +1 -1
- package/configure/lib/correct-response.js +402 -513
- package/configure/lib/correct-response.js.map +1 -1
- package/configure/lib/defaults.js +4 -4
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/graphing-config.js +312 -359
- package/configure/lib/graphing-config.js.map +1 -1
- package/configure/lib/index.js +130 -189
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/utils.js +43 -88
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +11 -8
- package/controller/CHANGELOG.md +11 -0
- package/controller/lib/defaults.js +5 -5
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +180 -267
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +301 -311
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +3 -3
- package/lib/index.js +48 -95
- package/lib/index.js.map +1 -1
- package/lib/main.js +145 -210
- package/lib/main.js.map +1 -1
- package/lib/utils.js +5 -19
- package/lib/utils.js.map +1 -1
- package/package.json +12 -9
- package/LICENSE.md +0 -5
package/controller/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -10,272 +9,219 @@ exports.model = model;
|
|
|
10
9
|
exports.normalize = void 0;
|
|
11
10
|
exports.outcome = outcome;
|
|
12
11
|
exports.validate = void 0;
|
|
13
|
-
|
|
14
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
15
|
-
|
|
16
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
-
|
|
18
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
|
-
|
|
20
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
21
|
-
|
|
22
12
|
var _debug = _interopRequireDefault(require("debug"));
|
|
23
|
-
|
|
24
13
|
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
25
|
-
|
|
26
14
|
var _uniqWith = _interopRequireDefault(require("lodash/uniqWith"));
|
|
27
|
-
|
|
28
15
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
29
|
-
|
|
30
16
|
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
31
|
-
|
|
32
17
|
var _utils = require("./utils");
|
|
33
|
-
|
|
34
18
|
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
vector: [],
|
|
51
|
-
polygon: [],
|
|
52
|
-
circle: [],
|
|
53
|
-
sine: [],
|
|
54
|
-
parabola: [],
|
|
55
|
-
absolute: [],
|
|
56
|
-
exponential: []
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
var graphObjectsOrder = {
|
|
19
|
+
const log = (0, _debug.default)('@pie-element:graphing:controller');
|
|
20
|
+
const initializeGraphMap = () => ({
|
|
21
|
+
point: [],
|
|
22
|
+
segment: [],
|
|
23
|
+
line: [],
|
|
24
|
+
ray: [],
|
|
25
|
+
vector: [],
|
|
26
|
+
polygon: [],
|
|
27
|
+
circle: [],
|
|
28
|
+
sine: [],
|
|
29
|
+
parabola: [],
|
|
30
|
+
absolute: [],
|
|
31
|
+
exponential: []
|
|
32
|
+
});
|
|
33
|
+
const graphObjectsOrder = {
|
|
61
34
|
incorrect: 0,
|
|
62
35
|
correct: 1,
|
|
63
36
|
missing: 2
|
|
64
37
|
};
|
|
65
|
-
|
|
66
|
-
var compareMarks = function compareMarks(mark1, mark2) {
|
|
38
|
+
const compareMarks = (mark1, mark2) => {
|
|
67
39
|
// marks can be compared with equalMarks[type] function only if they have the same type;
|
|
68
40
|
// if type is different, they are clearly not equal
|
|
69
41
|
return !!(mark1 && mark2 && mark1.type === mark2.type && _utils.equalMarks[mark1.type] && _utils.equalMarks[mark1.type](mark1, mark2));
|
|
70
42
|
};
|
|
71
|
-
|
|
72
43
|
exports.compareMarks = compareMarks;
|
|
73
|
-
|
|
74
|
-
var comparLabelMarks = function comparLabelMarks(mark1, mark2) {
|
|
44
|
+
const comparLabelMarks = (mark1, mark2) => {
|
|
75
45
|
return mark1.label === mark2.label ? 'correct' : 'incorrect';
|
|
76
46
|
};
|
|
77
|
-
|
|
78
47
|
exports.comparLabelMarks = comparLabelMarks;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
48
|
+
const getAnswerCorrected = ({
|
|
49
|
+
sessionAnswers,
|
|
50
|
+
marks: correctAnswers
|
|
51
|
+
}) => {
|
|
83
52
|
sessionAnswers = sessionAnswers || [];
|
|
84
53
|
correctAnswers = correctAnswers || [];
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return compareMarks(answer, mark);
|
|
88
|
-
});
|
|
54
|
+
const rez = (0, _cloneDeep.default)(sessionAnswers).reduce((correctedAnswer, answer) => {
|
|
55
|
+
const answerIsCorrect = correctAnswers.find(mark => compareMarks(answer, mark));
|
|
89
56
|
answer.correctness = answerIsCorrect ? 'correct' : 'incorrect';
|
|
90
|
-
|
|
91
57
|
if (answerIsCorrect) {
|
|
92
58
|
answer.correctnesslabel = comparLabelMarks(answer, answerIsCorrect);
|
|
93
59
|
answer.correctlabel = answerIsCorrect.label ? answerIsCorrect.label : '';
|
|
94
60
|
answer.label = answer.label ? answer.label : '';
|
|
95
61
|
}
|
|
62
|
+
return [...correctedAnswer, answer];
|
|
63
|
+
}, []);
|
|
96
64
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var missingAnswers = (0, _cloneDeep["default"])(correctAnswers).reduce(function (correctedAnswer, answer) {
|
|
101
|
-
var answerIndex = sessionAnswers.find(function (mark) {
|
|
102
|
-
return compareMarks(answer, mark);
|
|
103
|
-
});
|
|
104
|
-
|
|
65
|
+
// add missing objects from correct answer
|
|
66
|
+
const missingAnswers = (0, _cloneDeep.default)(correctAnswers).reduce((correctedAnswer, answer) => {
|
|
67
|
+
const answerIndex = sessionAnswers.find(mark => compareMarks(answer, mark));
|
|
105
68
|
if (!answerIndex) {
|
|
106
69
|
// means that corrected answer is missing from session, so we mark it as missing object
|
|
107
|
-
return [
|
|
70
|
+
return [...correctedAnswer, {
|
|
71
|
+
...answer,
|
|
108
72
|
correctness: 'missing'
|
|
109
|
-
}
|
|
73
|
+
}];
|
|
110
74
|
}
|
|
111
|
-
|
|
112
75
|
return correctedAnswer;
|
|
113
76
|
}, []);
|
|
114
|
-
return [
|
|
77
|
+
return [...rez, ...missingAnswers];
|
|
115
78
|
};
|
|
116
|
-
|
|
117
79
|
exports.getAnswerCorrected = getAnswerCorrected;
|
|
80
|
+
const getPartialScoring = ({
|
|
81
|
+
scoringType,
|
|
82
|
+
env
|
|
83
|
+
}) => {
|
|
84
|
+
let pS = scoringType;
|
|
118
85
|
|
|
119
|
-
|
|
120
|
-
var scoringType = _ref2.scoringType,
|
|
121
|
-
env = _ref2.env;
|
|
122
|
-
var pS = scoringType; // if scoringType is undefined, partialScoring should be considered undefined (not set)
|
|
86
|
+
// if scoringType is undefined, partialScoring should be considered undefined (not set)
|
|
123
87
|
// because partialScoring.enabled is using that information
|
|
124
88
|
// if it has a value, we check if it is partial scoring or dichotomous
|
|
125
|
-
|
|
126
89
|
if (scoringType) {
|
|
127
90
|
pS = scoringType === 'partial scoring';
|
|
128
91
|
}
|
|
129
|
-
|
|
130
92
|
return _controllerUtils.partialScoring.enabled({
|
|
131
93
|
partialScoring: pS
|
|
132
94
|
}, env);
|
|
133
95
|
};
|
|
134
|
-
|
|
135
|
-
var getBestAnswer = function getBestAnswer(question, session) {
|
|
136
|
-
var env = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
137
|
-
|
|
96
|
+
const getBestAnswer = (question, session, env = {}) => {
|
|
138
97
|
// questionPossibleAnswers contains all possible answers (correct response and alternates);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
Object.entries(questionPossibleAnswers || {}).forEach(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return questionPossibleAnswers[key] = _objectSpread(_objectSpread({}, value), {}, {
|
|
154
|
-
marks: value === null || value === void 0 ? void 0 : value.marks.filter(function (mark) {
|
|
155
|
-
return !mark.building;
|
|
156
|
-
})
|
|
157
|
-
});
|
|
158
|
-
}); // initialize answer if no values
|
|
98
|
+
let {
|
|
99
|
+
answers: questionPossibleAnswers = {},
|
|
100
|
+
scoringType
|
|
101
|
+
} = question || {};
|
|
102
|
+
let {
|
|
103
|
+
answer
|
|
104
|
+
} = session || {};
|
|
105
|
+
|
|
106
|
+
// filter the incomplete objects
|
|
107
|
+
Object.entries(questionPossibleAnswers || {}).forEach(([key, value]) => questionPossibleAnswers[key] = {
|
|
108
|
+
...value,
|
|
109
|
+
marks: value?.marks.filter(mark => !mark.building)
|
|
110
|
+
});
|
|
159
111
|
|
|
160
|
-
|
|
112
|
+
// initialize answer if no values
|
|
113
|
+
answer = answer || [];
|
|
161
114
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}); // initialize one possible answer if no values
|
|
115
|
+
//filter the incomplete objects for student response - Fix for SC-33160
|
|
116
|
+
answer = answer.filter(mark => !mark.building);
|
|
165
117
|
|
|
166
|
-
if
|
|
118
|
+
// initialize one possible answer if no values
|
|
119
|
+
if ((0, _isEmpty.default)(questionPossibleAnswers)) {
|
|
167
120
|
questionPossibleAnswers = {
|
|
168
121
|
correctAnswer: initializeGraphMap()
|
|
169
122
|
};
|
|
170
123
|
} else {
|
|
171
|
-
questionPossibleAnswers =
|
|
172
|
-
correctAnswer: questionPossibleAnswers.correctAnswer
|
|
173
|
-
|
|
124
|
+
questionPossibleAnswers = {
|
|
125
|
+
correctAnswer: questionPossibleAnswers.correctAnswer,
|
|
126
|
+
...(0, _utils.sortedAnswers)(questionPossibleAnswers)
|
|
127
|
+
};
|
|
174
128
|
}
|
|
129
|
+
const partialScoringEnabled = getPartialScoring({
|
|
130
|
+
scoringType,
|
|
131
|
+
env
|
|
132
|
+
});
|
|
175
133
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
var sessionAnswers = (0, _uniqWith["default"])(answer, compareMarks); // array of possible answers entries
|
|
182
|
-
|
|
183
|
-
var possibleAnswers = Object.entries(questionPossibleAnswers);
|
|
184
|
-
return possibleAnswers.reduce(function (acc, entry) {
|
|
134
|
+
// student's answers without DUPLICATES
|
|
135
|
+
const sessionAnswers = (0, _uniqWith.default)(answer, compareMarks);
|
|
136
|
+
// array of possible answers entries
|
|
137
|
+
const possibleAnswers = Object.entries(questionPossibleAnswers);
|
|
138
|
+
return possibleAnswers.reduce((acc, entry) => {
|
|
185
139
|
// iterating each possible answer (main + alternates)
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
140
|
+
const possibleAnswerKey = entry[0];
|
|
141
|
+
const possibleAnswer = entry[1] || {};
|
|
142
|
+
let {
|
|
143
|
+
marks
|
|
144
|
+
} = possibleAnswer;
|
|
190
145
|
if (!marks || !marks.length) {
|
|
191
146
|
return acc;
|
|
192
|
-
}
|
|
193
|
-
|
|
147
|
+
}
|
|
194
148
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
149
|
+
// returns array of marks, each having 'correctness' property
|
|
150
|
+
const correctedAnswer = getAnswerCorrected({
|
|
151
|
+
sessionAnswers,
|
|
152
|
+
marks
|
|
198
153
|
});
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}); // filter out missing objects because they do not affect the calculation of the score
|
|
154
|
+
const correctMarks = correctedAnswer.filter(answer => answer.correctness === 'correct');
|
|
155
|
+
// filter out missing objects because they do not affect the calculation of the score
|
|
202
156
|
// only correct and incorrect are needed
|
|
157
|
+
const scoredCorrectedAnswer = correctedAnswer.filter(answer => answer.correctness !== 'missing');
|
|
158
|
+
const maxScore = marks.length;
|
|
159
|
+
let score = correctMarks.length;
|
|
203
160
|
|
|
204
|
-
|
|
205
|
-
return answer.correctness !== 'missing';
|
|
206
|
-
});
|
|
207
|
-
var maxScore = marks.length;
|
|
208
|
-
var score = correctMarks.length; // if extra placements
|
|
209
|
-
|
|
161
|
+
// if extra placements
|
|
210
162
|
if (scoredCorrectedAnswer.length > maxScore) {
|
|
211
163
|
score -= scoredCorrectedAnswer.length - maxScore;
|
|
212
164
|
}
|
|
213
|
-
|
|
214
165
|
if (score < 0) {
|
|
215
166
|
score = 0;
|
|
216
167
|
}
|
|
217
|
-
|
|
218
168
|
if (score / maxScore > acc.bestScore || !acc.foundOneSolution) {
|
|
219
169
|
if (partialScoringEnabled) {
|
|
220
170
|
acc.bestScore = parseFloat((score / maxScore).toFixed(2));
|
|
221
171
|
} else {
|
|
222
172
|
acc.bestScore = Math.floor(score / maxScore);
|
|
223
173
|
}
|
|
224
|
-
|
|
225
174
|
acc.bestScoreAnswerKey = possibleAnswerKey;
|
|
226
175
|
acc.answersCorrected = correctedAnswer;
|
|
227
176
|
acc.foundOneSolution = true;
|
|
228
177
|
}
|
|
229
|
-
|
|
230
178
|
return acc;
|
|
231
179
|
}, {
|
|
232
180
|
bestScore: 0,
|
|
233
181
|
bestScoreAnswerKey: null,
|
|
234
182
|
// initially we just suppose all the answers are incorrect
|
|
235
|
-
answersCorrected: (0, _cloneDeep
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}),
|
|
183
|
+
answersCorrected: (0, _cloneDeep.default)(sessionAnswers).map(answer => ({
|
|
184
|
+
...answer,
|
|
185
|
+
correctness: 'incorrect'
|
|
186
|
+
})),
|
|
240
187
|
foundOneSolution: false
|
|
241
188
|
});
|
|
242
189
|
};
|
|
243
|
-
|
|
244
190
|
exports.getBestAnswer = getBestAnswer;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
};
|
|
249
|
-
|
|
191
|
+
const normalize = question => ({
|
|
192
|
+
..._defaults.default,
|
|
193
|
+
...question
|
|
194
|
+
});
|
|
250
195
|
exports.normalize = normalize;
|
|
251
|
-
|
|
252
196
|
function model(question, session, env) {
|
|
253
|
-
return new Promise(
|
|
254
|
-
|
|
197
|
+
return new Promise(resolve => {
|
|
198
|
+
const normalizedQuestion = normalize(question);
|
|
255
199
|
|
|
200
|
+
// added a sanity check for session for environments where it is not passed initially (ex. pie-website)
|
|
256
201
|
if (session === undefined || session === null) {
|
|
257
202
|
session = {};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
203
|
+
}
|
|
204
|
+
// console.log('normalizedQuestion', normalizedQuestion);
|
|
205
|
+
const {
|
|
206
|
+
defaultTool,
|
|
207
|
+
extraCSSRules,
|
|
208
|
+
prompt,
|
|
209
|
+
promptEnabled,
|
|
210
|
+
graph,
|
|
211
|
+
answers,
|
|
212
|
+
toolbarTools,
|
|
213
|
+
...questionProps
|
|
214
|
+
} = normalizedQuestion || {};
|
|
215
|
+
let {
|
|
216
|
+
arrows
|
|
217
|
+
} = normalizedQuestion;
|
|
218
|
+
const {
|
|
219
|
+
mode,
|
|
220
|
+
role
|
|
221
|
+
} = env || {};
|
|
222
|
+
|
|
223
|
+
// This is used for offering support for old models which have the property arrows: boolean
|
|
276
224
|
// Same thing is set in authoring : packages/graphing/configure/src/configure.jsx - componentDidMount
|
|
277
|
-
|
|
278
|
-
|
|
279
225
|
if (typeof arrows === 'boolean') {
|
|
280
226
|
if (arrows) {
|
|
281
227
|
arrows = {
|
|
@@ -292,51 +238,45 @@ function model(question, session, env) {
|
|
|
292
238
|
down: false
|
|
293
239
|
};
|
|
294
240
|
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
var toolbarToolsNoLabel = (toolbarTools || []).filter(function (tool) {
|
|
299
|
-
return tool !== 'label';
|
|
300
|
-
});
|
|
301
|
-
var normalizedDefaultTool = defaultTool || toolbarToolsNoLabel.length && toolbarToolsNoLabel[0] || '';
|
|
241
|
+
}
|
|
302
242
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
243
|
+
// added support for models without defaultTool defined; also used in packages/graphing/configure/src/index.js
|
|
244
|
+
const toolbarToolsNoLabel = (toolbarTools || []).filter(tool => tool !== 'label');
|
|
245
|
+
const normalizedDefaultTool = defaultTool || toolbarToolsNoLabel.length && toolbarToolsNoLabel[0] || '';
|
|
246
|
+
const base = {
|
|
247
|
+
...questionProps,
|
|
248
|
+
answers,
|
|
249
|
+
arrows,
|
|
306
250
|
defaultTool: normalizedDefaultTool,
|
|
307
251
|
disabled: env.mode !== 'gather',
|
|
308
252
|
prompt: promptEnabled ? prompt : null,
|
|
309
253
|
rationale: null,
|
|
310
254
|
size: graph,
|
|
311
255
|
showKeyLegend: env.mode === 'evaluate',
|
|
312
|
-
showToggle: env.mode === 'evaluate' && !(0, _isEmpty
|
|
256
|
+
showToggle: env.mode === 'evaluate' && !(0, _isEmpty.default)(answers) && answers.correctAnswer && answers.correctAnswer.marks && !(0, _isEmpty.default)(answers.correctAnswer.marks),
|
|
313
257
|
teacherInstructions: null,
|
|
314
|
-
toolbarTools
|
|
315
|
-
extraCSSRules
|
|
316
|
-
}
|
|
317
|
-
|
|
258
|
+
toolbarTools,
|
|
259
|
+
extraCSSRules
|
|
260
|
+
};
|
|
318
261
|
if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
262
|
+
const {
|
|
263
|
+
rationale,
|
|
264
|
+
rationaleEnabled,
|
|
265
|
+
teacherInstructions,
|
|
266
|
+
teacherInstructionsEnabled
|
|
267
|
+
} = normalizedQuestion || {};
|
|
325
268
|
base.rationale = rationaleEnabled ? rationale : null;
|
|
326
269
|
base.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;
|
|
327
270
|
}
|
|
328
|
-
|
|
329
271
|
if (mode === 'evaluate') {
|
|
330
|
-
if (!(0, _isEmpty
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
base.answersCorrected = answersCorrected.sort(
|
|
338
|
-
return graphObjectsOrder[a.correctness] - graphObjectsOrder[b.correctness];
|
|
339
|
-
});
|
|
272
|
+
if (!(0, _isEmpty.default)(answers) && answers.correctAnswer && answers.correctAnswer.marks && !(0, _isEmpty.default)(answers.correctAnswer.marks)) {
|
|
273
|
+
const {
|
|
274
|
+
answersCorrected,
|
|
275
|
+
bestScoreAnswerKey,
|
|
276
|
+
bestScore
|
|
277
|
+
} = getBestAnswer(normalizedQuestion, session, env);
|
|
278
|
+
// array of marks from session with 'correctness' property set
|
|
279
|
+
base.answersCorrected = answersCorrected.sort((a, b) => graphObjectsOrder[a.correctness] - graphObjectsOrder[b.correctness]);
|
|
340
280
|
base.correctResponse = bestScoreAnswerKey ? (answers[bestScoreAnswerKey] || {}).marks : [];
|
|
341
281
|
base.showToggle = base.showToggle && bestScore !== 1;
|
|
342
282
|
} else {
|
|
@@ -344,50 +284,42 @@ function model(question, session, env) {
|
|
|
344
284
|
base.correctResponse = [];
|
|
345
285
|
}
|
|
346
286
|
}
|
|
347
|
-
|
|
348
287
|
log('base: ', base);
|
|
349
288
|
resolve(base);
|
|
350
289
|
});
|
|
351
290
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return new Promise(function (resolve) {
|
|
356
|
-
if (!session || (0, _isEmpty["default"])(session)) {
|
|
291
|
+
function outcome(question, session, env = {}) {
|
|
292
|
+
return new Promise(resolve => {
|
|
293
|
+
if (!session || (0, _isEmpty.default)(session)) {
|
|
357
294
|
resolve({
|
|
358
295
|
score: 0,
|
|
359
296
|
empty: true
|
|
360
297
|
});
|
|
361
298
|
}
|
|
362
|
-
|
|
363
|
-
if (env.mode !== 'evaluate' || (0, _isEmpty["default"])(question.answers) || question.answers && question.answers.correctAnswer && (0, _isEmpty["default"])(question.answers.correctAnswer.marks)) {
|
|
299
|
+
if (env.mode !== 'evaluate' || (0, _isEmpty.default)(question.answers) || question.answers && question.answers.correctAnswer && (0, _isEmpty.default)(question.answers.correctAnswer.marks)) {
|
|
364
300
|
resolve({
|
|
365
301
|
score: 0
|
|
366
302
|
});
|
|
367
303
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
304
|
+
const {
|
|
305
|
+
bestScore
|
|
306
|
+
} = getBestAnswer(question, session, env);
|
|
372
307
|
resolve({
|
|
373
308
|
score: bestScore
|
|
374
309
|
});
|
|
375
310
|
});
|
|
376
311
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
return new Promise(function (resolve) {
|
|
312
|
+
const createCorrectResponseSession = (question, env) => {
|
|
313
|
+
return new Promise(resolve => {
|
|
380
314
|
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
315
|
+
const {
|
|
316
|
+
answers
|
|
317
|
+
} = question || {};
|
|
318
|
+
let marks = [];
|
|
386
319
|
if (answers && Object.values(answers)) {
|
|
387
|
-
|
|
320
|
+
const correctAnswer = answers.correctAnswer || Object.values(answers)[0] || {};
|
|
388
321
|
marks = correctAnswer.marks || [];
|
|
389
322
|
}
|
|
390
|
-
|
|
391
323
|
resolve({
|
|
392
324
|
answer: marks,
|
|
393
325
|
id: '1'
|
|
@@ -396,67 +328,48 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
|
|
|
396
328
|
resolve(null);
|
|
397
329
|
}
|
|
398
330
|
});
|
|
399
|
-
}; // remove all html tags
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
403
|
-
|
|
404
|
-
var getInnerText = function getInnerText(html) {
|
|
405
|
-
return (html || '').replaceAll(/<[^>]*>/g, '');
|
|
406
|
-
}; // remove all html tags except img, iframe and source tag for audio
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
var getContent = function getContent(html) {
|
|
410
|
-
return (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
411
331
|
};
|
|
412
332
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
333
|
+
// remove all html tags
|
|
334
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
335
|
+
const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
336
|
+
|
|
337
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
338
|
+
const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
339
|
+
const validate = (model = {}, config = {}) => {
|
|
340
|
+
const {
|
|
341
|
+
answers,
|
|
342
|
+
toolbarTools
|
|
343
|
+
} = model;
|
|
344
|
+
const errors = {};
|
|
345
|
+
const correctAnswerErrors = {};
|
|
346
|
+
const toolbarToolsNoLabel = (toolbarTools || []).filter(tool => tool !== 'label');
|
|
424
347
|
if (!toolbarToolsNoLabel.length) {
|
|
425
348
|
errors.toolbarToolsError = 'There should be at least 1 tool defined.';
|
|
426
349
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
var _config$field;
|
|
430
|
-
|
|
431
|
-
if ((_config$field = config[field]) !== null && _config$field !== void 0 && _config$field.required && !getContent(model[field])) {
|
|
350
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
|
|
351
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
432
352
|
errors[field] = 'This field is required.';
|
|
433
353
|
}
|
|
434
354
|
});
|
|
435
|
-
Object.entries(answers || {}).forEach(
|
|
436
|
-
var _ref12 = (0, _slicedToArray2["default"])(_ref11, 2),
|
|
437
|
-
key = _ref12[0],
|
|
438
|
-
value = _ref12[1];
|
|
439
|
-
|
|
355
|
+
Object.entries(answers || {}).forEach(([key, value]) => {
|
|
440
356
|
if (!value.marks.length) {
|
|
441
357
|
correctAnswerErrors[key] = 'At least 1 graph object should be defined.';
|
|
442
|
-
}
|
|
443
|
-
|
|
358
|
+
}
|
|
444
359
|
|
|
360
|
+
// check if all graph objects are correctly defined with respect to root, edge and from, to
|
|
445
361
|
if (value.marks.length > 0) {
|
|
446
|
-
value.marks.forEach(
|
|
362
|
+
value.marks.forEach(mark => {
|
|
447
363
|
if (mark.building) {
|
|
448
364
|
correctAnswerErrors[key] = 'At least 1 graph object is not correctly defined.';
|
|
449
365
|
}
|
|
450
366
|
});
|
|
451
367
|
}
|
|
452
368
|
});
|
|
453
|
-
|
|
454
|
-
if (!(0, _isEmpty["default"])(correctAnswerErrors)) {
|
|
369
|
+
if (!(0, _isEmpty.default)(correctAnswerErrors)) {
|
|
455
370
|
errors.correctAnswerErrors = correctAnswerErrors;
|
|
456
371
|
}
|
|
457
|
-
|
|
458
372
|
return errors;
|
|
459
373
|
};
|
|
460
|
-
|
|
461
374
|
exports.validate = validate;
|
|
462
375
|
//# sourceMappingURL=index.js.map
|