forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

homework-queue.ts35 lines, 1.5 KiBHistoryRawDownload
1import type { Homework, HomeworkRosterEntry } from "@/api/client";
2
3const DAY_MS = 24 * 60 * 60 * 1000;
4/** How far back a due date still counts as work waiting on the teacher. */
5export const QUEUE_LOOKBACK_MS = 14 * DAY_MS;
6/** How far ahead: homework due in the next two days is worth a glance now. */
7export const QUEUE_LOOKAHEAD_MS = 2 * DAY_MS;
8/** Roster reads per board load; there is no bulk endpoint. */
9export const QUEUE_CAP = 6;
10
11export type QueueRow = {
12 homework: Homework;
13 /** Students in the audience who have not handed in (`missing`). */
14 missing: number;
15 /** Handed in, not graded yet. */
16 toGrade: number;
17};
18
19/** The teacher's own homework due around now, most recently due first. */
20export function queueCandidates(items: Homework[], teacherId: string, now: number): Homework[] {
21 return items
22 .filter((item) => item.created_by === teacherId && item.due_at >= now - QUEUE_LOOKBACK_MS && item.due_at <= now + QUEUE_LOOKAHEAD_MS)
23 .sort((a, b) => Math.abs(now - a.due_at) - Math.abs(now - b.due_at))
24 .slice(0, QUEUE_CAP);
25}
26
27/** Counts from one homework's roster; rows left behind by an unenrollment are not owed. */
28export function queueRow(homework: Homework, roster: HomeworkRosterEntry[]): QueueRow {
29 const current = roster.filter((row) => !row.unenrolled);
30 return {
31 homework,
32 missing: current.filter((row) => row.missing).length,
33 toGrade: current.filter((row) => row.submission != null && row.result == null).length,
34 };
35}