DawnC commited on
Commit
eb7662c
1 Parent(s): 7409de7

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +49 -52
scoring_calculation_system.py CHANGED
@@ -1469,80 +1469,77 @@ def calculate_final_weighted_score(
1469
  adaptability_bonus: float
1470
  ) -> float:
1471
  """
1472
- 優化的最終分數計算系統
1473
  """
1474
- # 1. 基礎分數計算 - 使用更極端的權重
1475
  base_weights = {
1476
- 'space': 0.35, # 大幅提高空間權重
1477
- 'exercise': 0.25,
1478
  'grooming': 0.15,
1479
  'experience': 0.15,
1480
  'health': 0.07,
1481
- 'noise': 0.03 # 降低噪音的基礎權重
1482
  }
 
 
 
1483
 
1484
- # 2. 條件特殊化評分
1485
- condition_bonus = calculate_condition_bonus(breed_info, user_prefs, scores)
1486
-
1487
- # 3. 計算加權基礎分數
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1488
  weighted_base = sum(score * base_weights[category] for category, score in scores.items())
1489
 
1490
- # 4. 品種特性加成
1491
  breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
1492
 
1493
- # 5. 最終分數計算 - 改變權重分配
1494
- raw_score = (weighted_base * 0.60) + (breed_bonus * 0.25) + (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)
 
1469
  adaptability_bonus: float
1470
  ) -> float:
1471
  """
1472
+ 優化的最終分數計算系統,強化條件變化的影響力
1473
  """
1474
+ # 基礎權重 - 更極端的差異
1475
  base_weights = {
1476
+ 'space': 0.35, # 極度重視空間匹配
1477
+ 'exercise': 0.25, # 重視運動需求
1478
  'grooming': 0.15,
1479
  'experience': 0.15,
1480
  'health': 0.07,
1481
+ 'noise': 0.03
1482
  }
1483
+
1484
+ # 條件特殊化評分
1485
+ special_conditions = 0.0
1486
 
1487
+ # 極端條件判定
1488
+ if user_prefs.living_space == 'apartment':
1489
+ if breed_info['Size'] == 'Large':
1490
+ special_conditions -= 0.35 # 大型犬在公寓極度不適合
1491
+ elif breed_info['Size'] == 'Small':
1492
+ special_conditions += 0.15 # 小型犬在公寓加分
1493
+
1494
+ # 運動需求極端匹配
1495
+ exercise_needs = breed_info.get('Exercise_Needs', 'MODERATE').upper()
1496
+ if user_prefs.exercise_time > 120: # 高運動量
1497
+ if exercise_needs in ['VERY HIGH', 'HIGH']:
1498
+ special_conditions += 0.20
1499
+ elif exercise_needs == 'LOW':
1500
+ special_conditions -= 0.25
1501
+ elif user_prefs.exercise_time < 45: # 低運動量
1502
+ if exercise_needs in ['VERY HIGH', 'HIGH']:
1503
+ special_conditions -= 0.25
1504
+ elif exercise_needs == 'LOW':
1505
+ special_conditions += 0.15
1506
+
1507
+ # 經驗等級極端匹配
1508
+ if user_prefs.experience_level == 'beginner':
1509
+ if breed_info.get('Care_Level') == 'HIGH':
1510
+ special_conditions -= 0.30
1511
+ elif user_prefs.experience_level == 'advanced':
1512
+ if breed_info.get('Care_Level') == 'LOW':
1513
+ special_conditions -= 0.20
1514
+
1515
+ # 計算加權基礎分數
1516
  weighted_base = sum(score * base_weights[category] for category, score in scores.items())
1517
 
1518
+ # 品種特性加成
1519
  breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
1520
 
1521
+ # 最終分數計算
1522
+ raw_score = (weighted_base * 0.65) + (breed_bonus * 0.20) + (adaptability_bonus * 0.10) + (special_conditions * 0.05)
 
 
 
1523
 
1524
+ # 分數轉換 - 使用S型曲線
1525
+ return amplify_score_extreme(raw_score)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1526
 
 
1527
 
1528
  def amplify_score_extreme(score: float) -> float:
1529
  """
1530
+ 使用S型曲線進行分數轉換,加大差異
1531
  """
1532
+ # 基礎範圍
1533
+ base_min = 0.65
1534
+ base_max = 0.95
1535
 
1536
+ # 正規化
1537
  normalized = (score - 0.5) / 0.5
 
1538
 
1539
  # S型曲線轉換
1540
+ sigmoid = 1 / (1 + math.exp(-normalized * 4))
1541
 
1542
  # 映射到目標範圍
1543
  final = base_min + (base_max - base_min) * sigmoid
1544
 
1545
+ return round(min(base_max, max(base_min, final)), 4)