-
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
Conversation
Used the calculation that is used elsewhere within the validator to determine numCorrect
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (3ada8da) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1844 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1844 |
Size Change: -153 B (-0.02%) Total Size: 866 kB
ℹ️ View Unchanged
|
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
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.
Thanks Tamara, I like this. A good step forward both for our work and Perseus as a whole.
const numCorrect: number = _.reduce( | ||
rubric.choices, | ||
function (memo, choice) { | ||
return choice.correct ? memo + 1 : memo; | ||
}, | ||
0, | ||
); |
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.
const numCorrect: number = _.reduce( | |
rubric.choices, | |
function (memo, choice) { | |
return choice.correct ? memo + 1 : memo; | |
}, | |
0, | |
); | |
const numCorrect: number = rubric.choices.reduce( | |
(acc, curr) => { | |
return curr.correct ? acc + 1 : acc; | |
}, | |
0, | |
); |
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~
0, | ||
); | ||
|
||
if (numCorrect && numCorrect > 1 && numSelected !== numCorrect) { |
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.
if (numCorrect && numCorrect > 1 && numSelected !== numCorrect) { | |
if (numCorrect > 1 && numSelected !== numCorrect) { |
I know you're just moving existing code, but numCorrect
is a number and the only falsy number is 0 which is not greater than 1.
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.
Fixed!
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 comment
The 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:
let noneOfTheAboveSelected = false; | |
for (let i = 0; i < rubric.choices.length; i++) { | |
if ( | |
rubric.choices[i].isNoneOfTheAbove && | |
userInput.choicesSelected[i] | |
) { | |
noneOfTheAboveSelected = true; | |
break; | |
} | |
} | |
let noneOfTheAboveSelected = rubric.choices.some((e, i) => ( | |
e.isNoneOfTheAbove && userInput.choicesSelected[i] | |
) |
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.
Oh, I love this. Definitely updated to your alternative, though I tried to make the arguments a bit more descriptive :)
- Remove underscore and replace with native js - remove unneeded part of conditional - Simplify with array method
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @khanacademy/perseus@41.3.0 ### Minor Changes - [#1848](#1848) [`55371ded7`](55371de) Thanks [@Myranae](https://github.com/Myranae)! - Rename all validator functions and related code to reference scoring instead - [#1754](#1754) [`77f1bf98f`](77f1bf9) Thanks [@MikeKlemarewski](https://github.com/MikeKlemarewski)! - Adds the getPromptJSON utility method to the renderer and every widget. It can be used to get a JSON representation of the exercise to pass to an LLM. ### Patch Changes - [#1844](#1844) [`092c81f6c`](092c81f) Thanks [@Myranae](https://github.com/Myranae)! - Update Radio's userInput and rubric objects and types - [#1837](#1837) [`80f0480e6`](80f0480) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Type widget exports using 'satisfies' keyword instead of 'as' - [#1785](#1785) [`32b27322c`](32b2732) Thanks [@benchristel](https://github.com/benchristel)! - Internal: add a parsing layer to typecheck PerseusItem data at runtime (ADR #773). The parsing code is not used yet. - [#1838](#1838) [`08fa66103`](08fa661) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Introduce a PerseusArticle type - [#1825](#1825) [`3dd1fa5ce`](3dd1fa5) Thanks [@catandthemachines](https://github.com/catandthemachines)! - Adding stronger typing to expression editor issues. - [#1847](#1847) [`dcb4b27b3`](dcb4b27) Thanks [@nishasy](https://github.com/nishasy)! - [Locked Labels] Allow the usage of `{$}` to denote actual dollar signs within locked label TeX - [#1850](#1850) [`61dbd4a2c`](61dbd4a) Thanks [@MikeKlemarewski](https://github.com/MikeKlemarewski)! - Export WidgetPromptJSON type so it is accessible - [#1842](#1842) [`cf2ea471e`](cf2ea47) Thanks [@MikeKlemarewski](https://github.com/MikeKlemarewski)! - Fix function signature of getUserInputFromProps for radio widget ## @khanacademy/perseus-editor@14.11.1 ### Patch Changes - [#1825](#1825) [`3dd1fa5ce`](3dd1fa5) Thanks [@catandthemachines](https://github.com/catandthemachines)! - Adding stronger typing to expression editor issues. - [#1847](#1847) [`dcb4b27b3`](dcb4b27) Thanks [@nishasy](https://github.com/nishasy)! - [Locked Labels] Allow the usage of `{$}` to denote actual dollar signs within locked label TeX - Updated dependencies \[[`092c81f6c`](092c81f), [`80f0480e6`](80f0480), [`32b27322c`](32b2732), [`08fa66103`](08fa661), [`55371ded7`](55371de), [`3dd1fa5ce`](3dd1fa5), [`dcb4b27b3`](dcb4b27), [`61dbd4a2c`](61dbd4a), [`77f1bf98f`](77f1bf9), [`cf2ea471e`](cf2ea47)]: - @khanacademy/perseus@41.3.0 Author: khan-actions-bot Reviewers: Myranae Required Reviewers: Approved By: Myranae Checks: ⏭️ Publish npm snapshot, ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald, ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x) Pull Request URL: #1840
Summary:
There were a number of properties on Radio's rubric and userInput objects that did not need to be there. This work refines the objects to only be what is required from the user and what is required for scoring.
Issue: LEMS-2541
Test plan: