Skip to content
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

Refine Label Image Rubric type #1756

Merged
merged 8 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +126 to +128
Copy link
Contributor Author

@Myranae Myranae Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally just removed everything related to rubric, but I think we might want to pull answers out of userInput.


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