dwh_spota: nama kelompok keahlian, bukan ID

getListDataTAMahasiswa mengirim kelompokKeahlian berupa idKK (1..4), sehingga dashboard
menampilkan "1 2 3 4". Load kini ikut menarik getListKK ke raw.spota_kk dan staging
memetakan ID -> nama; daftar cadangan dari tb_kelompok_keahlian SPOTA dipakai bila
getListKK gagal atau bentuk responsnya lain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Power BI Dev
2026-10-20 15:24:30 +07:00
co-authored by Claude Opus 5.5
parent 02a9e6f848
commit ddf7ed0a17
2 changed files with 39 additions and 3 deletions
+20 -1
View File
@@ -85,13 +85,32 @@ def _waktu(v) -> datetime | None:
return None
def _kk_rows() -> list:
"""(id, nama) kelompok keahlian dari getListKK. Bentuk responsnya tidak terdokumentasi, jadi nama kolom
dicari dari beberapa kemungkinan; bila gagal, staging memakai daftar cadangan (lihat dwh_spota_sql.py)."""
try:
data = _spota_get("getListKK.php")
except Exception as exc: # noqa: BLE001 - KK hanya label, jangan gagalkan seluruh load
logger.warning("getListKK tidak terbaca, pakai daftar KK cadangan: %s", exc)
return []
rows = []
for k in data:
if not isinstance(k, dict):
continue
id_kk = next((k[c] for c in ("idKK", "id_kk", "id") if c in k), None)
nama = next((k[c] for c in ("namaKK", "nama_kk", "nama", "name") if c in k), None)
rows.append((_int(id_kk), _teks(nama)))
return rows
def _extract() -> list:
"""(tabel raw, [(kolom, tipe postgres)], baris) dari 4 endpoint SPOTA."""
"""(tabel raw, [(kolom, tipe postgres)], baris) dari 5 endpoint SPOTA."""
ta = _spota_get("getListTugasAkhir.php", {"withoutKep": 1})
data = _spota_get("getListDataTAMahasiswa.php")
mhs = _spota_get("getListMahasiswa.php") # tanpa withHP: nomor HP tidak ikut
dosen = _spota_get("getListDosen.php")
return [
("spota_kk", [("id", "int"), ("nama", "text")], _kk_rows()),
(
"spota_tugas_akhir",
[
+19 -2
View File
@@ -62,7 +62,19 @@ ON CONFLICT (id_ta) DO NOTHING;
STAGING_SQL = r"""
DROP TABLE IF EXISTS staging.spota_topik;
CREATE TABLE staging.spota_topik AS
WITH kk_id AS (
WITH kk_nama AS (
-- getListDataTAMahasiswa mengirim ID KK (tb_kelompok_keahlian.idKK); nama dari getListKK,
-- cadangan dari tabel SPOTA bila endpoint itu tidak terbaca
SELECT id, nama FROM raw.spota_kk WHERE id IS NOT NULL AND nama IS NOT NULL
UNION ALL
SELECT v.id, v.nama
FROM (VALUES (1, 'Computation & Artificial Intelligence'),
(2, 'Networking & Security'),
(3, 'Software Engineering & Mobile Computing'),
(4, 'Information System & Data Spatial')) AS v (id, nama)
WHERE NOT EXISTS (SELECT 1 FROM raw.spota_kk k WHERE k.id = v.id AND k.nama IS NOT NULL)
),
kk_id AS (
SELECT DISTINCT ON (id) id, nullif(trim(kelompok_keahlian), '') AS kk
FROM raw.spota_data_ta
WHERE id IS NOT NULL
@@ -91,11 +103,16 @@ SELECT DISTINCT ON (t.id)
nullif(regexp_replace(t.pemb2, '\s', '', 'g'), '') AS pemb2,
nullif(regexp_replace(t.peng1, '\s', '', 'g'), '') AS peng1,
nullif(regexp_replace(t.peng2, '\s', '', 'g'), '') AS peng2,
CASE WHEN t.keputusan = '1' THEN coalesce(ki.kk, kn.kk) END AS kelompok_keahlian,
CASE WHEN t.keputusan = '1' THEN
CASE WHEN coalesce(ki.kk, kn.kk) ~ '^[0-9]+$'
THEN coalesce(nk.nama, 'KK ' || coalesce(ki.kk, kn.kk))
ELSE coalesce(ki.kk, kn.kk) END
END AS kelompok_keahlian,
t.sidang
FROM raw.spota_tugas_akhir t
LEFT JOIN kk_id ki ON ki.id = t.id
LEFT JOIN kk_nim kn ON kn.nim = upper(t.nim)
LEFT JOIN kk_nama nk ON nk.id::text = coalesce(ki.kk, kn.kk) -- bandingkan teks: cast ::int bisa gagal pada nilai non-angka
WHERE t.id IS NOT NULL AND t.nim IS NOT NULL
ORDER BY t.id;