forge
Explore
Log in

Don't you dare go Hollow

hezarfen_zeka

Clone
★ 0

0 watching0 forksPython1.9 MiBe01a4faAhmet Kaan Gümüş2 months ago25 commits

load.py105 lines, 3.4 KiBHistoryRawDownload
1"""Demet kurulumu: `Reader` → `StudentFacingBundle` / `StaffBundle`.
2
3Kapı burada **okuma anında** uygulanır:
4
5* Öğrenci raporu için `student_summary` sorgusunun sütun listesinde
6 `attention` yoktur (`gate.SUMMARY_COLUMNS_STUDENT`) — satır veritabanından
7 dikkat listesi taşımadan çıkar.
8* Öğrenci raporu için `recommendation` sorgusu `audience_role = 'student'` ve
9 `audience = <öğrenci>` ile daraltılır; öğretmen satırı hiç getirilmez.
10* Öğretmen/yönetim raporu `StaffBundle` alır ve dikkat listesini taşır.
11"""
12
13from __future__ import annotations
14
15from typing import Any, Mapping
16
17from .gate import (
18 StaffBundle,
19 StudentFacingBundle,
20 staff_summary,
21 student_facing_summary,
22 summary_columns,
23)
24from .reader import Reader
25
26
27async def load_student_bundle(
28 reader: Reader, school: str, student: str, *, now_ms: int
29) -> StudentFacingBundle:
30 """Öğrenci/veli raporunun demeti. Dikkat listesi **okunmaz**."""
31 rows = await reader.summaries(
32 school, columns=summary_columns("ogrenci"), student=student
33 )
34 summary = student_facing_summary(rows[0]) if rows else None
35 recommendations = await reader.recommendations(
36 school, audience=student, audience_role="student"
37 )
38 profiles = await reader.segment_profiles(school, student=student)
39 return StudentFacingBundle(
40 school=school,
41 student=student,
42 generated_at=now_ms,
43 summary=summary,
44 recommendations=recommendations,
45 segment_profiles=profiles,
46 )
47
48
49async def load_staff_bundle(
50 reader: Reader,
51 school: str,
52 kind: str,
53 *,
54 now_ms: int,
55 teacher: str | None = None,
56 class_names: Mapping[str, str] | None = None,
57) -> StaffBundle:
58 """Yönetim / öğretmen / teknik rapor demeti.
59
60 `class_names` şube KİMLİĞİ -> görünen ad haritasıdır (payload'dan). Verilmezse
61 rapor "Adı bilinmeyen şube" yazar; ham kimlik hiçbir koşulda yazılmaz.
62 """
63 rows = await reader.summaries(school, columns=summary_columns(kind))
64 summaries = [staff_summary(row) for row in rows]
65 summaries.sort(key=lambda s: s.student)
66 recommendations = await reader.recommendations(school)
67 profiles = await reader.segment_profiles(school)
68 runs = await reader.runs(school)
69 question_segments: list[dict[str, Any]] = []
70 if kind == "ham":
71 question_segments = await reader.question_segments(school)
72 return StaffBundle(
73 school=school,
74 kind=kind,
75 generated_at=now_ms,
76 summaries=summaries,
77 recommendations=recommendations,
78 segment_profiles=profiles,
79 runs=runs,
80 question_segments=question_segments,
81 class_names=dict(class_names or {}),
82 teacher=teacher,
83 )
84
85
86async def load_bundle(
87 reader: Reader,
88 school: str,
89 kind: str,
90 *,
91 now_ms: int,
92 student: str | None = None,
93 teacher: str | None = None,
94 class_names: Mapping[str, str] | None = None,
95) -> Any:
96 """Rapor tipine göre doğru demeti kurar."""
97 if kind == "ogrenci":
98 if not student:
99 raise ValueError("öğrenci raporu için --about (öğrenci kimliği) zorunlu")
100 return await load_student_bundle(reader, school, student, now_ms=now_ms)
101 if kind == "ogretmen" and not teacher:
102 raise ValueError("öğretmen raporu için --teacher zorunlu")
103 return await load_staff_bundle(
104 reader, school, kind, now_ms=now_ms, teacher=teacher, class_names=class_names
105 )