DawnC commited on
Commit
6248439
1 Parent(s): 0bc770d

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +62 -61
scoring_calculation_system.py CHANGED
@@ -1460,6 +1460,7 @@ def calculate_environmental_fit(breed_info: dict, user_prefs: UserPreferences) -
1460
 
1461
  return min(0.2, adaptability_score)
1462
 
 
1463
  def calculate_final_weighted_score(
1464
  scores: dict,
1465
  user_prefs: UserPreferences,
@@ -1467,81 +1468,81 @@ def calculate_final_weighted_score(
1467
  adaptability_bonus: float
1468
  ) -> float:
1469
  """
1470
- 計算最終加權分數,強化條件變化的影響力
1471
  """
1472
- # 基礎權重設定 - 更極端化
1473
  base_weights = {
1474
- 'space': 0.30, # 提高空間權重
1475
- 'exercise': 0.25, # 提高運動權重
1476
  'grooming': 0.15,
1477
  'experience': 0.15,
1478
- 'health': 0.10,
1479
- 'noise': 0.05
1480
  }
1481
-
1482
- # 條件特殊化加權
1483
- special_conditions = 0.0
1484
-
1485
- # 1. 極端條件加權
1486
- if user_prefs.noise_tolerance == 'low':
1487
- if scores['noise'] < 0.7: # 對低噪音容忍度更嚴格
1488
- special_conditions -= 0.15
1489
-
1490
- if user_prefs.grooming_commitment == 'high':
1491
- if breed_info.get('Grooming Needs', '').upper() == 'HIGH':
1492
- special_conditions += 0.12 # 獎勵高美容需求品種
1493
-
1494
- # 2. 專業度差異化
1495
- if user_prefs.experience_level == 'advanced':
1496
- if breed_info.get('Care Level', '').upper() == 'HIGH':
1497
- special_conditions += 0.15 # 資深者配高難度品種加分
1498
- elif breed_info.get('Care Level', '').upper() == 'LOW':
1499
- special_conditions -= 0.10 # 資深者配低難度品種扣分
1500
-
1501
- # 3. 居住環境極端匹配
1502
- if user_prefs.living_space == 'apartment':
1503
- if breed_info.get('Size', '') == 'Large':
1504
- special_conditions -= 0.20 # 大型犬在公寓嚴重扣分
1505
- elif breed_info.get('Size', '') == 'Small':
1506
- special_conditions += 0.10 # 小型犬在公寓額外加分
1507
-
1508
- # 4. 品種特色加權
1509
- breed_traits = breed_info.get('Temperament', '').lower()
1510
- description = breed_info.get('Description', '').lower()
1511
 
1512
- if user_prefs.exercise_time > 120: # 高運動量使用者
1513
- if 'athletic' in breed_traits or 'energetic' in breed_traits:
1514
- special_conditions += 0.15
1515
- elif user_prefs.exercise_time < 45: # 低運動量使用者
1516
- if 'calm' in breed_traits or 'lazy' in breed_traits:
1517
- special_conditions += 0.12
1518
 
1519
- # 重新計算加權總分
1520
  weighted_base = sum(score * base_weights[category] for category, score in scores.items())
1521
 
1522
- # 品種特性加成
1523
  breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
1524
 
1525
- # 最終分數計算 - 加大特殊條件的影響
1526
- final_score = (weighted_base * 0.65) + (breed_bonus * 0.15) + (adaptability_bonus * 0.10) + (special_conditions * 0.10)
1527
-
1528
- # 分數放大,使差異更明顯
1529
- if final_score > 0.8:
1530
- final_score = 0.8 + (final_score - 0.8) * 1.5
1531
- elif final_score < 0.6:
1532
- final_score = 0.6 - (0.6 - final_score) * 1.5
1533
 
1534
- return round(min(0.95, max(0.45, final_score)), 4)
 
 
 
 
 
 
 
1535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1536
 
1537
- def amplify_score_range(score: float) -> float:
1538
- """擴大分數範圍,使差異更明顯"""
1539
- min_score = 0.40 # 降低最小分數
1540
- max_score = 0.98 # 提高最高分數
 
 
 
1541
 
1542
- # 使用更激進的非線性轉換
1543
  normalized = (score - 0.5) / 0.5
1544
- amplified = math.pow(abs(normalized), 1.3) * math.copysign(1, normalized)
 
 
 
 
 
 
 
 
 
1545
 
1546
- final = min_score + (max_score - min_score) * ((amplified + 1) / 2)
1547
- return max(min_score, min(max_score, final))
 
1460
 
1461
  return min(0.2, adaptability_score)
1462
 
1463
+
1464
  def calculate_final_weighted_score(
1465
  scores: dict,
1466
  user_prefs: UserPreferences,
 
1468
  adaptability_bonus: float
1469
  ) -> float:
1470
  """
1471
+ 優化的最終分數計算系統
1472
  """
1473
+ # 1. 基礎分數計算 - 使用更極端的權重
1474
  base_weights = {
1475
+ 'space': 0.35, # 大幅提高空間權重
1476
+ 'exercise': 0.25,
1477
  'grooming': 0.15,
1478
  'experience': 0.15,
1479
+ 'health': 0.07,
1480
+ 'noise': 0.03 # 降低噪音的基礎權重
1481
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1482
 
1483
+ # 2. 條件特殊化評分
1484
+ condition_bonus = calculate_condition_bonus(breed_info, user_prefs, scores)
 
 
 
 
1485
 
1486
+ # 3. 計算加權基礎分數
1487
  weighted_base = sum(score * base_weights[category] for category, score in scores.items())
1488
 
1489
+ # 4. 品種特性加成
1490
  breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
1491
 
1492
+ # 5. 最終分數計算 - 改變權重分配
1493
+ raw_score = (weighted_base * 0.60) + (breed_bonus * 0.25) +
1494
+ (adaptability_bonus * 0.10) + (condition_bonus * 0.05)
 
 
 
 
 
1495
 
1496
+ # 6. 分數轉換 - 使用更激進的轉換函數
1497
+ return amplify_score_extreme(raw_score)
1498
+
1499
+ def calculate_condition_bonus(breed_info: dict, user_prefs: UserPreferences, scores: dict) -> float:
1500
+ """
1501
+ 計算條件特殊化加分,強化極端條件的影響
1502
+ """
1503
+ bonus = 0.0
1504
 
1505
+ # 居住空間極端匹配
1506
+ if user_prefs.living_space == 'apartment':
1507
+ if breed_info['Size'] == 'Small' and scores['noise'] > 0.8:
1508
+ bonus += 0.25 # 顯著獎勵適合公寓的小型安靜犬種
1509
+ elif breed_info['Size'] in ['Large', 'Giant']:
1510
+ bonus -= 0.35 # 嚴重懲罰大型犬
1511
+
1512
+ # 美容需求匹配
1513
+ if user_prefs.grooming_commitment == 'low':
1514
+ if breed_info.get('Grooming Needs') == 'HIGH':
1515
+ bonus -= 0.30 # 嚴重懲罰高美容需求
1516
+
1517
+ # 經驗等級匹配
1518
+ if user_prefs.experience_level == 'beginner':
1519
+ if breed_info.get('Care Level') == 'HIGH':
1520
+ bonus -= 0.25
1521
+ elif user_prefs.experience_level == 'advanced':
1522
+ if breed_info.get('Care Level') == 'LOW':
1523
+ bonus -= 0.20
1524
+
1525
+ return bonus
1526
 
1527
+ def amplify_score_extreme(score: float) -> float:
1528
+ """
1529
+ 更激進��分數轉換函數
1530
+ """
1531
+ # 基礎範圍調整
1532
+ base_min = 0.65 # 提高最低分
1533
+ base_max = 0.98 # 提高最高分
1534
 
1535
+ # 非線性轉換
1536
  normalized = (score - 0.5) / 0.5
1537
+ amplified = math.pow(abs(normalized), 1.2) * math.copysign(1, normalized)
1538
+
1539
+ # S型曲線轉換
1540
+ sigmoid = 1 / (1 + math.exp(-amplified * 3))
1541
+
1542
+ # 映射到目標範圍
1543
+ final = base_min + (base_max - base_min) * sigmoid
1544
+
1545
+ # 加入隨機微擾動以打破相似分數
1546
+ noise = random.uniform(-0.002, 0.002)
1547
 
1548
+ return round(min(base_max, max(base_min, final + noise)), 4)