Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +66 -67
scoring_calculation_system.py
CHANGED
@@ -1660,9 +1660,34 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
1660 |
|
1661 |
# 確保最終分數在合理範圍內
|
1662 |
return max(0.15, min(1.0, final_score))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1663 |
|
|
|
|
|
|
|
|
|
|
|
1664 |
|
1665 |
-
|
|
|
|
|
|
|
1666 |
print("\n=== 開始計算品種相容性分數 ===")
|
1667 |
print(f"處理品種: {breed_info.get('Breed', 'Unknown')}")
|
1668 |
print(f"品種信息: {breed_info}")
|
@@ -1701,27 +1726,24 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
1701 |
)
|
1702 |
}
|
1703 |
|
1704 |
-
|
1705 |
-
|
1706 |
-
|
1707 |
-
breed_info=breed_info
|
1708 |
-
)
|
1709 |
-
|
1710 |
# 計算環境適應性加成
|
1711 |
adaptability_bonus = calculate_environmental_fit(breed_info, user_prefs)
|
1712 |
-
|
1713 |
# 整合最終分數和加成
|
1714 |
final_score = (final_score * 0.9) + (adaptability_bonus * 0.1)
|
1715 |
final_score = amplify_score_extreme(final_score)
|
1716 |
-
|
1717 |
# 更新並返回完整的評分結果
|
1718 |
scores.update({
|
1719 |
'overall': final_score,
|
1720 |
'adaptability_bonus': adaptability_bonus
|
1721 |
})
|
1722 |
-
|
1723 |
return scores
|
1724 |
-
|
1725 |
except Exception as e:
|
1726 |
print(f"\n!!!!! 發生嚴重錯誤 !!!!!")
|
1727 |
print(f"錯誤類型: {type(e).__name__}")
|
@@ -1731,29 +1753,6 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
1731 |
return {k: 0.6 for k in ['space', 'exercise', 'grooming', 'experience', 'health', 'noise', 'overall']}
|
1732 |
|
1733 |
|
1734 |
-
def calculate_environmental_fit(breed_info: dict, user_prefs: UserPreferences) -> float:
|
1735 |
-
"""計算品種與環境的適應性加成"""
|
1736 |
-
adaptability_score = 0.0
|
1737 |
-
description = breed_info.get('Description', '').lower()
|
1738 |
-
temperament = breed_info.get('Temperament', '').lower()
|
1739 |
-
|
1740 |
-
# 環境適應性評估
|
1741 |
-
if user_prefs.living_space == 'apartment':
|
1742 |
-
if 'adaptable' in temperament or 'apartment' in description:
|
1743 |
-
adaptability_score += 0.1
|
1744 |
-
if breed_info.get('Size') == 'Small':
|
1745 |
-
adaptability_score += 0.05
|
1746 |
-
elif user_prefs.living_space == 'house_large':
|
1747 |
-
if 'active' in temperament or 'energetic' in description:
|
1748 |
-
adaptability_score += 0.1
|
1749 |
-
|
1750 |
-
# 氣候適應性
|
1751 |
-
if user_prefs.climate in description or user_prefs.climate in temperament:
|
1752 |
-
adaptability_score += 0.05
|
1753 |
-
|
1754 |
-
return min(0.2, adaptability_score)
|
1755 |
-
|
1756 |
-
|
1757 |
# def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
|
1758 |
# """
|
1759 |
# 改進的品種相容性評分系統
|
@@ -1846,6 +1845,39 @@ def calculate_environmental_fit(breed_info: dict, user_prefs: UserPreferences) -
|
|
1846 |
# return min(1.0, max(0.0, (final_score * 0.85) + (breed_bonus * 0.15)))
|
1847 |
|
1848 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1849 |
def calculate_compatibility_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
|
1850 |
"""
|
1851 |
計算品種與使用者的整體相容性分數
|
@@ -1993,39 +2025,6 @@ def calculate_compatibility_score(scores: dict, user_prefs: UserPreferences, bre
|
|
1993 |
|
1994 |
# 確保分數在合理範圍內並保留兩位小數
|
1995 |
return round(max(60.0, min(95.0, final_score)), 2)
|
1996 |
-
|
1997 |
-
|
1998 |
-
# def amplify_score_extreme(score: float) -> float:
|
1999 |
-
# """
|
2000 |
-
# 改進的分數轉換函數
|
2001 |
-
# 提供更大的分數範圍和更明顯的差異
|
2002 |
-
|
2003 |
-
# 轉換邏輯:
|
2004 |
-
# - 極差匹配 (0.0-0.3) -> 60-68%
|
2005 |
-
# - 較差匹配 (0.3-0.5) -> 68-75%
|
2006 |
-
# - 中等匹配 (0.5-0.7) -> 75-85%
|
2007 |
-
# - 良好匹配 (0.7-0.85) -> 85-92%
|
2008 |
-
# - 優秀匹配 (0.85-1.0) -> 92-95%
|
2009 |
-
# """
|
2010 |
-
# if score < 0.3:
|
2011 |
-
# # 極差匹配:快速線性增長
|
2012 |
-
# return 0.60 + (score / 0.3) * 0.08
|
2013 |
-
# elif score < 0.5:
|
2014 |
-
# # 較差匹配:緩慢增長
|
2015 |
-
# position = (score - 0.3) / 0.2
|
2016 |
-
# return 0.68 + position * 0.07
|
2017 |
-
# elif score < 0.7:
|
2018 |
-
# # 中等匹配:穩定線性增長
|
2019 |
-
# position = (score - 0.5) / 0.2
|
2020 |
-
# return 0.75 + position * 0.10
|
2021 |
-
# elif score < 0.85:
|
2022 |
-
# # 良好匹配:加速增長
|
2023 |
-
# position = (score - 0.7) / 0.15
|
2024 |
-
# return 0.85 + position * 0.07
|
2025 |
-
# else:
|
2026 |
-
# # 優秀匹配:最後衝刺
|
2027 |
-
# position = (score - 0.85) / 0.15
|
2028 |
-
# return 0.92 + position * 0.03
|
2029 |
|
2030 |
|
2031 |
def amplify_score_extreme(score: float) -> float:
|
|
|
1660 |
|
1661 |
# 確保最終分數在合理範圍內
|
1662 |
return max(0.15, min(1.0, final_score))
|
1663 |
+
|
1664 |
+
|
1665 |
+
def calculate_environmental_fit(breed_info: dict, user_prefs: UserPreferences) -> float:
|
1666 |
+
"""計算品種與環境的適應性加成"""
|
1667 |
+
adaptability_score = 0.0
|
1668 |
+
description = breed_info.get('Description', '').lower()
|
1669 |
+
temperament = breed_info.get('Temperament', '').lower()
|
1670 |
+
|
1671 |
+
# 環境適應性評估
|
1672 |
+
if user_prefs.living_space == 'apartment':
|
1673 |
+
if 'adaptable' in temperament or 'apartment' in description:
|
1674 |
+
adaptability_score += 0.1
|
1675 |
+
if breed_info.get('Size') == 'Small':
|
1676 |
+
adaptability_score += 0.05
|
1677 |
+
elif user_prefs.living_space == 'house_large':
|
1678 |
+
if 'active' in temperament or 'energetic' in description:
|
1679 |
+
adaptability_score += 0.1
|
1680 |
|
1681 |
+
# 氣候適應性
|
1682 |
+
if user_prefs.climate in description or user_prefs.climate in temperament:
|
1683 |
+
adaptability_score += 0.05
|
1684 |
+
|
1685 |
+
return min(0.2, adaptability_score)
|
1686 |
|
1687 |
+
|
1688 |
+
def calculate_breed_matching(breed_info: dict, user_prefs: UserPreferences) -> dict:
|
1689 |
+
"""計算品種的整體評分與匹配度"""
|
1690 |
+
try:
|
1691 |
print("\n=== 開始計算品種相容性分數 ===")
|
1692 |
print(f"處理品種: {breed_info.get('Breed', 'Unknown')}")
|
1693 |
print(f"品種信息: {breed_info}")
|
|
|
1726 |
)
|
1727 |
}
|
1728 |
|
1729 |
+
# 計算最終相容性分數
|
1730 |
+
final_score = calculate_compatibility_score(scores, user_prefs, breed_info)
|
1731 |
+
|
|
|
|
|
|
|
1732 |
# 計算環境適應性加成
|
1733 |
adaptability_bonus = calculate_environmental_fit(breed_info, user_prefs)
|
1734 |
+
|
1735 |
# 整合最終分數和加成
|
1736 |
final_score = (final_score * 0.9) + (adaptability_bonus * 0.1)
|
1737 |
final_score = amplify_score_extreme(final_score)
|
1738 |
+
|
1739 |
# 更新並返回完整的評分結果
|
1740 |
scores.update({
|
1741 |
'overall': final_score,
|
1742 |
'adaptability_bonus': adaptability_bonus
|
1743 |
})
|
1744 |
+
|
1745 |
return scores
|
1746 |
+
|
1747 |
except Exception as e:
|
1748 |
print(f"\n!!!!! 發生嚴重錯誤 !!!!!")
|
1749 |
print(f"錯誤類型: {type(e).__name__}")
|
|
|
1753 |
return {k: 0.6 for k in ['space', 'exercise', 'grooming', 'experience', 'health', 'noise', 'overall']}
|
1754 |
|
1755 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1756 |
# def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
|
1757 |
# """
|
1758 |
# 改進的品種相容性評分系統
|
|
|
1845 |
# return min(1.0, max(0.0, (final_score * 0.85) + (breed_bonus * 0.15)))
|
1846 |
|
1847 |
|
1848 |
+
# def amplify_score_extreme(score: float) -> float:
|
1849 |
+
# """
|
1850 |
+
# 改進的分數轉換函數
|
1851 |
+
# 提供更大的分數範圍和更明顯的差異
|
1852 |
+
|
1853 |
+
# 轉換邏輯:
|
1854 |
+
# - 極差匹配 (0.0-0.3) -> 60-68%
|
1855 |
+
# - 較差匹配 (0.3-0.5) -> 68-75%
|
1856 |
+
# - 中等匹配 (0.5-0.7) -> 75-85%
|
1857 |
+
# - 良好匹配 (0.7-0.85) -> 85-92%
|
1858 |
+
# - 優秀匹配 (0.85-1.0) -> 92-95%
|
1859 |
+
# """
|
1860 |
+
# if score < 0.3:
|
1861 |
+
# # 極差匹配:快速線性增長
|
1862 |
+
# return 0.60 + (score / 0.3) * 0.08
|
1863 |
+
# elif score < 0.5:
|
1864 |
+
# # 較差匹配:緩慢增長
|
1865 |
+
# position = (score - 0.3) / 0.2
|
1866 |
+
# return 0.68 + position * 0.07
|
1867 |
+
# elif score < 0.7:
|
1868 |
+
# # 中等匹配:穩定線性增長
|
1869 |
+
# position = (score - 0.5) / 0.2
|
1870 |
+
# return 0.75 + position * 0.10
|
1871 |
+
# elif score < 0.85:
|
1872 |
+
# # 良好匹配:加速增長
|
1873 |
+
# position = (score - 0.7) / 0.15
|
1874 |
+
# return 0.85 + position * 0.07
|
1875 |
+
# else:
|
1876 |
+
# # 優秀匹配:最後衝刺
|
1877 |
+
# position = (score - 0.85) / 0.15
|
1878 |
+
# return 0.92 + position * 0.03
|
1879 |
+
|
1880 |
+
|
1881 |
def calculate_compatibility_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
|
1882 |
"""
|
1883 |
計算品種與使用者的整體相容性分數
|
|
|
2025 |
|
2026 |
# 確保分數在合理範圍內並保留兩位小數
|
2027 |
return round(max(60.0, min(95.0, final_score)), 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2028 |
|
2029 |
|
2030 |
def amplify_score_extreme(score: float) -> float:
|