Skip to content

Commit 3d7678c

Browse files
committed
course config: nbgrader
1 parent 4c660c9 commit 3d7678c

File tree

2 files changed

+74
-31
lines changed

2 files changed

+74
-31
lines changed

src/packages/frontend/course/configuration/actions.ts

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ import {
2929
} from "./customize-student-project-functionality";
3030
import type { PurchaseInfo } from "@cocalc/util/licenses/purchase/types";
3131
import { delay } from "awaiting";
32+
import {
33+
NBGRADER_CELL_TIMEOUT_MS,
34+
NBGRADER_MAX_OUTPUT,
35+
NBGRADER_MAX_OUTPUT_PER_CELL,
36+
NBGRADER_TIMEOUT_MS,
37+
} from "../assignments/consts";
3238

3339
interface ConfigurationTarget {
3440
project_id: string;
@@ -123,10 +129,6 @@ export class ConfigurationActions {
123129
set_student_project_functionality = async (
124130
student_project_functionality: StudentProjectFunctionality,
125131
): Promise<void> => {
126-
console.log(
127-
"set_student_project_functionalit",
128-
student_project_functionality,
129-
);
130132
this.set({ student_project_functionality, table: "settings" });
131133
await this.course_actions.student_projects.configure_all_projects();
132134
};
@@ -310,7 +312,9 @@ export class ConfigurationActions {
310312
};
311313

312314
// project_id is a uuid *or* empty string.
313-
set_nbgrader_grade_project = async (project_id: string): Promise<void> => {
315+
set_nbgrader_grade_project = async (
316+
project_id: string = "",
317+
): Promise<void> => {
314318
this.set({
315319
nbgrader_grade_project: project_id,
316320
table: "settings",
@@ -322,29 +326,35 @@ export class ConfigurationActions {
322326
}
323327
};
324328

325-
set_nbgrader_cell_timeout_ms = (nbgrader_cell_timeout_ms: number): void => {
329+
set_nbgrader_cell_timeout_ms = (
330+
nbgrader_cell_timeout_ms: number = NBGRADER_CELL_TIMEOUT_MS,
331+
): void => {
326332
this.set({
327333
nbgrader_cell_timeout_ms,
328334
table: "settings",
329335
});
330336
};
331337

332-
set_nbgrader_timeout_ms = (nbgrader_timeout_ms: number): void => {
338+
set_nbgrader_timeout_ms = (
339+
nbgrader_timeout_ms: number = NBGRADER_TIMEOUT_MS,
340+
): void => {
333341
this.set({
334342
nbgrader_timeout_ms,
335343
table: "settings",
336344
});
337345
};
338346

339-
set_nbgrader_max_output = (nbgrader_max_output: number): void => {
347+
set_nbgrader_max_output = (
348+
nbgrader_max_output: number = NBGRADER_MAX_OUTPUT,
349+
): void => {
340350
this.set({
341351
nbgrader_max_output,
342352
table: "settings",
343353
});
344354
};
345355

346356
set_nbgrader_max_output_per_cell = (
347-
nbgrader_max_output_per_cell: number,
357+
nbgrader_max_output_per_cell: number = NBGRADER_MAX_OUTPUT_PER_CELL,
348358
): void => {
349359
this.set({
350360
nbgrader_max_output_per_cell,
@@ -382,7 +392,7 @@ export class ConfigurationActions {
382392
this.set_compute_image(image);
383393
};
384394

385-
set_nbgrader_parallel = (nbgrader_parallel: number): void => {
395+
set_nbgrader_parallel = (nbgrader_parallel: number=PARALLEL_DEFAULT): void => {
386396
this.set({
387397
nbgrader_parallel,
388398
table: "settings",
@@ -498,7 +508,6 @@ async function configureGroup({
498508
settings: CourseSettingsRecord;
499509
actions: CourseActions;
500510
}) {
501-
console.log("configureGroup:", group);
502511
switch (group) {
503512
case "collaborator-policy":
504513
const allow_colabs = !!settings.get("allow_collabs");
@@ -517,6 +526,31 @@ async function configureGroup({
517526
),
518527
);
519528
return;
529+
case "nbgrader":
530+
await actions.configuration.set_nbgrader_grade_project(
531+
settings.get("nbgrader_grade_project"),
532+
);
533+
await actions.configuration.set_nbgrader_cell_timeout_ms(
534+
settings.get("nbgrader_cell_timeout_ms"),
535+
);
536+
await actions.configuration.set_nbgrader_timeout_ms(
537+
settings.get("nbgrader_timeout_ms"),
538+
);
539+
await actions.configuration.set_nbgrader_max_output(
540+
settings.get("nbgrader_max_output"),
541+
);
542+
await actions.configuration.set_nbgrader_max_output_per_cell(
543+
settings.get("nbgrader_max_output_per_cell"),
544+
);
545+
await actions.configuration.set_nbgrader_include_hidden_tests(
546+
!!settings.get("nbgrader_include_hidden_tests"),
547+
);
548+
return;
549+
550+
case "network-file-systems":
551+
case "env-variables":
552+
case "upgrades":
553+
case "software-environment":
520554
default:
521555
throw Error(`configuring group ${group} not implemented`);
522556
}

src/packages/frontend/course/configuration/nbgrader.tsx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
useActions,
1111
useRedux,
1212
} from "@cocalc/frontend/app-framework";
13-
import { A, Icon, NumberInput } from "@cocalc/frontend/components";
13+
import { A, Icon } from "@cocalc/frontend/components";
14+
import { InputNumber } from "antd";
1415
import { SelectProject } from "@cocalc/frontend/projects/select-project";
1516
import { Card, Radio } from "antd";
1617
import { CourseActions } from "../actions";
@@ -166,27 +167,29 @@ export function Nbgrader({ name }: Props) {
166167
<i>Grading timeout in seconds:</i> if grading a student notebook takes
167168
longer than <i>{timeout} seconds</i>, then it is terminated with a
168169
timeout error.
169-
<NumberInput
170-
on_change={(n) =>
171-
actions.configuration.set_nbgrader_timeout_ms(n * 1000)
170+
<InputNumber
171+
onChange={(n) =>
172+
actions.configuration.set_nbgrader_timeout_ms(
173+
n ? n * 1000 : undefined,
174+
)
172175
}
173176
min={30}
174177
max={3600}
175-
number={timeout}
178+
value={timeout}
176179
/>
177180
<br />
178181
<i>Cell grading timeout in seconds:</i> if grading a cell in a student
179182
notebook takes longer than <i>{cell_timeout} seconds</i>, then that cell
180183
is terminated with a timeout error.
181-
<NumberInput
182-
on_change={(n) =>
184+
<InputNumber
185+
onChange={(n) =>
183186
actions.configuration.set_nbgrader_cell_timeout_ms(
184-
Math.min(n * 1000, timeout * 1000),
187+
n ? Math.min(n * 1000, timeout * 1000) : undefined,
185188
)
186189
}
187190
min={5}
188191
max={3600}
189-
number={cell_timeout}
192+
value={cell_timeout}
190193
/>
191194
</div>
192195
);
@@ -213,25 +216,29 @@ export function Nbgrader({ name }: Props) {
213216
<h6>Nbgrader output limits: {Math.round(max_output / 1000)} KB</h6>
214217
<i>Max output:</i> if total output from all cells exceeds{" "}
215218
{Math.round(max_output / 1000)} KB, then further output is truncated.
216-
<NumberInput
217-
on_change={(n) =>
218-
actions.configuration.set_nbgrader_max_output(n * 1000)
219+
<InputNumber
220+
onChange={(n) =>
221+
actions.configuration.set_nbgrader_max_output(
222+
n ? n * 1000 : undefined,
223+
)
219224
}
220225
min={1}
221226
max={10000}
222-
number={Math.round(max_output / 1000)}
227+
value={Math.round(max_output / 1000)}
223228
/>
224229
<br />
225230
<i>Max output per cell:</i> if output from a cell exceeds{" "}
226231
{Math.round(max_output_per_cell / 1000)} KB, then further output is
227232
truncated.
228-
<NumberInput
229-
on_change={(n) =>
230-
actions.configuration.set_nbgrader_max_output_per_cell(n * 1000)
233+
<InputNumber
234+
onChange={(n) =>
235+
actions.configuration.set_nbgrader_max_output_per_cell(
236+
n ? n * 1000 : undefined,
237+
)
231238
}
232239
min={1}
233240
max={10000}
234-
number={Math.round(max_output_per_cell / 1000)}
241+
value={Math.round(max_output_per_cell / 1000)}
235242
/>
236243
</div>
237244
);
@@ -260,11 +267,13 @@ export function Nbgrader({ name }: Props) {
260267
could depend on where grading is happening (see "Where to autograde
261268
assignments" above), and compute resources you or your students have
262269
bought.
263-
<NumberInput
264-
on_change={(n) => actions.configuration.set_nbgrader_parallel(n)}
270+
<InputNumber
271+
onChange={(n) =>
272+
actions.configuration.set_nbgrader_parallel(n ? n : undefined)
273+
}
265274
min={1}
266275
max={50}
267-
number={parallel}
276+
value={parallel}
268277
/>
269278
</div>
270279
);

0 commit comments

Comments
 (0)