forge
Explore
Log in

Don't you dare go Hollow

🐛 move exam weights to exam kinds

Browse files at this commit

3f49c18700f07c0bf8daf5505a85bbb5601d4505Burak BoduroğluParent: 3d3511a
  • fix
    • 🐛 move exam weights to exam kinds
Show full message
fix: 🐛 move exam weights to exam kinds

- remove per-exam weight input and stop sending weight in exam create/update payloads

- accept exam kind weight fields from API and display them next to exam kind labels

- update course, exam, and marks views to tolerate missing per-exam weight

- refresh guide/help copy for exam-kind-based weighting
src/api/patchExamById.tsmodified+0 -1
@@ -5,7 +5,6 @@ export type PatchExamBody = {
5 title?: string | null;5 title?: string | null;
6 description?: string | null;6 description?: string | null;
7 kind?: string | null;7 kind?: string | null;
8- weight?: number | null;
9 mode?: string | null;8 mode?: string | null;
10 starts_at?: number | null;9 starts_at?: number | null;
11 ends_at?: number | null;10 ends_at?: number | null;
src/api/postCourseExam.tsmodified+0 -1
@@ -5,7 +5,6 @@ export type PostCourseExamBody = {
5 title: string;5 title: string;
6 description?: string | null;6 description?: string | null;
7 kind: string;7 kind: string;
8- weight: number;
9 mode?: string | null;8 mode?: string | null;
10 starts_at?: number | null;9 starts_at?: number | null;
11 ends_at?: number | null;10 ends_at?: number | null;
src/api/types.tsmodified+8 -2
@@ -74,7 +74,10 @@ export type Exam = {
74 title: string;74 title: string;
75 description: string;75 description: string;
76 kind: ExamKind | string;76 kind: ExamKind | string;
77- weight: number;77+ weight?: number | null;
78+ kind_weight?: number | null;
79+ type_weight?: number | null;
80+ exam_type_weight?: number | null;
78 mode: ExamMode | string | null;81 mode: ExamMode | string | null;
79 starts_at: number | null;82 starts_at: number | null;
80 ends_at: number | null;83 ends_at: number | null;
@@ -132,7 +135,10 @@ export type MarkEntry = {
132 exam: string;135 exam: string;
133 title: string;136 title: string;
134 kind: string;137 kind: string;
135- weight: number;138+ weight?: number | null;
139+ kind_weight?: number | null;
140+ type_weight?: number | null;
141+ exam_type_weight?: number | null;
136 mark: number;142 mark: number;
137 graded_by: string;143 graded_by: string;
138 };144 };
src/components/exams/exam-card.tsxmodified+4 -3
@@ -4,6 +4,7 @@ import type { Exam } from "@/api/types";
4 import { Badge } from "@/components/ui/badge";4 import { Badge } from "@/components/ui/badge";
5 import { cn } from "@/lib/cn";5 import { cn } from "@/lib/cn";
6 import { examKindLabel } from "@/lib/exam-labels";6 import { examKindLabel } from "@/lib/exam-labels";
7+import { examWeight } from "@/lib/exam-weight";
7 import { examDurationMs, formatDateTime, formatDurationMinutes } from "@/lib/format";8 import { examDurationMs, formatDateTime, formatDurationMinutes } from "@/lib/format";
8 import { usePreferences, useT } from "@/stores/preferences-context";9 import { usePreferences, useT } from "@/stores/preferences-context";
9 10
@@ -75,13 +76,13 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number
75 <div class="mt-4 flex flex-wrap gap-2">76 <div class="mt-4 flex flex-wrap gap-2">
76 <Badge variant="outline" class="rounded-full capitalize">77 <Badge variant="outline" class="rounded-full capitalize">
77 {examKindLabel(String(props.exam.kind), t)}78 {examKindLabel(String(props.exam.kind), t)}
79+ <Show when={examWeight(props.exam) != null}>
80+ {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}
81+ </Show>
78 </Badge>82 </Badge>
79 <Badge variant="outline" class="rounded-full">83 <Badge variant="outline" class="rounded-full">
80 {modeLabel()}84 {modeLabel()}
81 </Badge>85 </Badge>
82- <Badge variant="secondary" class="rounded-full">
83- {t("courses.weight")}: {props.exam.weight}
84- </Badge>
85 </div>86 </div>
86 </div>87 </div>
87 88
src/components/exams/exam-form.tsxmodified+0 -21
@@ -58,7 +58,6 @@ export type ExamFormValues = {
58 title: string;58 title: string;
59 description: string;59 description: string;
60 kind: string;60 kind: string;
61- weight: number;
62 mode: string | null;61 mode: string | null;
63 starts_at: number | null;62 starts_at: number | null;
64 ends_at: number | null;63 ends_at: number | null;
@@ -75,7 +74,6 @@ export function ExamForm(props: {
75 const [title, setTitle] = createSignal(props.initial?.title ?? "");74 const [title, setTitle] = createSignal(props.initial?.title ?? "");
76 const [description, setDescription] = createSignal(props.initial?.description ?? "");75 const [description, setDescription] = createSignal(props.initial?.description ?? "");
77 const [kind, setKind] = createSignal(String(props.initial?.kind && props.initial.kind !== "homework" ? props.initial.kind : "quiz"));76 const [kind, setKind] = createSignal(String(props.initial?.kind && props.initial.kind !== "homework" ? props.initial.kind : "quiz"));
78- const [weight, setWeight] = createSignal(String(props.initial?.weight ?? 1));
79 const [mode, setMode] = createSignal(String(props.initial?.mode ?? ""));77 const [mode, setMode] = createSignal(String(props.initial?.mode ?? ""));
80 const [startsDate, setStartsDate] = createSignal(dateInputFromMs(props.initial?.starts_at));78 const [startsDate, setStartsDate] = createSignal(dateInputFromMs(props.initial?.starts_at));
81 const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at));79 const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at));
@@ -95,8 +93,6 @@ export function ExamForm(props: {
95 if (!value) return t("form.titleRequired");93 if (!value) return t("form.titleRequired");
96 if (value.length > 200) return t("form.titleMax");94 if (value.length > 200) return t("form.titleMax");
97 if (description().length > 2000) return t("form.descriptionMax");95 if (description().length > 2000) return t("form.descriptionMax");
98- const w = Number(weight());
99- if (!Number.isInteger(w) || w < 1 || w > 100) return t("form.weightRange");
100 if (mode()) {96 if (mode()) {
101 if (starts == null || ends == null) return t("exams.scheduleRequired");97 if (starts == null || ends == null) return t("exams.scheduleRequired");
102 if (ends <= starts) return t("form.timeOrder");98 if (ends <= starts) return t("form.timeOrder");
@@ -119,7 +115,6 @@ export function ExamForm(props: {
119 setTitle("");115 setTitle("");
120 setDescription("");116 setDescription("");
121 setKind("quiz");117 setKind("quiz");
122- setWeight("1");
123 setMode("");118 setMode("");
124 setStartsDate("");119 setStartsDate("");
125 setStartsTime("");120 setStartsTime("");
@@ -149,7 +144,6 @@ export function ExamForm(props: {
149 title: title().trim(),144 title: title().trim(),
150 description: description(),145 description: description(),
151 kind: kind(),146 kind: kind(),
152- weight: Number(weight()),
153 mode: mode() || null,147 mode: mode() || null,
154 starts_at,148 starts_at,
155 ends_at,149 ends_at,
@@ -199,20 +193,6 @@ export function ExamForm(props: {
199 <For each={UI_EXAM_KINDS}>{(k) => <option value={k}>{examKindLabel(k, t)}</option>}</For>193 <For each={UI_EXAM_KINDS}>{(k) => <option value={k}>{examKindLabel(k, t)}</option>}</For>
200 </Select>194 </Select>
201 </div>195 </div>
202- <div class="grid gap-3 sm:grid-cols-2">
203- <div class="space-y-1.5">
204- <Label for="exam-weight">{t("courses.weight")}</Label>
205- <Input
206- id="exam-weight"
207- class="rounded-sm"
208- type="number"
209- min={1}
210- max={100}
211- value={weight()}
212- required
213- onInput={(e) => setWeight(e.currentTarget.value)}
214- />
215- </div>
216 <div class="space-y-1.5">196 <div class="space-y-1.5">
217 <Label for="exam-mode">{t("exams.mode")}</Label>197 <Label for="exam-mode">{t("exams.mode")}</Label>
218 <Select198 <Select
@@ -227,7 +207,6 @@ export function ExamForm(props: {
227 </For>207 </For>
228 </Select>208 </Select>
229 </div>209 </div>
230- </div>
231 <Show when={mode()}>210 <Show when={mode()}>
232 <div class="grid gap-3 sm:grid-cols-2">211 <div class="grid gap-3 sm:grid-cols-2">
233 <div class="space-y-1.5">212 <div class="space-y-1.5">
src/components/marks/marks-report-view.tsxmodified+2 -1
@@ -4,6 +4,7 @@ import type { MarksReport } from "@/api/types";
4 import { Badge } from "@/components/ui/badge";4 import { Badge } from "@/components/ui/badge";
5 import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";5 import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
6 import { examKindLabel } from "@/lib/exam-labels";6 import { examKindLabel } from "@/lib/exam-labels";
7+import { examWeight } from "@/lib/exam-weight";
7 import { useT } from "@/stores/preferences-context";8 import { useT } from "@/stores/preferences-context";
8 9
9 const round = (n: number) => (Math.round(n * 100) / 100).toString();10 const round = (n: number) => (Math.round(n * 100) / 100).toString();
@@ -76,7 +77,7 @@ export function MarksReportView(props: { report: MarksReport }) {
76 {examKindLabel(entry.kind, t)}77 {examKindLabel(entry.kind, t)}
77 </Badge>78 </Badge>
78 </TableCell>79 </TableCell>
79- <TableCell class="tabular-nums">{entry.weight}</TableCell>80+ <TableCell class="tabular-nums">{examWeight(entry) ?? "—"}</TableCell>
80 <TableCell class="font-semibold tabular-nums">{entry.mark}</TableCell>81 <TableCell class="font-semibold tabular-nums">{entry.mark}</TableCell>
81 </TableRow>82 </TableRow>
82 )}83 )}
src/i18n/messages.tsmodified+8 -8
@@ -573,7 +573,7 @@ const en: Dict = {
573 "attempt.inProgress": "In progress",573 "attempt.inProgress": "In progress",
574 "exams.helpTitle": "About exams",574 "exams.helpTitle": "About exams",
575 "exams.helpBody":575 "exams.helpBody":
576- "Exams belong to a course. Teachers add them from the course page with a kind and weight (1–100). Students only see their own mark (or “not graded yet”). Weighted averages appear on the report card.",576+ "Exams belong to a course. Teachers add them from the course page with a kind; weighting is defined by the exam kind. Students only see their own mark (or “not graded yet”). Weighted averages appear on the report card.",
577 "admin.title": "People & roles",577 "admin.title": "People & roles",
578 "admin.subtitle": "Promote or demote accounts. You can’t change your own role.",578 "admin.subtitle": "Promote or demote accounts. You can’t change your own role.",
579 "admin.username": "Username",579 "admin.username": "Username",
@@ -596,7 +596,7 @@ const en: Dict = {
596 "Open an event, pick present/absent/late/excused, save attendance. Teachers can mark others.",596 "Open an event, pick present/absent/late/excused, save attendance. Teachers can mark others.",
597 "guide.step4.title": "4. Courses",597 "guide.step4.title": "4. Courses",
598 "guide.step4.body":598 "guide.step4.body":
599- "Teachers create a course, enroll students, then add weighted exams inside that course.",599+ "Teachers create a course, enroll students, then add exams by kind inside that course.",
600 "guide.step5.title": "5. Exams",600 "guide.step5.title": "5. Exams",
601 "guide.step5.body":601 "guide.step5.body":
602 "List all exams here. New exams are created from a course page (not from this list).",602 "List all exams here. New exams are created from a course page (not from this list).",
@@ -609,10 +609,10 @@ const en: Dict = {
609 "guide.tipsTitle": "Tips",609 "guide.tipsTitle": "Tips",
610 "courses.helpTitle": "About courses",610 "courses.helpTitle": "About courses",
611 "courses.helpBody":611 "courses.helpBody":
612- "A course is the classroom container. Teachers enroll students and add weighted exams here. Deleting a course removes its exams, results, and enrollments.",612+ "A course is the classroom container. Teachers enroll students and add exams here; exam kind weights drive averages. Deleting a course removes its exams, results, and enrollments.",
613 "marks.helpTitle": "About the report card",613 "marks.helpTitle": "About the report card",
614 "marks.helpBody":614 "marks.helpBody":
615- "Course average = Σ(mark × weight) / Σ(weight) over graded exams. Overall average is the mean of non-null course averages. Ungraded exams are skipped, not zeroed.",615+ "Course average uses the weight defined on each exam kind over graded exams. Overall average is the mean of non-null course averages. Ungraded exams are skipped, not zeroed.",
616 "form.title": "Title",616 "form.title": "Title",
617 "form.content": "Content",617 "form.content": "Content",
618 "form.description": "Description",618 "form.description": "Description",
@@ -940,7 +940,7 @@ const tr: Dict = {
940 "attempt.inProgress": "Devam ediyor",940 "attempt.inProgress": "Devam ediyor",
941 "exams.helpTitle": "Sınavlar hakkında",941 "exams.helpTitle": "Sınavlar hakkında",
942 "exams.helpBody":942 "exams.helpBody":
943- "Sınavlar bir derse aittir. Öğretmenler ders sayfasından tür ve ağırlık (1–100) ile ekler. Öğrenciler yalnızca kendi notunu görür. Ağırlıklı ortalamalar Karnem’dedir.",943+ "Sınavlar bir derse aittir. Öğretmenler ders sayfasından tür seçerek ekler; ağırlık sınav türünde tanımlıdır. Öğrenciler yalnızca kendi notunu görür. Ağırlıklı ortalamalar Karnem’dedir.",
944 "admin.title": "Kişiler ve roller",944 "admin.title": "Kişiler ve roller",
945 "admin.subtitle": "Hesapları yükselt / düşür. Kendi rolünü değiştiremezsin.",945 "admin.subtitle": "Hesapları yükselt / düşür. Kendi rolünü değiştiremezsin.",
946 "admin.username": "Kullanıcı adı",946 "admin.username": "Kullanıcı adı",
@@ -963,7 +963,7 @@ const tr: Dict = {
963 "Etkinliği aç, var/yok/geç/mazeretli seç, yoklamayı kaydet. Öğretmen başkasını işaretleyebilir.",963 "Etkinliği aç, var/yok/geç/mazeretli seç, yoklamayı kaydet. Öğretmen başkasını işaretleyebilir.",
964 "guide.step4.title": "4. Dersler",964 "guide.step4.title": "4. Dersler",
965 "guide.step4.body":965 "guide.step4.body":
966- "Öğretmen ders oluşturur, öğrenci kaydeder, dersin içine ağırlıklı sınav ekler.",966+ "Öğretmen ders oluşturur, öğrenci kaydeder, dersin içine türe göre sınav ekler.",
967 "guide.step5.title": "5. Sınavlar",967 "guide.step5.title": "5. Sınavlar",
968 "guide.step5.body":968 "guide.step5.body":
969 "Tüm sınavlar burada listelenir. Yeni sınav bu listeden değil, ders sayfasından eklenir.",969 "Tüm sınavlar burada listelenir. Yeni sınav bu listeden değil, ders sayfasından eklenir.",
@@ -976,10 +976,10 @@ const tr: Dict = {
976 "guide.tipsTitle": "İpuçları",976 "guide.tipsTitle": "İpuçları",
977 "courses.helpTitle": "Dersler hakkında",977 "courses.helpTitle": "Dersler hakkında",
978 "courses.helpBody":978 "courses.helpBody":
979- "Ders, sınıf kabıdır. Öğretmen öğrenci kaydeder ve buradan ağırlıklı sınav ekler. Dersi silmek sınavları, sonuçları ve kayıtları da siler.",979+ "Ders, sınıf kabıdır. Öğretmen öğrenci kaydeder ve buradan sınav ekler; ortalamalarda sınav türü ağırlığı kullanılır. Dersi silmek sınavları, sonuçları ve kayıtları da siler.",
980 "marks.helpTitle": "Karne hakkında",980 "marks.helpTitle": "Karne hakkında",
981 "marks.helpBody":981 "marks.helpBody":
982- "Ders ortalaması = Σ(not × ağırlık) / Σ(ağırlık). Genel ortalama, dolu ders ortalamalarının aritmetik ortalamasıdır. Notlanmamış sınavlar sıfır sayılmaz, atlanır.",982+ "Ders ortalaması, notlanmış sınavlarda sınav türünde tanımlı ağırlıkla hesaplanır. Genel ortalama, dolu ders ortalamalarının aritmetik ortalamasıdır. Notlanmamış sınavlar sıfır sayılmaz, atlanır.",
983 "form.title": "Başlık",983 "form.title": "Başlık",
984 "form.content": "İçerik",984 "form.content": "İçerik",
985 "form.description": "Açıklama",985 "form.description": "Açıklama",
src/lib/exam-weight.tsadded+11 -0
@@ -0,0 +1,11 @@
1+type ExamWeightSource = {
2+ weight?: number | null;
3+ kind_weight?: number | null;
4+ type_weight?: number | null;
5+ exam_type_weight?: number | null;
6+};
7+
8+export function examWeight(source: ExamWeightSource): number | null {
9+ const value = source.kind_weight ?? source.type_weight ?? source.exam_type_weight ?? source.weight ?? null;
10+ return typeof value === "number" && Number.isFinite(value) ? value : null;
11+}
src/pages/course-detail-page.tsxmodified+8 -10
@@ -35,6 +35,7 @@ import { UserSearchSelect } from "@/components/users/user-search-select";
35 import { useAuth } from "@/stores/auth-context";35 import { useAuth } from "@/stores/auth-context";
36 import { useT } from "@/stores/preferences-context";36 import { useT } from "@/stores/preferences-context";
37 import { examKindLabel } from "@/lib/exam-labels";37 import { examKindLabel } from "@/lib/exam-labels";
38+import { examWeight } from "@/lib/exam-weight";
38 import { hasMinRole } from "@/lib/roles";39 import { hasMinRole } from "@/lib/roles";
39 40
40 export default function CourseDetailPage() {41 export default function CourseDetailPage() {
@@ -97,7 +98,7 @@ function CourseDetailContent() {
97 98
98 const examCount = createMemo(() => exams()?.length ?? 0);99 const examCount = createMemo(() => exams()?.length ?? 0);
99 const rosterCount = createMemo(() => roster()?.length ?? 0);100 const rosterCount = createMemo(() => roster()?.length ?? 0);
100- const totalWeight = createMemo(() => (exams() ?? []).reduce((sum, exam) => sum + exam.weight, 0));101+ const examKindCount = createMemo(() => new Set((exams() ?? []).map((exam) => exam.kind)).size);
101 102
102 const enrolledUserIds = () => (roster() ?? []).map((row) => row.user.id);103 const enrolledUserIds = () => (roster() ?? []).map((row) => row.user.id);
103 104
@@ -283,10 +284,10 @@ function CourseDetailContent() {
283 284
284 <div class="surface-card bg-card/80 p-4">285 <div class="surface-card bg-card/80 p-4">
285 <p class="text-xs font-semibold uppercase tracking-wider text-muted-foreground">286 <p class="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
286- {t("courses.weight")}287+ {t("exams.kind")}
287 </p>288 </p>
288- <p class="mt-2 font-display text-3xl font-semibold tabular-nums">{totalWeight()}</p>289+ <p class="mt-2 font-display text-3xl font-semibold tabular-nums">{examKindCount()}</p>
289- <p class="mt-1 text-xs text-muted-foreground">{t("marks.subtitle")}</p>290+ <p class="mt-1 text-xs text-muted-foreground">{t("courses.exams")}</p>
290 </div>291 </div>
291 </section>292 </section>
292 293
@@ -353,18 +354,15 @@ function CourseDetailContent() {
353 <div class="flex flex-wrap items-center gap-2">354 <div class="flex flex-wrap items-center gap-2">
354 <Badge variant="outline" class="rounded-full capitalize">355 <Badge variant="outline" class="rounded-full capitalize">
355 {examKindLabel(String(exam.kind), t)}356 {examKindLabel(String(exam.kind), t)}
357+ <Show when={examWeight(exam) != null}>
358+ {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}
359+ </Show>
356 </Badge>360 </Badge>
357 <Badge variant="secondary" class="rounded-full">361 <Badge variant="secondary" class="rounded-full">
358 {examModeLabel(exam.mode)}362 {examModeLabel(exam.mode)}
359 </Badge>363 </Badge>
360 </div>364 </div>
361 </div>365 </div>
362- <div class="shrink-0 rounded-lg border bg-card px-3 py-2 text-center shadow-sm">
363- <p class="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">
364- {t("courses.weight")}
365- </p>
366- <p class="font-display text-xl font-semibold tabular-nums">{exam.weight}</p>
367- </div>
368 </Link>366 </Link>
369 </li>367 </li>
370 )}368 )}
src/pages/exam-detail-page.tsxmodified+4 -3
@@ -36,6 +36,7 @@ import {
36 import { hasMinRole } from "@/lib/roles";36 import { hasMinRole } from "@/lib/roles";
37 import { createNow } from "@/lib/create-now";37 import { createNow } from "@/lib/create-now";
38 import { examKindLabel } from "@/lib/exam-labels";38 import { examKindLabel } from "@/lib/exam-labels";
39+import { examWeight } from "@/lib/exam-weight";
39 import { examDurationMs, formatDateTime, formatDurationMinutes } from "@/lib/format";40 import { examDurationMs, formatDateTime, formatDurationMinutes } from "@/lib/format";
40 import { personId, personLabel, personLabelWithId } from "@/lib/person";41 import { personId, personLabel, personLabelWithId } from "@/lib/person";
41 import { cn } from "@/lib/cn";42 import { cn } from "@/lib/cn";
@@ -257,9 +258,9 @@ function ExamDetailContent() {
257 </Badge>258 </Badge>
258 <Badge variant="outline" class="rounded-sm capitalize">259 <Badge variant="outline" class="rounded-sm capitalize">
259 {examKindLabel(String(ex().kind), t)}260 {examKindLabel(String(ex().kind), t)}
260- </Badge>261+ <Show when={examWeight(ex()) != null}>
261- <Badge variant="outline" class="rounded-sm">262+ {(weight) => <span class="ml-1 text-muted-foreground">({t("courses.weight")}: {weight()})</span>}
262- {t("courses.weight")}: {ex().weight}263+ </Show>
263 </Badge>264 </Badge>
264 <Badge variant="outline" class="rounded-sm">265 <Badge variant="outline" class="rounded-sm">
265 {examModeLabel(ex().mode)}266 {examModeLabel(ex().mode)}