DawnC commited on
Commit
2de2f9d
1 Parent(s): 5fd68e6

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +40 -3
scoring_calculation_system.py CHANGED
@@ -22,7 +22,7 @@ class UserPreferences:
22
  climate: str # "cold", "moderate", "hot"
23
  health_sensitivity: str = "medium"
24
  barking_acceptance: str = None
25
-
26
  training_commitment: str = "medium" # "low", "medium", "high" - 訓練投入程度
27
  living_environment: str = "ground_floor" # "ground_floor", "with_elevator", "walk_up" - 居住環境細節
28
 
@@ -30,6 +30,35 @@ class UserPreferences:
30
  if self.barking_acceptance is None:
31
  self.barking_acceptance = self.noise_tolerance
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  @staticmethod
35
  def calculate_breed_bonus(breed_info: dict, user_prefs: 'UserPreferences') -> float:
@@ -1248,8 +1277,16 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
1248
  adaptability_bonus = calculate_environmental_fit(breed_info, user_prefs)
1249
 
1250
  # 整合最終分數和加成
1251
- final_score = (final_score * 0.9) + (adaptability_bonus * 0.1)
1252
- final_score = amplify_score_extreme(final_score)
 
 
 
 
 
 
 
 
1253
 
1254
  # 更新並返回完整的評分結果
1255
  scores.update({
 
22
  climate: str # "cold", "moderate", "hot"
23
  health_sensitivity: str = "medium"
24
  barking_acceptance: str = None
25
+ size_preference: str = "no_preference" # "no_preference", "small", "medium", "large", "giant"
26
  training_commitment: str = "medium" # "low", "medium", "high" - 訓練投入程度
27
  living_environment: str = "ground_floor" # "ground_floor", "with_elevator", "walk_up" - 居住環境細節
28
 
 
30
  if self.barking_acceptance is None:
31
  self.barking_acceptance = self.noise_tolerance
32
 
33
+ def apply_size_filter(breed_score: float, user_preference: str, breed_size: str) -> float:
34
+ """
35
+ 強過濾機制,基於用戶的體型偏好過濾品種
36
+
37
+ Parameters:
38
+ breed_score (float): 原始品種評分
39
+ user_preference (str): 用戶偏好的體型
40
+ breed_size (str): 品種的實際體型
41
+
42
+ Returns:
43
+ float: 過濾後的評分,如果體型不符合會返回 0
44
+ """
45
+ if user_preference == "no_preference":
46
+ return breed_score
47
+
48
+ # 標準化 size 字串以進行比較
49
+ breed_size = breed_size.lower().strip()
50
+ user_preference = user_preference.lower().strip()
51
+
52
+ # 特殊處理 "varies" 的情況
53
+ if breed_size == "varies":
54
+ return breed_score * 0.5 # 給予一個折扣係數,因為不確定性
55
+
56
+ # 如果用戶有明確體型偏好但品種不符合,返回 0
57
+ if user_preference != breed_size:
58
+ return 0
59
+
60
+ return breed_score
61
+
62
 
63
  @staticmethod
64
  def calculate_breed_bonus(breed_info: dict, user_prefs: 'UserPreferences') -> float:
 
1277
  adaptability_bonus = calculate_environmental_fit(breed_info, user_prefs)
1278
 
1279
  # 整合最終分數和加成
1280
+ combined_score = (final_score * 0.9) + (adaptability_bonus * 0.1)
1281
+
1282
+ # 體型過濾
1283
+ filtered_score = apply_size_filter(
1284
+ breed_score=combined_score,
1285
+ user_preference=user_prefs.size_preference,
1286
+ breed_size=breed_info['Size']
1287
+ )
1288
+
1289
+ final_score = amplify_score_extreme(filtered_score)
1290
 
1291
  # 更新並返回完整的評分結果
1292
  scores.update({