- UI Vuexy biru UNTAN; 5 peran + pengalih peran; dasbor kaprodi (KPI), dosen (task-first), wali, mahasiswa - Raport CPL per mahasiswa/angkatan dengan rumus resmi Dokumen Kurikulum 2026 (skor maks CPMK), radar perjalanan CPL - CQI tiga loop + Laporan Pengukuran CPL (.docx) - Data Master: periode buka/tutup/kunci, dosen, mahasiswa, kelas & pengajar (papan seret), KRS, dosen wali, impor pratinjau - Kurikulum berversi dari PDF resmi (tools/extract_dokumen.py), halaman Kurikulum, revisi draf→berlaku, pemeriksa keselarasan, ekspor tabel Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
494 lines
21 KiB
Python
494 lines
21 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
Mesin pengukuran ketercapaian CPL/CPMK (inti OBE).
|
||
|
||
Kebijakan (Dokumen Kurikulum Informatika 2026, Bab 10.2–10.3; disepakati 13 Okt 2026):
|
||
- Nilai dicatat per mahasiswa per Sub-CPMK; mode 'agregat' (rata-rata kelas) boleh tapi ditandai.
|
||
- Skor CPMK di satu MK = rata-rata Sub-CPMK-nya (tertimbang bobot kisi-kisi RPS bila ada).
|
||
- Setiap CPMK di setiap MK punya SKOR MAKS resmi (Tabel 10.2; total 100 per MK).
|
||
- Skor CPL = Σ (skor CPMK × skor maks) ÷ Σ skor maks, lintas seluruh MK pendukung
|
||
(Tabel 10.3: total skor maks CPL). Bila skor maks belum ditetapkan → bobot sama.
|
||
- % kelulusan = persentase mahasiswa dengan skor ≥ ambang (hanya mode per-mahasiswa).
|
||
"""
|
||
import statistics
|
||
|
||
from . import db
|
||
|
||
|
||
def _bobot_resmi(mk: str, cpmk_list: list[str]) -> dict[str, float]:
|
||
"""Skor maks resmi tiap CPMK di MK (Tabel 10.2); fallback bobot sama bila belum ada."""
|
||
sm = db.skor_maks_mk(mk)
|
||
if sm and all(c in sm for c in cpmk_list):
|
||
return {c: sm[c] for c in cpmk_list}
|
||
return {c: sm.get(c, 100.0 / max(len(cpmk_list), 1)) for c in cpmk_list}
|
||
|
||
|
||
def _rata_tertimbang(pasangan) -> float | None:
|
||
"""[(bobot, skor)] → Σ b·s ÷ Σ b (abaikan skor kosong)."""
|
||
p = [(b, s) for b, s in pasangan if s is not None and b]
|
||
total = sum(b for b, _ in p)
|
||
return sum(b * s for b, s in p) / total if total else None
|
||
|
||
|
||
def _rata(xs):
|
||
xs = [x for x in xs if x is not None]
|
||
return sum(xs) / len(xs) if xs else None
|
||
|
||
|
||
def parse_skala(teks: str) -> list[dict]:
|
||
"""'A+|91|100|4.00' per baris → [{'huruf','lo','hi','angka'}] terurut turun."""
|
||
out = []
|
||
for line in (teks or "").splitlines():
|
||
bag = [b.strip() for b in line.split("|")]
|
||
if len(bag) >= 3:
|
||
try:
|
||
out.append({
|
||
"huruf": bag[0], "lo": float(bag[1]), "hi": float(bag[2]),
|
||
"angka": float(bag[3]) if len(bag) > 3 else None,
|
||
})
|
||
except ValueError:
|
||
continue
|
||
return sorted(out, key=lambda s: -s["lo"])
|
||
|
||
|
||
def huruf_mutu(skor: float, skala: list[dict]) -> str:
|
||
for s in skala:
|
||
if s["lo"] <= skor <= s["hi"]:
|
||
return s["huruf"]
|
||
return "?"
|
||
|
||
|
||
def skor_sub(nilai_data: dict, ambang: float) -> dict:
|
||
"""Skor per Sub-CPMK dari data nilai tersimpan.
|
||
|
||
nilai_data = {"mode": "per_mahasiswa"|"agregat",
|
||
"mahasiswa": [{"npm","nama","skor":{sub: nilai}}] |
|
||
"agregat": {sub: rata}}
|
||
→ {sub: {"rata": x, "n": jumlah_mhs, "lulus_pct": y|None}}
|
||
"""
|
||
out = {}
|
||
if nilai_data.get("mode") == "per_mahasiswa":
|
||
per_sub: dict[str, list[float]] = {}
|
||
for m in nilai_data.get("mahasiswa", []):
|
||
for sub, v in (m.get("skor") or {}).items():
|
||
if v is not None:
|
||
per_sub.setdefault(sub, []).append(float(v))
|
||
for sub, xs in per_sub.items():
|
||
out[sub] = {
|
||
"rata": _rata(xs),
|
||
"n": len(xs),
|
||
"lulus_pct": 100.0 * sum(1 for x in xs if x >= ambang) / len(xs),
|
||
}
|
||
else:
|
||
for sub, v in (nilai_data.get("agregat") or {}).items():
|
||
if v in (None, ""):
|
||
continue
|
||
out[sub] = {"rata": float(v), "n": None, "lulus_pct": None}
|
||
return out
|
||
|
||
|
||
def bobot_sub_dari_rps(rps_data: dict | None) -> dict[str, float]:
|
||
"""Bobot (%) tiap Sub-CPMK = jumlah porsi bagi-rata dari komponen RPS (kisi-kisi)."""
|
||
bobot: dict[str, float] = {}
|
||
if not rps_data:
|
||
return bobot
|
||
for k in rps_data.get("komponen", []):
|
||
subs = k.get("subs", [])
|
||
try:
|
||
b = float(k.get("bobot") or 0)
|
||
except (TypeError, ValueError):
|
||
continue
|
||
for s in subs:
|
||
bobot[s] = bobot.get(s, 0.0) + b / len(subs)
|
||
return bobot
|
||
|
||
|
||
def nilai_akhir_mahasiswa(nilai_data: dict, bobot_sub: dict[str, float]) -> list[dict]:
|
||
"""Nilai akhir tertimbang bobot Sub-CPMK per mahasiswa (mode per_mahasiswa)."""
|
||
out = []
|
||
for m in nilai_data.get("mahasiswa", []):
|
||
skor = m.get("skor") or {}
|
||
pasangan = [(bobot_sub.get(s), v) for s, v in skor.items() if v is not None]
|
||
berbobot = [(b, v) for b, v in pasangan if b]
|
||
if berbobot:
|
||
total_b = sum(b for b, _ in berbobot)
|
||
akhir = sum(b * v for b, v in berbobot) / total_b
|
||
else: # RPS belum mengisi bobot → rata-rata sederhana
|
||
akhir = _rata([v for _, v in pasangan])
|
||
if akhir is not None:
|
||
out.append({"npm": m.get("npm", ""), "nama": m.get("nama", ""),
|
||
"akhir": akhir})
|
||
return out
|
||
|
||
|
||
def statistik_akhir(akhir: list[dict], skala: list[dict]) -> dict | None:
|
||
xs = [a["akhir"] for a in akhir]
|
||
if not xs:
|
||
return None
|
||
frek = {s["huruf"]: 0 for s in skala}
|
||
for x in xs:
|
||
h = huruf_mutu(x, skala)
|
||
frek[h] = frek.get(h, 0) + 1
|
||
return {
|
||
"n": len(xs),
|
||
"mean": statistics.mean(xs),
|
||
"median": statistics.median(xs),
|
||
"stdev": statistics.stdev(xs) if len(xs) > 1 else 0.0,
|
||
"min": min(xs),
|
||
"max": max(xs),
|
||
"range": max(xs) - min(xs),
|
||
"frekuensi": frek,
|
||
}
|
||
|
||
|
||
def rollup_mk(peta: dict, nilai_data: dict, ambang: float) -> dict:
|
||
"""Ketercapaian satu MK: per Sub-CPMK → CPMK → CPL (bagi rata)."""
|
||
sub = skor_sub(nilai_data, ambang)
|
||
|
||
cpmk: dict[str, dict] = {}
|
||
for c in peta["cpmks"]:
|
||
skor = _rata([sub[s["kode"]]["rata"] for s in c["subs"] if s["kode"] in sub])
|
||
n_ternilai = sum(1 for s in c["subs"] if s["kode"] in sub)
|
||
cpmk[c["kode"]] = {"skor": skor, "cpl": c["cpl"],
|
||
"n_sub": len(c["subs"]), "n_ternilai": n_ternilai}
|
||
|
||
bobot = _bobot_resmi(peta["kode"], list(cpmk))
|
||
for kode, v in cpmk.items():
|
||
v["skor_maks"] = bobot.get(kode)
|
||
cpl: dict[str, dict] = {}
|
||
for cp in peta["cpls"]:
|
||
skor = _rata_tertimbang([(bobot.get(k), v["skor"]) for k, v in cpmk.items() if cp["kode"] in v["cpl"]])
|
||
cpl[cp["kode"]] = {"skor": skor}
|
||
|
||
return {"sub": sub, "cpmk": cpmk, "cpl": cpl,
|
||
"mode": nilai_data.get("mode", "agregat")}
|
||
|
||
|
||
def rollup_prodi(tahun: str | None = None) -> dict:
|
||
"""Ketercapaian tingkat prodi (rumus resmi Bab 10.3) + kelengkapan bukti per CPL/CPMK.
|
||
CPMK prodi & CPL = Σ skor × skor maks ÷ Σ skor maks lintas MK yang menyetor nilai."""
|
||
tahun = tahun or db.tahun_aktif()
|
||
ambang = float(db.ambil_pengaturan()["ambang"])
|
||
k = db.kurikulum()
|
||
semua = db.semua_nilai(tahun)
|
||
|
||
# (mk, skor, mode, skor_maks) per CPMK
|
||
per_cpmk: dict[str, list[tuple[str, float, str, float]]] = {}
|
||
for mk_kode, nilai_data in semua.items():
|
||
peta = db.peta_mk(mk_kode)
|
||
if not peta:
|
||
continue
|
||
hasil = rollup_mk(peta, nilai_data, ambang)
|
||
for kode_cpmk, v in hasil["cpmk"].items():
|
||
if v["skor"] is not None:
|
||
per_cpmk.setdefault(kode_cpmk, []).append(
|
||
(mk_kode, v["skor"], hasil["mode"], v["skor_maks"] or 1.0))
|
||
|
||
cpmk_prodi: dict[str, dict] = {}
|
||
for ckey, info in k["cpmk"].items():
|
||
kode = info.get("kode", ckey)
|
||
entri = per_cpmk.get(kode, [])
|
||
cpmk_prodi[kode] = {
|
||
"kode": kode,
|
||
"cpl": db.daftar_cpl(info.get("cpl")),
|
||
"skor": _rata_tertimbang([(w, sk) for _, sk, _, w in entri]),
|
||
"bobot": sum(w for *_, w in entri),
|
||
"n_pemikul": len(info.get("mk", [])),
|
||
"n_setor": len(entri),
|
||
"ada_agregat": any(m == "agregat" for _, _, m, _ in entri),
|
||
"mk_terlemah": min(entri, key=lambda e: e[1])[:2] if entri else None,
|
||
}
|
||
|
||
cpl_prodi: dict[str, dict] = {}
|
||
for kode_cpl, info in k["cpl"].items():
|
||
pendukung = [c for c in cpmk_prodi.values() if kode_cpl in c["cpl"]]
|
||
ternilai = [c for c in pendukung if c["skor"] is not None]
|
||
skor = _rata_tertimbang([(c["bobot"], c["skor"]) for c in ternilai])
|
||
terlemah = min(ternilai, key=lambda c: c["skor"]) if ternilai else None
|
||
cpl_prodi[kode_cpl] = {
|
||
"kode": kode_cpl,
|
||
"desk": info["desk"],
|
||
"skor": skor,
|
||
"tercapai": (skor is not None and skor >= ambang),
|
||
"n_cpmk": len(pendukung),
|
||
"n_cpmk_ternilai": len(ternilai),
|
||
"n_mk_pemikul": sum(c["n_pemikul"] for c in pendukung),
|
||
"n_mk_setor": sum(c["n_setor"] for c in pendukung),
|
||
"ada_agregat": any(c["ada_agregat"] for c in ternilai),
|
||
"cpmk_terlemah": terlemah["kode"] if terlemah else None,
|
||
"mk_terlemah": (terlemah["mk_terlemah"] if terlemah else None),
|
||
}
|
||
|
||
return {"cpl": cpl_prodi, "cpmk": cpmk_prodi, "ambang": ambang,
|
||
"n_mk_setor": len(semua), "tahun": tahun, "metode": "skor_maks"}
|
||
|
||
|
||
# ═══════════════ LOOP 2: CAPAIAN CPL PER MAHASISWA & ANGKATAN ═══════════════
|
||
#
|
||
# Metode PROPORSI dengan skor maks resmi (Dokumen Kurikulum 2026 Bab 10.3; Klinik 3 APTIKOM):
|
||
# CPL mahasiswa = Σ (skor CPMK di MK × skor maks CPMK di MK) ÷ Σ skor maks, lintas seluruh
|
||
# MK pendukung yang sudah dinilai — setara "Σ skor ÷ Σ skor maksimal".
|
||
# - skor CPMK di MK = rata-rata Sub-CPMK-nya, tertimbang bobot kisi-kisi RPS bila ada.
|
||
# - MK yang diulang: dipakai nilai tahun ajaran TERAKHIR.
|
||
# - kelengkapan bukti = Σ skor maks yang sudah dinilai ÷ total skor maks CPL (Tabel 10.3);
|
||
# < 50 % → status "bukti belum cukup".
|
||
# - data mode agregat (rata-rata kelas) tidak bisa dipakai per mahasiswa.
|
||
|
||
BATAS_BUKTI = 0.5
|
||
|
||
|
||
def _urut_tahun(t: str) -> tuple:
|
||
"""'2025/2026 Ganjil' < '2025/2026 Genap' < '2026/2027 Ganjil'."""
|
||
awal = t.split("/")[0].strip()
|
||
return (int(awal) if awal.isdigit() else 0, 1 if "genap" in t.lower() else 0, t)
|
||
|
||
|
||
def nilai_per_mahasiswa() -> dict[str, dict[str, dict]]:
|
||
"""{npm: {mk: {'tahun', 'skor': {sub: x}}}} — MK diulang memakai tahun terakhir."""
|
||
out: dict[str, dict[str, dict]] = {}
|
||
for tahun in sorted(db.daftar_tahun(), key=_urut_tahun):
|
||
for mk, data in db.semua_nilai(tahun).items():
|
||
if data.get("mode") != "per_mahasiswa":
|
||
continue
|
||
for m in data.get("mahasiswa", []):
|
||
npm = (m.get("npm") or "").strip()
|
||
skor = {s: float(v) for s, v in (m.get("skor") or {}).items()
|
||
if v is not None}
|
||
if npm and skor:
|
||
out.setdefault(npm, {})[mk] = {"tahun": tahun, "skor": skor}
|
||
return out
|
||
|
||
|
||
def _bobot_mk(mk: str, tahun: str, cache: dict) -> dict[str, float]:
|
||
kunci = (mk, tahun)
|
||
if kunci not in cache:
|
||
rps = db.ambil_rps(mk, tahun) or db.ambil_rps(mk)
|
||
cache[kunci] = bobot_sub_dari_rps(rps["data"] if rps else None)
|
||
return cache[kunci]
|
||
|
||
|
||
def _pemikul_cpl() -> dict[str, list[str]]:
|
||
"""{CPL: [kode MK pemikul]} dari pemetaan kurikulum."""
|
||
out: dict[str, list[str]] = {}
|
||
for kode, mk in db.kurikulum()["mk"].items():
|
||
for cpl in mk.get("cpls", {}):
|
||
out.setdefault(cpl, []).append(kode)
|
||
return out
|
||
|
||
|
||
def _sks(mk: str, sks: dict) -> float:
|
||
try:
|
||
return float((sks.get(mk) or {}).get("sks") or 0) or 1.0
|
||
except (TypeError, ValueError):
|
||
return 1.0
|
||
|
||
|
||
def capaian_mahasiswa(npm: str, rekaman: dict | None = None,
|
||
cache: dict | None = None) -> dict:
|
||
"""Capaian CPL & CPMK satu mahasiswa (rumus resmi) + jejak MK penyumbang."""
|
||
rekaman = rekaman if rekaman is not None else nilai_per_mahasiswa().get(npm, {})
|
||
cache = cache if cache is not None else {}
|
||
ambang = float(db.ambil_pengaturan()["ambang"])
|
||
k = db.kurikulum()
|
||
pemikul = _pemikul_cpl()
|
||
total_cpl = db.skor_maks_cpl()
|
||
|
||
cpl_acc: dict[str, list[float]] = {} # cpl → [Σ w·s, Σ w]
|
||
cpmk_acc: dict[str, list[float]] = {} # cpmk → [Σ w·s, Σ w]
|
||
jejak: dict[str, dict[str, dict]] = {} # cpl → mk → {ws, w, tahun, cpmk}
|
||
for mk, rec in rekaman.items():
|
||
peta = db.peta_mk(mk)
|
||
if not peta:
|
||
continue
|
||
bobot_sub = _bobot_mk(mk, rec["tahun"], cache)
|
||
resmi = _bobot_resmi(mk, [c["kode"] for c in peta["cpmks"]])
|
||
for c in peta["cpmks"]:
|
||
skor = _rata_tertimbang([((bobot_sub.get(s["kode"]) if bobot_sub else 1.0) or 1.0,
|
||
rec["skor"].get(s["kode"])) for s in c["subs"]])
|
||
if skor is None:
|
||
continue
|
||
w = resmi.get(c["kode"]) or 0.0
|
||
if not w:
|
||
continue
|
||
a = cpmk_acc.setdefault(c["kode"], [0.0, 0.0])
|
||
a[0] += w * skor
|
||
a[1] += w
|
||
for cpl in c["cpl"]:
|
||
a = cpl_acc.setdefault(cpl, [0.0, 0.0])
|
||
a[0] += w * skor
|
||
a[1] += w
|
||
j = jejak.setdefault(cpl, {}).setdefault(
|
||
mk, {"ws": 0.0, "w": 0.0, "tahun": rec["tahun"], "cpmk": set()})
|
||
j["ws"] += w * skor
|
||
j["w"] += w
|
||
j["cpmk"].add(c["kode"])
|
||
|
||
cpl_out = {}
|
||
for kode_cpl in sorted(k["cpl"]):
|
||
acc = cpl_acc.get(kode_cpl)
|
||
skor = acc[0] / acc[1] if acc and acc[1] else None
|
||
mk_pemikul = pemikul.get(kode_cpl, [])
|
||
mk_dinilai = [m for m in mk_pemikul if m in jejak.get(kode_cpl, {})]
|
||
total = total_cpl.get(kode_cpl) or 0.0
|
||
bukti = min(1.0, (acc[1] if acc else 0.0) / total) if total else 0.0
|
||
if skor is None:
|
||
status = "belum"
|
||
elif bukti < BATAS_BUKTI:
|
||
status = "bukti_kurang"
|
||
else:
|
||
status = "tercapai" if skor >= ambang else "tidak"
|
||
rincian = sorted(
|
||
({"mk": m, "tahun": j["tahun"], "skor": j["ws"] / j["w"], "skor_maks": j["w"],
|
||
"cpmk": sorted(j["cpmk"])}
|
||
for m, j in jejak.get(kode_cpl, {}).items() if j["w"]),
|
||
key=lambda r: r["skor"])
|
||
cpl_out[kode_cpl] = {
|
||
"kode": kode_cpl, "desk": k["cpl"][kode_cpl]["desk"], "skor": skor,
|
||
"bukti": bukti, "skor_maks_dinilai": acc[1] if acc else 0.0, "skor_maks_total": total,
|
||
"n_mk_pemikul": len(mk_pemikul),
|
||
"n_mk_dinilai": len(mk_dinilai), "status": status, "rincian": rincian,
|
||
}
|
||
cpmk_out = {c: {"skor": a[0] / a[1]} for c, a in cpmk_acc.items() if a[1]}
|
||
return {"npm": npm, "angkatan": db.angkatan(npm), "cpl": cpl_out,
|
||
"cpmk": cpmk_out, "ambang": ambang,
|
||
"n_tercapai": sum(1 for c in cpl_out.values() if c["status"] == "tercapai"),
|
||
"n_terukur": sum(1 for c in cpl_out.values() if c["skor"] is not None),
|
||
"n_cpl": len(cpl_out), "n_mk": len(rekaman)}
|
||
|
||
|
||
def perjalanan_cpl(c: dict) -> dict:
|
||
"""Perjalanan CPL mahasiswa sepanjang kurikulum (untuk motivasi), per CPL:
|
||
- terkumpul: poin yang sudah diraih ÷ total skor maks CPL × 100 (tumbuh tiap semester)
|
||
- potensi : terkumpul + seluruh skor maks MK yang belum dinilai (bila nanti sempurna)
|
||
- terbuka : MK pemikul yang belum dinilai, urut poin terbesar."""
|
||
k = db.kurikulum()
|
||
nama_mk = {kode: m["nama"] for kode, m in k["mk"].items()}
|
||
cpmk_cpl = {kode: db.daftar_cpl(v.get("cpl")) for kode, v in k["cpmk"].items()}
|
||
out, raih, total_semua, sisa_semua = {}, 0.0, 0.0, 0.0
|
||
for kode, v in c["cpl"].items():
|
||
total = v.get("skor_maks_total") or 0.0
|
||
dinilai = v.get("skor_maks_dinilai") or 0.0
|
||
diraih = (v["skor"] or 0.0) * dinilai / 100.0
|
||
sudah = {r["mk"] for r in v.get("rincian", [])}
|
||
terbuka = []
|
||
for mk in _pemikul_cpl().get(kode, []):
|
||
if mk in sudah:
|
||
continue
|
||
poin = sum(s for cp, s in db.skor_maks_mk(mk).items() if kode in cpmk_cpl.get(cp, []))
|
||
if poin:
|
||
terbuka.append({"mk": mk, "nama": nama_mk.get(mk, mk), "poin": poin,
|
||
"semester": (db.sks_mk().get(mk) or {}).get("semester")})
|
||
terbuka.sort(key=lambda t: -t["poin"])
|
||
sisa = sum(t["poin"] for t in terbuka)
|
||
terkumpul = 100.0 * diraih / total if total else 0.0
|
||
potensi = 100.0 * (diraih + sisa) / total if total else 0.0
|
||
out[kode] = {"kode": kode, "terkumpul": terkumpul, "potensi": min(potensi, 100.0),
|
||
"terbuka": terbuka, "sisa_poin": sisa, "total": total,
|
||
"bisa_ambang": potensi >= c["ambang"]}
|
||
raih, total_semua, sisa_semua = raih + diraih, total_semua + total, sisa_semua + sisa
|
||
return {"cpl": out,
|
||
"terkumpul": 100.0 * raih / total_semua if total_semua else 0.0,
|
||
"potensi": 100.0 * (raih + sisa_semua) / total_semua if total_semua else 0.0,
|
||
"n_mk_terbuka": len({t["mk"] for v in out.values() for t in v["terbuka"]})}
|
||
|
||
|
||
def capaian_semua() -> dict[str, dict]:
|
||
"""Capaian seluruh mahasiswa yang punya nilai per mahasiswa (sekali hitung)."""
|
||
rek = nilai_per_mahasiswa()
|
||
cache: dict = {}
|
||
return {npm: capaian_mahasiswa(npm, r, cache) for npm, r in rek.items()}
|
||
|
||
|
||
def rekap_kelompok(capaian: list[dict]) -> dict:
|
||
"""Ringkasan CPL sekelompok mahasiswa (angkatan / perwalian)."""
|
||
if not capaian:
|
||
return {"n": 0, "cpl": {}, "ambang": float(db.ambil_pengaturan()["ambang"])}
|
||
ambang = capaian[0]["ambang"]
|
||
out = {}
|
||
for kode in capaian[0]["cpl"]:
|
||
skor = [c["cpl"][kode]["skor"] for c in capaian
|
||
if c["cpl"][kode]["skor"] is not None]
|
||
cukup = [c for c in capaian if c["cpl"][kode]["status"] in ("tercapai", "tidak")]
|
||
tuntas = sum(1 for c in cukup if c["cpl"][kode]["status"] == "tercapai")
|
||
out[kode] = {
|
||
"rata": _rata(skor),
|
||
"n_skor": len(skor),
|
||
"n_cukup": len(cukup),
|
||
"pct_tuntas": (100.0 * tuntas / len(cukup)) if cukup else None,
|
||
"di_bawah": sum(1 for x in skor if x < ambang),
|
||
}
|
||
return {"n": len(capaian), "cpl": out, "ambang": ambang}
|
||
|
||
|
||
def capaian_angkatan(semua: dict[str, dict] | None = None) -> dict[str, dict]:
|
||
"""{angkatan: rekap_kelompok} untuk semua angkatan yang punya data."""
|
||
semua = semua if semua is not None else capaian_semua()
|
||
per: dict[str, list[dict]] = {}
|
||
for c in semua.values():
|
||
per.setdefault(c["angkatan"] or "?", []).append(c)
|
||
return {a: rekap_kelompok(cs) for a, cs in sorted(per.items())}
|
||
|
||
|
||
STATUS_WALI = {
|
||
"perhatian": ("Perlu perhatian", "danger", "alert-triangle"),
|
||
"awal": ("Bukti belum cukup", "warning", "hourglass"),
|
||
"jalur": ("Sesuai jalur", "success", "circle-check"),
|
||
"belum": ("Belum ada nilai", "secondary", "clock"),
|
||
}
|
||
|
||
|
||
def status_wali(c: dict) -> str:
|
||
"""perhatian: ada CPL < ambang · awal: belum ada yang di bawah ambang tetapi sebagian CPL
|
||
masih kurang bukti · jalur: semua CPL terukur tercapai dengan bukti cukup · belum: tanpa nilai."""
|
||
if not c["n_terukur"]:
|
||
return "belum"
|
||
if berisiko(c):
|
||
return "perhatian"
|
||
if any(v["status"] == "bukti_kurang" for v in c["cpl"].values()):
|
||
return "awal"
|
||
return "jalur"
|
||
|
||
|
||
def berisiko(c: dict) -> bool:
|
||
"""Perlu perhatian: ada CPL dengan skor di bawah ambang."""
|
||
return any(v["skor"] is not None and v["skor"] < c["ambang"]
|
||
for v in c["cpl"].values())
|
||
|
||
|
||
def _fmt(x: float) -> str:
|
||
return f"{x:.1f}".replace(".", ",")
|
||
|
||
|
||
def wawasan_mahasiswa(c: dict, nama_mk: dict[str, str]) -> str:
|
||
"""Kalimat ringkas raport: capaian + CPL terlemah + penyumbangnya."""
|
||
terukur = [v for v in c["cpl"].values() if v["skor"] is not None]
|
||
if not terukur:
|
||
return "Belum ada nilai per Sub-CPMK yang tercatat."
|
||
lemah = min(terukur, key=lambda v: v["skor"])
|
||
kal = f"{c['n_tercapai']} dari {c['n_cpl']} CPL tercapai"
|
||
kurang = sum(1 for v in c["cpl"].values() if v["status"] == "bukti_kurang")
|
||
if kurang:
|
||
kal += f"; {kurang} CPL masih kurang bukti"
|
||
kal += f". Terendah {lemah['kode']} ({_fmt(lemah['skor'])})"
|
||
if lemah["rincian"]:
|
||
mk = lemah["rincian"][0]["mk"]
|
||
kal += f", penyumbang terlemah {nama_mk.get(mk, mk)}"
|
||
return kal + "."
|
||
|
||
|
||
def wawasan_prodi(hasil: dict, nama_mk: dict[str, str]) -> str:
|
||
"""Kalimat ringkas ketercapaian CPL prodi (Loop 1) untuk judul kartu Analisis."""
|
||
terukur = [c for c in hasil["cpl"].values() if c["skor"] is not None]
|
||
if not terukur:
|
||
return "Belum ada CPL yang terukur — menunggu MK pertama menyetor nilai."
|
||
rendah = [c for c in terukur if not c["tercapai"]]
|
||
if not rendah:
|
||
return f"Semua {len(terukur)} CPL terukur berada di atas ambang."
|
||
t = min(rendah, key=lambda c: c["skor"])
|
||
kal = (f"{len(rendah)} dari {len(terukur)} CPL terukur di bawah ambang — "
|
||
f"terendah {t['kode']} ({_fmt(t['skor'])})")
|
||
if t.get("mk_terlemah"):
|
||
mk = t["mk_terlemah"][0]
|
||
kal += f", penyumbang terlemah {nama_mk.get(mk, mk)}"
|
||
return kal + "."
|