Skip to content

Commit

Permalink
Improve type coverage for auto-grading (#6655)
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya authored Sep 5, 2024
1 parent 1a4d5dd commit ffc2af3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
39 changes: 35 additions & 4 deletions lms/static/scripts/frontend_apps/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ export type CoursesMetricsResponse = {
courses: CourseWithMetrics[];
};

/**
* Response for `/api/dashboard/assignments/{assignment_id}` call.
*/
export type Assignment = {
id: number;
title: string;
Expand All @@ -204,10 +201,44 @@ export type StudentsMetricsResponse = {
students: StudentWithMetrics[];
};

export type AssignmentWithCourse = Assignment & {
type AssignmentWithCourse = Assignment & {
course: Course;
};

/**
* - all_or_nothing: students need to meet a minimum value, making them get
* either 0% or 100%
* - scaled: students may get a proportional grade based on the amount of
* annotations. If requirement is 4, and they created 3, they'll
* get a 75%
*/
export type GradingType = 'all_or_nothing' | 'scaled';

/**
* - cumulative: both annotations and replies will be counted together for
* the grade calculation
* - separate: students will have different annotation and reply goals.
*/
export type ActivityCalculation = 'cumulative' | 'separate';

export type AutoGradingConfig = {
grading_type: GradingType;
activity_calculation: ActivityCalculation;
required_annotations: number;
required_replies?: number;
};

/**
* Response for `/api/dashboard/assignments/{assignment_id}` call.
*/
export type AssignmentDetails = AssignmentWithCourse & {
/**
* If defined, it indicates this assignment was configured with auto grading
* enabled.
*/
auto_grading_config?: AutoGradingConfig;
};

export type AssignmentWithMetrics = AssignmentWithCourse & {
annotation_metrics: AnnotationMetrics;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,13 @@ import {
import type { ComponentChildren } from 'preact';
import { useCallback, useId } from 'preact/hooks';

export type GradingType = 'all_or_nothing' | 'scaled';
import type { ActivityCalculation, GradingType } from '../api-types';

export type AutoGradingConfig = {
/** Whether auto grading is enabled for the assignment or not */
enabled?: boolean;

/**
* - all_or_nothing: students need to meet a minimum value, making them get
* either 0% or 100%
* - scaled: students may get a proportional grade based on the amount of
* annotations. If requirement is 4, and they created 3, they'll
* get a 75%
*/
gradingType: GradingType;

/**
* - cumulative: both annotations and replies will be counted together for
* the grade calculation
* - separate: students will have different annotation and reply goals.
*/
activityCalculation: 'cumulative' | 'separate';
activityCalculation: ActivityCalculation;

/**
* Required number of annotations if activityCalculation is 'separate' or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { ComponentChildren } from 'preact';
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
import { Link as RouterLink } from 'wouter-preact';

import type { AutoGradingConfig as APIAutoGradingConfig } from '../api-types';
import { useConfig } from '../config';
import type { ConfigObject } from '../config';
import { apiCall } from '../utils/api';
Expand Down Expand Up @@ -160,6 +161,10 @@ function PanelLabel({
);
}

type DeepLinkingAPIData = Record<string, unknown> & {
auto_grading_config: APIAutoGradingConfig | null;
};

/**
* An application that allows the user to choose the web page or PDF for an
* assignment.
Expand Down Expand Up @@ -256,7 +261,7 @@ export default function FilePickerApp({ onSubmit }: FilePickerAppProps) {
// When deepLinkingAPI is present we want to call the backend to return the form
// fields we'll forward to the LMS to complete the Deep Linking request
try {
const data = {
const data: DeepLinkingAPIData = {
...deepLinkingAPI.data,
auto_grading_config:
autoGradingEnabled && autoGradingConfig.enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'preact/hooks';
import { useLocation, useParams, useSearch } from 'wouter-preact';

import type {
AssignmentWithCourse,
AssignmentDetails,
StudentsMetricsResponse,
} from '../../api-types';
import { useConfig } from '../../config';
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function AssignmentActivity() {
const search = useSearch();
const [, navigate] = useLocation();

const assignment = useAPIFetch<AssignmentWithCourse>(
const assignment = useAPIFetch<AssignmentDetails>(
replaceURLParams(routes.assignment, { assignment_id: assignmentId }),
);

Expand Down

0 comments on commit ffc2af3

Please sign in to comment.