+
+
+
+
+
+
+
+
{tx("insights.summary")}
+
+
+ {(summary) => (
+
+ {confidenceLabel(summary().confidence)}
+
+ )}
+
+
+
+
+ }
+ >
+ {(summary) => (
+ <>
+
+
+
{tx("insights.computedAt")}
+
{formatDateTime(summary().computed_at, prefs.locale())}
+
+
+
{tx("insights.retainUntil")}
+
{formatDateTime(summary().retain_until, prefs.locale())}
+
+
+
+
+ {(section) => (
+
+ {section.label}
+ {tx("insights.sectionNotComputed")}}
+ >
+
+
+
+ )}
+
+
+ >
+ )}
+
+
+
+
+
+
+
+
+
{tx("insights.attention")}
+ {props.insight.attention.length}
+
+ 0}
+ fallback={}
+ >
+
+
+ {(item) => (
+
+
+
+
{item.fact}
+
+ {courseLine(item.course)} · {formatDateTime(item.window_from, prefs.locale())} – {formatDateTime(item.window_to, prefs.locale())}
+
+
+
+ {(key) => {detailText(key())}}
+
+
+
+
+ )}
+
+
+
+
+
+
+
-
{tx("insights.summary")}
+ {tx("insights.recommendations")}
+ {props.insight.cards.length}
-
- {(summary) => (
-
- {confidenceLabel(summary().confidence)}
-
- )}
+ 0}
+ fallback={}
+ >
+
+
+ {(card) => {
+ const context = () => [courseTitle(card.course), scopeText(card.scope)].filter(Boolean).join(" · ");
+ return (
+
+
+
+ {PRODUCT_KEYS[card.product] ? detailText(PRODUCT_KEYS[card.product]) : detailText("product.unknown")}
+
+
+ {confidenceLabel(card.confidence)}
+
+
+ 0}>
+ {context()}
+
+
+
+ {tx("insights.expiresAt")}: {formatDateTime(card.expires_at, prefs.locale())}
+
+
+ );
+ }}
+
+
-
+
-
- }
- >
- {(summary) => (
- <>
-
-
-
{tx("insights.computedAt")}
-
{formatDateTime(summary().computed_at, prefs.locale())}
-
-
-
{tx("insights.retainUntil")}
-
{formatDateTime(summary().retain_until, prefs.locale())}
-
-
-
-
- {(section) => (
+
+
+
+
+
{tx("insights.segments")}
+ {props.insight.segments.length}
+
+ 0}
+ fallback={}
+ >
+
+
+ {(segment) => (
- {section.label}
- {tx("insights.sectionNotComputed")}}
- >
-
-
+
+
+
{segment.label}
+
+ {(label) => {label()}
}
+
+
+
+ {confidenceLabel(segment.confidence)}
+
+
+
+
+ {tx("insights.accuracy")}
+ {percent(segment.accuracy)}
+
+
+
+
+
+
{segment.n_correct}/{segment.n_answers}
+
{tx("insights.answers")}
+
+
+
{percent(segment.overall_accuracy)}
+
{tx("insights.overall")}
+
+
+
+ {segment.contrast > 0 ? "+" : ""}{percent(segment.contrast)}
+
+
{tx("insights.contrast")}
+
+
)}
- >
- )}
-
-
-
-
-
-
-
-
-
{tx("insights.attention")}
- {props.insight.attention.length}
-
- 0}
- fallback={}
- >
-
-
- {(item) => (
-
-
-
-
{item.fact}
-
- {item.course || tx("insights.schoolWide")} · {formatDateTime(item.window_from, prefs.locale())} – {formatDateTime(item.window_to, prefs.locale())}
-
-
-
{item.trigger}
-
-
-
- )}
-
-
-
-
-
-
-
-
-
-
{tx("insights.recommendations")}
- {props.insight.cards.length}
-
- 0}
- fallback={}
- >
-
-
- {(card) => (
-
-
-
- {card.product}
- {card.rule_id} · v{card.rule_version}
-
-
- {confidenceLabel(card.confidence)}
-
-
-
- {[card.course, card.scope].filter(Boolean).join(" · ")}
-
-
-
- {tx("insights.expiresAt")}: {formatDateTime(card.expires_at, prefs.locale())}
-
-
- )}
-
-
+
+
-
+
-
-
-
-
{tx("insights.segments")}
- {props.insight.segments.length}
-
- 0}
- fallback={}
- >
-
-
- {(segment) => (
-
-
-
-
{segment.label}
-
{segment.dimension}
-
-
- {confidenceLabel(segment.confidence)}
-
-
-
-
- {tx("insights.accuracy")}
- {percent(segment.accuracy)}
-
-
-
-
-
-
{segment.n_correct}/{segment.n_answers}
-
{tx("insights.answers")}
-
-
-
{percent(segment.overall_accuracy)}
-
{tx("insights.overall")}
-
-
-
- {segment.contrast > 0 ? "+" : ""}{percent(segment.contrast)}
-
-
{tx("insights.contrast")}
-
-
-
- )}
-
-
-
-
+
);
diff --git a/src/components/insights/insight-module-views.tsx b/src/components/insights/insight-module-views.tsx
new file mode 100644
index 0000000..929b524
--- /dev/null
+++ b/src/components/insights/insight-module-views.tsx
@@ -0,0 +1,781 @@
+import { For, Show, type JSX } from "solid-js";
+import { Badge } from "@/components/ui/badge";
+import { detailText, type InsightDetailKey } from "@/i18n/insights-detail";
+import type { Locale } from "@/i18n/messages";
+import { cn } from "@/lib/cn";
+import { formatDateTime } from "@/lib/format";
+import { isRecord, type UnknownRecord } from "@/lib/is-record";
+import { usePreferences } from "@/stores/preferences-context";
+
+/**
+ * Human-readable renderers for one ZEKA insight module.
+ *
+ * The payload the drawer receives is ZEKA's own shape, stored and served
+ * unread (`student_profile()` in the service's `compute/*.py`): dicts keyed by
+ * course id, snake_case field names and honest Turkish `reason`/`limitation`
+ * sentences for everything the service could not compute. Rendering that with
+ * a generic key walker is what made the drawer unreadable — `Class es`,
+ * `Trend Available` and a raw course uuid in a 5rem column.
+ *
+ * So each module gets its own renderer: labels come from the drawer's own
+ * dictionary, course/class ids are resolved to titles, ratios are formatted as
+ * percents and milliseconds as durations, and a `reason` is rendered as the
+ * sentence it already is. Nothing is hidden: the caller keeps the whole payload
+ * in a collapsed technical disclosure underneath.
+ */
+
+type Rec = UnknownRecord;
+type CourseTitle = (id: string) => string | null;
+
+/** A payload member as a record: a missing or non-object member reads as an
+ * empty one, so every field below renders as "—" instead of throwing. */
+const obj = (value: unknown): Rec => (isRecord(value) ? value : {});
+
+const str = (value: unknown): string | null =>
+ typeof value === "string" && value.length > 0 ? value : null;
+const num = (value: unknown): number | null =>
+ typeof value === "number" && Number.isFinite(value) ? value : null;
+const isUuid = (value: unknown): value is string =>
+ 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);
+
+const n1 = (value: number) => value.toLocaleString("tr-TR", { maximumFractionDigits: 1 });
+/** A nullable number as display text — the shape most payload fields arrive in. */
+const nText = (value: unknown) => {
+ const x = num(value);
+ return x === null ? null : n1(x);
+};
+const pct = (value: unknown) => {
+ const x = num(value);
+ return x === null ? null : `%${Math.round(x * 100)}`;
+};
+/** A signed number in percentage points, for `relative_gap`-style differences. */
+const points = (value: unknown) => {
+ const x = num(value);
+ return x === null ? null : `${x > 0 ? "+" : ""}${n1(x)} puan`;
+};
+/** The same, for a difference that is itself a rate (`relative_gap`): -0.16 is
+ * "-16 puan", not "-0,2 puan". */
+const ratePoints = (value: unknown) => {
+ const x = num(value);
+ return x === null ? null : `${x > 0 ? "+" : ""}${n1(Math.round(x * 1000) / 10)} puan`;
+};
+const zText = (value: unknown) => {
+ const x = num(value);
+ return x === null ? null : x.toLocaleString("tr-TR", { maximumFractionDigits: 2 });
+};
+const durationText = (value: unknown) => {
+ const ms = num(value);
+ if (ms === null) return null;
+ const minutes = Math.round(ms / 60_000);
+ if (minutes < 60) return `${minutes} dk`;
+ return `${Math.floor(minutes / 60)} sa ${minutes % 60} dk`;
+};
+const hoursText = (value: unknown) => {
+ const hours = num(value);
+ return hours === null ? null : `${n1(Math.round(hours * 10) / 10)} saat`;
+};
+
+/** One label/value row. The value column takes the remaining width, so a long
+ * value wraps instead of squeezing the label into a broken column. */
+export function LabeledRow(props: { label: string; value: string | null; mono?: boolean }) {
+ return (
+
+
{props.label}
+
+ {props.value ?? detailText("detail.value.missing")}
+
+
+ );
+}
+
+/** A sentence the service wrote for something it could not compute, or a
+ * limitation line. Never a field dump. */
+export function NoteLine(props: { label?: string; children: JSX.Element }) {
+ return (
+
+
+ {props.label}:
+
+ {props.children}
+
+ );
+}
+
+function StatCell(props: { label: string; value: string | null }) {
+ return (
+
+
+ {props.value ?? detailText("detail.value.missing")}
+
+
{props.label}
+
+ );
+}
+
+/** One course row resolved to its title: used by the attendance list, which
+ * carries no title of its own — the marks module keys the same course ids. */
+function courseLabel(id: string, title: CourseTitle, index: number): string {
+ return title(id) ?? detailText("marks.courseFallback", { n: index + 1 });
+}
+
+// ---------------------------------------------------------------------------
+// attendance
+// ---------------------------------------------------------------------------
+
+function AttendanceView(props: { value: Rec; courseTitle: CourseTitle }) {
+ const overall = () => obj(props.value.overall);
+ const courses = () => Object.entries(obj(props.value.courses));
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {detailText("attendance.rateSuppressed")}
+
+
+
0}
+ fallback={{detailText("attendance.coursesEmpty")}}
+ >
+
+
+ {([id, raw], index) => {
+ const stat = () => obj(raw);
+ return (
+
+
+ {courseLabel(id, props.courseTitle, index())}
+
+
+
+
+ {detailText("attendance.rateSuppressed")}
+
+
+
+
+
+
+
+
+
+
+ );
+ }}
+
+
+
+
+
+
+
+
+ {str(props.value.weekday_pattern_reason) ?? detailText("detail.value.missing")}
+
+
+ {str(obj(props.value.trend).reason) ?? detailText("detail.value.missing")}
+
+
+ {(value) => {value()}}
+
+
+ );
+}
+
+// ---------------------------------------------------------------------------
+// marks
+// ---------------------------------------------------------------------------
+
+const BAND_KEYS: Record
= {
+ review: "marks.band.review",
+ on_track: "marks.band.on_track",
+ strong: "marks.band.strong",
+ insufficient_data: "marks.band.insufficient_data",
+};
+
+function MarksCourseCard(props: { id: string; statRaw: unknown; courseTitle: CourseTitle; index: number }) {
+ const stat = () => obj(props.statRaw);
+ const placement = () => obj(stat().placement);
+ const trend = () => obj(stat().trend);
+ const band = () => str(placement().band);
+ const bandKey = (): InsightDetailKey => {
+ const value = band();
+ return (value === null ? undefined : BAND_KEYS[value]) ?? "marks.band.insufficient_data";
+ };
+ /** A real placement is one with a band other than "not enough data". */
+ const placed = () => band() !== null && band() !== "insufficient_data";
+ const bandVariant = () =>
+ band() === "review" ? ("warning" as const) : band() === "strong" ? ("success" as const) : ("secondary" as const);
+
+ return (
+
+
+ {str(stat().course_title) ?? courseLabel(props.id, props.courseTitle, props.index)}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- {detailText("marks.placement")}
+ -
+ {detailText(bandKey())}
+
+
+
+
+
+ {(progress) => (
+ {detailText("marks.progress", { progress: progress() })}
+ )}
+
+ {/* `reason` repeats the progress line verbatim when the gate is the
+ mark count ("veri toplanıyor"); show the sentence only when it
+ says something the progress line does not. */}
+
+ {(reason) => (
+
+ {reason()}
+
+ )}
+
+
+
+
+
+
+
+
+
+ {(reason) => {reason()}}
+
+
+
+
+
+
+
{detailText("marks.trend")}
+
+
+
+ {detailText("marks.dropped")}
+
+
+ {detailText("marks.rising")}
+
+
+
+
+
+ {detailText("marks.band.insufficient_data")}
+ {(reason) => {reason()}}
+
+
+
+
+ }
+ >
+
+
+
+
+
+
+
+
+
+
+
+ );
+}
+
+function MarksView(props: { value: Rec; courseTitle: CourseTitle }) {
+ const courses = () => Object.entries(obj(props.value.courses));
+ const contrast = () => obj(props.value.within_student_contrast);
+ const contrastTitle = () =>
+ str(contrast().course_title) ??
+ (str(contrast().course) ? props.courseTitle(contrast().course as string) : null);
+
+ return (
+