87 lines
3.7 KiB
Python
87 lines
3.7 KiB
Python
import sys
|
|
import pandas as pd
|
|
sys.path.append('Backend')
|
|
|
|
from app.parsers.column_finder import find_column, get_value
|
|
from app.parsers.mappings import (
|
|
YEAR_CONFIG, IDENTITAS_MAPPING, PEKERJAAN_MAPPING, STUDI_LANJUT_MAPPING,
|
|
KESESUAIAN_MAPPING, KOMPETENSI_LULUS_MAPPING, KOMPETENSI_SAAT_INI_MAPPING,
|
|
METODE_PEMBELAJARAN_MAPPING, WAKTU_CARI_KERJA_MAPPING, CARA_CARI_KERJA_MAPPING,
|
|
LAMARAN_KEAKTIFAN_MAPPING, KESESUAIAN_PEKERJAAN_MAPPING, get_field_code
|
|
)
|
|
from app.parsers.converters import konversi_jawaban, parse_2024_value
|
|
|
|
all_mapping = {}
|
|
all_mapping.update(IDENTITAS_MAPPING)
|
|
all_mapping.update(PEKERJAAN_MAPPING)
|
|
all_mapping.update(STUDI_LANJUT_MAPPING)
|
|
all_mapping.update(KESESUAIAN_MAPPING)
|
|
all_mapping.update(KOMPETENSI_LULUS_MAPPING)
|
|
all_mapping.update(KOMPETENSI_SAAT_INI_MAPPING)
|
|
all_mapping.update(METODE_PEMBELAJARAN_MAPPING)
|
|
all_mapping.update(WAKTU_CARI_KERJA_MAPPING)
|
|
all_mapping.update(CARA_CARI_KERJA_MAPPING)
|
|
all_mapping.update(LAMARAN_KEAKTIFAN_MAPPING)
|
|
all_mapping.update(KESESUAIAN_PEKERJAAN_MAPPING)
|
|
|
|
years = ['2019', '2020', '2021', '2022', '2023']
|
|
|
|
for yr in years:
|
|
fpath = f'Data_Tracerstudy/Data_{yr}_Tracer_study.csv'
|
|
df = pd.read_csv(fpath, sep=';', encoding='utf-8-sig')
|
|
source_cols = list(df.columns)
|
|
|
|
print("=" * 60)
|
|
print(f"ANALISIS DATA TAHUN {yr} (Total: {len(df)} rows, {len(source_cols)} cols)")
|
|
print("=" * 60)
|
|
|
|
# 1. Cek baris yang skip (terutama 2021)
|
|
nim_col = find_column(source_cols, IDENTITAS_MAPPING['nim'])
|
|
skipped_indices = []
|
|
for idx, row in df.iterrows():
|
|
nim = get_value(row, source_cols, IDENTITAS_MAPPING['nim'], '')
|
|
if not nim or str(nim).strip() in ['', 'nan', 'none']:
|
|
skipped_indices.append(idx)
|
|
if skipped_indices:
|
|
print(f"[!] SKIPPED ROWS ({len(skipped_indices)} baris): index {skipped_indices}")
|
|
for sidx in skipped_indices:
|
|
print(f" Sample row {sidx}: {df.iloc[sidx].dropna().to_dict()}")
|
|
else:
|
|
print(f"[*] Tidak ada baris yang diskip berdasarkan NIM.")
|
|
|
|
# 2. Cek pemetaan kolom ke all_mapping
|
|
unmapped_fields = []
|
|
mapped_fields = {}
|
|
for field, possible_cols in all_mapping.items():
|
|
found = find_column(source_cols, possible_cols)
|
|
if found:
|
|
mapped_fields[field] = found
|
|
else:
|
|
unmapped_fields.append((field, possible_cols[0] if possible_cols else ''))
|
|
|
|
print(f"\n[*] Total fields di mapping: {len(all_mapping)}")
|
|
print(f"[*] Berhasil dimap ke kolom CSV: {len(mapped_fields)}")
|
|
print(f"[*] TIDAK BERHASIL DIMAP ({len(unmapped_fields)} fields):")
|
|
for uf, fc in unmapped_fields:
|
|
# cari apakah kodenya ada di source_cols
|
|
code = get_field_code(uf, all_mapping)
|
|
similar = [c for c in source_cols if code and code.lower() in c.lower()]
|
|
print(f" - {uf} (kode: {code}): mirip di CSV -> {similar}")
|
|
|
|
# 3. Cek kolom spesifik yang user sebutkan:
|
|
# kerja_tidak_sesuai_2, cari_melamar_tanpa_lowongan
|
|
print(f"\n[*] Pengecekan Khusus Field Target:")
|
|
targets = ['kerja_tidak_sesuai_1', 'kerja_tidak_sesuai_2', 'cari_iklan', 'cari_melamar_tanpa_lowongan', 'cari_bursa_pameran']
|
|
for t in targets:
|
|
col = mapped_fields.get(t)
|
|
code = get_field_code(t, all_mapping)
|
|
if col:
|
|
sample_raw = df[col].dropna().unique()
|
|
print(f" {t} ({code}) -> col '{col}': raw unique values = {sample_raw[:5]}")
|
|
# Cek konversi
|
|
conv_samples = [(v, konversi_jawaban(code, v)) for v in sample_raw[:3]]
|
|
print(f" Hasil konversi: {conv_samples}")
|
|
else:
|
|
print(f" {t} ({code}) -> TIDAK DITEMUKAN DI CSV!")
|
|
print()
|