Skip to content

Commit

Permalink
Merge pull request #607 from ccnmtl/ERD-322
Browse files Browse the repository at this point in the history
Set up state for answers
  • Loading branch information
ndittren authored Dec 5, 2024
2 parents 49107a9 + 18740fb commit 788bbba
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 46 deletions.
7 changes: 4 additions & 3 deletions media/js/src/simulations/simulation1/criticalValue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { saveAnswer } from '../../utils/utils';

export const CriticalValue = ({
hypothesisTest2validate, tvalue, n, alpha, hypothesisTest, hypothesis,
nullHypothesis, submissionId, plotType,
setHypothesisTest2validate, criticalValues, isRedo,
nullHypothesis, submissionId, plotType, criticalValues, isRedo,
setHypothesisTest2validate, answers
}) => {
const [nullHypothesisChoice2, setNullHypothesisChoice2] = useState(null);
const [userCriticalValue, setUserCriticalValue] = useState('');
Expand Down Expand Up @@ -448,5 +448,6 @@ CriticalValue.propTypes = {
plotType: PropTypes.string.isRequired,
setHypothesisTest2validate: PropTypes.func.isRequired,
criticalValues: PropTypes.object,
isRedo: PropTypes.bool
isRedo: PropTypes.bool,
answers: PropTypes.array
};
7 changes: 5 additions & 2 deletions media/js/src/simulations/simulation1/hypothesisTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import axios from 'axios';
export const HypothesisTest = ({
selectedAltHypothesis, appRvalue, tvalue, hypothesizedSlope, n,
completedChoices, submissionId, plotType, setSelectedAltHypothesis,
setIsHypothesisCompleted, isRedo, setIsRedo, isHypothesisCompleted
setIsHypothesisCompleted, isRedo, setIsRedo, isHypothesisCompleted,
answers
}) => {
const [pvalues, setPvalues] = useState(null);
const [alpha, setAlpha] = useState(null);
Expand Down Expand Up @@ -161,6 +162,7 @@ export const HypothesisTest = ({
setIsRedo={setIsRedo}
tvalue={tvalue}
pvalue={parseFloat(pvalue)}
answers={answers}
alpha={alpha}
hypothesis={hypothesis}
nullHypothesis={nullHypothesis}
Expand Down Expand Up @@ -194,5 +196,6 @@ HypothesisTest.propTypes = {
setIsHypothesisCompleted: PropTypes.func,
isRedo: PropTypes.bool,
setIsRedo: PropTypes.func,
isHypothesisCompleted: PropTypes.bool
isHypothesisCompleted: PropTypes.bool,
answers: PropTypes.array
};
5 changes: 3 additions & 2 deletions media/js/src/simulations/simulation1/pvalueComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PropTypes from 'prop-types';
export const PvalueComponent = ({
pvalue, tvalue, submissionId, hypothesis, nullHypothesis,
alpha, hypothesisTest1validate, setHypothesisTest1validate,
plotType, isRedo, hypothesisTest
plotType, isRedo, hypothesisTest, answers
}) => {

const [userPvalue, setUserPvalue] = useState('');
Expand Down Expand Up @@ -392,5 +392,6 @@ PvalueComponent.propTypes = {
setHypothesisTest1validate: PropTypes.func,
plotType: PropTypes.string,
isRedo: PropTypes.bool,
hypothesisTest: PropTypes.string
hypothesisTest: PropTypes.string,
answers: PropTypes.array
};
6 changes: 5 additions & 1 deletion media/js/src/simulations/simulation1/quiz.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { CriticalValue } from './criticalValue.jsx';
export const Quiz = ({
tvalue, pvalue, alpha, hypothesisTest, hypothesis,
nullHypothesis, n, completedChoices, submissionId,
plotType, isRedo, setIsRedo, setIsHypothesisCompleted, isHypothesisCompleted
plotType, isRedo, setIsRedo, setIsHypothesisCompleted,
isHypothesisCompleted, answers
}) => {
// eslint-disable-next-line max-len
const [hypothesisTest1validate, setHypothesisTest1validate] = useState(null);
Expand Down Expand Up @@ -65,6 +66,7 @@ export const Quiz = ({
hypothesisTest={hypothesisTest}
hypothesis={hypothesis}
nullHypothesis={nullHypothesis}
answers={answers}
plotType={plotType}
isRedo={isRedo}
submissionId={submissionId} />
Expand All @@ -78,6 +80,7 @@ export const Quiz = ({
hypothesis={hypothesis}
nullHypothesis={nullHypothesis}
isRedo={isRedo}
answers={answers}
n={n}
hypothesisTest2validate={hypothesisTest2validate}
setHypothesisTest2validate={setHypothesisTest2validate}
Expand Down Expand Up @@ -130,4 +133,5 @@ Quiz.propTypes = {
setIsRedo: PropTypes.func,
setIsHypothesisCompleted: PropTypes.func,
isHypothesisCompleted: PropTypes.bool,
answers: PropTypes.array
};
4 changes: 4 additions & 0 deletions media/js/src/simulations/simulation1/simulationOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const SimulationOne = () => {
const [completedChoices3d, setCompletedChoices3d] = useState([]);
const [selectedAltHypothesis, setSelectedAltHypothesis] = useState(null);
const [isNInvalid, setIsNInvalid] = useState(false);
const [answers, setAnswers] = useState([]);


const createSubmission = async() => {
Expand Down Expand Up @@ -159,6 +160,7 @@ export const SimulationOne = () => {
setStartQuiz2(true);
}
setSubmissionId(data.submission_id);
setAnswers(data.answers);
}
});
}, []);
Expand Down Expand Up @@ -404,6 +406,7 @@ export const SimulationOne = () => {
<SimulationOneQuiz
plotType={plotType}
coursePk={coursePk}
answers={answers}
tvalue={tvalue}
hypothesizedSlope={hypothesizedSlope}
n={N}
Expand All @@ -422,6 +425,7 @@ export const SimulationOne = () => {
<SimulationOneQuiz
plotType={plotType}
coursePk={coursePk}
answers={answers}
tvalue={tvalue3d}
hypothesizedSlope={hypothesizedSlope}
n={N}
Expand Down
88 changes: 50 additions & 38 deletions media/js/src/simulations/simulation1/simulationOneQuiz.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const SimulationOneQuiz = ({
appRvalue, tvalue, hypothesizedSlope, n, setIsCompleted,
isCompleted, submissionId, handlePlotTypeChange, plotType,
completedChoices, setCompletedChoices, selectedAltHypothesis,
setSelectedAltHypothesis, coursePk
setSelectedAltHypothesis, coursePk, answers
}) => {
const [isSubmitted, setIsSubmitted] = useState(false);
const [isTakeawayCorrect, setIsTakeawayCorrect] = useState({
Expand Down Expand Up @@ -145,46 +145,56 @@ export const SimulationOneQuiz = ({

const renderTakeawayQuestion = (
choiceKey, question, options, answer, correctFeedback,
incorrectFeedback, questionNumber) => (
<MultipleChoiceQuestion
question={question}
header={'Takeaway'}
options={options}
answer={answer}
submissionId={submissionId}
questionNumber={questionNumber}
isSubmitted={isSubmitted}
setIsSubmitted={
(correct) => handleTakeawaySubmit(choiceKey, correct)}
questionStyle={{}}
optionStyle={{}}
answerStyle={{}}
correctFeedback={correctFeedback}
incorrectFeedback={incorrectFeedback}
idkey={`${choiceKey}-${plotType}`}
/>
);
incorrectFeedback, questionNumber) => {
const userAnswer = answers.find(
answer => answer.question_number === questionNumber);
return (
<MultipleChoiceQuestion
question={question}
header={'Takeaway'}
options={options}
answer={answer}
submissionId={submissionId}
questionNumber={questionNumber}
isSubmitted={isSubmitted}
setIsSubmitted={
(correct) => handleTakeawaySubmit(choiceKey, correct)}
questionStyle={{}}
optionStyle={{}}
answerStyle={{}}
userAnswer={userAnswer}
correctFeedback={correctFeedback}
incorrectFeedback={incorrectFeedback}
idkey={`${choiceKey}-${plotType}`}
/>
);
};

const renderQualifierQuestion = (
question, options, answer, correctFeedback,
incorrectFeedback, questionNumber) => (
<MultipleChoiceQuestion
question={question}
header={'Qualifier'}
options={options}
answer={answer}
submissionId={submissionId}
questionNumber={questionNumber}
isSubmitted={isSubmitted}
setIsSubmitted={handleQualifierSubmit}
questionStyle={{}}
optionStyle={{}}
answerStyle={{}}
correctFeedback={correctFeedback}
incorrectFeedback={incorrectFeedback}
idkey={'qualifier'}
/>
);
incorrectFeedback, questionNumber) => {
const userAnswer = answers.find(
answer => answer.question_number === questionNumber);
return (
<MultipleChoiceQuestion
question={question}
header={'Qualifier'}
options={options}
answer={answer}
submissionId={submissionId}
questionNumber={questionNumber}
isSubmitted={isSubmitted}
setIsSubmitted={handleQualifierSubmit}
questionStyle={{}}
optionStyle={{}}
answerStyle={{}}
userAnswer={userAnswer}
correctFeedback={correctFeedback}
incorrectFeedback={incorrectFeedback}
idkey={'qualifier'}
/>
);
};

useEffect(() => {
isCompletedfunc();
Expand Down Expand Up @@ -273,6 +283,7 @@ export const SimulationOneQuiz = ({
isHypothesisCompleted={isHypothesisCompleted}
isRedo={isRedo}
setIsRedo={setIsRedo}
answers={answers}
/>
)}
{isHypothesisCompleted && selectedAltHypothesis === 'A'
Expand Down Expand Up @@ -613,4 +624,5 @@ SimulationOneQuiz.propTypes = {
selectedAltHypothesis: PropTypes.string,
setSelectedAltHypothesis: PropTypes.func,
coursePk: PropTypes.number.isRequired,
answers: PropTypes.array
};

0 comments on commit 788bbba

Please sign in to comment.