-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Udpate Radio's userInput and rubric to be as focused as possible #1844
Changes from 9 commits
29d8c3f
009bd41
89b59e4
f3c7719
7aae2f1
992e9bd
bea6a85
1f3a831
3dfaf4d
5928467
166f709
3ada8da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Update Radio's userInput and rubric objects and types |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,6 @@ describe("group widget", () => { | |
false, | ||
false, | ||
], | ||
isNoneOfTheAboveSelected: false, | ||
}, | ||
}, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||||||||||||||||||||||||||
import _ from "underscore"; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import type {PerseusStrings} from "../../strings"; | ||||||||||||||||||||||||||||
import type {PerseusScore} from "../../types"; | ||||||||||||||||||||||||||||
import type { | ||||||||||||||||||||||||||||
|
@@ -21,23 +23,33 @@ function radioValidator( | |||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// TODO(LEMS-2541): should numCorrect actually be on the rubric | ||||||||||||||||||||||||||||
// instead of the userInput? | ||||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||||
userInput.numCorrect && | ||||||||||||||||||||||||||||
userInput.numCorrect > 1 && | ||||||||||||||||||||||||||||
numSelected !== userInput.numCorrect | ||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||
const numCorrect: number = _.reduce( | ||||||||||||||||||||||||||||
rubric.choices, | ||||||||||||||||||||||||||||
function (memo, choice) { | ||||||||||||||||||||||||||||
return choice.correct ? memo + 1 : memo; | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
0, | ||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if (numCorrect && numCorrect > 1 && numSelected !== numCorrect) { | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I know you're just moving existing code, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! |
||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||
type: "invalid", | ||||||||||||||||||||||||||||
message: strings.chooseCorrectNum, | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
// If NOTA and some other answer are checked, ... | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
let noneOfTheAboveSelected = false; | ||||||||||||||||||||||||||||
for (let i = 0; i < rubric.choices.length; i++) { | ||||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||||
rubric.choices[i].isNoneOfTheAbove && | ||||||||||||||||||||||||||||
userInput.choicesSelected[i] | ||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||
noneOfTheAboveSelected = true; | ||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your code is clearer, but just because I like the new methods here is an alternative:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I love this. Definitely updated to your alternative, though I tried to make the arguments a bit more descriptive :) |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// TODO(LEMS-2541): should noneOfTheAboveSelected be replaced with a | ||||||||||||||||||||||||||||
// combination of choicesSelected and noneOfTheAboveIndex? | ||||||||||||||||||||||||||||
if (userInput.noneOfTheAboveSelected && numSelected > 1) { | ||||||||||||||||||||||||||||
if (noneOfTheAboveSelected && numSelected > 1) { | ||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||
type: "invalid", | ||||||||||||||||||||||||||||
message: strings.notNoneOfTheAbove, | ||||||||||||||||||||||||||||
|
@@ -46,9 +58,7 @@ function radioValidator( | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const correct = userInput.choicesSelected.every((selected, i) => { | ||||||||||||||||||||||||||||
let isCorrect: boolean; | ||||||||||||||||||||||||||||
// TODO(LEMS-2541): should noneOfTheAboveIndex actually be on the rubric | ||||||||||||||||||||||||||||
// instead of the userInput? | ||||||||||||||||||||||||||||
if (userInput.noneOfTheAboveIndex === i) { | ||||||||||||||||||||||||||||
if (rubric.choices[i].isNoneOfTheAbove) { | ||||||||||||||||||||||||||||
isCorrect = rubric.choices.every((choice, j) => { | ||||||||||||||||||||||||||||
return i === j || !choice.correct; | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When it's an option, I'd like to move away from underscore and use native JS; reduce is native now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also try to get rid of underscore stuff. Sometimes my brain refuses to realize I can update something I copy and pasted from another part of the codebase 😂 Thanks! Updated~