Path: blob/master/src/packages/frontend/course/nbgrader/util.ts
1503 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Map } from "immutable";67export function nbgrader_status(assignment: Map<string, any>): {8succeeded: number;9failed: number;10not_attempted: number;11attempted: number;12} {13const student_ids = assignment.get("last_collect").keySeq().toJS(); // students whose work has been collected14const scores = assignment.get("nbgrader_scores");15const result = { succeeded: 0, failed: 0, not_attempted: 0, attempted: 0 };16if (scores == null) {17result.not_attempted = student_ids.length;18} else {19for (const student_id of student_ids) {20const state = grading_state(student_id, scores);21result[state] += 1;22}23}24result.attempted = result.succeeded + result.failed;25return result;26}2728type GradingState = "succeeded" | "failed" | "not_attempted";2930export function grading_state(31student_id: string,32nbgrader_scores,33): GradingState {34const x = nbgrader_scores?.get(student_id);35if (x == null) {36return "not_attempted";37} else {38for (const [_, val] of x) {39if (typeof val == "string") {40return "failed";41}42}43return "succeeded";44}45}464748