merge: readable student analysis drawer
Browse files at this commit5 changed files +1571 -174
- src/components/insights/insight-detail.test.tsx +339 -0
- src/components/insights/insight-detail.tsx +242 -174
- src/components/insights/insight-module-views.tsx +781 -0
- src/i18n/insights-detail.ts +199 -0
- src/lib/is-record.ts +10 -0
src/components/insights/insight-detail.test.tsxadded+339 -0
| @@ -0,0 +1,339 @@ | ||
| 1 | +import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; | |
| 2 | +import { afterEach, describe, expect, it } from "vitest"; | |
| 3 | +import type { StudentInsight } from "@/api/client"; | |
| 4 | +import { InsightDetail } from "@/components/insights/insight-detail"; | |
| 5 | +import { PreferencesProvider } from "@/stores/preferences-context"; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * The drawer renders ZEKA's raw payloads. These tests pin the line the drawer | |
| 9 | + * must not cross: a school manager sees Turkish labels and titles, never a raw | |
| 10 | + * key or a uuid — while the whole payload stays reachable in the collapsed | |
| 11 | + * technical disclosure underneath. | |
| 12 | + */ | |
| 13 | + | |
| 14 | +const STUDENT_ID = "01a0b1b0-9d58-77f7-966f-5bfa87cb7e9d"; | |
| 15 | +const COURSE_ID = "01a0b1b0-9d58-77f7-966f-5bfa87cb7e9e"; | |
| 16 | +const CLASS_ID = "01a0b1b0-9d58-77f7-966f-5bfa87cb7e9f"; | |
| 17 | +const HOMEWORK_ID = "01a0b1b0-9d58-77f7-966f-5bfa87cb7ea0"; | |
| 18 | + | |
| 19 | +const NOW = 1_758_000_000_000; | |
| 20 | +const WEEK = 7 * 86_400_000; | |
| 21 | + | |
| 22 | +const insight: StudentInsight = { | |
| 23 | + user_id: STUDENT_ID, | |
| 24 | + summary: { | |
| 25 | + confidence: "exploratory", | |
| 26 | + computed_at: NOW, | |
| 27 | + retain_until: NOW + 30 * 86_400_000, | |
| 28 | + attendance: { | |
| 29 | + overall: { | |
| 30 | + present: 51, | |
| 31 | + absent: 8, | |
| 32 | + late: 2, | |
| 33 | + excused: 4, | |
| 34 | + n_obs: 61, | |
| 35 | + rate: 0.86, | |
| 36 | + rate_suppressed: false, | |
| 37 | + relative_gap: -0.04, | |
| 38 | + }, | |
| 39 | + courses: { | |
| 40 | + [COURSE_ID]: { | |
| 41 | + course: COURSE_ID, | |
| 42 | + present: 18, | |
| 43 | + absent: 6, | |
| 44 | + late: 1, | |
| 45 | + excused: 2, | |
| 46 | + custom_total: 0, | |
| 47 | + n_obs: 25, | |
| 48 | + rate: 0.76, | |
| 49 | + rate_suppressed: false, | |
| 50 | + cohort_median: 0.92, | |
| 51 | + cohort_n: 24, | |
| 52 | + relative_gap: -0.16, | |
| 53 | + }, | |
| 54 | + }, | |
| 55 | + weekday_pattern: null, | |
| 56 | + weekday_pattern_reason: | |
| 57 | + "Devam ucu yalnız sayaç döndürüyor; oturum tarihi yok. Haftanın günü deseni için course_session.starts_at gerekir.", | |
| 58 | + trend: { | |
| 59 | + available: false, | |
| 60 | + reason: | |
| 61 | + "İki pencere karşılaştırması için satır düzeyinde zaman damgası gerekir; devam verisinde tarih yok.", | |
| 62 | + delta: null, | |
| 63 | + }, | |
| 64 | + limitation: | |
| 65 | + "Devam oranı dönem başından bugüne kümülatiftir, son 30 gün değildir; raporlu (excused) devamsızlık orana girmez.", | |
| 66 | + }, | |
| 67 | + marks: { | |
| 68 | + classes: [CLASS_ID], | |
| 69 | + courses: { | |
| 70 | + [COURSE_ID]: { | |
| 71 | + course: COURSE_ID, | |
| 72 | + course_title: "Matematik", | |
| 73 | + n_marks: 2, | |
| 74 | + average: 72.5, | |
| 75 | + mean: 72.5, | |
| 76 | + median: 72.5, | |
| 77 | + min: 60, | |
| 78 | + max: 85, | |
| 79 | + trend: { | |
| 80 | + available: false, | |
| 81 | + reason: "eğilim için en az 6 not gerekir", | |
| 82 | + n: 2, | |
| 83 | + slope_per_30d: null, | |
| 84 | + recent_mean: null, | |
| 85 | + previous_mean: null, | |
| 86 | + delta: null, | |
| 87 | + dropped: false, | |
| 88 | + rising: false, | |
| 89 | + }, | |
| 90 | + placement: { | |
| 91 | + band: "insufficient_data", | |
| 92 | + confidence: "none", | |
| 93 | + z: null, | |
| 94 | + class_average: null, | |
| 95 | + class_sd: null, | |
| 96 | + cohort_n: 0, | |
| 97 | + progress: "2/3", | |
| 98 | + reason: "veri toplanıyor", | |
| 99 | + }, | |
| 100 | + }, | |
| 101 | + }, | |
| 102 | + within_student_contrast: { | |
| 103 | + available: false, | |
| 104 | + reason: "kontrast için bantlanmış en az 3 ders gerekir", | |
| 105 | + n_courses: 1, | |
| 106 | + course: null, | |
| 107 | + course_title: null, | |
| 108 | + z: null, | |
| 109 | + others_median_z: null, | |
| 110 | + delta: null, | |
| 111 | + flagged: false, | |
| 112 | + }, | |
| 113 | + limitation: | |
| 114 | + "Konu (subject) kırılımı bu sürümde yok: köprü ham sınav cevabı vermiyor.", | |
| 115 | + }, | |
| 116 | + study: { | |
| 117 | + recent_28d: { | |
| 118 | + n_stints: 3, | |
| 119 | + active_days: 2, | |
| 120 | + total_focus_ms: 5_400_000, | |
| 121 | + median_stint_ms: 1_800_000, | |
| 122 | + regularity: null, | |
| 123 | + regularity_suppressed: true, | |
| 124 | + burstiness: 1.5, | |
| 125 | + burstiness_limitation: | |
| 126 | + "Gün-arası yığılmayı ölçer; sınav/ödev öncesi yığılmayı ÖLÇMEZ.", | |
| 127 | + night_share: 0.33, | |
| 128 | + night_window_tr: "[22:00, 02:00)", | |
| 129 | + }, | |
| 130 | + previous_28d: { n_stints: 1, active_days: 1, total_focus_ms: 1_800_000 }, | |
| 131 | + change: { active_days_delta: 1, stints_delta: 2, focus_ms_delta: 3_600_000 }, | |
| 132 | + streak_local: 2, | |
| 133 | + heatmap: null, | |
| 134 | + heatmap_progress: "3/5", | |
| 135 | + pre_deadline_share: 0.5, | |
| 136 | + pre_exam_share: null, | |
| 137 | + pre_exam_reason: "Sınav takvimi Source arayüzünde yok; sınav öncesi yığılma hesaplanamaz.", | |
| 138 | + limitation: "Çalışma oturumlarının ders bağı yoktur.", | |
| 139 | + }, | |
| 140 | + submission: { | |
| 141 | + overall: { | |
| 142 | + n: 9, | |
| 143 | + n_submitted: 7, | |
| 144 | + n_on_time: 5, | |
| 145 | + n_late: 2, | |
| 146 | + n_missing: 2, | |
| 147 | + n_marked_missing: 1, | |
| 148 | + on_time_rate_by_last_touch: 0.71, | |
| 149 | + late_rate: 0.29, | |
| 150 | + missing_rate: 0.22, | |
| 151 | + rates_suppressed: false, | |
| 152 | + }, | |
| 153 | + recent_30d: { n: 4, n_submitted: 3, n_late: 1, n_missing: 1, rates_suppressed: true }, | |
| 154 | + previous_30d: { n: 5, n_submitted: 4, n_late: 1, n_missing: 1, rates_suppressed: false }, | |
| 155 | + upcoming: [ | |
| 156 | + { | |
| 157 | + homework: HOMEWORK_ID, | |
| 158 | + course: COURSE_ID, | |
| 159 | + title: "Türev alıştırmaları", | |
| 160 | + due_at: NOW + 2 * 86_400_000, | |
| 161 | + hours_left: 30.5, | |
| 162 | + submitted: false, | |
| 163 | + remind_at: NOW + 86_400_000, | |
| 164 | + high_priority: true, | |
| 165 | + }, | |
| 166 | + ], | |
| 167 | + procrastination: { | |
| 168 | + available: false, | |
| 169 | + reason: "Erteleme profili submitted_at gerektirir; öğrenci ödev raporu teslim anını taşımıyor.", | |
| 170 | + median_lead_ms: null, | |
| 171 | + last_minute: null, | |
| 172 | + last_24h_share: null, | |
| 173 | + }, | |
| 174 | + counted_on_time_available: false, | |
| 175 | + measure: "last_touch", | |
| 176 | + limitation: "Teslim saati bilinmediği için erteleme yorumu yapılmaz.", | |
| 177 | + }, | |
| 178 | + }, | |
| 179 | + attention: [ | |
| 180 | + { | |
| 181 | + trigger: "attendance", | |
| 182 | + fact: "Derslere katılım oranı %76; aynı şubedeki arkadaşlarının ortancasından 16 puan düşük.", | |
| 183 | + course: COURSE_ID, | |
| 184 | + window_from: NOW - WEEK, | |
| 185 | + window_to: NOW, | |
| 186 | + evidence: { | |
| 187 | + rate: 0.76, | |
| 188 | + relative_gap: -0.16, | |
| 189 | + n_obs: 25, | |
| 190 | + rule_basis: "level", | |
| 191 | + measure: "level_vs_cohort_median", | |
| 192 | + limitation: "Dönem kümülatifi; son 30 gün penceresi yok.", | |
| 193 | + }, | |
| 194 | + }, | |
| 195 | + ], | |
| 196 | + cards: [ | |
| 197 | + { | |
| 198 | + id: "card-1", | |
| 199 | + product: "O1", | |
| 200 | + rule_id: "O1.review_band", | |
| 201 | + rule_version: 1, | |
| 202 | + scope: null, | |
| 203 | + audience_role: "student", | |
| 204 | + course: COURSE_ID, | |
| 205 | + evidence: { | |
| 206 | + course: COURSE_ID, | |
| 207 | + course_title: "Matematik", | |
| 208 | + n_marks: 4, | |
| 209 | + average: 48.5, | |
| 210 | + class_average: 66.2, | |
| 211 | + class_sd: 14.1, | |
| 212 | + z: -1.25, | |
| 213 | + cohort_n: 24, | |
| 214 | + band: "review", | |
| 215 | + rule: "z < -0.8 (MODULLER.md §2.3 adım 4)", | |
| 216 | + }, | |
| 217 | + confidence: "exploratory", | |
| 218 | + created_at: NOW, | |
| 219 | + expires_at: NOW + WEEK, | |
| 220 | + }, | |
| 221 | + ], | |
| 222 | + segments: [ | |
| 223 | + { | |
| 224 | + dimension: "dikkat_tuzagi", | |
| 225 | + label: "var", | |
| 226 | + n_answers: 20, | |
| 227 | + n_correct: 9, | |
| 228 | + accuracy: 0.45, | |
| 229 | + overall_n_answers: 100, | |
| 230 | + overall_accuracy: 0.6, | |
| 231 | + contrast: -0.15, | |
| 232 | + confidence: "exploratory", | |
| 233 | + computed_at: NOW, | |
| 234 | + }, | |
| 235 | + ], | |
| 236 | +}; | |
| 237 | + | |
| 238 | +const renderDrawer = (props: { mode?: "full" | "cards" } = {}) => | |
| 239 | + render(() => ( | |
| 240 | + <PreferencesProvider> | |
| 241 | + <InsightDetail insight={insight} mode={props.mode} /> | |
| 242 | + </PreferencesProvider> | |
| 243 | + )); | |
| 244 | + | |
| 245 | +describe("InsightDetail", () => { | |
| 246 | + afterEach(cleanup); | |
| 247 | + | |
| 248 | + it("labels every module member in Turkish instead of echoing payload keys", () => { | |
| 249 | + renderDrawer(); | |
| 250 | + const human = screen.getByTestId("insight-human").textContent ?? ""; | |
| 251 | + | |
| 252 | + for (const label of [ | |
| 253 | + "Devam oranı", | |
| 254 | + "Şube ortancasına göre fark", | |
| 255 | + "Ağırlıklı ortalama", | |
| 256 | + "En yüksek", | |
| 257 | + "Not sayısı", | |
| 258 | + "Şubedeki konumu", | |
| 259 | + "Yeterli veri yok", | |
| 260 | + ]) { | |
| 261 | + expect(human, `label ${label}`).toContain(label); | |
| 262 | + } | |
| 263 | + expect(human).toContain("Dersler arası denge"); | |
| 264 | + expect(human).toContain("Yaklaşan teslimler"); | |
| 265 | + expect(human).toContain("Matematik"); | |
| 266 | + expect(human).toContain("Türev alıştırmaları"); | |
| 267 | + expect(human).toContain("Öncelikli"); | |
| 268 | + | |
| 269 | + for (const rawKey of [ | |
| 270 | + "Class es", | |
| 271 | + "Course ses", | |
| 272 | + "Trend Available", | |
| 273 | + "Weekday Pattern", | |
| 274 | + "Overall - Absent", | |
| 275 | + "class_average", | |
| 276 | + "cohort_n", | |
| 277 | + "rate_suppressed", | |
| 278 | + "n_marks", | |
| 279 | + "within_student_contrast", | |
| 280 | + ]) { | |
| 281 | + expect(human, `raw key ${rawKey}`).not.toContain(rawKey); | |
| 282 | + } | |
| 283 | + }); | |
| 284 | + | |
| 285 | + it("shows courses, classes and homework by name, never by id", () => { | |
| 286 | + renderDrawer(); | |
| 287 | + const human = screen.getByTestId("insight-human").textContent ?? ""; | |
| 288 | + | |
| 289 | + for (const id of [STUDENT_ID, COURSE_ID, CLASS_ID, HOMEWORK_ID]) { | |
| 290 | + expect(human, `uuid ${id}`).not.toContain(id); | |
| 291 | + } | |
| 292 | + // The class list has no titles in the payload, so it is reported as a | |
| 293 | + // count instead of a uuid column. | |
| 294 | + expect(human).toContain("Kayıtlı şube sayısı"); | |
| 295 | + }); | |
| 296 | + | |
| 297 | + it("renders the service's honest reasons as sentences", () => { | |
| 298 | + renderDrawer(); | |
| 299 | + const human = screen.getByTestId("insight-human").textContent ?? ""; | |
| 300 | + | |
| 301 | + expect(human).toContain("eğilim için en az 6 not gerekir"); | |
| 302 | + expect(human).toContain("Veri toplanıyor (2/3)"); | |
| 303 | + expect(human).toContain("kontrast için bantlanmış en az 3 ders gerekir"); | |
| 304 | + expect(human).toContain("Isı haritası için 3/5 oturum"); | |
| 305 | + expect(human).toContain("Erteleme profili submitted_at gerektirir"); | |
| 306 | + expect(human).toContain("Dönem kümülatifi; son 30 gün penceresi yok."); | |
| 307 | + // A rate-space difference is percentage points: -0.16 is "-16 puan", not | |
| 308 | + // "-0,2 puan" — the raw number must never leak through unconverted. | |
| 309 | + expect(human).toContain("-16 puan"); | |
| 310 | + expect(human).toContain("-4 puan"); | |
| 311 | + }); | |
| 312 | + | |
| 313 | + it("keeps the whole raw payload in the collapsed technical disclosure", () => { | |
| 314 | + renderDrawer(); | |
| 315 | + const disclosure = screen.getByTestId("insight-technical") as HTMLDetailsElement; | |
| 316 | + | |
| 317 | + expect(disclosure.open).toBe(false); | |
| 318 | + expect(disclosure.textContent).toContain(STUDENT_ID); | |
| 319 | + expect(disclosure.textContent).toContain(COURSE_ID); | |
| 320 | + expect(disclosure.textContent).toContain(CLASS_ID); | |
| 321 | + expect(disclosure.textContent).toContain(HOMEWORK_ID); | |
| 322 | + for (const rawKey of ["class_average", "cohort_n", "within_student_contrast", "rate_suppressed"]) { | |
| 323 | + expect(disclosure.textContent, `raw key ${rawKey}`).toContain(rawKey); | |
| 324 | + } | |
| 325 | + | |
| 326 | + fireEvent.click(disclosure.querySelector("summary")!); | |
| 327 | + expect(disclosure.open).toBe(true); | |
| 328 | + }); | |
| 329 | + | |
| 330 | + it("keeps the cards-only mode free of the drawer's full-view sections", () => { | |
| 331 | + renderDrawer({ mode: "cards" }); | |
| 332 | + const human = screen.getByTestId("insight-human").textContent ?? ""; | |
| 333 | + | |
| 334 | + expect(human).toContain("Ders konumu"); | |
| 335 | + expect(screen.queryByTestId("insight-technical")).toBeNull(); | |
| 336 | + expect(human).not.toContain("Devam oranı"); | |
| 337 | + expect(human).not.toContain(STUDENT_ID); | |
| 338 | + }); | |
| 339 | +}); |
src/components/insights/insight-detail.tsxmodified+242 -174
| @@ -1,11 +1,17 @@ | ||
| 1 | 1 | import { For, Show } from "solid-js"; |
| 2 | 2 | import type { InsightConfidence, StudentInsight } from "@/api/client"; |
| 3 | -import { InsightDataList } from "@/components/insights/insight-data-list"; | |
| 3 | +import { | |
| 4 | + InsightEvidenceView, | |
| 5 | + InsightModuleView, | |
| 6 | + InsightTechnicalDetails, | |
| 7 | +} from "@/components/insights/insight-module-views"; | |
| 4 | 8 | import { Badge } from "@/components/ui/badge"; |
| 5 | 9 | import { EmptyInline } from "@/components/ui/empty-inline"; |
| 6 | 10 | import { IconAlert, IconChart, IconSparkles } from "@/components/ui/icons"; |
| 11 | +import { detailText, type InsightDetailKey } from "@/i18n/insights-detail"; | |
| 7 | 12 | import { cn } from "@/lib/cn"; |
| 8 | 13 | import { formatDateTime } from "@/lib/format"; |
| 14 | +import { isRecord } from "@/lib/is-record"; | |
| 9 | 15 | import { usePreferences } from "@/stores/preferences-context"; |
| 10 | 16 | |
| 11 | 17 | const percent = (value: number) => `${Math.round(value * 100)}%`; |
| @@ -17,6 +23,27 @@ function confidenceVariant(confidence: InsightConfidence) { | ||
| 17 | 23 | return "secondary" as const; |
| 18 | 24 | } |
| 19 | 25 | |
| 26 | +/** Attention triggers and segment dimensions arrive as machine names; a name | |
| 27 | + * with no label here is left out of the human view rather than shown raw. */ | |
| 28 | +const TRIGGER_KEYS: Record<string, InsightDetailKey> = { | |
| 29 | + attendance: "trigger.attendance", | |
| 30 | + homework: "trigger.homework", | |
| 31 | + mark_trend: "trigger.mark_trend", | |
| 32 | +}; | |
| 33 | +const DIMENSION_KEYS: Record<string, InsightDetailKey> = { | |
| 34 | + bilissel_talep: "segments.dimension.bilissel_talep", | |
| 35 | + dikkat_tuzagi: "segments.dimension.dikkat_tuzagi", | |
| 36 | + okuma_yuku: "segments.dimension.okuma_yuku", | |
| 37 | +}; | |
| 38 | +const PRODUCT_KEYS: Record<string, InsightDetailKey> = { | |
| 39 | + O1: "product.O1", | |
| 40 | + O2: "product.O2", | |
| 41 | + O3: "product.O3", | |
| 42 | + O4: "product.O4", | |
| 43 | + T3: "product.T3", | |
| 44 | + T4: "product.T4", | |
| 45 | +}; | |
| 46 | + | |
| 20 | 47 | export function InsightDetail(props: { insight: StudentInsight; mode?: "full" | "cards" }) { |
| 21 | 48 | const prefs = usePreferences(); |
| 22 | 49 | const tx = (key: string, vars?: Record<string, string | number>) => prefs.t(key as never, vars); |
| @@ -24,6 +51,35 @@ export function InsightDetail(props: { insight: StudentInsight; mode?: "full" | | ||
| 24 | 51 | confidence === "none" || confidence === "exploratory" || confidence === "stable" |
| 25 | 52 | ? tx(`insights.confidence.${confidence}`) |
| 26 | 53 | : confidence; |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Course ids are the payload's own keys; a school manager reads titles. | |
| 57 | + * The marks module is the one place a title is carried, and it keys the same | |
| 58 | + * ids the attendance module and the cards use, so it answers for all of | |
| 59 | + * them. `undefined` means "no title known" — never the id itself. | |
| 60 | + */ | |
| 61 | + const courseTitle = (id?: string | null): string | null => { | |
| 62 | + if (!id) return null; | |
| 63 | + const marks: unknown = props.insight.summary?.marks; | |
| 64 | + const allCourses = isRecord(marks) ? marks.courses : undefined; | |
| 65 | + const entry = isRecord(allCourses) ? allCourses[id] : undefined; | |
| 66 | + const title = isRecord(entry) ? entry.course_title : undefined; | |
| 67 | + return typeof title === "string" && title.length > 0 ? title : null; | |
| 68 | + }; | |
| 69 | + const courseLine = (id?: string | null) => courseTitle(id) ?? (id ? tx("insights.schoolWide") : null); | |
| 70 | + const dimensionLabel = (dimension: string | null | undefined) => { | |
| 71 | + const key = dimension ? DIMENSION_KEYS[dimension] : undefined; | |
| 72 | + return key ? detailText(key) : null; | |
| 73 | + }; | |
| 74 | + /** A card scope is `<dimension>=<label>`; the label half is already Turkish. */ | |
| 75 | + const scopeText = (scope?: string | null) => { | |
| 76 | + if (!scope) return null; | |
| 77 | + const [dimension, label] = scope.split("="); | |
| 78 | + const name = dimensionLabel(dimension); | |
| 79 | + if (!name) return null; | |
| 80 | + return label ? `${name}: ${label}` : name; | |
| 81 | + }; | |
| 82 | + | |
| 27 | 83 | const summarySections = () => { |
| 28 | 84 | const summary = props.insight.summary; |
| 29 | 85 | if (!summary) return []; |
| @@ -36,192 +92,204 @@ export function InsightDetail(props: { insight: StudentInsight; mode?: "full" | | ||
| 36 | 92 | }; |
| 37 | 93 | |
| 38 | 94 | return ( |
| 39 | - <div class="space-y-5"> | |
| 40 | - <Show when={props.mode !== "cards"}> | |
| 41 | - <section class="space-y-3"> | |
| 42 | - <div class="flex items-center justify-between gap-3"> | |
| 95 | + <div class="@container space-y-5"> | |
| 96 | + <div class="space-y-5" data-testid="insight-human"> | |
| 97 | + <Show when={props.mode !== "cards"}> | |
| 98 | + <section class="space-y-3"> | |
| 99 | + <div class="flex items-center justify-between gap-3"> | |
| 100 | + <div class="flex items-center gap-2"> | |
| 101 | + <IconSparkles class="h-4 w-4 text-primary" /> | |
| 102 | + <h3 class="text-sm font-semibold text-text-strong">{tx("insights.summary")}</h3> | |
| 103 | + </div> | |
| 104 | + <Show when={props.insight.summary}> | |
| 105 | + {(summary) => ( | |
| 106 | + <Badge variant={confidenceVariant(summary().confidence)} class="rounded-full"> | |
| 107 | + {confidenceLabel(summary().confidence)} | |
| 108 | + </Badge> | |
| 109 | + )} | |
| 110 | + </Show> | |
| 111 | + </div> | |
| 112 | + | |
| 113 | + <Show | |
| 114 | + when={props.insight.summary} | |
| 115 | + fallback={ | |
| 116 | + <EmptyInline | |
| 117 | + illustration="charts" | |
| 118 | + size="md" | |
| 119 | + title={tx("insights.noSummary")} | |
| 120 | + hint={tx("insights.noSummaryHint")} | |
| 121 | + /> | |
| 122 | + } | |
| 123 | + > | |
| 124 | + {(summary) => ( | |
| 125 | + <> | |
| 126 | + <div class="grid gap-2 @md:grid-cols-2"> | |
| 127 | + <div class="detail-metric-card"> | |
| 128 | + <p class="text-xs text-muted-foreground">{tx("insights.computedAt")}</p> | |
| 129 | + <p class="mono mt-1 text-sm font-medium">{formatDateTime(summary().computed_at, prefs.locale())}</p> | |
| 130 | + </div> | |
| 131 | + <div class="detail-metric-card"> | |
| 132 | + <p class="text-xs text-muted-foreground">{tx("insights.retainUntil")}</p> | |
| 133 | + <p class="mono mt-1 text-sm font-medium">{formatDateTime(summary().retain_until, prefs.locale())}</p> | |
| 134 | + </div> | |
| 135 | + </div> | |
| 136 | + <div class="space-y-3"> | |
| 137 | + <For each={summarySections()}> | |
| 138 | + {(section) => ( | |
| 139 | + <article class="space-y-3 rounded-xl border border-border-line bg-surface-base p-4"> | |
| 140 | + <h4 class="text-sm font-semibold text-text-strong">{section.label}</h4> | |
| 141 | + <Show | |
| 142 | + when={section.value != null} | |
| 143 | + fallback={<p class="text-xs text-muted-foreground">{tx("insights.sectionNotComputed")}</p>} | |
| 144 | + > | |
| 145 | + <InsightModuleView module={section.id} value={section.value} courseTitle={courseTitle} /> | |
| 146 | + </Show> | |
| 147 | + </article> | |
| 148 | + )} | |
| 149 | + </For> | |
| 150 | + </div> | |
| 151 | + </> | |
| 152 | + )} | |
| 153 | + </Show> | |
| 154 | + </section> | |
| 155 | + </Show> | |
| 156 | + | |
| 157 | + <Show when={props.mode !== "cards"}> | |
| 158 | + <section class="space-y-3 border-t border-border-hairline pt-5"> | |
| 159 | + <div class="flex items-center gap-2"> | |
| 160 | + <IconAlert class="h-4 w-4 text-warning" /> | |
| 161 | + <h3 class="text-sm font-semibold text-text-strong">{tx("insights.attention")}</h3> | |
| 162 | + <Badge variant="warning" class="rounded-full">{props.insight.attention.length}</Badge> | |
| 163 | + </div> | |
| 164 | + <Show | |
| 165 | + when={props.insight.attention.length > 0} | |
| 166 | + fallback={<EmptyInline title={tx("insights.noAttention")} illustration="empty" />} | |
| 167 | + > | |
| 168 | + <div class="space-y-3"> | |
| 169 | + <For each={props.insight.attention}> | |
| 170 | + {(item) => ( | |
| 171 | + <article class="space-y-3 rounded-xl border border-warning/25 bg-warning/5 p-4"> | |
| 172 | + <div class="flex flex-wrap items-start justify-between gap-2"> | |
| 173 | + <div class="min-w-0"> | |
| 174 | + <p class="text-sm font-medium leading-5 text-text-strong">{item.fact}</p> | |
| 175 | + <p class="mt-1 text-xs text-muted-foreground"> | |
| 176 | + {courseLine(item.course)} · {formatDateTime(item.window_from, prefs.locale())} – {formatDateTime(item.window_to, prefs.locale())} | |
| 177 | + </p> | |
| 178 | + </div> | |
| 179 | + <Show when={TRIGGER_KEYS[item.trigger]}> | |
| 180 | + {(key) => <Badge variant="outline" class="rounded-full">{detailText(key())}</Badge>} | |
| 181 | + </Show> | |
| 182 | + </div> | |
| 183 | + <InsightEvidenceView value={item.evidence} /> | |
| 184 | + </article> | |
| 185 | + )} | |
| 186 | + </For> | |
| 187 | + </div> | |
| 188 | + </Show> | |
| 189 | + </section> | |
| 190 | + </Show> | |
| 191 | + | |
| 192 | + <section class={cn("space-y-3", props.mode !== "cards" && "border-t border-border-hairline pt-5")}> | |
| 43 | 193 | <div class="flex items-center gap-2"> |
| 44 | 194 | <IconSparkles class="h-4 w-4 text-primary" /> |
| 45 | - <h3 class="text-sm font-semibold text-text-strong">{tx("insights.summary")}</h3> | |
| 195 | + <h3 class="text-sm font-semibold text-text-strong">{tx("insights.recommendations")}</h3> | |
| 196 | + <Badge variant="secondary" class="rounded-full">{props.insight.cards.length}</Badge> | |
| 46 | 197 | </div> |
| 47 | - <Show when={props.insight.summary}> | |
| 48 | - {(summary) => ( | |
| 49 | - <Badge variant={confidenceVariant(summary().confidence)} class="rounded-full"> | |
| 50 | - {confidenceLabel(summary().confidence)} | |
| 51 | - </Badge> | |
| 52 | - )} | |
| 198 | + <Show | |
| 199 | + when={props.insight.cards.length > 0} | |
| 200 | + fallback={<EmptyInline title={tx("insights.noRecommendations")} illustration="empty" />} | |
| 201 | + > | |
| 202 | + <div class="space-y-3"> | |
| 203 | + <For each={props.insight.cards}> | |
| 204 | + {(card) => { | |
| 205 | + const context = () => [courseTitle(card.course), scopeText(card.scope)].filter(Boolean).join(" · "); | |
| 206 | + return ( | |
| 207 | + <article class="space-y-3 rounded-xl border border-primary/20 bg-primary/5 p-4"> | |
| 208 | + <div class="flex flex-wrap items-center justify-between gap-2"> | |
| 209 | + <Badge class="rounded-full"> | |
| 210 | + {PRODUCT_KEYS[card.product] ? detailText(PRODUCT_KEYS[card.product]) : detailText("product.unknown")} | |
| 211 | + </Badge> | |
| 212 | + <Badge variant={confidenceVariant(card.confidence)} class="rounded-full"> | |
| 213 | + {confidenceLabel(card.confidence)} | |
| 214 | + </Badge> | |
| 215 | + </div> | |
| 216 | + <Show when={context().length > 0}> | |
| 217 | + <p class="text-xs text-muted-foreground">{context()}</p> | |
| 218 | + </Show> | |
| 219 | + <InsightEvidenceView value={card.evidence} /> | |
| 220 | + <p class="text-[11px] text-muted-foreground"> | |
| 221 | + {tx("insights.expiresAt")}: {formatDateTime(card.expires_at, prefs.locale())} | |
| 222 | + </p> | |
| 223 | + </article> | |
| 224 | + ); | |
| 225 | + }} | |
| 226 | + </For> | |
| 227 | + </div> | |
| 53 | 228 | </Show> |
| 54 | - </div> | |
| 229 | + </section> | |
| 55 | 230 | |
| 56 | - <Show | |
| 57 | - when={props.insight.summary} | |
| 58 | - fallback={ | |
| 59 | - <EmptyInline | |
| 60 | - illustration="charts" | |
| 61 | - size="md" | |
| 62 | - title={tx("insights.noSummary")} | |
| 63 | - hint={tx("insights.noSummaryHint")} | |
| 64 | - /> | |
| 65 | - } | |
| 66 | - > | |
| 67 | - {(summary) => ( | |
| 68 | - <> | |
| 69 | - <div class="grid gap-2 sm:grid-cols-2"> | |
| 70 | - <div class="detail-metric-card"> | |
| 71 | - <p class="text-xs text-muted-foreground">{tx("insights.computedAt")}</p> | |
| 72 | - <p class="mono mt-1 text-sm font-medium">{formatDateTime(summary().computed_at, prefs.locale())}</p> | |
| 73 | - </div> | |
| 74 | - <div class="detail-metric-card"> | |
| 75 | - <p class="text-xs text-muted-foreground">{tx("insights.retainUntil")}</p> | |
| 76 | - <p class="mono mt-1 text-sm font-medium">{formatDateTime(summary().retain_until, prefs.locale())}</p> | |
| 77 | - </div> | |
| 78 | - </div> | |
| 79 | - <div class="grid gap-3 sm:grid-cols-2"> | |
| 80 | - <For each={summarySections()}> | |
| 81 | - {(section) => ( | |
| 231 | + <Show when={props.mode !== "cards"}> | |
| 232 | + <section class="space-y-3 border-t border-border-hairline pt-5"> | |
| 233 | + <div class="flex items-center gap-2"> | |
| 234 | + <IconChart class="h-4 w-4 text-info" /> | |
| 235 | + <h3 class="text-sm font-semibold text-text-strong">{tx("insights.segments")}</h3> | |
| 236 | + <Badge variant="info" class="rounded-full">{props.insight.segments.length}</Badge> | |
| 237 | + </div> | |
| 238 | + <Show | |
| 239 | + when={props.insight.segments.length > 0} | |
| 240 | + fallback={<EmptyInline title={tx("insights.noSegments")} illustration="charts" />} | |
| 241 | + > | |
| 242 | + <div class="space-y-3"> | |
| 243 | + <For each={props.insight.segments}> | |
| 244 | + {(segment) => ( | |
| 82 | 245 | <article class="space-y-3 rounded-xl border border-border-line bg-surface-base p-4"> |
| 83 | - <h4 class="text-sm font-semibold text-text-strong">{section.label}</h4> | |
| 84 | - <Show | |
| 85 | - when={section.value != null} | |
| 86 | - fallback={<p class="text-xs text-muted-foreground">{tx("insights.sectionNotComputed")}</p>} | |
| 87 | - > | |
| 88 | - <InsightDataList value={section.value} emptyLabel={tx("insights.noEvidence")} /> | |
| 89 | - </Show> | |
| 246 | + <div class="flex flex-wrap items-center justify-between gap-2"> | |
| 247 | + <div> | |
| 248 | + <p class="text-sm font-semibold text-text-strong">{segment.label}</p> | |
| 249 | + <Show when={dimensionLabel(segment.dimension)}> | |
| 250 | + {(label) => <p class="text-xs text-muted-foreground">{label()}</p>} | |
| 251 | + </Show> | |
| 252 | + </div> | |
| 253 | + <Badge variant={confidenceVariant(segment.confidence)} class="rounded-full"> | |
| 254 | + {confidenceLabel(segment.confidence)} | |
| 255 | + </Badge> | |
| 256 | + </div> | |
| 257 | + <div class="space-y-1.5"> | |
| 258 | + <div class="flex items-center justify-between text-xs"> | |
| 259 | + <span class="text-muted-foreground">{tx("insights.accuracy")}</span> | |
| 260 | + <span class="font-mono font-semibold">{percent(segment.accuracy)}</span> | |
| 261 | + </div> | |
| 262 | + <div class="h-2.5 overflow-hidden rounded-full bg-surface-fill"> | |
| 263 | + <div class="h-full rounded-full bg-info" style={{ width: `${clampPercent(segment.accuracy)}%` }} /> | |
| 264 | + </div> | |
| 265 | + </div> | |
| 266 | + <div class="grid grid-cols-3 gap-2 text-center"> | |
| 267 | + <div class="rounded-lg bg-surface-overlay px-2 py-2"> | |
| 268 | + <p class="font-mono text-sm font-semibold">{segment.n_correct}/{segment.n_answers}</p> | |
| 269 | + <p class="text-[10px] text-muted-foreground">{tx("insights.answers")}</p> | |
| 270 | + </div> | |
| 271 | + <div class="rounded-lg bg-surface-overlay px-2 py-2"> | |
| 272 | + <p class="font-mono text-sm font-semibold">{percent(segment.overall_accuracy)}</p> | |
| 273 | + <p class="text-[10px] text-muted-foreground">{tx("insights.overall")}</p> | |
| 274 | + </div> | |
| 275 | + <div class="rounded-lg bg-surface-overlay px-2 py-2"> | |
| 276 | + <p class={cn("font-mono text-sm font-semibold", segment.contrast < 0 ? "text-destructive" : "text-success")}> | |
| 277 | + {segment.contrast > 0 ? "+" : ""}{percent(segment.contrast)} | |
| 278 | + </p> | |
| 279 | + <p class="text-[10px] text-muted-foreground">{tx("insights.contrast")}</p> | |
| 280 | + </div> | |
| 281 | + </div> | |
| 90 | 282 | </article> |
| 91 | 283 | )} |
| 92 | 284 | </For> |
| 93 | 285 | </div> |
| 94 | - </> | |
| 95 | - )} | |
| 96 | - </Show> | |
| 97 | - </section> | |
| 98 | - </Show> | |
| 99 | - | |
| 100 | - <Show when={props.mode !== "cards"}> | |
| 101 | - <section class="space-y-3 border-t border-border-hairline pt-5"> | |
| 102 | - <div class="flex items-center gap-2"> | |
| 103 | - <IconAlert class="h-4 w-4 text-warning" /> | |
| 104 | - <h3 class="text-sm font-semibold text-text-strong">{tx("insights.attention")}</h3> | |
| 105 | - <Badge variant="warning" class="rounded-full">{props.insight.attention.length}</Badge> | |
| 106 | - </div> | |
| 107 | - <Show | |
| 108 | - when={props.insight.attention.length > 0} | |
| 109 | - fallback={<EmptyInline title={tx("insights.noAttention")} illustration="empty" />} | |
| 110 | - > | |
| 111 | - <div class="space-y-3"> | |
| 112 | - <For each={props.insight.attention}> | |
| 113 | - {(item) => ( | |
| 114 | - <article class="space-y-3 rounded-xl border border-warning/25 bg-warning/5 p-4"> | |
| 115 | - <div class="flex flex-wrap items-start justify-between gap-2"> | |
| 116 | - <div class="min-w-0"> | |
| 117 | - <p class="text-sm font-medium leading-5 text-text-strong">{item.fact}</p> | |
| 118 | - <p class="mt-1 text-xs text-muted-foreground"> | |
| 119 | - {item.course || tx("insights.schoolWide")} · {formatDateTime(item.window_from, prefs.locale())} – {formatDateTime(item.window_to, prefs.locale())} | |
| 120 | - </p> | |
| 121 | - </div> | |
| 122 | - <Badge variant="outline" class="rounded-full">{item.trigger}</Badge> | |
| 123 | - </div> | |
| 124 | - <InsightDataList value={item.evidence} emptyLabel={tx("insights.noEvidence")} /> | |
| 125 | - </article> | |
| 126 | - )} | |
| 127 | - </For> | |
| 128 | - </div> | |
| 129 | - </Show> | |
| 130 | - </section> | |
| 131 | - </Show> | |
| 132 | - | |
| 133 | - <section class={cn("space-y-3", props.mode !== "cards" && "border-t border-border-hairline pt-5")}> | |
| 134 | - <div class="flex items-center gap-2"> | |
| 135 | - <IconSparkles class="h-4 w-4 text-primary" /> | |
| 136 | - <h3 class="text-sm font-semibold text-text-strong">{tx("insights.recommendations")}</h3> | |
| 137 | - <Badge variant="secondary" class="rounded-full">{props.insight.cards.length}</Badge> | |
| 138 | - </div> | |
| 139 | - <Show | |
| 140 | - when={props.insight.cards.length > 0} | |
| 141 | - fallback={<EmptyInline title={tx("insights.noRecommendations")} illustration="empty" />} | |
| 142 | - > | |
| 143 | - <div class="space-y-3"> | |
| 144 | - <For each={props.insight.cards}> | |
| 145 | - {(card) => ( | |
| 146 | - <article class="space-y-3 rounded-xl border border-primary/20 bg-primary/5 p-4"> | |
| 147 | - <div class="flex flex-wrap items-center justify-between gap-2"> | |
| 148 | - <div class="flex items-center gap-2"> | |
| 149 | - <Badge class="rounded-full">{card.product}</Badge> | |
| 150 | - <span class="text-xs text-muted-foreground">{card.rule_id} · v{card.rule_version}</span> | |
| 151 | - </div> | |
| 152 | - <Badge variant={confidenceVariant(card.confidence)} class="rounded-full"> | |
| 153 | - {confidenceLabel(card.confidence)} | |
| 154 | - </Badge> | |
| 155 | - </div> | |
| 156 | - <Show when={card.course || card.scope}> | |
| 157 | - <p class="text-xs text-muted-foreground">{[card.course, card.scope].filter(Boolean).join(" · ")}</p> | |
| 158 | - </Show> | |
| 159 | - <InsightDataList value={card.evidence} emptyLabel={tx("insights.noEvidence")} /> | |
| 160 | - <p class="text-[11px] text-muted-foreground"> | |
| 161 | - {tx("insights.expiresAt")}: {formatDateTime(card.expires_at, prefs.locale())} | |
| 162 | - </p> | |
| 163 | - </article> | |
| 164 | - )} | |
| 165 | - </For> | |
| 166 | - </div> | |
| 286 | + </Show> | |
| 287 | + </section> | |
| 167 | 288 | </Show> |
| 168 | - </section> | |
| 289 | + </div> | |
| 169 | 290 | |
| 170 | 291 | <Show when={props.mode !== "cards"}> |
| 171 | - <section class="space-y-3 border-t border-border-hairline pt-5"> | |
| 172 | - <div class="flex items-center gap-2"> | |
| 173 | - <IconChart class="h-4 w-4 text-info" /> | |
| 174 | - <h3 class="text-sm font-semibold text-text-strong">{tx("insights.segments")}</h3> | |
| 175 | - <Badge variant="info" class="rounded-full">{props.insight.segments.length}</Badge> | |
| 176 | - </div> | |
| 177 | - <Show | |
| 178 | - when={props.insight.segments.length > 0} | |
| 179 | - fallback={<EmptyInline title={tx("insights.noSegments")} illustration="charts" />} | |
| 180 | - > | |
| 181 | - <div class="space-y-3"> | |
| 182 | - <For each={props.insight.segments}> | |
| 183 | - {(segment) => ( | |
| 184 | - <article class="space-y-3 rounded-xl border border-border-line bg-surface-base p-4"> | |
| 185 | - <div class="flex flex-wrap items-center justify-between gap-2"> | |
| 186 | - <div> | |
| 187 | - <p class="text-sm font-semibold text-text-strong">{segment.label}</p> | |
| 188 | - <p class="text-xs text-muted-foreground">{segment.dimension}</p> | |
| 189 | - </div> | |
| 190 | - <Badge variant={confidenceVariant(segment.confidence)} class="rounded-full"> | |
| 191 | - {confidenceLabel(segment.confidence)} | |
| 192 | - </Badge> | |
| 193 | - </div> | |
| 194 | - <div class="space-y-1.5"> | |
| 195 | - <div class="flex items-center justify-between text-xs"> | |
| 196 | - <span class="text-muted-foreground">{tx("insights.accuracy")}</span> | |
| 197 | - <span class="font-mono font-semibold">{percent(segment.accuracy)}</span> | |
| 198 | - </div> | |
| 199 | - <div class="h-2.5 overflow-hidden rounded-full bg-surface-fill"> | |
| 200 | - <div class="h-full rounded-full bg-info" style={{ width: `${clampPercent(segment.accuracy)}%` }} /> | |
| 201 | - </div> | |
| 202 | - </div> | |
| 203 | - <div class="grid grid-cols-3 gap-2 text-center"> | |
| 204 | - <div class="rounded-lg bg-surface-overlay px-2 py-2"> | |
| 205 | - <p class="font-mono text-sm font-semibold">{segment.n_correct}/{segment.n_answers}</p> | |
| 206 | - <p class="text-[10px] text-muted-foreground">{tx("insights.answers")}</p> | |
| 207 | - </div> | |
| 208 | - <div class="rounded-lg bg-surface-overlay px-2 py-2"> | |
| 209 | - <p class="font-mono text-sm font-semibold">{percent(segment.overall_accuracy)}</p> | |
| 210 | - <p class="text-[10px] text-muted-foreground">{tx("insights.overall")}</p> | |
| 211 | - </div> | |
| 212 | - <div class="rounded-lg bg-surface-overlay px-2 py-2"> | |
| 213 | - <p class={cn("font-mono text-sm font-semibold", segment.contrast < 0 ? "text-destructive" : "text-success")}> | |
| 214 | - {segment.contrast > 0 ? "+" : ""}{percent(segment.contrast)} | |
| 215 | - </p> | |
| 216 | - <p class="text-[10px] text-muted-foreground">{tx("insights.contrast")}</p> | |
| 217 | - </div> | |
| 218 | - </div> | |
| 219 | - </article> | |
| 220 | - )} | |
| 221 | - </For> | |
| 222 | - </div> | |
| 223 | - </Show> | |
| 224 | - </section> | |
| 292 | + <InsightTechnicalDetails value={props.insight} /> | |
| 225 | 293 | </Show> |
| 226 | 294 | </div> |
| 227 | 295 | ); |
src/components/insights/insight-module-views.tsxadded+781 -0
| @@ -0,0 +1,781 @@ | ||
| 1 | +import { For, Show, type JSX } from "solid-js"; | |
| 2 | +import { Badge } from "@/components/ui/badge"; | |
| 3 | +import { detailText, type InsightDetailKey } from "@/i18n/insights-detail"; | |
| 4 | +import type { Locale } from "@/i18n/messages"; | |
| 5 | +import { cn } from "@/lib/cn"; | |
| 6 | +import { formatDateTime } from "@/lib/format"; | |
| 7 | +import { isRecord, type UnknownRecord } from "@/lib/is-record"; | |
| 8 | +import { usePreferences } from "@/stores/preferences-context"; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Human-readable renderers for one ZEKA insight module. | |
| 12 | + * | |
| 13 | + * The payload the drawer receives is ZEKA's own shape, stored and served | |
| 14 | + * unread (`student_profile()` in the service's `compute/*.py`): dicts keyed by | |
| 15 | + * course id, snake_case field names and honest Turkish `reason`/`limitation` | |
| 16 | + * sentences for everything the service could not compute. Rendering that with | |
| 17 | + * a generic key walker is what made the drawer unreadable — `Class es`, | |
| 18 | + * `Trend Available` and a raw course uuid in a 5rem column. | |
| 19 | + * | |
| 20 | + * So each module gets its own renderer: labels come from the drawer's own | |
| 21 | + * dictionary, course/class ids are resolved to titles, ratios are formatted as | |
| 22 | + * percents and milliseconds as durations, and a `reason` is rendered as the | |
| 23 | + * sentence it already is. Nothing is hidden: the caller keeps the whole payload | |
| 24 | + * in a collapsed technical disclosure underneath. | |
| 25 | + */ | |
| 26 | + | |
| 27 | +type Rec = UnknownRecord; | |
| 28 | +type CourseTitle = (id: string) => string | null; | |
| 29 | + | |
| 30 | +/** A payload member as a record: a missing or non-object member reads as an | |
| 31 | + * empty one, so every field below renders as "—" instead of throwing. */ | |
| 32 | +const obj = (value: unknown): Rec => (isRecord(value) ? value : {}); | |
| 33 | + | |
| 34 | +const str = (value: unknown): string | null => | |
| 35 | + typeof value === "string" && value.length > 0 ? value : null; | |
| 36 | +const num = (value: unknown): number | null => | |
| 37 | + typeof value === "number" && Number.isFinite(value) ? value : null; | |
| 38 | +const isUuid = (value: unknown): value is string => | |
| 39 | + typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value); | |
| 40 | + | |
| 41 | +const n1 = (value: number) => value.toLocaleString("tr-TR", { maximumFractionDigits: 1 }); | |
| 42 | +/** A nullable number as display text — the shape most payload fields arrive in. */ | |
| 43 | +const nText = (value: unknown) => { | |
| 44 | + const x = num(value); | |
| 45 | + return x === null ? null : n1(x); | |
| 46 | +}; | |
| 47 | +const pct = (value: unknown) => { | |
| 48 | + const x = num(value); | |
| 49 | + return x === null ? null : `%${Math.round(x * 100)}`; | |
| 50 | +}; | |
| 51 | +/** A signed number in percentage points, for `relative_gap`-style differences. */ | |
| 52 | +const points = (value: unknown) => { | |
| 53 | + const x = num(value); | |
| 54 | + return x === null ? null : `${x > 0 ? "+" : ""}${n1(x)} puan`; | |
| 55 | +}; | |
| 56 | +/** The same, for a difference that is itself a rate (`relative_gap`): -0.16 is | |
| 57 | + * "-16 puan", not "-0,2 puan". */ | |
| 58 | +const ratePoints = (value: unknown) => { | |
| 59 | + const x = num(value); | |
| 60 | + return x === null ? null : `${x > 0 ? "+" : ""}${n1(Math.round(x * 1000) / 10)} puan`; | |
| 61 | +}; | |
| 62 | +const zText = (value: unknown) => { | |
| 63 | + const x = num(value); | |
| 64 | + return x === null ? null : x.toLocaleString("tr-TR", { maximumFractionDigits: 2 }); | |
| 65 | +}; | |
| 66 | +const durationText = (value: unknown) => { | |
| 67 | + const ms = num(value); | |
| 68 | + if (ms === null) return null; | |
| 69 | + const minutes = Math.round(ms / 60_000); | |
| 70 | + if (minutes < 60) return `${minutes} dk`; | |
| 71 | + return `${Math.floor(minutes / 60)} sa ${minutes % 60} dk`; | |
| 72 | +}; | |
| 73 | +const hoursText = (value: unknown) => { | |
| 74 | + const hours = num(value); | |
| 75 | + return hours === null ? null : `${n1(Math.round(hours * 10) / 10)} saat`; | |
| 76 | +}; | |
| 77 | + | |
| 78 | +/** One label/value row. The value column takes the remaining width, so a long | |
| 79 | + * value wraps instead of squeezing the label into a broken column. */ | |
| 80 | +export function LabeledRow(props: { label: string; value: string | null; mono?: boolean }) { | |
| 81 | + return ( | |
| 82 | + <div class="flex items-baseline justify-between gap-3 text-xs"> | |
| 83 | + <dt class="min-w-0 text-muted-foreground">{props.label}</dt> | |
| 84 | + <dd | |
| 85 | + class={cn( | |
| 86 | + "min-w-0 text-right font-medium text-foreground", | |
| 87 | + props.mono && "font-mono", | |
| 88 | + )} | |
| 89 | + > | |
| 90 | + {props.value ?? detailText("detail.value.missing")} | |
| 91 | + </dd> | |
| 92 | + </div> | |
| 93 | + ); | |
| 94 | +} | |
| 95 | + | |
| 96 | +/** A sentence the service wrote for something it could not compute, or a | |
| 97 | + * limitation line. Never a field dump. */ | |
| 98 | +export function NoteLine(props: { label?: string; children: JSX.Element }) { | |
| 99 | + return ( | |
| 100 | + <p class="text-[11px] leading-5 text-muted-foreground"> | |
| 101 | + <Show when={props.label}> | |
| 102 | + <span class="font-medium">{props.label}: </span> | |
| 103 | + </Show> | |
| 104 | + {props.children} | |
| 105 | + </p> | |
| 106 | + ); | |
| 107 | +} | |
| 108 | + | |
| 109 | +function StatCell(props: { label: string; value: string | null }) { | |
| 110 | + return ( | |
| 111 | + <div class="rounded-lg bg-surface-overlay px-2.5 py-2 text-center"> | |
| 112 | + <p class="font-mono text-sm font-semibold text-foreground"> | |
| 113 | + {props.value ?? detailText("detail.value.missing")} | |
| 114 | + </p> | |
| 115 | + <p class="mt-0.5 text-[10px] text-muted-foreground">{props.label}</p> | |
| 116 | + </div> | |
| 117 | + ); | |
| 118 | +} | |
| 119 | + | |
| 120 | +/** One course row resolved to its title: used by the attendance list, which | |
| 121 | + * carries no title of its own — the marks module keys the same course ids. */ | |
| 122 | +function courseLabel(id: string, title: CourseTitle, index: number): string { | |
| 123 | + return title(id) ?? detailText("marks.courseFallback", { n: index + 1 }); | |
| 124 | +} | |
| 125 | + | |
| 126 | +// --------------------------------------------------------------------------- | |
| 127 | +// attendance | |
| 128 | +// --------------------------------------------------------------------------- | |
| 129 | + | |
| 130 | +function AttendanceView(props: { value: Rec; courseTitle: CourseTitle }) { | |
| 131 | + const overall = () => obj(props.value.overall); | |
| 132 | + const courses = () => Object.entries(obj(props.value.courses)); | |
| 133 | + | |
| 134 | + return ( | |
| 135 | + <div class="space-y-3"> | |
| 136 | + <div class="grid grid-cols-2 gap-2 @md:grid-cols-4"> | |
| 137 | + <StatCell label={detailText("attendance.rate")} value={pct(overall().rate)} /> | |
| 138 | + <StatCell label={detailText("attendance.present")} value={String(num(overall().present) ?? 0)} /> | |
| 139 | + <StatCell label={detailText("attendance.absent")} value={String(num(overall().absent) ?? 0)} /> | |
| 140 | + <StatCell label={detailText("attendance.late")} value={String(num(overall().late) ?? 0)} /> | |
| 141 | + </div> | |
| 142 | + <dl class="space-y-1.5"> | |
| 143 | + <LabeledRow label={detailText("attendance.excused")} value={String(num(overall().excused) ?? 0)} mono /> | |
| 144 | + <LabeledRow label={detailText("attendance.nObs")} value={String(num(overall().n_obs) ?? 0)} mono /> | |
| 145 | + <LabeledRow | |
| 146 | + label={detailText("attendance.relativeGap")} | |
| 147 | + value={ratePoints(overall().relative_gap)} | |
| 148 | + mono | |
| 149 | + /> | |
| 150 | + </dl> | |
| 151 | + <Show when={num(overall().rate) === null}> | |
| 152 | + <NoteLine>{detailText("attendance.rateSuppressed")}</NoteLine> | |
| 153 | + </Show> | |
| 154 | + | |
| 155 | + <Show | |
| 156 | + when={courses().length > 0} | |
| 157 | + fallback={<NoteLine>{detailText("attendance.coursesEmpty")}</NoteLine>} | |
| 158 | + > | |
| 159 | + <div class="max-h-80 space-y-2 overflow-y-auto pr-1"> | |
| 160 | + <For each={courses()}> | |
| 161 | + {([id, raw], index) => { | |
| 162 | + const stat = () => obj(raw); | |
| 163 | + return ( | |
| 164 | + <div class="space-y-1.5 rounded-lg border border-border-hairline bg-surface-base p-3"> | |
| 165 | + <p class="text-xs font-semibold text-text-strong"> | |
| 166 | + {courseLabel(id, props.courseTitle, index())} | |
| 167 | + </p> | |
| 168 | + <dl class="space-y-1"> | |
| 169 | + <LabeledRow label={detailText("attendance.rate")} value={pct(stat().rate)} mono /> | |
| 170 | + <Show when={num(stat().rate) === null}> | |
| 171 | + <NoteLine>{detailText("attendance.rateSuppressed")}</NoteLine> | |
| 172 | + </Show> | |
| 173 | + <LabeledRow | |
| 174 | + label={detailText("attendance.present")} | |
| 175 | + value={String(num(stat().present) ?? 0)} | |
| 176 | + mono | |
| 177 | + /> | |
| 178 | + <LabeledRow | |
| 179 | + label={detailText("attendance.absent")} | |
| 180 | + value={String(num(stat().absent) ?? 0)} | |
| 181 | + mono | |
| 182 | + /> | |
| 183 | + <LabeledRow | |
| 184 | + label={detailText("attendance.late")} | |
| 185 | + value={String(num(stat().late) ?? 0)} | |
| 186 | + mono | |
| 187 | + /> | |
| 188 | + <LabeledRow label={detailText("attendance.excused")} value={String(num(stat().excused) ?? 0)} mono /> | |
| 189 | + <LabeledRow | |
| 190 | + label={detailText("attendance.cohortMedian")} | |
| 191 | + value={pct(stat().cohort_median)} | |
| 192 | + mono | |
| 193 | + /> | |
| 194 | + <LabeledRow | |
| 195 | + label={detailText("attendance.cohortN")} | |
| 196 | + value={String(num(stat().cohort_n) ?? 0)} | |
| 197 | + mono | |
| 198 | + /> | |
| 199 | + <LabeledRow | |
| 200 | + label={detailText("attendance.relativeGap")} | |
| 201 | + value={ratePoints(stat().relative_gap)} | |
| 202 | + mono | |
| 203 | + /> | |
| 204 | + </dl> | |
| 205 | + </div> | |
| 206 | + ); | |
| 207 | + }} | |
| 208 | + </For> | |
| 209 | + </div> | |
| 210 | + </Show> | |
| 211 | + | |
| 212 | + <dl class="space-y-1.5 border-t border-border-hairline pt-3"> | |
| 213 | + <LabeledRow label={detailText("attendance.weekdayPattern")} value={null} /> | |
| 214 | + </dl> | |
| 215 | + <NoteLine label={detailText("detail.notComputed")}> | |
| 216 | + {str(props.value.weekday_pattern_reason) ?? detailText("detail.value.missing")} | |
| 217 | + </NoteLine> | |
| 218 | + <NoteLine label={detailText("attendance.trend")}> | |
| 219 | + {str(obj(props.value.trend).reason) ?? detailText("detail.value.missing")} | |
| 220 | + </NoteLine> | |
| 221 | + <Show when={str(props.value.limitation)}> | |
| 222 | + {(value) => <NoteLine label={detailText("evidence.limitation")}>{value()}</NoteLine>} | |
| 223 | + </Show> | |
| 224 | + </div> | |
| 225 | + ); | |
| 226 | +} | |
| 227 | + | |
| 228 | +// --------------------------------------------------------------------------- | |
| 229 | +// marks | |
| 230 | +// --------------------------------------------------------------------------- | |
| 231 | + | |
| 232 | +const BAND_KEYS: Record<string, InsightDetailKey> = { | |
| 233 | + review: "marks.band.review", | |
| 234 | + on_track: "marks.band.on_track", | |
| 235 | + strong: "marks.band.strong", | |
| 236 | + insufficient_data: "marks.band.insufficient_data", | |
| 237 | +}; | |
| 238 | + | |
| 239 | +function MarksCourseCard(props: { id: string; statRaw: unknown; courseTitle: CourseTitle; index: number }) { | |
| 240 | + const stat = () => obj(props.statRaw); | |
| 241 | + const placement = () => obj(stat().placement); | |
| 242 | + const trend = () => obj(stat().trend); | |
| 243 | + const band = () => str(placement().band); | |
| 244 | + const bandKey = (): InsightDetailKey => { | |
| 245 | + const value = band(); | |
| 246 | + return (value === null ? undefined : BAND_KEYS[value]) ?? "marks.band.insufficient_data"; | |
| 247 | + }; | |
| 248 | + /** A real placement is one with a band other than "not enough data". */ | |
| 249 | + const placed = () => band() !== null && band() !== "insufficient_data"; | |
| 250 | + const bandVariant = () => | |
| 251 | + band() === "review" ? ("warning" as const) : band() === "strong" ? ("success" as const) : ("secondary" as const); | |
| 252 | + | |
| 253 | + return ( | |
| 254 | + <div class="space-y-2.5 rounded-lg border border-border-hairline bg-surface-base p-3"> | |
| 255 | + <p class="text-xs font-semibold text-text-strong"> | |
| 256 | + {str(stat().course_title) ?? courseLabel(props.id, props.courseTitle, props.index)} | |
| 257 | + </p> | |
| 258 | + <div class="grid grid-cols-2 gap-2 @md:grid-cols-4"> | |
| 259 | + <StatCell label={detailText("marks.average")} value={nText(stat().average)} /> | |
| 260 | + <StatCell label={detailText("marks.max")} value={nText(stat().max)} /> | |
| 261 | + <StatCell label={detailText("marks.min")} value={nText(stat().min)} /> | |
| 262 | + <StatCell label={detailText("marks.nMarks")} value={String(num(stat().n_marks) ?? 0)} /> | |
| 263 | + </div> | |
| 264 | + <dl class="space-y-1"> | |
| 265 | + <LabeledRow label={detailText("marks.median")} value={nText(stat().median)} mono /> | |
| 266 | + <LabeledRow label={detailText("marks.mean")} value={nText(stat().mean)} mono /> | |
| 267 | + </dl> | |
| 268 | + | |
| 269 | + <dl class="space-y-1.5 border-t border-border-hairline pt-2.5"> | |
| 270 | + <div class="flex items-center justify-between gap-3"> | |
| 271 | + <dt class="text-xs text-muted-foreground">{detailText("marks.placement")}</dt> | |
| 272 | + <dd> | |
| 273 | + <Badge variant={bandVariant()} class="rounded-full">{detailText(bandKey())}</Badge> | |
| 274 | + </dd> | |
| 275 | + </div> | |
| 276 | + <Show when={!placed()}> | |
| 277 | + <div> | |
| 278 | + <Show when={str(placement().progress)}> | |
| 279 | + {(progress) => ( | |
| 280 | + <NoteLine>{detailText("marks.progress", { progress: progress() })}</NoteLine> | |
| 281 | + )} | |
| 282 | + </Show> | |
| 283 | + {/* `reason` repeats the progress line verbatim when the gate is the | |
| 284 | + mark count ("veri toplanıyor"); show the sentence only when it | |
| 285 | + says something the progress line does not. */} | |
| 286 | + <Show when={str(placement().reason)}> | |
| 287 | + {(reason) => ( | |
| 288 | + <Show when={!str(placement().progress) || !reason().startsWith("veri toplanıyor")}> | |
| 289 | + <NoteLine>{reason()}</NoteLine> | |
| 290 | + </Show> | |
| 291 | + )} | |
| 292 | + </Show> | |
| 293 | + </div> | |
| 294 | + </Show> | |
| 295 | + <Show when={placed()}> | |
| 296 | + <LabeledRow label={detailText("marks.classAverage")} value={nText(placement().class_average)} mono /> | |
| 297 | + <LabeledRow label={detailText("marks.classSd")} value={nText(placement().class_sd)} mono /> | |
| 298 | + <LabeledRow label={detailText("marks.cohortN")} value={String(num(placement().cohort_n) ?? 0)} mono /> | |
| 299 | + <LabeledRow label={detailText("marks.z")} value={zText(placement().z)} mono /> | |
| 300 | + <Show when={str(placement().reason)}> | |
| 301 | + {(reason) => <NoteLine>{reason()}</NoteLine>} | |
| 302 | + </Show> | |
| 303 | + </Show> | |
| 304 | + </dl> | |
| 305 | + | |
| 306 | + <div class="space-y-1.5 border-t border-border-hairline pt-2.5"> | |
| 307 | + <div class="flex items-center justify-between gap-3"> | |
| 308 | + <p class="text-xs text-muted-foreground">{detailText("marks.trend")}</p> | |
| 309 | + <Show when={trend().available === true}> | |
| 310 | + <div class="flex gap-1.5"> | |
| 311 | + <Show when={trend().dropped === true}> | |
| 312 | + <Badge variant="warning" class="rounded-full">{detailText("marks.dropped")}</Badge> | |
| 313 | + </Show> | |
| 314 | + <Show when={trend().rising === true}> | |
| 315 | + <Badge variant="success" class="rounded-full">{detailText("marks.rising")}</Badge> | |
| 316 | + </Show> | |
| 317 | + </div> | |
| 318 | + </Show> | |
| 319 | + </div> | |
| 320 | + <Show | |
| 321 | + when={trend().available === true} | |
| 322 | + fallback={ | |
| 323 | + <div class="space-y-1"> | |
| 324 | + <NoteLine>{detailText("marks.band.insufficient_data")}</NoteLine> | |
| 325 | + <Show when={str(trend().reason)}>{(reason) => <NoteLine>{reason()}</NoteLine>}</Show> | |
| 326 | + <Show when={num(trend().n) !== null}> | |
| 327 | + <LabeledRow label={detailText("marks.nMarks")} value={String(num(trend().n))} mono /> | |
| 328 | + </Show> | |
| 329 | + </div> | |
| 330 | + } | |
| 331 | + > | |
| 332 | + <dl class="space-y-1"> | |
| 333 | + <LabeledRow label={detailText("marks.recentMean")} value={nText(trend().recent_mean)} mono /> | |
| 334 | + <LabeledRow label={detailText("marks.previousMean")} value={nText(trend().previous_mean)} mono /> | |
| 335 | + <LabeledRow label={detailText("marks.trendDelta")} value={points(trend().delta)} mono /> | |
| 336 | + <Show when={num(trend().slope_per_30d) !== null}> | |
| 337 | + <LabeledRow | |
| 338 | + label={detailText("marks.trendSlope")} | |
| 339 | + value={`${points(trend().slope_per_30d)} / 30 gün`} | |
| 340 | + mono | |
| 341 | + /> | |
| 342 | + </Show> | |
| 343 | + </dl> | |
| 344 | + </Show> | |
| 345 | + </div> | |
| 346 | + </div> | |
| 347 | + ); | |
| 348 | +} | |
| 349 | + | |
| 350 | +function MarksView(props: { value: Rec; courseTitle: CourseTitle }) { | |
| 351 | + const courses = () => Object.entries(obj(props.value.courses)); | |
| 352 | + const contrast = () => obj(props.value.within_student_contrast); | |
| 353 | + const contrastTitle = () => | |
| 354 | + str(contrast().course_title) ?? | |
| 355 | + (str(contrast().course) ? props.courseTitle(contrast().course as string) : null); | |
| 356 | + | |
| 357 | + return ( | |
| 358 | + <div class="space-y-3"> | |
| 359 | + <dl class="space-y-1.5"> | |
| 360 | + <LabeledRow label={detailText("marks.classCount")} value={String((props.value.classes as unknown[] | undefined)?.length ?? 0)} mono /> | |
| 361 | + </dl> | |
| 362 | + <div class="max-h-[28rem] space-y-2 overflow-y-auto pr-1"> | |
| 363 | + <For each={courses()}> | |
| 364 | + {([id, stat], index) => ( | |
| 365 | + <MarksCourseCard id={id} statRaw={stat} courseTitle={props.courseTitle} index={index()} /> | |
| 366 | + )} | |
| 367 | + </For> | |
| 368 | + </div> | |
| 369 | + | |
| 370 | + <div class="space-y-1.5 border-t border-border-hairline pt-3"> | |
| 371 | + <p class="text-xs font-medium text-text-strong">{detailText("marks.contrast")}</p> | |
| 372 | + <Show | |
| 373 | + when={contrast().available === true} | |
| 374 | + fallback={ | |
| 375 | + <div class="space-y-1"> | |
| 376 | + <NoteLine>{detailText("marks.band.insufficient_data")}</NoteLine> | |
| 377 | + <Show when={str(contrast().reason)}>{(reason) => <NoteLine>{reason()}</NoteLine>}</Show> | |
| 378 | + </div> | |
| 379 | + } | |
| 380 | + > | |
| 381 | + <dl class="space-y-1"> | |
| 382 | + <LabeledRow label={detailText("marks.contrastWorst")} value={contrastTitle()} /> | |
| 383 | + <LabeledRow label={detailText("marks.contrastDelta")} value={zText(contrast().delta)} mono /> | |
| 384 | + </dl> | |
| 385 | + <Show when={contrast().flagged === true}> | |
| 386 | + <NoteLine>{detailText("marks.contrastFlagged")}</NoteLine> | |
| 387 | + </Show> | |
| 388 | + </Show> | |
| 389 | + </div> | |
| 390 | + | |
| 391 | + <Show when={str(props.value.limitation)}> | |
| 392 | + {(value) => <NoteLine label={detailText("evidence.limitation")}>{value()}</NoteLine>} | |
| 393 | + </Show> | |
| 394 | + </div> | |
| 395 | + ); | |
| 396 | +} | |
| 397 | + | |
| 398 | +// --------------------------------------------------------------------------- | |
| 399 | +// study | |
| 400 | +// --------------------------------------------------------------------------- | |
| 401 | + | |
| 402 | +function StudyWindow(props: { value: Rec }) { | |
| 403 | + return ( | |
| 404 | + <div class="grid grid-cols-2 gap-2 @md:grid-cols-4"> | |
| 405 | + <StatCell label={detailText("study.stints")} value={String(num(props.value.n_stints) ?? 0)} /> | |
| 406 | + <StatCell label={detailText("study.activeDays")} value={String(num(props.value.active_days) ?? 0)} /> | |
| 407 | + <StatCell label={detailText("study.totalFocus")} value={durationText(props.value.total_focus_ms)} /> | |
| 408 | + <StatCell label={detailText("study.medianStint")} value={durationText(props.value.median_stint_ms)} /> | |
| 409 | + </div> | |
| 410 | + ); | |
| 411 | +} | |
| 412 | + | |
| 413 | +function StudyView(props: { value: Rec }) { | |
| 414 | + const recent = () => obj(props.value.recent_28d); | |
| 415 | + const change = () => obj(props.value.change); | |
| 416 | + return ( | |
| 417 | + <div class="space-y-3"> | |
| 418 | + <p class="text-xs font-medium text-text-strong">{detailText("study.recent")}</p> | |
| 419 | + <StudyWindow value={recent()} /> | |
| 420 | + <dl class="space-y-1.5"> | |
| 421 | + <LabeledRow label={detailText("study.regularity")} value={pct(recent().regularity)} mono /> | |
| 422 | + <Show when={num(recent().regularity) === null}> | |
| 423 | + <NoteLine>{detailText("study.regularitySuppressed")}</NoteLine> | |
| 424 | + </Show> | |
| 425 | + <LabeledRow label={detailText("study.burstiness")} value={nText(recent().burstiness)} mono /> | |
| 426 | + <LabeledRow label={detailText("study.nightShare")} value={pct(recent().night_share)} mono /> | |
| 427 | + <LabeledRow label={detailText("study.nightWindow")} value={str(recent().night_window_tr)} mono /> | |
| 428 | + <LabeledRow label={detailText("study.streak")} value={String(num(props.value.streak_local) ?? 0)} mono /> | |
| 429 | + </dl> | |
| 430 | + <Show when={str(recent().burstiness_limitation)}> | |
| 431 | + {(value) => <NoteLine label={detailText("evidence.burstinessLimitation")}>{value()}</NoteLine>} | |
| 432 | + </Show> | |
| 433 | + | |
| 434 | + <div class="space-y-1.5 border-t border-border-hairline pt-3"> | |
| 435 | + <p class="text-xs font-medium text-text-strong">{detailText("study.change")}</p> | |
| 436 | + <dl class="space-y-1"> | |
| 437 | + <LabeledRow | |
| 438 | + label={detailText("study.changeActiveDays")} | |
| 439 | + value={num(change().active_days_delta) === null ? null : `${num(change().active_days_delta)! > 0 ? "+" : ""}${num(change().active_days_delta)!} gün`} | |
| 440 | + mono | |
| 441 | + /> | |
| 442 | + <LabeledRow | |
| 443 | + label={detailText("study.changeStints")} | |
| 444 | + value={num(change().stints_delta) === null ? null : `${num(change().stints_delta)! > 0 ? "+" : ""}${num(change().stints_delta)!}`} | |
| 445 | + mono | |
| 446 | + /> | |
| 447 | + <LabeledRow label={detailText("study.changeFocus")} value={durationText(change().focus_ms_delta)} mono /> | |
| 448 | + </dl> | |
| 449 | + </div> | |
| 450 | + | |
| 451 | + <div class="space-y-1.5 border-t border-border-hairline pt-3"> | |
| 452 | + <dl> | |
| 453 | + <LabeledRow label={detailText("study.preDeadline")} value={pct(props.value.pre_deadline_share)} mono /> | |
| 454 | + </dl> | |
| 455 | + <Show | |
| 456 | + when={props.value.heatmap != null} | |
| 457 | + fallback={ | |
| 458 | + <NoteLine> | |
| 459 | + {str(props.value.heatmap_progress) | |
| 460 | + ? detailText("study.heatmapProgress", { progress: str(props.value.heatmap_progress)! }) | |
| 461 | + : detailText("detail.value.missing")} | |
| 462 | + </NoteLine> | |
| 463 | + } | |
| 464 | + > | |
| 465 | + <NoteLine>{detailText("study.heatmapReady")}</NoteLine> | |
| 466 | + </Show> | |
| 467 | + <NoteLine label={detailText("study.preExam")}> | |
| 468 | + {str(props.value.pre_exam_reason) ?? detailText("detail.value.missing")} | |
| 469 | + </NoteLine> | |
| 470 | + </div> | |
| 471 | + | |
| 472 | + <Show when={str(props.value.limitation)}> | |
| 473 | + {(value) => <NoteLine label={detailText("evidence.limitation")}>{value()}</NoteLine>} | |
| 474 | + </Show> | |
| 475 | + </div> | |
| 476 | + ); | |
| 477 | +} | |
| 478 | + | |
| 479 | +// --------------------------------------------------------------------------- | |
| 480 | +// submission | |
| 481 | +// --------------------------------------------------------------------------- | |
| 482 | + | |
| 483 | +/** One tally: the counts, then the rates the service's gate let through. */ | |
| 484 | +function SubmissionTally(props: { label: string; value: Rec; showRates: boolean }) { | |
| 485 | + const v = () => props.value; | |
| 486 | + const suppressed = () => v().rates_suppressed === true; | |
| 487 | + return ( | |
| 488 | + <div class="space-y-1.5 rounded-lg border border-border-hairline bg-surface-base p-3"> | |
| 489 | + <p class="text-xs font-medium text-text-strong">{props.label}</p> | |
| 490 | + <div class="grid grid-cols-2 gap-2 @md:grid-cols-4"> | |
| 491 | + <StatCell label={detailText("submission.n")} value={String(num(v().n) ?? 0)} /> | |
| 492 | + <StatCell label={detailText("submission.submitted")} value={String(num(v().n_submitted) ?? 0)} /> | |
| 493 | + <StatCell label={detailText("submission.late")} value={String(num(v().n_late) ?? 0)} /> | |
| 494 | + <StatCell label={detailText("submission.missing")} value={String(num(v().n_missing) ?? 0)} /> | |
| 495 | + </div> | |
| 496 | + <Show when={props.showRates}> | |
| 497 | + <dl class="space-y-1"> | |
| 498 | + <LabeledRow label={detailText("submission.onTime")} value={String(num(v().n_on_time) ?? 0)} mono /> | |
| 499 | + <LabeledRow label={detailText("submission.onTimeRate")} value={pct(v().on_time_rate_by_last_touch)} mono /> | |
| 500 | + <LabeledRow label={detailText("submission.lateRate")} value={pct(v().late_rate)} mono /> | |
| 501 | + <LabeledRow label={detailText("submission.missingRate")} value={pct(v().missing_rate)} mono /> | |
| 502 | + </dl> | |
| 503 | + <Show when={suppressed()}> | |
| 504 | + <NoteLine>{detailText("submission.ratesSuppressed")}</NoteLine> | |
| 505 | + </Show> | |
| 506 | + </Show> | |
| 507 | + </div> | |
| 508 | + ); | |
| 509 | +} | |
| 510 | + | |
| 511 | +function UpcomingList(props: { items: unknown[]; locale: () => Locale }) { | |
| 512 | + return ( | |
| 513 | + <Show when={props.items.length > 0} fallback={<NoteLine>{detailText("submission.upcomingNone")}</NoteLine>}> | |
| 514 | + <div class="max-h-72 space-y-2 overflow-y-auto pr-1"> | |
| 515 | + <For each={props.items}> | |
| 516 | + {(raw) => { | |
| 517 | + const item = obj(raw); | |
| 518 | + const title = () => str(item.title) ?? detailText("submission.homework"); | |
| 519 | + return ( | |
| 520 | + <div class="space-y-1 rounded-lg border border-border-hairline bg-surface-base p-3"> | |
| 521 | + <div class="flex flex-wrap items-center justify-between gap-2"> | |
| 522 | + <p class="text-xs font-medium text-text-strong">{title()}</p> | |
| 523 | + <div class="flex gap-1.5"> | |
| 524 | + <Show when={item.high_priority === true}> | |
| 525 | + <Badge variant="warning" class="rounded-full">{detailText("submission.highPriority")}</Badge> | |
| 526 | + </Show> | |
| 527 | + <Show when={item.submitted === true}> | |
| 528 | + <Badge variant="secondary" class="rounded-full">{detailText("submission.done")}</Badge> | |
| 529 | + </Show> | |
| 530 | + </div> | |
| 531 | + </div> | |
| 532 | + <dl class="space-y-1"> | |
| 533 | + <LabeledRow | |
| 534 | + label={detailText("submission.due")} | |
| 535 | + value={num(item.due_at) === null ? null : formatDateTime(num(item.due_at)!, props.locale())} | |
| 536 | + mono | |
| 537 | + /> | |
| 538 | + <LabeledRow label={detailText("submission.hoursLeft")} value={hoursText(item.hours_left)} mono /> | |
| 539 | + </dl> | |
| 540 | + </div> | |
| 541 | + ); | |
| 542 | + }} | |
| 543 | + </For> | |
| 544 | + </div> | |
| 545 | + </Show> | |
| 546 | + ); | |
| 547 | +} | |
| 548 | + | |
| 549 | +function SubmissionView(props: { value: Rec; locale: () => Locale }) { | |
| 550 | + const procrastination = () => obj(props.value.procrastination); | |
| 551 | + const upcoming = () => (Array.isArray(props.value.upcoming) ? props.value.upcoming : []); | |
| 552 | + return ( | |
| 553 | + <div class="space-y-3"> | |
| 554 | + <SubmissionTally label={detailText("submission.overall")} value={obj(props.value.overall)} showRates /> | |
| 555 | + <div class="grid gap-2 @lg:grid-cols-2"> | |
| 556 | + <SubmissionTally label={detailText("submission.recent")} value={obj(props.value.recent_30d)} showRates /> | |
| 557 | + <SubmissionTally label={detailText("submission.previous")} value={obj(props.value.previous_30d)} showRates /> | |
| 558 | + </div> | |
| 559 | + <NoteLine>{detailText("submission.windows")}</NoteLine> | |
| 560 | + | |
| 561 | + <div class="space-y-1.5 border-t border-border-hairline pt-3"> | |
| 562 | + <p class="text-xs font-medium text-text-strong">{detailText("submission.upcoming")}</p> | |
| 563 | + <UpcomingList items={upcoming()} locale={props.locale} /> | |
| 564 | + </div> | |
| 565 | + | |
| 566 | + <div class="space-y-1.5 border-t border-border-hairline pt-3"> | |
| 567 | + <dl class="space-y-1"> | |
| 568 | + <LabeledRow | |
| 569 | + label={detailText("submission.measure")} | |
| 570 | + value={props.value.measure === "last_touch" ? detailText("submission.measureLastTouch") : str(props.value.measure)} | |
| 571 | + /> | |
| 572 | + <LabeledRow | |
| 573 | + label={detailText("submission.markedMissing")} | |
| 574 | + value={String(num(obj(props.value.overall).n_marked_missing) ?? 0)} | |
| 575 | + mono | |
| 576 | + /> | |
| 577 | + </dl> | |
| 578 | + <NoteLine label={detailText("submission.procrastination")}> | |
| 579 | + {str(procrastination().reason) ?? detailText("detail.value.missing")} | |
| 580 | + </NoteLine> | |
| 581 | + </div> | |
| 582 | + | |
| 583 | + <Show when={str(props.value.limitation)}> | |
| 584 | + {(value) => <NoteLine label={detailText("evidence.limitation")}>{value()}</NoteLine>} | |
| 585 | + </Show> | |
| 586 | + </div> | |
| 587 | + ); | |
| 588 | +} | |
| 589 | + | |
| 590 | +// --------------------------------------------------------------------------- | |
| 591 | +// entry points | |
| 592 | +// --------------------------------------------------------------------------- | |
| 593 | + | |
| 594 | +/** One module's human view. `module` is the summary member's name; an | |
| 595 | + * unrecognised payload is left to the technical disclosure rather than dumped | |
| 596 | + * as keys. */ | |
| 597 | +export function InsightModuleView(props: { module: string; value: unknown; courseTitle: CourseTitle }) { | |
| 598 | + const prefs = usePreferences(); | |
| 599 | + const value = () => obj(props.value); | |
| 600 | + return ( | |
| 601 | + <Show | |
| 602 | + when={props.module === "attendance" || props.module === "marks" || props.module === "study" || props.module === "submission"} | |
| 603 | + fallback={<NoteLine>{detailText("detail.elsewhere")}</NoteLine>} | |
| 604 | + > | |
| 605 | + <Show when={props.module === "attendance"}> | |
| 606 | + <AttendanceView value={value()} courseTitle={props.courseTitle} /> | |
| 607 | + </Show> | |
| 608 | + <Show when={props.module === "marks"}> | |
| 609 | + <MarksView value={value()} courseTitle={props.courseTitle} /> | |
| 610 | + </Show> | |
| 611 | + <Show when={props.module === "study"}> | |
| 612 | + <StudyView value={value()} /> | |
| 613 | + </Show> | |
| 614 | + <Show when={props.module === "submission"}> | |
| 615 | + <SubmissionView value={value()} locale={() => prefs.locale()} /> | |
| 616 | + </Show> | |
| 617 | + </Show> | |
| 618 | + ); | |
| 619 | +} | |
| 620 | + | |
| 621 | +// --------------------------------------------------------------------------- | |
| 622 | +// evidence (attention items, recommendation cards) | |
| 623 | +// --------------------------------------------------------------------------- | |
| 624 | + | |
| 625 | +type EvidenceKind = "rate" | "ratePoints" | "points" | "number" | "z" | "ms" | "minutes" | "hours" | "date" | "text" | "band" | "skip"; | |
| 626 | + | |
| 627 | +/** Evidence is ZEKA's loose "neden?" object, one shape per rule. A field with | |
| 628 | + * no entry here has no honest label yet, so it stays in the technical | |
| 629 | + * disclosure; the count is surfaced so nothing looks silently dropped. */ | |
| 630 | +const EVIDENCE_FIELDS: Record<string, { key: InsightDetailKey; kind: EvidenceKind }> = { | |
| 631 | + rate: { key: "evidence.rate", kind: "rate" }, | |
| 632 | + relative_gap: { key: "evidence.relativeGap", kind: "ratePoints" }, | |
| 633 | + n_obs: { key: "evidence.nObs", kind: "number" }, | |
| 634 | + n_missing_30d: { key: "evidence.nMissing30", kind: "number" }, | |
| 635 | + missing_rate_30d: { key: "evidence.missingRate30", kind: "rate" }, | |
| 636 | + cohort_missing_rate_median: { key: "evidence.cohortMissingMedian", kind: "rate" }, | |
| 637 | + on_time_rate_30d: { key: "evidence.onTimeRate30", kind: "rate" }, | |
| 638 | + on_time_rate_prev_30d: { key: "evidence.onTimeRatePrev", kind: "rate" }, | |
| 639 | + missing_rate_prev_30d: { key: "evidence.missingRatePrev", kind: "rate" }, | |
| 640 | + n_30d: { key: "evidence.n30", kind: "number" }, | |
| 641 | + n_prev_30d: { key: "evidence.nPrev30", kind: "number" }, | |
| 642 | + recent_mean: { key: "evidence.recentMean", kind: "number" }, | |
| 643 | + previous_mean: { key: "evidence.previousMean", kind: "number" }, | |
| 644 | + delta: { key: "evidence.delta", kind: "points" }, | |
| 645 | + n_marks: { key: "evidence.nMarks", kind: "number" }, | |
| 646 | + measure: { key: "evidence.measure", kind: "skip" }, | |
| 647 | + student_average: { key: "evidence.studentAverage", kind: "number" }, | |
| 648 | + class_average: { key: "evidence.classAverage", kind: "number" }, | |
| 649 | + class_sd: { key: "evidence.classSd", kind: "number" }, | |
| 650 | + z: { key: "evidence.z", kind: "z" }, | |
| 651 | + cohort_n: { key: "evidence.cohortN", kind: "number" }, | |
| 652 | + average: { key: "evidence.average", kind: "number" }, | |
| 653 | + band: { key: "evidence.band", kind: "band" }, | |
| 654 | + reading: { key: "evidence.reading", kind: "text" }, | |
| 655 | + n_stints_28: { key: "evidence.nStints28", kind: "number" }, | |
| 656 | + active_days_28: { key: "evidence.activeDays28", kind: "number" }, | |
| 657 | + regularity: { key: "evidence.regularity", kind: "rate" }, | |
| 658 | + burstiness: { key: "evidence.burstiness", kind: "number" }, | |
| 659 | + median_stint_min: { key: "evidence.medianStintMin", kind: "minutes" }, | |
| 660 | + streak_local: { key: "evidence.streakLocal", kind: "number" }, | |
| 661 | + active_days_delta: { key: "evidence.activeDaysDelta", kind: "number" }, | |
| 662 | + due_at: { key: "evidence.dueAt", kind: "date" }, | |
| 663 | + hours_left: { key: "evidence.hoursLeft", kind: "hours" }, | |
| 664 | + high_priority: { key: "evidence.highPriority", kind: "number" }, | |
| 665 | + title: { key: "evidence.title", kind: "text" }, | |
| 666 | + n_answers: { key: "evidence.nAnswers", kind: "number" }, | |
| 667 | + n_correct: { key: "evidence.nCorrect", kind: "number" }, | |
| 668 | + accuracy: { key: "evidence.accuracy", kind: "rate" }, | |
| 669 | + overall_accuracy: { key: "evidence.overallAccuracy", kind: "rate" }, | |
| 670 | + overall_n_answers: { key: "evidence.overallNAnswers", kind: "number" }, | |
| 671 | + contrast: { key: "evidence.contrast", kind: "rate" }, | |
| 672 | + reference_mean_contrast: { key: "evidence.referenceMeanContrast", kind: "rate" }, | |
| 673 | + reference_n_students: { key: "evidence.referenceNStudents", kind: "number" }, | |
| 674 | + relative_contrast: { key: "evidence.relativeContrast", kind: "rate" }, | |
| 675 | + dimension: { key: "evidence.dimension", kind: "text" }, | |
| 676 | + label: { key: "evidence.label", kind: "text" }, | |
| 677 | + fact: { key: "evidence.fact", kind: "text" }, | |
| 678 | + window_from: { key: "evidence.windowFrom", kind: "date" }, | |
| 679 | + window_to: { key: "evidence.windowTo", kind: "date" }, | |
| 680 | + burstiness_limitation: { key: "evidence.burstinessLimitation", kind: "text" }, | |
| 681 | + limitation: { key: "evidence.limitation", kind: "text" }, | |
| 682 | +}; | |
| 683 | + | |
| 684 | +function evidenceValue(kind: EvidenceKind, value: unknown, locale: Locale): { text: string | null; sentence: boolean } { | |
| 685 | + switch (kind) { | |
| 686 | + case "rate": | |
| 687 | + return { text: pct(value), sentence: false }; | |
| 688 | + case "points": | |
| 689 | + return { text: points(value), sentence: false }; | |
| 690 | + case "ratePoints": | |
| 691 | + return { text: ratePoints(value), sentence: false }; | |
| 692 | + case "z": | |
| 693 | + return { text: zText(value), sentence: false }; | |
| 694 | + case "ms": | |
| 695 | + return { text: durationText(value), sentence: false }; | |
| 696 | + case "minutes": | |
| 697 | + return { text: durationText(num(value) === null ? null : num(value)! * 60_000), sentence: false }; | |
| 698 | + case "hours": | |
| 699 | + return { text: hoursText(value), sentence: false }; | |
| 700 | + case "date": | |
| 701 | + return { text: num(value) === null ? null : formatDateTime(num(value)!, locale), sentence: false }; | |
| 702 | + case "band": | |
| 703 | + return { text: bandLabel(value), sentence: false }; | |
| 704 | + case "text": { | |
| 705 | + const text = str(value); | |
| 706 | + return { text, sentence: text !== null && /\s/.test(text) }; | |
| 707 | + } | |
| 708 | + case "skip": | |
| 709 | + return { text: null, sentence: false }; | |
| 710 | + default: | |
| 711 | + return { text: nText(value), sentence: false }; | |
| 712 | + } | |
| 713 | +} | |
| 714 | + | |
| 715 | +function bandLabel(value: unknown): string | null { | |
| 716 | + const band = str(value); | |
| 717 | + if (!band) return null; | |
| 718 | + const key = BAND_KEYS[band]; | |
| 719 | + return key ? detailText(key) : null; | |
| 720 | +} | |
| 721 | + | |
| 722 | +/** The "neden?" numbers behind one attention item or recommendation card. */ | |
| 723 | +export function InsightEvidenceView(props: { value: unknown }) { | |
| 724 | + const prefs = usePreferences(); | |
| 725 | + const rows = () => { | |
| 726 | + const source = obj(props.value); | |
| 727 | + const out: { key: InsightDetailKey; text: string; sentence: boolean }[] = []; | |
| 728 | + let skipped = 0; | |
| 729 | + for (const [field, spec] of Object.entries(EVIDENCE_FIELDS)) { | |
| 730 | + if (!(field in source)) continue; | |
| 731 | + const raw = source[field]; | |
| 732 | + // A raw id has no human form here; the technical disclosure keeps it. | |
| 733 | + if (isUuid(raw) || (Array.isArray(raw) && raw.some(isUuid))) { | |
| 734 | + skipped += 1; | |
| 735 | + continue; | |
| 736 | + } | |
| 737 | + const { text, sentence } = evidenceValue(spec.kind, raw, prefs.locale()); | |
| 738 | + if (text === null || spec.kind === "skip") { | |
| 739 | + skipped += 1; | |
| 740 | + continue; | |
| 741 | + } | |
| 742 | + out.push({ key: spec.key, text, sentence }); | |
| 743 | + } | |
| 744 | + for (const field of Object.keys(source)) { | |
| 745 | + if (!(field in EVIDENCE_FIELDS)) skipped += 1; | |
| 746 | + } | |
| 747 | + return { out, skipped }; | |
| 748 | + }; | |
| 749 | + | |
| 750 | + return ( | |
| 751 | + <Show when={rows().out.length > 0 || rows().skipped > 0}> | |
| 752 | + <div class="space-y-1.5"> | |
| 753 | + <dl class="space-y-1 rounded-lg bg-surface-overlay px-3 py-2"> | |
| 754 | + <For each={rows().out}> | |
| 755 | + {(row) => <LabeledRow label={detailText(row.key)} value={row.text} mono={!row.sentence} />} | |
| 756 | + </For> | |
| 757 | + </dl> | |
| 758 | + <Show when={rows().skipped > 0}> | |
| 759 | + <NoteLine>{detailText("evidence.hiddenFields", { count: rows().skipped })}</NoteLine> | |
| 760 | + </Show> | |
| 761 | + </div> | |
| 762 | + </Show> | |
| 763 | + ); | |
| 764 | +} | |
| 765 | + | |
| 766 | +/** The collapsed raw payload behind every labelled view. */ | |
| 767 | +export function InsightTechnicalDetails(props: { value: unknown }) { | |
| 768 | + return ( | |
| 769 | + <details class="rounded-xl border border-border-hairline bg-surface-overlay" data-testid="insight-technical"> | |
| 770 | + <summary class="cursor-pointer select-none px-4 py-3 text-xs font-medium text-muted-foreground"> | |
| 771 | + {detailText("detail.technical")} | |
| 772 | + </summary> | |
| 773 | + <p class="border-t border-border-hairline px-4 pt-2 text-[11px] text-muted-foreground"> | |
| 774 | + {detailText("detail.technicalHint")} | |
| 775 | + </p> | |
| 776 | + <pre class="max-h-96 overflow-auto px-4 pb-3 font-mono text-[11px] leading-5 text-muted-foreground"> | |
| 777 | + {JSON.stringify(props.value, null, 2)} | |
| 778 | + </pre> | |
| 779 | + </details> | |
| 780 | + ); | |
| 781 | +} |
src/i18n/insights-detail.tsadded+199 -0
| @@ -0,0 +1,199 @@ | ||
| 1 | +import { formatMessage } from "@/i18n/messages"; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Turkish copy for the student insight drawer (`components/insights/insight-detail.tsx`). | |
| 5 | + * | |
| 6 | + * Lane-scoped on purpose: two lanes were adding insight strings at the same | |
| 7 | + * time, so the shared `messages.ts` dictionary is left untouched here and this | |
| 8 | + * module carries the drawer's own copy. Turkish-only is not an oversight — | |
| 9 | + * the insight payloads arrive Turkish from ZEKA (the attention `fact` | |
| 10 | + * sentences, every `reason`/`limitation` line), so the surrounding labels stay | |
| 11 | + * in the same language rather than half-translating one screen. | |
| 12 | + * | |
| 13 | + * `insights.*` keys that already exist in `messages.ts` are still read through | |
| 14 | + * `prefs.t`; only strings that had no key live here. | |
| 15 | + */ | |
| 16 | +export const insightsDetailTr = { | |
| 17 | + /** The collapsed raw-payload disclosure at the bottom of the drawer. */ | |
| 18 | + "detail.technical": "Teknik ayrıntı", | |
| 19 | + "detail.technicalHint": "Etiketlenmemiş ham veri; kayıt anahtarları burada görünür.", | |
| 20 | + "detail.hiddenFields": "{count} alan bu bölümde etiketsiz; teknik ayrıntıda.", | |
| 21 | + "detail.elsewhere": "Bu bölümün ham verisi Teknik ayrıntı bölümünde.", | |
| 22 | + "detail.notComputed": "Bu sürümde üretilemiyor", | |
| 23 | + "detail.reason": "Neden", | |
| 24 | + "detail.value.missing": "—", | |
| 25 | + | |
| 26 | + // --- attendance -------------------------------------------------------- | |
| 27 | + "attendance.rate": "Devam oranı", | |
| 28 | + "attendance.present": "Katıldı", | |
| 29 | + "attendance.absent": "Katılmadı", | |
| 30 | + "attendance.late": "Geç kaldı", | |
| 31 | + "attendance.excused": "Raporlu", | |
| 32 | + "attendance.custom": "Diğer (okul tanımlı)", | |
| 33 | + "attendance.nObs": "Değerlendirilen kayıt", | |
| 34 | + "attendance.cohortMedian": "Şube ortancası", | |
| 35 | + "attendance.cohortN": "Şubedeki öğrenci sayısı", | |
| 36 | + "attendance.relativeGap": "Şube ortancasına göre fark", | |
| 37 | + "attendance.rateSuppressed": "Oran için en az 10 devam kaydı gerekir; henüz gösterilmiyor.", | |
| 38 | + "attendance.weekdayPattern": "Haftanın günü deseni", | |
| 39 | + "attendance.trend": "Dönem içi eğilim", | |
| 40 | + "attendance.course": "Ders {n}", | |
| 41 | + "attendance.coursesEmpty": "Ders bazında devam kaydı yok.", | |
| 42 | + | |
| 43 | + // --- marks ------------------------------------------------------------- | |
| 44 | + "marks.courseFallback": "Ders {n}", | |
| 45 | + "marks.nMarks": "Not sayısı", | |
| 46 | + "marks.average": "Ağırlıklı ortalama", | |
| 47 | + "marks.mean": "Basit ortalama", | |
| 48 | + "marks.median": "Ortanca", | |
| 49 | + "marks.min": "En düşük", | |
| 50 | + "marks.max": "En yüksek", | |
| 51 | + "marks.placement": "Şubedeki konumu", | |
| 52 | + "marks.band.review": "Tekrar önerilir", | |
| 53 | + "marks.band.on_track": "Şube düzeyinde", | |
| 54 | + "marks.band.strong": "Güçlü", | |
| 55 | + "marks.band.insufficient_data": "Yeterli veri yok", | |
| 56 | + "marks.progress": "Veri toplanıyor ({progress})", | |
| 57 | + "marks.classAverage": "Şube ortalaması", | |
| 58 | + "marks.classSd": "Şube standart sapması", | |
| 59 | + "marks.cohortN": "Şubedeki öğrenci sayısı", | |
| 60 | + "marks.z": "Şubeye göre sapma (z)", | |
| 61 | + "marks.trend": "Eğilim", | |
| 62 | + "marks.trendSlope": "30 günlük değişim", | |
| 63 | + "marks.recentMean": "Son 3 notun ortalaması", | |
| 64 | + "marks.previousMean": "Önceki 3 notun ortalaması", | |
| 65 | + "marks.trendDelta": "Son 3 nottaki fark", | |
| 66 | + "marks.dropped": "Düşüş eşiği aşıldı", | |
| 67 | + "marks.rising": "Yükseliş var", | |
| 68 | + "marks.contrast": "Dersler arası denge", | |
| 69 | + "marks.contrastWorst": "En düşük ders", | |
| 70 | + "marks.contrastDelta": "Diğer derslerin ortancasına göre fark", | |
| 71 | + "marks.contrastFlagged": "Bu ders, öğrencinin diğer derslerine göre belirgin biçimde düşük.", | |
| 72 | + "marks.classCount": "Kayıtlı şube sayısı", | |
| 73 | + | |
| 74 | + // --- study ------------------------------------------------------------- | |
| 75 | + "study.recent": "Son 28 gün", | |
| 76 | + "study.previous": "Önceki 28 gün", | |
| 77 | + "study.stints": "Çalışma oturumu", | |
| 78 | + "study.activeDays": "Çalışılan gün", | |
| 79 | + "study.totalFocus": "Toplam çalışma süresi", | |
| 80 | + "study.medianStint": "Oturum süresi (ortanca)", | |
| 81 | + "study.regularity": "Düzenlilik", | |
| 82 | + "study.regularitySuppressed": "Düzenlilik için en az 3 gün çalışılmış olması gerekir.", | |
| 83 | + "study.burstiness": "Günler arası yığılma", | |
| 84 | + "study.nightShare": "Gece çalışma payı", | |
| 85 | + "study.nightWindow": "Gece penceresi", | |
| 86 | + "study.change": "Önceki 28 güne göre değişim", | |
| 87 | + "study.changeActiveDays": "Çalışılan gün", | |
| 88 | + "study.changeStints": "Oturum", | |
| 89 | + "study.changeFocus": "Süre", | |
| 90 | + "study.streak": "Kesintisiz gün", | |
| 91 | + "study.heatmap": "Isı haritası", | |
| 92 | + "study.heatmapProgress": "Isı haritası için {progress} oturum", | |
| 93 | + "study.heatmapReady": "7×24 ısı haritası teknik ayrıntıda.", | |
| 94 | + "study.preDeadline": "Teslim öncesi 48 saatteki çalışma payı", | |
| 95 | + "study.preExam": "Sınav öncesi yığılma", | |
| 96 | + | |
| 97 | + // --- submission -------------------------------------------------------- | |
| 98 | + "submission.overall": "Genel", | |
| 99 | + "submission.recent": "Son 30 gün", | |
| 100 | + "submission.previous": "Önceki 30 gün", | |
| 101 | + "submission.n": "Ödev sayısı", | |
| 102 | + "submission.submitted": "Teslim edilen", | |
| 103 | + "submission.onTime": "Zamanında", | |
| 104 | + "submission.late": "Geç teslim", | |
| 105 | + "submission.missing": "Teslim edilmemiş", | |
| 106 | + "submission.markedMissing": "Öğretmen “yapılmadı” işaretledi", | |
| 107 | + "submission.onTimeRate": "Zamanında teslim oranı", | |
| 108 | + "submission.lateRate": "Geç teslim oranı", | |
| 109 | + "submission.missingRate": "Eksik teslim oranı", | |
| 110 | + "submission.ratesSuppressed": "Oranlar için en az 5 teslim gerekir; henüz gösterilmiyor.", | |
| 111 | + "submission.upcoming": "Yaklaşan teslimler", | |
| 112 | + "submission.upcomingNone": "Yaklaşan teslim yok.", | |
| 113 | + "submission.due": "Teslim", | |
| 114 | + "submission.hoursLeft": "Kalan süre", | |
| 115 | + "submission.highPriority": "Öncelikli", | |
| 116 | + "submission.done": "Teslim edildi", | |
| 117 | + "submission.homework": "Ödev", | |
| 118 | + "submission.procrastination": "Erteleme profili", | |
| 119 | + "submission.measure": "Ölçü", | |
| 120 | + "submission.measureLastTouch": "son dokunuş zamanı", | |
| 121 | + "submission.windows": "Pencereler teslim tarihine (due_at) göredir.", | |
| 122 | + | |
| 123 | + // --- evidence (attention items and recommendation cards) --------------- | |
| 124 | + "evidence.hiddenFields": "{count} alan yalnız teknik ayrıntıda.", | |
| 125 | + "evidence.rate": "Oran", | |
| 126 | + "evidence.relativeGap": "Şube ortancasına göre fark", | |
| 127 | + "evidence.nObs": "Kayıt sayısı", | |
| 128 | + "evidence.nMissing30": "Son 30 günde teslim edilmeyen", | |
| 129 | + "evidence.missingRate30": "Son 30 günde eksik teslim oranı", | |
| 130 | + "evidence.cohortMissingMedian": "Şube ortancası (eksik teslim oranı)", | |
| 131 | + "evidence.onTimeRate30": "Son 30 günde zamanında teslim oranı", | |
| 132 | + "evidence.onTimeRatePrev": "Önceki 30 günde zamanında teslim oranı", | |
| 133 | + "evidence.missingRatePrev": "Önceki 30 günde eksik teslim oranı", | |
| 134 | + "evidence.n30": "Son 30 günde ödev sayısı", | |
| 135 | + "evidence.nPrev30": "Önceki 30 günde ödev sayısı", | |
| 136 | + "evidence.recentMean": "Son 3 notun ortalaması", | |
| 137 | + "evidence.previousMean": "Önceki 3 notun ortalaması", | |
| 138 | + "evidence.delta": "Fark", | |
| 139 | + "evidence.nMarks": "Not sayısı", | |
| 140 | + "evidence.measure": "Ölçü", | |
| 141 | + "evidence.studentAverage": "Öğrenci ortalaması", | |
| 142 | + "evidence.classAverage": "Şube ortalaması", | |
| 143 | + "evidence.classSd": "Şube standart sapması", | |
| 144 | + "evidence.z": "Şubeye göre sapma (z)", | |
| 145 | + "evidence.cohortN": "Şubedeki öğrenci sayısı", | |
| 146 | + "evidence.average": "Ortalama", | |
| 147 | + "evidence.band": "Şube konumu", | |
| 148 | + "evidence.reading": "Okuma notu", | |
| 149 | + "evidence.nStints28": "Son 28 günde oturum", | |
| 150 | + "evidence.activeDays28": "Son 28 günde çalışılan gün", | |
| 151 | + "evidence.regularity": "Düzenlilik", | |
| 152 | + "evidence.burstiness": "Günler arası yığılma", | |
| 153 | + "evidence.medianStintMin": "Oturum süresi (ortanca)", | |
| 154 | + "evidence.streakLocal": "Kesintisiz gün", | |
| 155 | + "evidence.activeDaysDelta": "Çalışılan gün farkı", | |
| 156 | + "evidence.dueAt": "Teslim", | |
| 157 | + "evidence.hoursLeft": "Kalan süre", | |
| 158 | + "evidence.highPriority": "Öncelikli", | |
| 159 | + "evidence.title": "Ödev", | |
| 160 | + "evidence.nAnswers": "Cevap sayısı", | |
| 161 | + "evidence.nCorrect": "Doğru cevap", | |
| 162 | + "evidence.accuracy": "Doğruluk", | |
| 163 | + "evidence.overallAccuracy": "Öğrencinin genel doğruluğu", | |
| 164 | + "evidence.overallNAnswers": "Genel cevap sayısı", | |
| 165 | + "evidence.contrast": "Fark (doğruluk)", | |
| 166 | + "evidence.referenceMeanContrast": "Referans farkı (ortanca)", | |
| 167 | + "evidence.referenceNStudents": "Referans öğrenci sayısı", | |
| 168 | + "evidence.relativeContrast": "Referansa göre fark", | |
| 169 | + "evidence.dimension": "Boyut", | |
| 170 | + "evidence.label": "Etiket", | |
| 171 | + "evidence.fact": "Olgu", | |
| 172 | + "evidence.windowFrom": "Pencere başlangıcı", | |
| 173 | + "evidence.windowTo": "Pencere bitişi", | |
| 174 | + "evidence.limitation": "Sınır", | |
| 175 | + "evidence.burstinessLimitation": "Yığılma ölçüsünün sınırı", | |
| 176 | + | |
| 177 | + // --- segments / recommendations --------------------------------------- | |
| 178 | + "segments.dimension.bilissel_talep": "Bilişsel talep", | |
| 179 | + "segments.dimension.dikkat_tuzagi": "Dikkat tuzağı", | |
| 180 | + "segments.dimension.okuma_yuku": "Okuma yükü", | |
| 181 | + "segments.dimension.unknown": "Boyut", | |
| 182 | + "product.O1": "Ders konumu", | |
| 183 | + "product.O2": "Beceri boşluğu", | |
| 184 | + "product.O3": "Çalışma düzeni", | |
| 185 | + "product.O4": "Teslim hatırlatıcısı", | |
| 186 | + "product.T3": "Sınıf uyarısı", | |
| 187 | + "product.T4": "Öğrenci uyarısı", | |
| 188 | + "product.unknown": "Öneri", | |
| 189 | + "trigger.attendance": "Devamsızlık", | |
| 190 | + "trigger.homework": "Ödev", | |
| 191 | + "trigger.mark_trend": "Not eğilimi", | |
| 192 | +} as const; | |
| 193 | + | |
| 194 | +export type InsightDetailKey = keyof typeof insightsDetailTr; | |
| 195 | + | |
| 196 | +/** One label from the drawer's own dictionary, with `{name}` interpolation. */ | |
| 197 | +export function detailText(key: InsightDetailKey, vars?: Record<string, string | number>): string { | |
| 198 | + return formatMessage(insightsDetailTr[key], vars); | |
| 199 | +} |
src/lib/is-record.tsadded+10 -0
| @@ -0,0 +1,10 @@ | ||
| 1 | +/** | |
| 2 | + * The one record guard for payloads whose shape is only known at runtime — | |
| 3 | + * ZEKA's insight JSON is stored and served unread, so every reader narrows it | |
| 4 | + * field by field. Keep this canonical: a guard redefined per file drifts. | |
| 5 | + */ | |
| 6 | +export type UnknownRecord = Record<string, unknown>; | |
| 7 | + | |
| 8 | +export function isRecord(value: unknown): value is UnknownRecord { | |
| 9 | + return typeof value === "object" && value !== null && !Array.isArray(value); | |
| 10 | +} |