feat: Group, General Feedback Settings, Randomization

This Ticket adds three new settings widgets to the Problem Editor:
Randomization: This is a setting for advanced problems only which deals with python scripts.
General Feedback: This is feedback which is only applied to certain problem types for mass-adding feedback to incorrect problems.
Group Feedback: For certain problems, the user can provide specific feedback for a combination of specific answers.
This commit is contained in:
connorhaugh
2023-02-10 08:50:32 -05:00
committed by GitHub
parent 7c0309189f
commit d69d3e1ce7
32 changed files with 1303 additions and 22 deletions

View File

@@ -373,6 +373,24 @@ export class OLXParser {
return problemType;
}
getGeneralFeedback({ answers, problemType }) {
/* Feedback is Generalized for a Problem IFF:
1. The problem is of Types: Single Select or Dropdown.
2. All the problem's incorrect, if Selected answers are equivalent strings, and there is no other feedback.
*/
if (problemType === ProblemTypeKeys.SINGLESELECT || problemType === ProblemTypeKeys.DROPDOWN) {
const firstIncorrectAnswerText = answers.find(answer => answer.correct === false).selectedFeedback;
const isAllIncorrectSelectedFeedbackTheSame = answers.every(answer => (answer.correct
? true
: answer?.selectedFeedback === firstIncorrectAnswerText
));
if (isAllIncorrectSelectedFeedbackTheSame) {
return firstIncorrectAnswerText;
}
}
return '';
}
getParsedOLXData() {
if (_.isEmpty(this.problem)) {
return {};
@@ -410,7 +428,7 @@ export class OLXParser {
// if problem is unset, return null
return {};
}
const generalFeedback = this.getGeneralFeedback({ answers: answersObject.answers, problemType });
if (_.has(answersObject, 'additionalStringAttributes')) {
additionalAttributes = { ...answersObject.additionalStringAttributes };
}
@@ -428,6 +446,7 @@ export class OLXParser {
answers,
problemType,
additionalAttributes,
generalFeedback,
groupFeedbackList,
};
}

View File

@@ -65,7 +65,21 @@ class ReactStateOLXParser {
const choice = [];
let compoundhint = [];
let widget = {};
const { answers } = this.problemState;
// eslint-disable-next-line prefer-const
let { answers, generalFeedback } = this.problemState;
// general feedback replaces selected feedback if all incorrect selected feedback is the same.
if (generalFeedback !== ''
&& answers.every(
answer => (
answer.correct
? true
: answer?.selectedFeedback === answers.find(a => a.correct === false).selectedFeedback
),
)) {
answers = answers.map(answer => (!answer?.correct
? { ...answer, selectedFeedback: generalFeedback }
: answer));
}
answers.forEach((answer) => {
const feedback = [];
let singleAnswer = {};

View File

@@ -16,6 +16,7 @@ class ReactStateSettingsParser {
settings = popuplateItem(settings, 'afterAttempts', 'attempts_before_showanswer_button', stateSettings.showAnswer);
settings = popuplateItem(settings, 'showResetButton', 'show_reset_button', stateSettings);
settings = popuplateItem(settings, 'timeBetween', 'submission_wait_seconds', stateSettings);
settings = popuplateItem(settings, 'randomization', 'rerandomize', stateSettings);
return settings;
}

View File

@@ -1,6 +1,6 @@
import _ from 'lodash-es';
import { ShowAnswerTypes } from '../../../data/constants/problem';
import { ShowAnswerTypes, RandomizationTypesKeys } from '../../../data/constants/problem';
export const popuplateItem = (parentObject, itemName, statekey, metadata) => {
let parent = parentObject;
@@ -57,8 +57,13 @@ export const parseSettings = (metadata) => {
if (!_.isEmpty(showAnswer)) {
settings = { ...settings, showAnswer };
}
const randomizationType = _.get(metadata, 'rerandomize', {});
if (!_.isEmpty(randomizationType) && Object.values(RandomizationTypesKeys).includes(randomizationType)) {
settings = popuplateItem(settings, 'rerandomize', 'randomization', metadata);
}
settings = popuplateItem(settings, 'show_reset_button', 'showResetButton', metadata);
settings = popuplateItem(settings, 'submission_wait_seconds', 'timeBetween', metadata);
return settings;
};