DawnC commited on
Commit
e1ee9f9
1 Parent(s): b9f7c90

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +18 -17
scoring_calculation_system.py CHANGED
@@ -1202,31 +1202,32 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
1202
 
1203
  def calculate_weighted_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
1204
  """
1205
- 優化的加權分數計算函數
1206
 
1207
- 主要改進:
1208
- 1. 動態權重調整
1209
- 2. 品種特性加成
1210
- 3. 更平衡的分數分配
 
 
 
1211
  """
1212
  # 基礎權重設定
1213
  base_weights = {
1214
- 'space': 0.25, # 稍微降低空間權重
1215
- 'exercise': 0.20, # 提高運動權重
1216
- 'grooming': 0.15, # 略微提高美容權重
1217
- 'experience': 0.18, # 降低經驗權重,避免過度主導
1218
  'health': 0.12,
1219
- 'noise': 0.10 # 提高噪音權重
1220
  }
1221
 
1222
  # 根據使用者經驗調整權重
1223
  if user_prefs.experience_level == 'beginner':
1224
- # 新手更注重易照顧程度
1225
  base_weights['experience'] *= 1.2
1226
  base_weights['health'] *= 1.1
1227
  base_weights['grooming'] *= 0.9
1228
  elif user_prefs.experience_level == 'advanced':
1229
- # 專家更注重運動和訓練潛力
1230
  base_weights['exercise'] *= 1.2
1231
  base_weights['experience'] *= 0.8
1232
 
@@ -1247,16 +1248,16 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
1247
  total_weight = sum(base_weights.values())
1248
  weights = {k: v/total_weight for k, v in base_weights.items()}
1249
 
1250
- # 計算基礎加權分數
1251
- weighted_base = sum(score * weights[category] for category, score in scores.items())
1252
 
1253
  # 計算品種特性加成
1254
  breed_bonus = calculate_breed_characteristic_bonus(breed_info, user_prefs)
1255
 
1256
  # 混合基礎分數和特性加成
1257
- final_score = (weighted_base * 0.85) + (breed_bonus * 0.15)
1258
 
1259
- return final_score
1260
 
1261
  def calculate_breed_characteristic_bonus(breed_info: dict, user_prefs: UserPreferences) -> float:
1262
  """
@@ -1311,7 +1312,7 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
1311
 
1312
  # 執行計算流程
1313
  penalty = check_critical_issues(scores, breed_info)
1314
- weighted_score = calculate_weighted_score(scores)
1315
  final_score = calculate_final_score(weighted_score, penalty)
1316
 
1317
  # 準備返回結果
 
1202
 
1203
  def calculate_weighted_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
1204
  """
1205
+ 計算加權分數的函數
1206
 
1207
+ Parameters:
1208
+ scores: dict - 包含各項評分的字典
1209
+ user_prefs: UserPreferences - 使用者偏好設定
1210
+ breed_info: dict - 品種資訊
1211
+
1212
+ Returns:
1213
+ float: 加權後的最終分數
1214
  """
1215
  # 基礎權重設定
1216
  base_weights = {
1217
+ 'space': 0.25,
1218
+ 'exercise': 0.20,
1219
+ 'grooming': 0.15,
1220
+ 'experience': 0.18,
1221
  'health': 0.12,
1222
+ 'noise': 0.10
1223
  }
1224
 
1225
  # 根據使用者經驗調整權重
1226
  if user_prefs.experience_level == 'beginner':
 
1227
  base_weights['experience'] *= 1.2
1228
  base_weights['health'] *= 1.1
1229
  base_weights['grooming'] *= 0.9
1230
  elif user_prefs.experience_level == 'advanced':
 
1231
  base_weights['exercise'] *= 1.2
1232
  base_weights['experience'] *= 0.8
1233
 
 
1248
  total_weight = sum(base_weights.values())
1249
  weights = {k: v/total_weight for k, v in base_weights.items()}
1250
 
1251
+ # 計算加權分數
1252
+ weighted_score = sum(score * weights[category] for category, score in scores.items())
1253
 
1254
  # 計算品種特性加成
1255
  breed_bonus = calculate_breed_characteristic_bonus(breed_info, user_prefs)
1256
 
1257
  # 混合基礎分數和特性加成
1258
+ final_score = (weighted_score * 0.85) + (breed_bonus * 0.15)
1259
 
1260
+ return min(0.95, max(0.55, final_score))
1261
 
1262
  def calculate_breed_characteristic_bonus(breed_info: dict, user_prefs: UserPreferences) -> float:
1263
  """
 
1312
 
1313
  # 執行計算流程
1314
  penalty = check_critical_issues(scores, breed_info)
1315
+ weighted_score = calculate_weighted_score(scores, user_prefs, breed_info)
1316
  final_score = calculate_final_score(weighted_score, penalty)
1317
 
1318
  # 準備返回結果