-
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
Plotter: Extract validation out of scoring #1899
Merged
jeremywiebe
merged 7 commits into
release/server-side-scoring
from
tb/LEMS-2604/plotter-split-out-validation
Nov 26, 2024
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d83d721
Add, refine, and rename plotter data types
Myranae e1e2199
Split out validation logic and rename rubric
Myranae d606930
Split out tests for validation
Myranae 04ac86e
Rename rubric in plotter
Myranae 58fe8b2
Add changeset
Myranae 7d12856
Remove unneeded import
Myranae c75de6d
Remove unnecessary part of doc
Myranae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Introduces a validation function for the plotter widget (extracted from the scoring function). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 14 additions & 49 deletions
63
packages/perseus/src/widgets/plotter/score-plotter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,40 @@ | ||
import scorePlotter from "./score-plotter"; | ||
|
||
import type { | ||
PerseusPlotterRubric, | ||
PerseusPlotterScoringData, | ||
PerseusPlotterUserInput, | ||
} from "../../validation.types"; | ||
|
||
const baseRubric: PerseusPlotterRubric = { | ||
categories: [ | ||
"$1^{\\text{st}} \\text{}$", | ||
"$2^{\\text{nd}} \\text{}$", | ||
"$3^{\\text{rd}} \\text{}$", | ||
"$4^{\\text{th}} \\text{}$", | ||
"$5^{\\text{th}} \\text{}$", | ||
], | ||
picBoxHeight: 300, | ||
picSize: 300, | ||
picUrl: "", | ||
plotDimensions: [0, 0], | ||
correct: [15, 25, 5, 10, 10], | ||
labelInterval: 1, | ||
labels: ["School grade", "Number of absent students"], | ||
maxY: 30, | ||
scaleY: 5, | ||
snapsPerLine: 1, | ||
starting: [0, 0, 0, 0, 0], | ||
type: "bar", | ||
}; | ||
|
||
function generateRubric( | ||
extend?: Partial<PerseusPlotterRubric>, | ||
): PerseusPlotterRubric { | ||
return {...baseRubric, ...extend}; | ||
} | ||
|
||
describe("scorePlotter", () => { | ||
it("is invalid if the start and end are the same", () => { | ||
// Arrange | ||
const rubric = generateRubric(); | ||
|
||
const userInput: PerseusPlotterUserInput = rubric.starting; | ||
|
||
// Act | ||
const result = scorePlotter(userInput, rubric); | ||
|
||
// Assert | ||
expect(result).toHaveInvalidInput(); | ||
}); | ||
|
||
it("can be answered correctly", () => { | ||
// Arrange | ||
const rubric = generateRubric(); | ||
const scoringData: PerseusPlotterScoringData = { | ||
correct: [15, 25, 5, 10, 10], | ||
starting: [0, 0, 0, 0, 0], | ||
}; | ||
|
||
const userInput: PerseusPlotterUserInput = rubric.correct; | ||
const userInput: PerseusPlotterUserInput = scoringData.correct; | ||
|
||
// Act | ||
const result = scorePlotter(userInput, rubric); | ||
const score = scorePlotter(userInput, scoringData); | ||
|
||
// Assert | ||
expect(result).toHaveBeenAnsweredCorrectly(); | ||
expect(score).toHaveBeenAnsweredCorrectly(); | ||
}); | ||
|
||
it("can be answered incorrectly", () => { | ||
// Arrange | ||
const rubric = generateRubric(); | ||
const scoringData: PerseusPlotterScoringData = { | ||
correct: [15, 25, 5, 10, 10], | ||
starting: [0, 0, 0, 0, 0], | ||
}; | ||
|
||
const userInput: PerseusPlotterUserInput = [8, 6, 7, 5, 3, 0, 9]; | ||
|
||
// Act | ||
const result = scorePlotter(userInput, rubric); | ||
const score = scorePlotter(userInput, scoringData); | ||
|
||
// Assert | ||
expect(result).toHaveBeenAnsweredIncorrectly(); | ||
expect(score).toHaveBeenAnsweredIncorrectly(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/perseus/src/widgets/plotter/validate-plotter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import validatePlotter from "./validate-plotter"; | ||
|
||
import type { | ||
PerseusPlotterUserInput, | ||
PerseusPlotterValidationData, | ||
} from "../../validation.types"; | ||
|
||
describe("validatePlotter", () => { | ||
it("is invalid if the start and end are the same", () => { | ||
// Arrange | ||
const validationData: PerseusPlotterValidationData = { | ||
starting: [0, 0, 0, 0, 0], | ||
}; | ||
|
||
const userInput: PerseusPlotterUserInput = validationData.starting; | ||
|
||
// Act | ||
const validationError = validatePlotter(userInput, validationData); | ||
|
||
// Assert | ||
expect(validationError).toHaveInvalidInput(); | ||
}); | ||
|
||
it("returns null if the start and end are not the same and the user has modified the graph", () => { | ||
// Arrange | ||
const validationData: PerseusPlotterValidationData = { | ||
starting: [0, 0, 0, 0, 0], | ||
}; | ||
|
||
const userInput: PerseusPlotterUserInput = [0, 1, 2, 3, 4]; | ||
|
||
// Act | ||
const validationError = validatePlotter(userInput, validationData); | ||
|
||
// Assert | ||
expect(validationError).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Util from "../../util"; | ||
|
||
import type {PerseusScore} from "../../types"; | ||
import type { | ||
PerseusPlotterUserInput, | ||
PerseusPlotterValidationData, | ||
} from "../../validation.types"; | ||
|
||
const {deepEq} = Util; | ||
|
||
/** | ||
* Checks user input to confirm it is not the same as the starting values for the graph. | ||
* This means the user has modified the graph, and the question can be scored. | ||
* @param userInput | ||
* @param validationData | ||
* @see 'scorePlotter' for more details on scoring. | ||
*/ | ||
function validatePlotter( | ||
userInput: PerseusPlotterUserInput, | ||
validationData: PerseusPlotterValidationData, | ||
): Extract<PerseusScore, {type: "invalid"}> | null { | ||
if (deepEq(userInput, validationData.starting)) { | ||
return { | ||
type: "invalid", | ||
message: null, | ||
}; | ||
} | ||
return null; | ||
} | ||
|
||
export default validatePlotter; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's remove these. They don't add any new information.
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.
Removed!