@pie-element/placement-ordering 7.4.0 → 7.4.1-beta.587

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/README.md +1 -1
  3. package/configure/CHANGELOG.md +486 -0
  4. package/configure/lib/choice-editor.js +239 -62
  5. package/configure/lib/choice-editor.js.map +1 -1
  6. package/configure/lib/choice-tile.js +71 -14
  7. package/configure/lib/choice-tile.js.map +1 -1
  8. package/configure/lib/defaults.js +29 -5
  9. package/configure/lib/defaults.js.map +1 -1
  10. package/configure/lib/design.js +230 -78
  11. package/configure/lib/design.js.map +1 -1
  12. package/configure/lib/help.js.map +1 -1
  13. package/configure/lib/index.js +17 -3
  14. package/configure/lib/index.js.map +1 -1
  15. package/configure/lib/utils.js +14 -0
  16. package/configure/lib/utils.js.map +1 -0
  17. package/configure/package.json +7 -6
  18. package/controller/CHANGELOG.md +126 -0
  19. package/controller/lib/defaults.js +4 -2
  20. package/controller/lib/defaults.js.map +1 -1
  21. package/controller/lib/index.js +79 -20
  22. package/controller/lib/index.js.map +1 -1
  23. package/controller/lib/scoring.js +11 -4
  24. package/controller/lib/scoring.js.map +1 -1
  25. package/controller/package.json +3 -3
  26. package/docs/config-schema.json +142 -23
  27. package/docs/config-schema.json.md +106 -16
  28. package/docs/demo/config.js +2 -2
  29. package/docs/demo/generate.js +10 -9
  30. package/docs/demo/index.html +1 -2
  31. package/docs/demo/session.js +1 -1
  32. package/docs/pie-schema.json +96 -42
  33. package/docs/pie-schema.json.md +67 -37
  34. package/lib/index.js +5 -2
  35. package/lib/index.js.map +1 -1
  36. package/lib/main.js +1 -1
  37. package/lib/main.js.map +1 -1
  38. package/lib/ordering.js +2 -1
  39. package/lib/ordering.js.map +1 -1
  40. package/lib/placement-ordering.js +131 -53
  41. package/lib/placement-ordering.js.map +1 -1
  42. package/lib/tile.js +1 -1
  43. package/lib/tile.js.map +1 -1
  44. package/lib/tiler.js +7 -5
  45. package/lib/tiler.js.map +1 -1
  46. package/package.json +8 -7
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateValidationMessage = void 0;
7
+
8
+ var generateValidationMessage = function generateValidationMessage() {
9
+ var answersMessage = '\nThere should be at least 3 tokens.' + '\nThe tokens should not be empty and should be unique.' + '\nThe correct ordering should not be identical to the initial ordering.';
10
+ return 'Validation requirements:' + answersMessage;
11
+ };
12
+
13
+ exports.generateValidationMessage = generateValidationMessage;
14
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.js"],"names":["generateValidationMessage","answersMessage"],"mappings":";;;;;;;AAAO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAA4B,GAAM;AAC7C,MAAMC,cAAc,GAClB,yCACA,wDADA,GAEA,yEAHF;AAKA,SAAO,6BAA6BA,cAApC;AACD,CAPM","sourcesContent":["export const generateValidationMessage = () => {\n const answersMessage =\n '\\nThere should be at least 3 tokens.' +\n '\\nThe tokens should not be empty and should be unique.' +\n '\\nThe correct ordering should not be identical to the initial ordering.';\n\n return 'Validation requirements:' + answersMessage;\n};\n"],"file":"utils.js"}
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "@pie-element/placement-ordering-configure",
3
- "version": "5.2.0",
3
+ "version": "6.5.0",
4
4
  "private": true,
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
7
7
  "dependencies": {
8
8
  "@material-ui/core": "^3.9.2",
9
9
  "@material-ui/icons": "^3.0.1",
10
- "@pie-framework/pie-configure-events": "^1.2.0",
11
- "@pie-lib/config-ui": "^10.8.57",
12
- "@pie-lib/editable-html": "^7.16.16",
13
- "@pie-lib/scoring-config": "^3.5.125",
10
+ "@pie-framework/pie-configure-events": "^1.3.0",
11
+ "@pie-lib/config-ui": "12.0.0-beta.3",
12
+ "@pie-lib/editable-html": "10.0.0-beta.4",
13
+ "@pie-lib/scoring-config": "4.0.0-beta.2",
14
14
  "debug": "^3.1.0",
15
15
  "lodash": "^4.17.15",
16
16
  "nested-property": "^0.0.7",
17
+ "pluralize": "^8.0.0",
17
18
  "prop-types": "^15.6.2",
18
19
  "react": "^16.8.1",
19
- "react-dnd": "^9.3.2",
20
+ "react-dnd": "^14.0.5",
20
21
  "react-dom": "^16.8.1"
21
22
  }
22
23
  }
@@ -3,6 +3,132 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [6.5.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.5.1...@pie-element/placement-ordering-controller@6.5.2) (2022-12-07)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * revert Patricia's latest changes related to PD-2155, revert Carla's changes related to PD-1559, and updated the approach of setting a default session value PD-2155 ([890f3a3](https://github.com/pie-framework/pie-elements/commit/890f3a3fb9077d7f2e53062ad9d4cd43c7d30365))
12
+ * update libs ([441f403](https://github.com/pie-framework/pie-elements/commit/441f403870b7bec0d61fab58b8d93dbe0ead4c32))
13
+ * **placement-ordering:** disable feedbackEnabled if feedback object is not present in model PD-2182 ([98aa82a](https://github.com/pie-framework/pie-elements/commit/98aa82a7f153471217e53c3ff8e942d9a9b31975))
14
+
15
+
16
+
17
+
18
+
19
+ ## [6.5.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.5.0...@pie-element/placement-ordering-controller@6.5.1) (2022-11-15)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **placement-ordering:** fix feedback behavior PD-2156 ([561c36f](https://github.com/pie-framework/pie-elements/commit/561c36fdd2467fcc38907cdbbb91d990ef5c8ee3))
25
+
26
+
27
+
28
+
29
+
30
+ # [6.5.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.7...@pie-element/placement-ordering-controller@6.5.0) (2022-10-31)
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * add choices validation in controller method, remove from autoring PD-2152 ([8c49a7f](https://github.com/pie-framework/pie-elements/commit/8c49a7f6500bf541e03d86276292189aeadb465a))
36
+ * **placement-ordering:** add sanity check for alternateResponses to prevent console.error if it's undefined PD-2135 ([5290755](https://github.com/pie-framework/pie-elements/commit/5290755b2b4a339f81835a6c8dfd0dacee540630))
37
+
38
+
39
+ ### Features
40
+
41
+ * **placement-ordering:** added validation PD-1743 ([a2f2611](https://github.com/pie-framework/pie-elements/commit/a2f2611da08ab41f2944b9dd5adaca1fc4821d8a))
42
+
43
+
44
+
45
+
46
+
47
+ ## [6.4.7](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.6...@pie-element/placement-ordering-controller@6.4.7) (2022-05-16)
48
+
49
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
50
+
51
+
52
+
53
+
54
+
55
+ ## [6.4.6](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.5...@pie-element/placement-ordering-controller@6.4.6) (2022-03-08)
56
+
57
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
58
+
59
+
60
+
61
+
62
+
63
+ ## [6.4.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.1...@pie-element/placement-ordering-controller@6.4.2) (2021-12-01)
64
+
65
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
66
+
67
+
68
+
69
+
70
+
71
+ ## [6.4.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.3.3...@pie-element/placement-ordering-controller@6.4.1) (2021-11-11)
72
+
73
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
74
+
75
+
76
+
77
+
78
+
79
+ # [6.4.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.3.2...@pie-element/placement-ordering-controller@6.4.0) (2021-11-11)
80
+
81
+
82
+ ### Bug Fixes
83
+
84
+ * **placement-ordering:** fix create correct session for IBX browse items PD-1349 ([e84c30d](https://github.com/pie-framework/pie-elements/commit/e84c30dd075085ef5d917f2893568bca2003d225))
85
+
86
+
87
+ ### Features
88
+
89
+ * **placement-ordering:** add baseline validation for authoring PD-600, PD-1334 ([2350279](https://github.com/pie-framework/pie-elements/commit/23502790000e3c4f14e4dae6744519b004eb1172))
90
+
91
+
92
+
93
+
94
+
95
+
96
+ ## [6.3.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.3.2...@pie-element/placement-ordering-controller@6.3.3) (2021-11-01)
97
+
98
+ **Note:** Version bump only for package @pie-element/placement-ordering-controller
99
+
100
+
101
+
102
+
103
+
104
+ ## [6.3.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.3.0...@pie-element/placement-ordering-controller@6.3.2) (2021-08-05)
105
+
106
+
107
+ ### Bug Fixes
108
+
109
+ * force bump ([5ea7295](https://github.com/pie-framework/pie-elements/commit/5ea7295e4755fbc492a76e7ec69e5fc35b196919))
110
+
111
+
112
+
113
+
114
+
115
+ # [6.3.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.2.0...@pie-element/placement-ordering-controller@6.3.0) (2021-06-29)
116
+
117
+
118
+ ### Bug Fixes
119
+
120
+ * **placement-ordering:** fixed createCorrectResponseSession and added more tests for it PD-542 ([#574](https://github.com/pie-framework/pie-elements/issues/574)) ([16fb27f](https://github.com/pie-framework/pie-elements/commit/16fb27f1c32d75f7744cf5f24dc53b9a251090c2))
121
+ * **placement-ordering:** Fixed Placement Ordering items are displaying an incorrect label - PD-1147 ([#576](https://github.com/pie-framework/pie-elements/issues/576)) ([c7e3284](https://github.com/pie-framework/pie-elements/commit/c7e3284d0eadd6ccc082f474f385b565217db0f9))
122
+
123
+
124
+ ### Features
125
+
126
+ * Displayed a message when the item has one or more alternate answers - PD-167 ([#590](https://github.com/pie-framework/pie-elements/issues/590)) ([889d8b5](https://github.com/pie-framework/pie-elements/commit/889d8b578a915c997a95bd5cd4bdf18f53cc2b68))
127
+
128
+
129
+
130
+
131
+
6
132
  # [6.2.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.1.14...@pie-element/placement-ordering-controller@6.2.0) (2021-04-07)
7
133
 
8
134
 
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _default = {
8
- choiceLabel: 'Choice Label goes here',
8
+ choiceLabel: '',
9
9
  choices: [],
10
10
  correctResponse: [],
11
11
  enableImages: false,
@@ -14,9 +14,11 @@ var _default = {
14
14
  orientation: 'vertical',
15
15
  partialScoring: true,
16
16
  placementArea: false,
17
+ choiceLabelEnabled: true,
17
18
  removeTilesAfterPlacing: true,
18
19
  scoringType: 'auto',
19
- targetLabel: 'Target Label goes here',
20
+ targetLabel: '',
21
+ note: 'The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.',
20
22
  rationaleEnabled: true,
21
23
  feedbackEnabled: true,
22
24
  promptEnabled: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.js"],"names":["choiceLabel","choices","correctResponse","enableImages","prompt","numberedGuides","orientation","partialScoring","placementArea","removeTilesAfterPlacing","scoringType","targetLabel","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled"],"mappings":";;;;;;eAAe;AACbA,EAAAA,WAAW,EAAE,wBADA;AAEbC,EAAAA,OAAO,EAAE,EAFI;AAGbC,EAAAA,eAAe,EAAE,EAHJ;AAIbC,EAAAA,YAAY,EAAE,KAJD;AAKbC,EAAAA,MAAM,EAAE,qBALK;AAMbC,EAAAA,cAAc,EAAE,KANH;AAObC,EAAAA,WAAW,EAAE,UAPA;AAQbC,EAAAA,cAAc,EAAE,IARH;AASbC,EAAAA,aAAa,EAAE,KATF;AAUbC,EAAAA,uBAAuB,EAAE,IAVZ;AAWbC,EAAAA,WAAW,EAAE,MAXA;AAYbC,EAAAA,WAAW,EAAE,wBAZA;AAabC,EAAAA,gBAAgB,EAAE,IAbL;AAcbC,EAAAA,eAAe,EAAE,IAdJ;AAebC,EAAAA,aAAa,EAAE,IAfF;AAgBbC,EAAAA,0BAA0B,EAAE,IAhBf;AAiBbC,EAAAA,0BAA0B,EAAE;AAjBf,C","sourcesContent":["export default {\n choiceLabel: 'Choice Label goes here',\n choices: [],\n correctResponse: [],\n enableImages: false,\n prompt: 'Item Stem goes here',\n numberedGuides: false,\n orientation: 'vertical',\n partialScoring: true,\n placementArea: false,\n removeTilesAfterPlacing: true,\n scoringType: 'auto',\n targetLabel: 'Target Label goes here',\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true\n};\n"],"file":"defaults.js"}
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["choiceLabel","choices","correctResponse","enableImages","prompt","numberedGuides","orientation","partialScoring","placementArea","choiceLabelEnabled","removeTilesAfterPlacing","scoringType","targetLabel","note","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled"],"mappings":";;;;;;eAAe;AACbA,EAAAA,WAAW,EAAE,EADA;AAEbC,EAAAA,OAAO,EAAE,EAFI;AAGbC,EAAAA,eAAe,EAAE,EAHJ;AAIbC,EAAAA,YAAY,EAAE,KAJD;AAKbC,EAAAA,MAAM,EAAE,qBALK;AAMbC,EAAAA,cAAc,EAAE,KANH;AAObC,EAAAA,WAAW,EAAE,UAPA;AAQbC,EAAAA,cAAc,EAAE,IARH;AASbC,EAAAA,aAAa,EAAE,KATF;AAUbC,EAAAA,kBAAkB,EAAE,IAVP;AAWbC,EAAAA,uBAAuB,EAAE,IAXZ;AAYbC,EAAAA,WAAW,EAAE,MAZA;AAabC,EAAAA,WAAW,EAAE,EAbA;AAcbC,EAAAA,IAAI,EAAE,0KAdO;AAebC,EAAAA,gBAAgB,EAAE,IAfL;AAgBbC,EAAAA,eAAe,EAAE,IAhBJ;AAiBbC,EAAAA,aAAa,EAAE,IAjBF;AAkBbC,EAAAA,0BAA0B,EAAE,IAlBf;AAmBbC,EAAAA,0BAA0B,EAAE;AAnBf,C","sourcesContent":["export default {\n choiceLabel: '',\n choices: [],\n correctResponse: [],\n enableImages: false,\n prompt: 'Item Stem goes here',\n numberedGuides: false,\n orientation: 'vertical',\n partialScoring: true,\n placementArea: false,\n choiceLabelEnabled: true,\n removeTilesAfterPlacing: true,\n scoringType: 'auto',\n targetLabel: '',\n note: 'The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.',\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n};\n"],"file":"defaults.js"}
@@ -5,13 +5,17 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.outcome = outcome;
8
+ exports.createCorrectResponseSession = void 0;
9
9
  exports.createDefaultModel = createDefaultModel;
10
10
  exports.model = model;
11
- exports.createCorrectResponseSession = exports.normalize = exports.questionError = void 0;
11
+ exports.normalize = void 0;
12
+ exports.outcome = outcome;
13
+ exports.validate = exports.questionError = void 0;
12
14
 
13
15
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
16
 
17
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
+
15
19
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
20
 
17
21
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -28,9 +32,13 @@ var _debug = _interopRequireDefault(require("debug"));
28
32
 
29
33
  var _defaults = _interopRequireDefault(require("./defaults"));
30
34
 
31
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
35
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
36
+
37
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
32
38
 
33
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
39
+ 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; }
40
+
41
+ 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; }
34
42
 
35
43
  var log = (0, _debug["default"])('@pie-element:placement-ordering:controller');
36
44
 
@@ -94,28 +102,33 @@ exports.normalize = normalize;
94
102
  function model(question, session, env) {
95
103
  return new Promise( /*#__PURE__*/function () {
96
104
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
97
- var normalizedQuestion, base, value, allCorrectResponses, bestSetOfResponses, allCorrect;
105
+ var normalizedQuestion, base, value, allCorrectResponses, bestSetOfResponses, allCorrect, fb;
98
106
  return _regenerator["default"].wrap(function _callee$(_context) {
99
107
  while (1) {
100
108
  switch (_context.prev = _context.next) {
101
109
  case 0:
102
110
  normalizedQuestion = normalize(question);
103
111
  base = {};
104
- base.outcomes = [];
105
- base.completeLength = (normalizedQuestion.correctResponse || []).length;
106
- base.choices = normalizedQuestion.choices;
107
112
 
108
- if (env.mode === 'gather' && !normalizedQuestion.placementArea) {
109
- session.value = base.choices.map(function (m) {
110
- return m.id;
111
- });
113
+ if (question.alternateResponses && _lodash["default"].every(question.alternateResponses, _lodash["default"].isArray)) {
114
+ log('Deprecated structure of alternateResponses is in use');
115
+ console.error('Deprecated structure of alternateResponses is in use');
112
116
  }
113
117
 
118
+ base.env = env;
119
+ base.outcomes = [];
120
+ base.completeLength = (normalizedQuestion.correctResponse || []).length;
121
+ base.choices = (normalizedQuestion.choices || []).filter(function (choice) {
122
+ return choice.label;
123
+ });
124
+ base.note = normalizedQuestion.note;
125
+ base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;
114
126
  log('[model] removing tileSize for the moment.');
115
127
  base.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;
116
128
  base.config = {
117
129
  orientation: normalizedQuestion.orientation || 'vertical',
118
130
  includeTargets: normalizedQuestion.placementArea,
131
+ choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,
119
132
  targetLabel: normalizedQuestion.targetLabel,
120
133
  choiceLabel: normalizedQuestion.choiceLabel,
121
134
  showOrdering: normalizedQuestion.numberedGuides,
@@ -131,7 +144,7 @@ function model(question, session, env) {
131
144
  base.teacherInstructions = null;
132
145
  }
133
146
 
134
- if (env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled) {
147
+ if (env.mode === 'evaluate') {
135
148
  value = session && session.value || [];
136
149
  allCorrectResponses = (0, _scoring.getAllCorrectResponses)(normalizedQuestion);
137
150
  bestSetOfResponses = allCorrectResponses.reduce(function (info, cr) {
@@ -168,9 +181,15 @@ function model(question, session, env) {
168
181
 
169
182
  if (!allCorrect) {
170
183
  base.correctResponse = (0, _scoring.flattenCorrect)(normalizedQuestion);
184
+ } // requirement made in PD-2182
185
+
186
+
187
+ if (!normalizedQuestion.feedback) {
188
+ normalizedQuestion.feedbackEnabled = false;
171
189
  }
172
190
 
173
- (0, _feedback.getFeedbackForCorrectness)(base.correctness, normalizedQuestion.feedback).then(function (feedback) {
191
+ fb = normalizedQuestion.feedbackEnabled ? (0, _feedback.getFeedbackForCorrectness)(base.correctness, normalizedQuestion.feedback) : Promise.resolve(undefined);
192
+ fb.then(function (feedback) {
174
193
  base.feedback = feedback;
175
194
  resolve(base);
176
195
  });
@@ -178,7 +197,7 @@ function model(question, session, env) {
178
197
  resolve(base);
179
198
  }
180
199
 
181
- case 12:
200
+ case 15:
182
201
  case "end":
183
202
  return _context.stop();
184
203
  }
@@ -195,13 +214,9 @@ function model(question, session, env) {
195
214
  var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
196
215
  return new Promise(function (resolve) {
197
216
  if (env.mode !== 'evaluate' && env.role === 'instructor') {
198
- var choices = question.choices;
199
- var value = choices.map(function (c) {
200
- return c.id;
201
- });
202
217
  resolve({
203
218
  id: '1',
204
- value: value
219
+ value: (0, _scoring.flattenCorrect)(question)
205
220
  });
206
221
  } else {
207
222
  resolve(null);
@@ -210,4 +225,48 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
210
225
  };
211
226
 
212
227
  exports.createCorrectResponseSession = createCorrectResponseSession;
228
+
229
+ var validate = function validate() {
230
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
231
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
232
+ var choices = model.choices,
233
+ correctResponse = model.correctResponse;
234
+ var errors = {};
235
+ var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
236
+ var choicesErrors = {};
237
+ reversedChoices.forEach(function (choice, index) {
238
+ var id = choice.id,
239
+ label = choice.label;
240
+
241
+ if (label === '' || label === '<div></div>') {
242
+ choicesErrors[id] = 'Content should not be empty.';
243
+ } else {
244
+ var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
245
+ return c.label === label;
246
+ });
247
+
248
+ if (identicalAnswer) {
249
+ choicesErrors[id] = 'Content should be unique.';
250
+ }
251
+ }
252
+ });
253
+ var choicesIds = (choices || []).map(function (choice) {
254
+ return choice.id;
255
+ });
256
+ var correctResponseIds = (correctResponse || []).map(function (response) {
257
+ return response.id || response;
258
+ });
259
+
260
+ if ((0, _isEqual["default"])(choicesIds, correctResponseIds)) {
261
+ errors.orderError = 'The correct ordering should not be identical to the initial ordering.';
262
+ }
263
+
264
+ if (!(0, _isEmpty["default"])(choicesErrors)) {
265
+ errors.choicesErrors = choicesErrors;
266
+ }
267
+
268
+ return errors;
269
+ };
270
+
271
+ exports.validate = validate;
213
272
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","questionError","Error","outcome","question","session","env","Promise","resolve","reject","_","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","outcomes","completeLength","length","choices","mode","placementArea","value","map","m","id","prompt","config","orientation","includeTargets","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","role","rationale","teacherInstructions","allCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","arr","allCorrect","correct","isEqual","correctness","feedback","then","createCorrectResponseSession"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB;AAAA,SAC3B,IAAIC,KAAJ,CAAU,q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;AACA7D,kBAAAA,OAAO,CAACsB,IAAD,CAAP;AACD,iBAND;AAOD,eApDD,MAoDO;AACLtB,gBAAAA,OAAO,CAACsB,IAAD,CAAP;AACD;;AAjGgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAZ;;AAAA;AAAA;AAAA;AAAA,MAAP;AAmGD;;AAEM,IAAMyC,4BAA4B,GAAG,SAA/BA,4BAA+B,CAACnE,QAAD,EAAWE,GAAX,EAAmB;AAC7D,SAAO,IAAIC,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAC5B,QAAIF,GAAG,CAAC6B,IAAJ,KAAa,UAAb,IAA2B7B,GAAG,CAAC8C,IAAJ,KAAa,YAA5C,EAA0D;AAAA,UAChDlB,OADgD,GACpC9B,QADoC,CAChD8B,OADgD;AAExD,UAAMG,KAAK,GAAGH,OAAO,CAACI,GAAR,CAAY,UAAAwB,CAAC;AAAA,eAAIA,CAAC,CAACtB,EAAN;AAAA,OAAb,CAAd;AAEAhC,MAAAA,OAAO,CAAC;AACNgC,QAAAA,EAAE,EAAE,GADE;AAENH,QAAAA,KAAK,EAALA;AAFM,OAAD,CAAP;AAID,KARD,MAQO;AACL7B,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAZM,CAAP;AAaD,CAdM","sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport _ from 'lodash';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\n\nconst log = debug('@pie-element:placement-ordering:controller');\n\nexport const questionError = () =>\n new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || _.isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (\n !question ||\n !question.correctResponse ||\n _.isEmpty(question.correctResponse)\n ) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {})\n ? s\n : s === 1\n ? 1\n : 0;\n resolve({\n score: finalScore\n });\n } catch (e) {\n reject(e);\n }\n }\n });\n}\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => {\n resolve({\n ...defaults,\n ...model\n });\n });\n}\n\nexport const normalize = question => ({\n ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = normalizedQuestion.choices;\n\n if (env.mode === 'gather' && !normalizedQuestion.placementArea) {\n session.value = base.choices.map(m => m.id);\n }\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n base.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled) {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = _.reduce(\n value,\n (acc, c, idx) => acc + (cr[idx] === c ? 1 : 0),\n 0\n );\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore\n };\n }\n\n return info;\n },\n { arr: [], score: 0 }\n );\n\n base.outcomes = _.map(value, function(c, idx) {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'\n };\n });\n\n const allCorrect = allCorrectResponses.reduce((correct, cr) => {\n if (_.isEqual(cr, value)) {\n return true;\n }\n\n return correct;\n }, false);\n\n base.correctness = allCorrect ? 'correct' : 'incorrect';\n\n if (!allCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n getFeedbackForCorrectness(\n base.correctness,\n normalizedQuestion.feedback\n ).then(feedback => {\n base.feedback = feedback;\n resolve(base);\n });\n } else {\n resolve(base);\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question;\n const value = choices.map(c => c.id);\n\n resolve({\n id: '1',\n value\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","questionError","Error","outcome","question","session","env","Promise","resolve","reject","_","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","alternateResponses","every","isArray","console","error","outcomes","completeLength","length","choices","filter","choice","label","note","showNote","prompt","config","orientation","includeTargets","placementArea","choiceLabelEnabled","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","mode","role","rationale","teacherInstructions","value","allCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","arr","map","id","allCorrect","correct","isEqual","correctness","feedback","fb","undefined","then","createCorrectResponseSession","validate","errors","reversedChoices","reverse","choicesErrors","forEach","index","identicalAnswer","slice","some","choicesIds","correctResponseIds","response","orderError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB;AAAA,SAC3B,IAAIC,KAAJ,CAAU,qDAAV,CAD2B;AAAA,CAAtB;;;;AAGA,SAASC,OAAT,CAAiBC,QAAjB,EAA2BC,OAA3B,EAAoCC,GAApC,EAAyC;AAC9C,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;AACtC,QAAI,CAACJ,OAAD,IAAYK,mBAAEC,OAAF,CAAUN,OAAV,CAAhB,EAAoC;AAClCG,MAAAA,OAAO,CAAC;AAAEI,QAAAA,KAAK,EAAE,CAAT;AAAYC,QAAAA,KAAK,EAAE;AAAnB,OAAD,CAAP;AACD;;AAED,QACE,CAACT,QAAD,IACA,CAACA,QAAQ,CAACU,eADV,IAEAJ,mBAAEC,OAAF,CAAUP,QAAQ,CAACU,eAAnB,CAHF,EAIE;AACAL,MAAAA,MAAM,CAACR,aAAa,EAAd,CAAN;AACD,KAND,MAMO;AACL,UAAI;AACF,YAAMc,CAAC,GAAG,oBAAMX,QAAN,EAAgBC,OAAhB,CAAV;AACA,YAAMW,UAAU,GAAGC,gCAAeC,OAAf,CAAuBd,QAAvB,EAAiCE,GAAG,IAAI,EAAxC,IACfS,CADe,GAEfA,CAAC,KAAK,CAAN,GACA,CADA,GAEA,CAJJ;AAKAP,QAAAA,OAAO,CAAC;AACNI,UAAAA,KAAK,EAAEI;AADD,SAAD,CAAP;AAGD,OAVD,CAUE,OAAOG,CAAP,EAAU;AACVV,QAAAA,MAAM,CAACU,CAAD,CAAN;AACD;AACF;AACF,GA1BM,CAAP;AA2BD;;AAEM,SAASC,kBAAT,GAAwC;AAAA,MAAZC,KAAY,uE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ApB;AACD;AACF;AACF,GAZD;AAcA,MAAMoB,UAAU,GAAG,CAACvD,OAAO,IAAI,EAAZ,EAAgBkC,GAAhB,CAAoB,UAAAhC,MAAM;AAAA,WAAIA,MAAM,CAACiC,EAAX;AAAA,GAA1B,CAAnB;AACA,MAAMqB,kBAAkB,GAAG,CAACjF,eAAe,IAAI,EAApB,EAAwB2D,GAAxB,CAA4B,UAAAuB,QAAQ;AAAA,WAAIA,QAAQ,CAACtB,EAAT,IAAesB,QAAnB;AAAA,GAApC,CAA3B;;AAEA,MAAI,yBAAQF,UAAR,EAAoBC,kBAApB,CAAJ,EAA6C;AAC3CV,IAAAA,MAAM,CAACY,UAAP,GAAoB,uEAApB;AACD;;AAED,MAAI,CAAC,yBAAQT,aAAR,CAAL,EAA6B;AAC3BH,IAAAA,MAAM,CAACG,aAAP,GAAuBA,aAAvB;AACD;;AAED,SAAOH,MAAP;AACD,CAjCM","sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport _ from 'lodash';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\nimport isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\n\nconst log = debug('@pie-element:placement-ordering:controller');\n\nexport const questionError = () =>\n new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || _.isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (\n !question ||\n !question.correctResponse ||\n _.isEmpty(question.correctResponse)\n ) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {})\n ? s\n : s === 1\n ? 1\n : 0;\n resolve({\n score: finalScore\n });\n } catch (e) {\n reject(e);\n }\n }\n });\n}\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => {\n resolve({\n ...defaults,\n ...model\n });\n });\n}\n\nexport const normalize = question => ({\n ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n if (question.alternateResponses && _.every(question.alternateResponses, _.isArray)) {\n log('Deprecated structure of alternateResponses is in use');\n console.error('Deprecated structure of alternateResponses is in use');\n }\n\n base.env = env;\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = (normalizedQuestion.choices || []).filter(choice => choice.label);\n base.note = normalizedQuestion.note;\n base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n base.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate') {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = _.reduce(\n value,\n (acc, c, idx) => acc + (cr[idx] === c ? 1 : 0),\n 0\n );\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore\n };\n }\n\n return info;\n },\n { arr: [], score: 0 }\n );\n\n base.outcomes = _.map(value, function(c, idx) {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'\n };\n });\n\n const allCorrect = allCorrectResponses.reduce((correct, cr) => {\n if (_.isEqual(cr, value)) {\n return true;\n }\n\n return correct;\n }, false);\n\n base.correctness = allCorrect ? 'correct' : 'incorrect';\n\n if (!allCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n // requirement made in PD-2182\n if (!normalizedQuestion.feedback) {\n normalizedQuestion.feedbackEnabled = false;\n }\n\n const fb = normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(base.correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then((feedback) => {\n base.feedback = feedback;\n resolve(base);\n });\n } else {\n resolve(base);\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n id: '1',\n value: flattenCorrect(question)\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { choices, correctResponse } = model;\n const errors = {};\n\n const reversedChoices = [...choices || []].reverse();\n const choicesErrors = {};\n\n reversedChoices.forEach((choice, index) => {\n const { id, label } = choice;\n\n if (label === '' || label === '<div></div>') {\n choicesErrors[id] = '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[id] = 'Content should be unique.';\n }\n }\n });\n\n const choicesIds = (choices || []).map(choice => choice.id);\n const correctResponseIds = (correctResponse || []).map(response => response.id || response);\n\n if (isEqual(choicesIds, correctResponseIds)) {\n errors.orderError = 'The correct ordering should not be identical to the initial ordering.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.score = exports.getAllCorrectResponses = exports.flattenCorrect = exports.pairwiseCombinationScore = exports.illegalArgumentError = void 0;
8
+ exports.score = exports.pairwiseCombinationScore = exports.illegalArgumentError = exports.getAllCorrectResponses = exports.flattenCorrect = void 0;
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
@@ -17,9 +17,9 @@ var _jsCombinatorics = require("js-combinatorics");
17
17
 
18
18
  var _debug = _interopRequireDefault(require("debug"));
19
19
 
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
20
+ 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; }
21
21
 
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
22
+ 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; }
23
23
 
24
24
  var log = (0, _debug["default"])('pie-elements:placement-ordering:controller');
25
25
 
@@ -99,7 +99,14 @@ var flattenCorrect = function flattenCorrect(question) {
99
99
  exports.flattenCorrect = flattenCorrect;
100
100
 
101
101
  var getAllCorrectResponses = function getAllCorrectResponses(question) {
102
- return [flattenCorrect(question)].concat((0, _toConsumableArray2["default"])(question.alternateResponses || []));
102
+ var alternates = (question.alternateResponses || []).map(function (alternate) {
103
+ if (Array.isArray(alternate)) {
104
+ return alternate;
105
+ }
106
+
107
+ return alternate.response;
108
+ });
109
+ return [flattenCorrect(question)].concat((0, _toConsumableArray2["default"])(alternates));
103
110
  };
104
111
  /**
105
112
  * Returns the score for a session. If weighted scoring is present in the correctResponse
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/scoring.js"],"names":["log","illegalArgumentError","answer","Error","pairwiseCombinationScore","correct","opts","allowDuplicates","orderMustBeComplete","_","isEqual","uniq","length","Array","isArray","correctCombo","toArray","answerCombo","diff","differenceWith","comboLengthDiff","total","actual","n","toFixed","parseFloat","flattenCorrect","question","correctResponse","map","r","id","getAllCorrectResponses","alternateResponses","score","session","value","allCorrectResponse","configure","removeTilesAfterPlacing","bestScore","forEach","cr","currentScore"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAAAC,MAAM;AAAA,SACxC,IAAIC,KAAJ,8BACwBD,MADxB,qDADwC;AAAA,CAAnC;;;;AAIA,IAAME,wBAAwB,GAAG,SAA3BA,wBAA2B,CAACC,OAAD,EAAUH,MAAV,E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,EADa;AAAA,MAClCC,KADkC,QAClCA,KADkC;;AAG1C,MAAI,CAACA,KAAL,EAAY;AACV,WAAO,CAAP;AACD;;AAED,MAAMC,kBAAkB,GAAGL,sBAAsB,CAACL,QAAD,CAAjD;AACA,MAAMpB,eAAe,GACnB,CAACoB,QAAQ,CAACW,SAAT,IAAsBX,QAAQ,CAACW,SAAT,CAAmBC,uBAA1C,MAAuE,KADzE;AAGA;AACF;AACA;AACE;;AAEA,MAAIC,SAAS,GAAG,CAAhB;AAEAH,EAAAA,kBAAkB,CAACI,OAAnB,CAA2B,UAACC,EAAD,EAAQ;AACjC,QAAMC,YAAY,GAAGvC,wBAAwB,CAACsC,EAAD,EAAKN,KAAL,EAAY;AACvD7B,MAAAA,eAAe,EAAfA;AADuD,KAAZ,CAA7C;;AAIA,QAAIoC,YAAY,IAAIH,SAApB,EAA+B;AAC7BA,MAAAA,SAAS,GAAGG,YAAZ;AACD;AACF,GARD;AAUA,SAAOH,SAAP;AACD,CA7BM","sourcesContent":["import _ from 'lodash';\nimport { combination } from 'js-combinatorics';\nimport debug from 'debug';\n\nconst log = debug('pie-elements:placement-ordering:controller');\n\nexport const illegalArgumentError = answer =>\n new Error(\n `Cant score answer: ${answer} it has duplicates and allowDuplicates is false`\n );\nexport const pairwiseCombinationScore = (correct, answer, opts) => {\n opts = { allowDuplicates: false, orderMustBeComplete: false, ...opts };\n\n if (!opts.allowDuplicates && !_.isEqual(_.uniq(correct), correct)) {\n throw illegalArgumentError(answer);\n }\n\n if (\n opts.allowDuplicates === false &&\n answer.length !== _.uniq(answer).length\n ) {\n return 0;\n }\n\n answer = opts.allowDuplicates !== false ? answer : _.uniq(answer);\n\n log('answer:', answer);\n if (!Array.isArray(correct) || correct.length === 0) {\n throw new Error('correct must be non empty an array');\n }\n\n if (correct.length === 1) {\n return _.isEqual(correct, answer) ? 1 : 0;\n }\n\n if (!Array.isArray(answer) || answer.length < 2) {\n return 0;\n }\n\n if (answer.length > correct.length) {\n return 0;\n }\n\n if (correct.length !== answer.length && opts.orderMustBeComplete) {\n return 0;\n }\n\n const correctCombo = combination(correct, 2).toArray();\n const answerCombo = combination(answer, 2).toArray();\n\n const diff = _.differenceWith(answerCombo, correctCombo, _.isEqual);\n\n const comboLengthDiff = correctCombo.length - answerCombo.length;\n\n const total = correctCombo.length;\n const actual = total - diff.length - comboLengthDiff;\n\n const n = (actual / total).toFixed(2);\n\n return parseFloat(n);\n};\n\n/**\n * Flattens the correctResponse into an array of ordered identifiers representing the\n * correct response.\n */\nexport const flattenCorrect = question =>\n question.correctResponse\n ? question.correctResponse.map(r => (r && r.id ? r.id : r))\n : [];\n\n/**\n * Returns all correct responses for this question\n * @param question - array\n */\nexport const getAllCorrectResponses = question => [\n flattenCorrect(question),\n ...(question.alternateResponses || [])\n];\n\n/**\n * Returns the score for a session. If weighted scoring is present in the correctResponse\n * field for the question, this will be used. If partial scoring is present in the question\n * model, this will be used. Otherwise the default scoring mechanism (0 for any incorrect, 1\n * for all correct) will be used.\n */\n\nexport const score = (question, session) => {\n const { value } = session || {};\n\n if (!value) {\n return 0;\n }\n\n const allCorrectResponse = getAllCorrectResponses(question);\n const allowDuplicates =\n (question.configure && question.configure.removeTilesAfterPlacing) !== false;\n\n /**\n * We require this to be the case - locking\n */\n //const orderMustBeComplete = true;\n\n let bestScore = 0;\n\n allCorrectResponse.forEach((cr) => {\n const currentScore = pairwiseCombinationScore(cr, value, {\n allowDuplicates\n });\n\n if (currentScore >= bestScore) {\n bestScore = currentScore;\n }\n });\n\n return bestScore;\n};\n"],"file":"scoring.js"}
1
+ {"version":3,"sources":["../src/scoring.js"],"names":["log","illegalArgumentError","answer","Error","pairwiseCombinationScore","correct","opts","allowDuplicates","orderMustBeComplete","_","isEqual","uniq","length","Array","isArray","correctCombo","toArray","answerCombo","diff","differenceWith","comboLengthDiff","total","actual","n","toFixed","parseFloat","flattenCorrect","question","correctResponse","map","r","id","getAllCorrectResponses","alternates","alternateResponses","alternate","response","score","session","value","allCorrectResponse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3B,GAAyF,EAD7D;AAAA,CAAvB;AAGP;AACA;AACA;AACA;;;;;AACO,IAAME,sBAAsB,GAAG,SAAzBA,sBAAyB,CAACL,QAAD,EAAc;AAClD,MAAMM,UAAU,GAAG,CAACN,QAAQ,CAACO,kBAAT,IAA+B,EAAhC,EAAoCL,GAApC,CAAwC,UAACM,SAAD,EAAe;AACxE,QAAItB,KAAK,CAACC,OAAN,CAAcqB,SAAd,CAAJ,EAA8B;AAC5B,aAAOA,SAAP;AACD;;AAED,WAAOA,SAAS,CAACC,QAAjB;AACD,GANkB,CAAnB;AAQA,UAAQV,cAAc,CAACC,QAAD,CAAtB,6CAAqCM,UAArC;AACD,CAVM;AAYP;AACA;AACA;AACA;AACA;AACA;;;;;AAEO,IAAMI,KAAK,GAAG,SAARA,KAAQ,CAACV,QAAD,EAAWW,OAAX,EAAuB;AAC1C,aAAkBA,OAAO,IAAI,EAA7B;AAAA,MAAQC,KAAR,QAAQA,KAAR;;AAEA,MAAI,CAACA,KAAL,EAAY;AACV,WAAO,CAAP;AACD;;AAED,MAAMC,kBAAkB,GAAGR,sBAAsB,CAACL,QAAD,CAAjD;AACA,MAAMpB,eAAe,GAAG,CAACoB,QAAQ,CAACc,SAAT,IAAsBd,QAAQ,CAACc,SAAT,CAAmBC,uBAA1C,MAAuE,KAA/F;AAEA;AACF;AACA;AACE;;AAEA,MAAIC,SAAS,GAAG,CAAhB;AAEAH,EAAAA,kBAAkB,CAACI,OAAnB,CAA2B,UAACC,EAAD,EAAQ;AACjC,QAAMC,YAAY,GAAG1C,wBAAwB,CAACyC,EAAD,EAAKN,KAAL,EAAY;AACvDhC,MAAAA,eAAe,EAAfA;AADuD,KAAZ,CAA7C;;AAIA,QAAIuC,YAAY,IAAIH,SAApB,EAA+B;AAC7BA,MAAAA,SAAS,GAAGG,YAAZ;AACD;AACF,GARD;AAUA,SAAOH,SAAP;AACD,CA5BM","sourcesContent":["import _ from 'lodash';\nimport { combination } from 'js-combinatorics';\nimport debug from 'debug';\n\nconst log = debug('pie-elements:placement-ordering:controller');\n\nexport const illegalArgumentError = (answer) =>\n new Error(`Cant score answer: ${answer} it has duplicates and allowDuplicates is false`);\nexport const pairwiseCombinationScore = (correct, answer, opts) => {\n opts = { allowDuplicates: false, orderMustBeComplete: false, ...opts };\n\n if (!opts.allowDuplicates && !_.isEqual(_.uniq(correct), correct)) {\n throw illegalArgumentError(answer);\n }\n\n if (opts.allowDuplicates === false && answer.length !== _.uniq(answer).length) {\n return 0;\n }\n\n answer = opts.allowDuplicates !== false ? answer : _.uniq(answer);\n\n log('answer:', answer);\n if (!Array.isArray(correct) || correct.length === 0) {\n throw new Error('correct must be non empty an array');\n }\n\n if (correct.length === 1) {\n return _.isEqual(correct, answer) ? 1 : 0;\n }\n\n if (!Array.isArray(answer) || answer.length < 2) {\n return 0;\n }\n\n if (answer.length > correct.length) {\n return 0;\n }\n\n if (correct.length !== answer.length && opts.orderMustBeComplete) {\n return 0;\n }\n\n const correctCombo = combination(correct, 2).toArray();\n const answerCombo = combination(answer, 2).toArray();\n\n const diff = _.differenceWith(answerCombo, correctCombo, _.isEqual);\n\n const comboLengthDiff = correctCombo.length - answerCombo.length;\n\n const total = correctCombo.length;\n const actual = total - diff.length - comboLengthDiff;\n\n const n = (actual / total).toFixed(2);\n\n return parseFloat(n);\n};\n\n/**\n * Flattens the correctResponse into an array of ordered identifiers representing the\n * correct response.\n */\nexport const flattenCorrect = (question) =>\n question.correctResponse ? question.correctResponse.map((r) => (r && r.id ? r.id : r)) : [];\n\n/**\n * Returns all correct responses for this question\n * @param question - array\n */\nexport const getAllCorrectResponses = (question) => {\n const alternates = (question.alternateResponses || []).map((alternate) => {\n if (Array.isArray(alternate)) {\n return alternate;\n }\n\n return alternate.response;\n });\n\n return [flattenCorrect(question), ...alternates];\n};\n\n/**\n * Returns the score for a session. If weighted scoring is present in the correctResponse\n * field for the question, this will be used. If partial scoring is present in the question\n * model, this will be used. Otherwise the default scoring mechanism (0 for any incorrect, 1\n * for all correct) will be used.\n */\n\nexport const score = (question, session) => {\n const { value } = session || {};\n\n if (!value) {\n return 0;\n }\n\n const allCorrectResponse = getAllCorrectResponses(question);\n const allowDuplicates = (question.configure && question.configure.removeTilesAfterPlacing) !== false;\n\n /**\n * We require this to be the case - locking\n */\n //const orderMustBeComplete = true;\n\n let bestScore = 0;\n\n allCorrectResponse.forEach((cr) => {\n const currentScore = pairwiseCombinationScore(cr, value, {\n allowDuplicates,\n });\n\n if (currentScore >= bestScore) {\n bestScore = currentScore;\n }\n });\n\n return bestScore;\n};\n"],"file":"scoring.js"}
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pie-element/placement-ordering-controller",
3
- "version": "6.2.0",
3
+ "version": "6.5.2",
4
4
  "private": true,
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
7
7
  "dependencies": {
8
- "@pie-lib/controller-utils": "^0.2.24",
9
- "@pie-lib/feedback": "^0.4.25",
8
+ "@pie-lib/controller-utils": "^0.2.42",
9
+ "@pie-lib/feedback": "^0.4.42",
10
10
  "debug": "^3.1.0",
11
11
  "js-combinatorics": "^0.5.4",
12
12
  "lodash": "^4.17.19"