Skip to content

Commit

Permalink
Refine Label Image Rubric type (#1756)
Browse files Browse the repository at this point in the history
## Summary:
As part of the Server Side Scoring project, this refactors Label Image's Rubric type based on current usage. It is not currently used in this widget. As we plan to review the use of rubric during LEMS-2440, the Rubric type was left in but changed to `Empty`. It was also added in one place where rubric was listed as a parameter (but was not in use).

Issue: LEMS-2468

## Test plan:
- Confirm all tests pass
- Confirm the label image widget still works in Storybook

Author: Myranae

Reviewers: Myranae, handeyeco

Required Reviewers:

Approved By: handeyeco

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1756
  • Loading branch information
Myranae authored Oct 17, 2024
1 parent c95d080 commit 3a208ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-points-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Refine LabelImage's Rubric type
5 changes: 3 additions & 2 deletions packages/perseus/src/validation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
PerseusIFrameWidgetOptions,
PerseusImageWidgetOptions,
PerseusInteractionWidgetOptions,
PerseusLabelImageWidgetOptions,
PerseusMatcherWidgetOptions,
PerseusMatrixWidgetOptions,
PerseusNumberLineWidgetOptions,
Expand Down Expand Up @@ -124,7 +123,9 @@ export type PerseusInteractiveGraphRubric = {

export type PerseusInteractiveGraphUserInput = PerseusGraphType;

export type PerseusLabelImageRubric = PerseusLabelImageWidgetOptions;
/* TODO(LEMS-2440): Should be removed or refactored. Grading info may need
to be moved to the rubric from userInput. */
export type PerseusLabelImageRubric = Empty;

export type PerseusLabelImageUserInput = {
markers: ReadonlyArray<InteractiveMarkerType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ export function scoreMarker(
return score;
}

// TODO(LEMS-2440): May need to pull answers out of PerseusLabelImageWidgetOptions[markers] for the rubric
function labelImageValidator(
state: PerseusLabelImageUserInput,
userInput: PerseusLabelImageUserInput,
rubric?: PerseusLabelImageRubric,
): PerseusScore {
let numAnswered = 0;
let numCorrect = 0;

for (const marker of state.markers) {
for (const marker of userInput.markers) {
const score = scoreMarker(marker);

if (score.hasAnswers) {
Expand All @@ -63,7 +64,7 @@ function labelImageValidator(
}

// We expect all question markers to be answered before grading.
if (numAnswered !== state.markers.length) {
if (numAnswered !== userInput.markers.length) {
return {
type: "invalid",
message: null,
Expand All @@ -74,7 +75,7 @@ function labelImageValidator(
type: "points",
// Markers with no expected answers are graded as correct if user
// makes no answer selection.
earned: numCorrect === state.markers.length ? 1 : 0,
earned: numCorrect === userInput.markers.length ? 1 : 0,
total: 1,
message: null,
};
Expand Down
8 changes: 6 additions & 2 deletions packages/perseus/src/widgets/label-image/label-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import type {InteractiveMarkerType} from "./types";
import type {DependencyProps} from "../../dependencies";
import type {ChangeableProps} from "../../mixins/changeable";
import type {APIOptions, Widget, WidgetExports} from "../../types";
import type {PerseusLabelImageUserInput} from "../../validation.types";
import type {
PerseusLabelImageRubric,
PerseusLabelImageUserInput,
} from "../../validation.types";
import type {PropsFor} from "@khanacademy/wonder-blocks-core";
import type {CSSProperties} from "aphrodite";

Expand Down Expand Up @@ -317,7 +320,8 @@ export class LabelImage
return {markers};
}

showRationalesForCurrentlySelectedChoices(rubric: LabelImageProps) {
// TODO(LEMS-2544): Investigate impact on scoring; possibly pull out &/or remove rubric parameter.
showRationalesForCurrentlySelectedChoices(rubric: PerseusLabelImageRubric) {
const {markers} = this.props;
const {onChange} = this.props;

Expand Down

0 comments on commit 3a208ba

Please sign in to comment.