From 3f49c18700f07c0bf8daf5505a85bbb5601d4505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Tue, 14 Jul 2026 09:12:48 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20move=20exam=20weights=20t?= =?UTF-8?q?o=20exam=20kinds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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.ts | 1 - src/api/postCourseExam.ts | 1 - src/api/types.ts | 10 ++++++++-- src/components/exams/exam-card.tsx | 7 ++++--- src/components/exams/exam-form.tsx | 21 --------------------- src/components/marks/marks-report-view.tsx | 3 ++- src/i18n/messages.ts | 16 ++++++++-------- src/lib/exam-weight.ts | 11 +++++++++++ src/pages/course-detail-page.tsx | 18 ++++++++---------- src/pages/exam-detail-page.tsx | 7 ++++--- 10 files changed, 45 insertions(+), 50 deletions(-) create mode 100644 src/lib/exam-weight.ts diff --git a/src/api/patchExamById.ts b/src/api/patchExamById.ts index 064f869..87e4391 100644 --- a/src/api/patchExamById.ts +++ b/src/api/patchExamById.ts @@ -5,7 +5,6 @@ export type PatchExamBody = { title?: string | null; description?: string | null; kind?: string | null; - weight?: number | null; mode?: string | null; starts_at?: number | null; ends_at?: number | null; diff --git a/src/api/postCourseExam.ts b/src/api/postCourseExam.ts index 5c45d45..17194a0 100644 --- a/src/api/postCourseExam.ts +++ b/src/api/postCourseExam.ts @@ -5,7 +5,6 @@ export type PostCourseExamBody = { title: string; description?: string | null; kind: string; - weight: number; mode?: string | null; starts_at?: number | null; ends_at?: number | null; diff --git a/src/api/types.ts b/src/api/types.ts index 9380467..e9de366 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -74,7 +74,10 @@ export type Exam = { title: string; description: string; kind: ExamKind | string; - weight: number; + weight?: number | null; + kind_weight?: number | null; + type_weight?: number | null; + exam_type_weight?: number | null; mode: ExamMode | string | null; starts_at: number | null; ends_at: number | null; @@ -132,7 +135,10 @@ export type MarkEntry = { exam: string; title: string; kind: string; - weight: number; + weight?: number | null; + kind_weight?: number | null; + type_weight?: number | null; + exam_type_weight?: number | null; mark: number; graded_by: string; }; diff --git a/src/components/exams/exam-card.tsx b/src/components/exams/exam-card.tsx index d377bc9..64ae1eb 100644 --- a/src/components/exams/exam-card.tsx +++ b/src/components/exams/exam-card.tsx @@ -4,6 +4,7 @@ import type { Exam } from "@/api/types"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/cn"; import { examKindLabel } from "@/lib/exam-labels"; +import { examWeight } from "@/lib/exam-weight"; import { examDurationMs, formatDateTime, formatDurationMinutes } from "@/lib/format"; import { usePreferences, useT } from "@/stores/preferences-context"; @@ -75,13 +76,13 @@ export function ExamCard(props: { exam: Exam; courseTitle?: string; now?: number
{examKindLabel(String(props.exam.kind), t)} + + {(weight) => ({t("courses.weight")}: {weight()})} + {modeLabel()} - - {t("courses.weight")}: {props.exam.weight} -
diff --git a/src/components/exams/exam-form.tsx b/src/components/exams/exam-form.tsx index d65f476..f6e8c8d 100644 --- a/src/components/exams/exam-form.tsx +++ b/src/components/exams/exam-form.tsx @@ -58,7 +58,6 @@ export type ExamFormValues = { title: string; description: string; kind: string; - weight: number; mode: string | null; starts_at: number | null; ends_at: number | null; @@ -75,7 +74,6 @@ export function ExamForm(props: { const [title, setTitle] = createSignal(props.initial?.title ?? ""); const [description, setDescription] = createSignal(props.initial?.description ?? ""); const [kind, setKind] = createSignal(String(props.initial?.kind && props.initial.kind !== "homework" ? props.initial.kind : "quiz")); - const [weight, setWeight] = createSignal(String(props.initial?.weight ?? 1)); const [mode, setMode] = createSignal(String(props.initial?.mode ?? "")); const [startsDate, setStartsDate] = createSignal(dateInputFromMs(props.initial?.starts_at)); const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at)); @@ -95,8 +93,6 @@ export function ExamForm(props: { if (!value) return t("form.titleRequired"); if (value.length > 200) return t("form.titleMax"); if (description().length > 2000) return t("form.descriptionMax"); - const w = Number(weight()); - if (!Number.isInteger(w) || w < 1 || w > 100) return t("form.weightRange"); if (mode()) { if (starts == null || ends == null) return t("exams.scheduleRequired"); if (ends <= starts) return t("form.timeOrder"); @@ -119,7 +115,6 @@ export function ExamForm(props: { setTitle(""); setDescription(""); setKind("quiz"); - setWeight("1"); setMode(""); setStartsDate(""); setStartsTime(""); @@ -149,7 +144,6 @@ export function ExamForm(props: { title: title().trim(), description: description(), kind: kind(), - weight: Number(weight()), mode: mode() || null, starts_at, ends_at, @@ -199,20 +193,6 @@ export function ExamForm(props: { {(k) => } -
-
- - setWeight(e.currentTarget.value)} - /> -
-
diff --git a/src/components/marks/marks-report-view.tsx b/src/components/marks/marks-report-view.tsx index fe590f9..63a3165 100644 --- a/src/components/marks/marks-report-view.tsx +++ b/src/components/marks/marks-report-view.tsx @@ -4,6 +4,7 @@ import type { MarksReport } from "@/api/types"; import { Badge } from "@/components/ui/badge"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { examKindLabel } from "@/lib/exam-labels"; +import { examWeight } from "@/lib/exam-weight"; import { useT } from "@/stores/preferences-context"; const round = (n: number) => (Math.round(n * 100) / 100).toString(); @@ -76,7 +77,7 @@ export function MarksReportView(props: { report: MarksReport }) { {examKindLabel(entry.kind, t)} - {entry.weight} + {examWeight(entry) ?? "—"} {entry.mark} )} diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index f94caa2..2f2b88c 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -573,7 +573,7 @@ const en: Dict = { "attempt.inProgress": "In progress", "exams.helpTitle": "About exams", "exams.helpBody": - "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.", + "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.", "admin.title": "People & roles", "admin.subtitle": "Promote or demote accounts. You can’t change your own role.", "admin.username": "Username", @@ -596,7 +596,7 @@ const en: Dict = { "Open an event, pick present/absent/late/excused, save attendance. Teachers can mark others.", "guide.step4.title": "4. Courses", "guide.step4.body": - "Teachers create a course, enroll students, then add weighted exams inside that course.", + "Teachers create a course, enroll students, then add exams by kind inside that course.", "guide.step5.title": "5. Exams", "guide.step5.body": "List all exams here. New exams are created from a course page (not from this list).", @@ -609,10 +609,10 @@ const en: Dict = { "guide.tipsTitle": "Tips", "courses.helpTitle": "About courses", "courses.helpBody": - "A course is the classroom container. Teachers enroll students and add weighted exams here. Deleting a course removes its exams, results, and enrollments.", + "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.", "marks.helpTitle": "About the report card", "marks.helpBody": - "Course average = Σ(mark × weight) / Σ(weight) over graded exams. Overall average is the mean of non-null course averages. Ungraded exams are skipped, not zeroed.", + "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.", "form.title": "Title", "form.content": "Content", "form.description": "Description", @@ -940,7 +940,7 @@ const tr: Dict = { "attempt.inProgress": "Devam ediyor", "exams.helpTitle": "Sınavlar hakkında", "exams.helpBody": - "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.", + "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.", "admin.title": "Kişiler ve roller", "admin.subtitle": "Hesapları yükselt / düşür. Kendi rolünü değiştiremezsin.", "admin.username": "Kullanıcı adı", @@ -963,7 +963,7 @@ const tr: Dict = { "Etkinliği aç, var/yok/geç/mazeretli seç, yoklamayı kaydet. Öğretmen başkasını işaretleyebilir.", "guide.step4.title": "4. Dersler", "guide.step4.body": - "Öğretmen ders oluşturur, öğrenci kaydeder, dersin içine ağırlıklı sınav ekler.", + "Öğretmen ders oluşturur, öğrenci kaydeder, dersin içine türe göre sınav ekler.", "guide.step5.title": "5. Sınavlar", "guide.step5.body": "Tüm sınavlar burada listelenir. Yeni sınav bu listeden değil, ders sayfasından eklenir.", @@ -976,10 +976,10 @@ const tr: Dict = { "guide.tipsTitle": "İpuçları", "courses.helpTitle": "Dersler hakkında", "courses.helpBody": - "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.", + "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.", "marks.helpTitle": "Karne hakkında", "marks.helpBody": - "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.", + "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.", "form.title": "Başlık", "form.content": "İçerik", "form.description": "Açıklama", diff --git a/src/lib/exam-weight.ts b/src/lib/exam-weight.ts new file mode 100644 index 0000000..057e659 --- /dev/null +++ b/src/lib/exam-weight.ts @@ -0,0 +1,11 @@ +type ExamWeightSource = { + weight?: number | null; + kind_weight?: number | null; + type_weight?: number | null; + exam_type_weight?: number | null; +}; + +export function examWeight(source: ExamWeightSource): number | null { + const value = source.kind_weight ?? source.type_weight ?? source.exam_type_weight ?? source.weight ?? null; + return typeof value === "number" && Number.isFinite(value) ? value : null; +} diff --git a/src/pages/course-detail-page.tsx b/src/pages/course-detail-page.tsx index 36ea24d..7521a79 100644 --- a/src/pages/course-detail-page.tsx +++ b/src/pages/course-detail-page.tsx @@ -35,6 +35,7 @@ import { UserSearchSelect } from "@/components/users/user-search-select"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; import { examKindLabel } from "@/lib/exam-labels"; +import { examWeight } from "@/lib/exam-weight"; import { hasMinRole } from "@/lib/roles"; export default function CourseDetailPage() { @@ -97,7 +98,7 @@ function CourseDetailContent() { const examCount = createMemo(() => exams()?.length ?? 0); const rosterCount = createMemo(() => roster()?.length ?? 0); - const totalWeight = createMemo(() => (exams() ?? []).reduce((sum, exam) => sum + exam.weight, 0)); + const examKindCount = createMemo(() => new Set((exams() ?? []).map((exam) => exam.kind)).size); const enrolledUserIds = () => (roster() ?? []).map((row) => row.user.id); @@ -283,10 +284,10 @@ function CourseDetailContent() {

- {t("courses.weight")} + {t("exams.kind")}

-

{totalWeight()}

-

{t("marks.subtitle")}

+

{examKindCount()}

+

{t("courses.exams")}

@@ -353,18 +354,15 @@ function CourseDetailContent() {
{examKindLabel(String(exam.kind), t)} + + {(weight) => ({t("courses.weight")}: {weight()})} + {examModeLabel(exam.mode)}
-
-

- {t("courses.weight")} -

-

{exam.weight}

-
)} diff --git a/src/pages/exam-detail-page.tsx b/src/pages/exam-detail-page.tsx index 988bf19..7794df8 100644 --- a/src/pages/exam-detail-page.tsx +++ b/src/pages/exam-detail-page.tsx @@ -36,6 +36,7 @@ import { import { hasMinRole } from "@/lib/roles"; import { createNow } from "@/lib/create-now"; import { examKindLabel } from "@/lib/exam-labels"; +import { examWeight } from "@/lib/exam-weight"; import { examDurationMs, formatDateTime, formatDurationMinutes } from "@/lib/format"; import { personId, personLabel, personLabelWithId } from "@/lib/person"; import { cn } from "@/lib/cn"; @@ -257,9 +258,9 @@ function ExamDetailContent() { {examKindLabel(String(ex().kind), t)} - - - {t("courses.weight")}: {ex().weight} + + {(weight) => ({t("courses.weight")}: {weight()})} + {examModeLabel(ex().mode)}