CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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