@@ -15,6 +15,8 @@ public class FinanceMbtiScoringService {
1515
1616 private final FinanceMbtiProvider typeInfoProvider ;
1717
18+ private static final double BASE_SCORE = 10.0 ;
19+
1820 public record ScoreResult (
1921 int anxietyScore ,
2022 int stabilityScore ,
@@ -28,38 +30,42 @@ public record ScoreResult(
2830 ) {}
2931
3032 public ScoreResult score (List <MbtiQuestion > questions , Map <Long , Integer > answersByQuestionId ) {
31- int anxiety = 0 , stability = 0 ;
32- int impulse = 0 , planning = 0 ;
33- int aggressive = 0 , conservative = 0 ;
34- int avoidance = 0 , rational = 0 ;
33+ // 모든 점수를 BASE_SCORE(10.0)에서 시작하도록 변경
34+ double anxiety = BASE_SCORE , stability = BASE_SCORE ;
35+ double impulse = BASE_SCORE , planning = BASE_SCORE ;
36+ double aggressive = BASE_SCORE , conservative = BASE_SCORE ;
37+ double avoidance = BASE_SCORE , rational = BASE_SCORE ;
3538
3639 for (MbtiQuestion q : questions ) {
3740 Integer choice = answersByQuestionId .get (q .getId ());
3841 if (choice == null ) continue ;
3942
40- int w = 3 - choice ; // 1~5 -> +2,+1,0,-1,-2
43+ // DB에 추가한 가중치(weight) 적용 (없을 경우 1)
44+ double weight = (q .getWeight () != null ) ? q .getWeight () : 1.0 ;
45+ double point = (3 - choice ) * weight ;
4146
4247 MbtiQuestionCategory cat = q .getCategory ();
4348 switch (cat ) {
44- case ANXIETY_STABILITY -> { if (w >= 0 ) anxiety += w ; else stability += -w ; }
45- case IMPULSE_PLANNING -> { if (w >= 0 ) impulse += w ; else planning += -w ; }
46- case AGGRESSIVE_CONSERVATIVE -> { if (w >= 0 ) aggressive += w ; else conservative += -w ; }
47- case AVOIDANCE_RATIONAL -> { if (w >= 0 ) avoidance += w ; else rational += -w ; }
49+ case ANXIETY_STABILITY -> { if (point >= 0 ) anxiety += point ; else stability += -point ; }
50+ case IMPULSE_PLANNING -> { if (point >= 0 ) impulse += point ; else planning += -point ; }
51+ case AGGRESSIVE_CONSERVATIVE -> { if (point >= 0 ) aggressive += point ; else conservative += -point ; }
52+ case AVOIDANCE_RATIONAL -> { if (point >= 0 ) avoidance += point ; else rational += -point ; }
4853 }
4954 }
5055
56+ // 최종 결과 타입 결정 (실수를 정수로 캐스팅)
5157 MbtiType type = MbtiType .fromScores (
52- anxiety , stability ,
53- impulse , planning ,
54- aggressive , conservative ,
55- avoidance , rational
58+ ( int ) anxiety , ( int ) stability ,
59+ ( int ) impulse , ( int ) planning ,
60+ ( int ) aggressive , ( int ) conservative ,
61+ ( int ) avoidance , ( int ) rational
5662 );
5763
5864 return new ScoreResult (
59- anxiety , stability ,
60- impulse , planning ,
61- aggressive , conservative ,
62- avoidance , rational ,
65+ ( int ) anxiety , ( int ) stability ,
66+ ( int ) impulse , ( int ) planning ,
67+ ( int ) aggressive , ( int ) conservative ,
68+ ( int ) avoidance , ( int ) rational ,
6369 type
6470 );
6571 }
0 commit comments