fjarsra commited on
Commit
24b202b
·
verified ·
1 Parent(s): 5868a56

Update app/services/psych_service.py

Browse files
Files changed (1) hide show
  1. app/services/psych_service.py +96 -96
app/services/psych_service.py CHANGED
@@ -1,97 +1,97 @@
1
- # app/services/psych_service.py
2
- from typing import Dict
3
-
4
- # Bank Soal Psikologis (Bisa ditambah nanti)
5
- PSYCH_QUESTIONS = [
6
- {
7
- "id": 1,
8
- "question": "Mana kegiatan yang paling relate denganmu di pagi hari?",
9
- "options": {
10
- "A": "Baca atau lihat info viral dari berbagai sumber",
11
- "B": "Coret-coret atau menulis di buku"
12
- },
13
- "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
14
- },
15
- {
16
- "id": 2,
17
- "question": "JJika sedang menghadapi masalah, cara mana yang paling mirip denganmu?",
18
- "options": {
19
- "A": "Cari tahu masalahnya dari berbagai macam sudut pandang",
20
- "B": "Ngobrol dengan teman untuk mendapatkan ide baru"
21
- },
22
- "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
23
- },
24
- {
25
- "id": 3,
26
- "question": "Kalau lagi bermain sosial media, mana aktivitas yang paling relate denganmu?",
27
- "options": {
28
- "A": "Stalking akun-akun yang suka share fakta-fakta seru",
29
- "B": "Share-share postingan teman sambil comment"
30
- },
31
- "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
32
- },
33
- {
34
- "id": 4,
35
- "question": "Nah, kalau lagi liburan, kegiatan mana yang paling bikin kamu excited?",
36
- "options": {
37
- "A": "Mencari review tempat yang akan dikunjungi",
38
- "B": "Membuat konten blog atau vlog tentang petualangan liburan"
39
- },
40
- "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
41
- },
42
- {
43
- "id": 5,
44
- "question": "Kalau lagi kerja bareng tim, mana peran yang paling mirip dengamu?",
45
- "options": {
46
- "A": "Jadi orang yang bantu tim ngambil keputusan dengan analisis situasi",
47
- "B": "Jadi orang yang bikin presentasi buat menyampaikan ide-ide tim"
48
- },
49
- "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
50
- }
51
- ]
52
-
53
- class PsychService:
54
- def get_all_questions(self):
55
- """Mengembalikan soal tanpa kunci jawaban (untuk frontend)"""
56
- return [
57
- {
58
- "id": q["id"],
59
- "question": q["question"],
60
- "options": q["options"]
61
- }
62
- for q in PSYCH_QUESTIONS
63
- ]
64
-
65
- def calculate_result(self, user_answers: Dict[int, str]):
66
- """
67
- Menghitung skor berdasarkan jawaban user.
68
- user_answers contoh: {1: "A", 2: "B"}
69
- """
70
- scores = {"AI Engineer": 0, "Front-End Web Developer": 0}
71
-
72
- # Simpan trait kepribadian user untuk dikirim ke LLM nanti
73
- user_traits = []
74
-
75
- for q in PSYCH_QUESTIONS:
76
- q_id = q["id"]
77
- user_choice = user_answers.get(q_id) # "A" atau "B"
78
-
79
- if user_choice and user_choice in q["role_mapping"]:
80
- # 1. Tambah Skor
81
- role = q["role_mapping"][user_choice]
82
- scores[role] += 1
83
-
84
- # 2. Catat trait (pilihan user) untuk konteks LLM
85
- chosen_text = q["options"][user_choice]
86
- user_traits.append(f"- Lebih suka: {chosen_text}")
87
-
88
- # Tentukan Pemenang
89
- winner_role = max(scores, key=scores.get)
90
-
91
- return {
92
- "winner": winner_role,
93
- "scores": scores,
94
- "traits": user_traits
95
- }
96
-
97
  psych_service = PsychService()
 
1
+ # app/services/psych_service.py
2
+ from typing import Dict
3
+
4
+ # Bank Soal Psikologis (Bisa ditambah nanti)
5
+ PSYCH_QUESTIONS = [
6
+ {
7
+ "id": 1,
8
+ "question": "Mana kegiatan yang paling relate denganmu di pagi hari?",
9
+ "options": {
10
+ "A": "Baca atau lihat info viral dari berbagai sumber",
11
+ "B": "Coret-coret atau menulis di buku"
12
+ },
13
+ "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
14
+ },
15
+ {
16
+ "id": 2,
17
+ "question": "Jika sedang menghadapi masalah, cara mana yang paling mirip denganmu?",
18
+ "options": {
19
+ "A": "Cari tahu masalahnya dari berbagai macam sudut pandang",
20
+ "B": "Ngobrol dengan teman untuk mendapatkan ide baru"
21
+ },
22
+ "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
23
+ },
24
+ {
25
+ "id": 3,
26
+ "question": "Kalau lagi bermain sosial media, mana aktivitas yang paling relate denganmu?",
27
+ "options": {
28
+ "A": "Stalking akun-akun yang suka share fakta-fakta seru",
29
+ "B": "Share-share postingan teman sambil comment"
30
+ },
31
+ "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
32
+ },
33
+ {
34
+ "id": 4,
35
+ "question": "Nah, kalau lagi liburan, kegiatan mana yang paling bikin kamu excited?",
36
+ "options": {
37
+ "A": "Mencari review tempat yang akan dikunjungi",
38
+ "B": "Membuat konten blog atau vlog tentang petualangan liburan"
39
+ },
40
+ "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
41
+ },
42
+ {
43
+ "id": 5,
44
+ "question": "Kalau lagi kerja bareng tim, mana peran yang paling mirip dengamu?",
45
+ "options": {
46
+ "A": "Jadi orang yang bantu tim ngambil keputusan dengan analisis situasi",
47
+ "B": "Jadi orang yang bikin presentasi buat menyampaikan ide-ide tim"
48
+ },
49
+ "role_mapping": {"A": "AI Engineer", "B": "Front-End Web Developer"}
50
+ }
51
+ ]
52
+
53
+ class PsychService:
54
+ def get_all_questions(self):
55
+ """Mengembalikan soal tanpa kunci jawaban (untuk frontend)"""
56
+ return [
57
+ {
58
+ "id": q["id"],
59
+ "question": q["question"],
60
+ "options": q["options"]
61
+ }
62
+ for q in PSYCH_QUESTIONS
63
+ ]
64
+
65
+ def calculate_result(self, user_answers: Dict[int, str]):
66
+ """
67
+ Menghitung skor berdasarkan jawaban user.
68
+ user_answers contoh: {1: "A", 2: "B"}
69
+ """
70
+ scores = {"AI Engineer": 0, "Front-End Web Developer": 0}
71
+
72
+ # Simpan trait kepribadian user untuk dikirim ke LLM nanti
73
+ user_traits = []
74
+
75
+ for q in PSYCH_QUESTIONS:
76
+ q_id = q["id"]
77
+ user_choice = user_answers.get(q_id) # "A" atau "B"
78
+
79
+ if user_choice and user_choice in q["role_mapping"]:
80
+ # 1. Tambah Skor
81
+ role = q["role_mapping"][user_choice]
82
+ scores[role] += 1
83
+
84
+ # 2. Catat trait (pilihan user) untuk konteks LLM
85
+ chosen_text = q["options"][user_choice]
86
+ user_traits.append(f"- Lebih suka: {chosen_text}")
87
+
88
+ # Tentukan Pemenang
89
+ winner_role = max(scores, key=scores.get)
90
+
91
+ return {
92
+ "winner": winner_role,
93
+ "scores": scores,
94
+ "traits": user_traits
95
+ }
96
+
97
  psych_service = PsychService()