TIF_E41253310/scripts/tests/test_f8_all_years.py

84 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pandas as pd
import glob
import re
def parse_status_pekerjaan_new(status_sp):
if status_sp is None:
return None
sp = str(status_sp).strip().lower()
if sp in ['', 'nan', 'none', '0', '0.0', '-']:
return None
# 1. Cek kode numerik: misal "1", "1 - ...", "... (1)", "2- ..."
code_match = re.search(r'(?:^|\s|\()([1-5])(?:\s*[-–)]|$)', sp)
if code_match:
code = code_match.group(1)
if code == '1':
return 'bekerja'
elif code == '2':
return 'belum_bekerja'
elif code == '3':
return 'wiraswasta'
elif code == '4':
return 'melanjutkan'
elif code == '5':
return 'mencari_kerja'
# 2. Fallback pencocokan teks
if 'tidak kerja' in sp or 'mencari kerja' in sp or 'sedang mencari' in sp:
return 'mencari_kerja'
elif 'belum' in sp:
return 'belum_bekerja'
elif 'wiraswasta' in sp:
return 'wiraswasta'
elif 'melanjutkan' in sp or 'pendidikan' in sp or 'studi' in sp:
return 'melanjutkan'
elif 'bekerja' in sp:
return 'bekerja'
return None
test_cases = [
# 2019-2023 numbers
('1', 'bekerja'),
(1, 'bekerja'),
('2', 'belum_bekerja'),
(2, 'belum_bekerja'),
('3', 'wiraswasta'),
(3, 'wiraswasta'),
('4', 'melanjutkan'),
(4, 'melanjutkan'),
('5', 'mencari_kerja'),
(5, 'mencari_kerja'),
# 2024 format
('1 - Bekerja (full time/part time)', 'bekerja'),
('2 - Belum memungkinkan bekerja', 'belum_bekerja'),
('3 - Wiraswasta', 'wiraswasta'),
('4 - Melanjutkan Pendidikan', 'melanjutkan'),
('5 - Tidak kerja tetapi sedang mencari kerja', 'mencari_kerja'),
# 2025 format
('Bekerja (full time/part time) (1)', 'bekerja'),
('Belum memungkinkan bekerja (2)', 'belum_bekerja'),
('2- Belum memungkinkan bekerja', 'belum_bekerja'),
('Wiraswasta (3)', 'wiraswasta'),
('Melanjutkan Pendidikan (4)', 'melanjutkan'),
('Tidak kerja tetapi sedang mencari kerja (5)', 'mencari_kerja'),
# Edge cases
(None, None),
('', None),
('0', None),
]
all_passed = True
for val, expected in test_cases:
actual = parse_status_pekerjaan_new(val)
if actual != expected:
print(f"FAILED: {repr(val)} -> Got {repr(actual)}, Expected {repr(expected)}")
all_passed = False
else:
print(f"PASSED: {repr(val)} -> {repr(actual)}")
if all_passed:
print("\nALL TEST CASES PASSED 100%!")