@khanacademy/perseus-score 2.3.5 → 2.3.7
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/dist/es/index.js +21 -16
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +22 -16
- package/dist/index.js.map +1 -1
- package/dist/score.d.ts +7 -0
- package/dist/widgets/categorizer/validate-categorizer.d.ts +1 -1
- package/dist/widgets/interactive-graph/score-interactive-graph.d.ts +1 -1
- package/package.json +7 -7
- package/dist/shared-utils/add-library-version-to-perseus-debug.d.ts +0 -9
package/dist/es/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
1
2
|
import * as KAS from '@khanacademy/kas';
|
|
2
3
|
import { KhanMath, number, geometry, angles, coefficients } from '@khanacademy/kmath';
|
|
3
4
|
import { PerseusError, Errors, getDecimalSeparator, GrapherUtil, approximateDeepEqual, approximateEqual, deepClone, getMatrixSize, getWidgetIdsFromContent, getUpgradedWidgetOptions } from '@khanacademy/perseus-core';
|
|
4
|
-
import $ from 'jquery';
|
|
5
5
|
import _ from 'underscore';
|
|
6
|
-
import { ErrorCodes as ErrorCodes$1 } from '@khanacademy/perseus-score';
|
|
7
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
8
6
|
|
|
9
7
|
const MISSING_PERCENT_ERROR = "MISSING_PERCENT_ERROR";
|
|
10
8
|
const NEEDS_TO_BE_SIMPLIFIED_ERROR = "NEEDS_TO_BE_SIMPLIFIED_ERROR";
|
|
@@ -31,7 +29,6 @@ const ErrorCodes = {
|
|
|
31
29
|
FILL_ALL_CELLS_ERROR
|
|
32
30
|
};
|
|
33
31
|
|
|
34
|
-
/* eslint-disable no-useless-escape */
|
|
35
32
|
const MAXERROR_EPSILON = Math.pow(2, -42);
|
|
36
33
|
|
|
37
34
|
// TOOD(kevinb): Figure out how this relates to KEScore in
|
|
@@ -219,7 +216,8 @@ const KhanAnswerTypes = {
|
|
|
219
216
|
},
|
|
220
217
|
// A proper fraction
|
|
221
218
|
proper: function (text) {
|
|
222
|
-
|
|
219
|
+
const transformed = fractionTransformer(text);
|
|
220
|
+
return transformed.flatMap(o => {
|
|
223
221
|
// All fractions that are less than 1
|
|
224
222
|
if (Math.abs(o.value) < 1) {
|
|
225
223
|
return [o];
|
|
@@ -237,7 +235,8 @@ const KhanAnswerTypes = {
|
|
|
237
235
|
if (!fractionExists) {
|
|
238
236
|
return [];
|
|
239
237
|
}
|
|
240
|
-
|
|
238
|
+
const transformed = fractionTransformer(text);
|
|
239
|
+
return transformed.flatMap(o => {
|
|
241
240
|
// All fractions that are greater than 1
|
|
242
241
|
if (Math.abs(o.value) >= 1) {
|
|
243
242
|
return [o];
|
|
@@ -338,7 +337,7 @@ const KhanAnswerTypes = {
|
|
|
338
337
|
if (text.match(/pau/)) {
|
|
339
338
|
multiplier = Math.PI * 1.5;
|
|
340
339
|
}
|
|
341
|
-
|
|
340
|
+
possibilities.forEach(possibility => {
|
|
342
341
|
possibility.value *= multiplier;
|
|
343
342
|
});
|
|
344
343
|
return possibilities;
|
|
@@ -385,15 +384,15 @@ const KhanAnswerTypes = {
|
|
|
385
384
|
},
|
|
386
385
|
// Numbers with percent signs
|
|
387
386
|
percent: function (text) {
|
|
388
|
-
text =
|
|
387
|
+
text = String(text).trim();
|
|
389
388
|
// store whether or not there is a percent sign
|
|
390
389
|
let hasPercentSign = false;
|
|
391
390
|
if (text.indexOf("%") === text.length - 1) {
|
|
392
|
-
text =
|
|
391
|
+
text = text.substring(0, text.length - 1).trim();
|
|
393
392
|
hasPercentSign = true;
|
|
394
393
|
}
|
|
395
394
|
const transformed = forms.decimal(text);
|
|
396
|
-
|
|
395
|
+
transformed.forEach(t => {
|
|
397
396
|
t.exact = hasPercentSign;
|
|
398
397
|
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
399
398
|
t.value = t.value / 100;
|
|
@@ -430,7 +429,7 @@ const KhanAnswerTypes = {
|
|
|
430
429
|
// precision == 1.)
|
|
431
430
|
decimal: function (text, precision = 1e10) {
|
|
432
431
|
const normal = function normal(text) {
|
|
433
|
-
text =
|
|
432
|
+
text = String(text).trim();
|
|
434
433
|
const match = text
|
|
435
434
|
// Replace unicode minus sign with hyphen
|
|
436
435
|
.replace(/\u2212/, "-")
|
|
@@ -473,7 +472,7 @@ const KhanAnswerTypes = {
|
|
|
473
472
|
// The fallback variable is used in place of the answer, if no
|
|
474
473
|
// answer is provided (i.e. the field is left blank)
|
|
475
474
|
const fallback = options.fallback != null ? "" + options.fallback : "";
|
|
476
|
-
guess =
|
|
475
|
+
guess = String(guess).trim() || fallback;
|
|
477
476
|
const score = {
|
|
478
477
|
empty: guess === "",
|
|
479
478
|
correct: false,
|
|
@@ -483,7 +482,7 @@ const KhanAnswerTypes = {
|
|
|
483
482
|
|
|
484
483
|
// iterate over all the acceptable forms, and if one of the
|
|
485
484
|
// answers is correct, return true
|
|
486
|
-
|
|
485
|
+
acceptableForms.forEach(form => {
|
|
487
486
|
const transformed = forms[form](guess);
|
|
488
487
|
for (let j = 0, l = transformed.length; j < l; j++) {
|
|
489
488
|
const val = transformed[j].value;
|
|
@@ -554,7 +553,7 @@ const KhanAnswerTypes = {
|
|
|
554
553
|
const correctFloat = parseFloat(correctAnswer);
|
|
555
554
|
return [function (guess, maxError) {
|
|
556
555
|
return Math.abs(guess - correctFloat) < maxError;
|
|
557
|
-
},
|
|
556
|
+
}, _extends({}, options, {
|
|
558
557
|
type: "predicate"
|
|
559
558
|
})];
|
|
560
559
|
},
|
|
@@ -743,7 +742,7 @@ function validateCategorizer(userInput, validationData) {
|
|
|
743
742
|
if (incomplete) {
|
|
744
743
|
return {
|
|
745
744
|
type: "invalid",
|
|
746
|
-
message: ErrorCodes
|
|
745
|
+
message: ErrorCodes.INVALID_SELECTION_ERROR
|
|
747
746
|
};
|
|
748
747
|
}
|
|
749
748
|
return null;
|
|
@@ -2221,7 +2220,13 @@ function flattenScores(widgetScoreMap) {
|
|
|
2221
2220
|
return Object.values(widgetScoreMap).reduce(combineScores, noScore);
|
|
2222
2221
|
}
|
|
2223
2222
|
|
|
2224
|
-
|
|
2223
|
+
/**
|
|
2224
|
+
* score a Perseus item
|
|
2225
|
+
*
|
|
2226
|
+
* @param perseusRenderData - the full answer data, includes the correct answer
|
|
2227
|
+
* @param userInputMap - the user's input for each widget, mapped by ID
|
|
2228
|
+
* @param locale - string locale for math parsing ("de" 1.000,00 vs "en" 1,000.00)
|
|
2229
|
+
*/
|
|
2225
2230
|
function scorePerseusItem(perseusRenderData, userInputMap, locale) {
|
|
2226
2231
|
// There seems to be a chance that PerseusRenderer.widgets might include
|
|
2227
2232
|
// widget data for widgets that are not in PerseusRenderer.content,
|