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
+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;