Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files
scoring_calculation_system.py
CHANGED
@@ -27,7 +27,6 @@ class UserPreferences:
|
|
27 |
living_environment: str = "ground_floor" # "ground_floor", "with_elevator", "walk_up" - 居住環境細節
|
28 |
|
29 |
def __post_init__(self):
|
30 |
-
"""在初始化後運行,用於設置派生值"""
|
31 |
if self.barking_acceptance is None:
|
32 |
self.barking_acceptance = self.noise_tolerance
|
33 |
|
@@ -96,7 +95,7 @@ def calculate_breed_bonus(breed_info: dict, user_prefs: 'UserPreferences') -> fl
|
|
96 |
'territorial': -0.05
|
97 |
}
|
98 |
|
99 |
-
#
|
100 |
age_adjustments = {
|
101 |
'toddler': {'bonus_mult': 0.7, 'penalty_mult': 1.3},
|
102 |
'school_age': {'bonus_mult': 1.0, 'penalty_mult': 1.0},
|
@@ -129,7 +128,7 @@ def calculate_breed_bonus(breed_info: dict, user_prefs: 'UserPreferences') -> fl
|
|
129 |
bonus += min(0.1, skill_bonus)
|
130 |
|
131 |
|
132 |
-
# 6. 適應性評估
|
133 |
adaptability_bonus = 0.0
|
134 |
if breed_info.get('Size') == "Small" and user_prefs.living_space == "apartment":
|
135 |
adaptability_bonus += 0.08 # 小型犬更適合公寓
|
@@ -165,7 +164,6 @@ def calculate_additional_factors(breed_info: dict, user_prefs: 'UserPreferences'
|
|
165 |
"""
|
166 |
計算額外的評估因素,結合品種特性與使用者需求的全面評估系統
|
167 |
|
168 |
-
此函數整合了:
|
169 |
1. 多功能性評估 - 品種的多樣化能力
|
170 |
2. 訓練性評估 - 學習和服從能力
|
171 |
3. 能量水平評估 - 活力和運動需求
|
@@ -229,7 +227,7 @@ def calculate_additional_factors(breed_info: dict, user_prefs: 'UserPreferences'
|
|
229 |
|
230 |
factors['versatility'] = min(1.0, trait_score + role_score)
|
231 |
|
232 |
-
# 2. 訓練性評估
|
233 |
trainable_traits = {
|
234 |
'intelligent': 0.3,
|
235 |
'eager to please': 0.3,
|
@@ -251,7 +249,7 @@ def calculate_additional_factors(breed_info: dict, user_prefs: 'UserPreferences'
|
|
251 |
factors['trainability'] = min(1.0, base_trainability *
|
252 |
experience_multipliers.get(user_prefs.experience_level, 1.0))
|
253 |
|
254 |
-
# 3. 能量水平評估
|
255 |
exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
|
256 |
energy_levels = {
|
257 |
'VERY HIGH': {
|
@@ -288,7 +286,7 @@ def calculate_additional_factors(breed_info: dict, user_prefs: 'UserPreferences'
|
|
288 |
|
289 |
factors['energy_level'] = energy_score
|
290 |
|
291 |
-
# 4. 美容需求評估
|
292 |
grooming_needs = breed_info.get('Grooming Needs', 'MODERATE').upper()
|
293 |
grooming_levels = {
|
294 |
'HIGH': 1.0,
|
@@ -316,7 +314,7 @@ def calculate_additional_factors(breed_info: dict, user_prefs: 'UserPreferences'
|
|
316 |
factors['grooming_needs'] = min(1.0, base_grooming *
|
317 |
commitment_multipliers.get(user_prefs.grooming_commitment, 1.0))
|
318 |
|
319 |
-
# 5. 社交需求評估
|
320 |
social_traits = {
|
321 |
'friendly': 0.25,
|
322 |
'social': 0.25,
|
@@ -973,8 +971,7 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
973 |
def calculate_health_score(breed_name: str, user_prefs: UserPreferences) -> float:
|
974 |
"""
|
975 |
計算品種健康分數,加強健康問題的影響力和與使用者敏感度的連結
|
976 |
-
|
977 |
-
重要改進:
|
978 |
1. 根據使用者的健康敏感度調整分數
|
979 |
2. 更嚴格的健康問題評估
|
980 |
3. 考慮多重健康問題的累積效應
|
@@ -1009,7 +1006,7 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
1009 |
# 輕微健康問題 - 輕微扣分
|
1010 |
minor_conditions = {
|
1011 |
'dental issues': -0.08, # 牙齒問題,需要定期護理
|
1012 |
-
'weight gain tendency': -0.08,
|
1013 |
'minor allergies': -0.06, # 輕微過敏,可控制
|
1014 |
'seasonal allergies': -0.06 # 季節性過敏
|
1015 |
}
|
@@ -1080,7 +1077,7 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
1080 |
|
1081 |
def calculate_noise_score(breed_name: str, user_prefs: UserPreferences) -> float:
|
1082 |
"""
|
1083 |
-
|
1084 |
"""
|
1085 |
if breed_name not in breed_noise_info:
|
1086 |
return 0.5
|
@@ -1601,7 +1598,6 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
1601 |
|
1602 |
def calculate_weights():
|
1603 |
"""
|
1604 |
-
計算動態權重,特別關注:
|
1605 |
1. 條件極端度對權重的影響
|
1606 |
2. 多重條件組合的權重調整
|
1607 |
3. 品種特性對權重分配的影響
|
@@ -1659,7 +1655,6 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
1659 |
|
1660 |
def calculate_weight_adjustments(extremities):
|
1661 |
"""
|
1662 |
-
根據條件極端度計算權重調整,特別強化:
|
1663 |
1. 高運動量時對耐力型犬種的偏好
|
1664 |
2. 專家級別對工作犬種的偏好
|
1665 |
3. 條件組合的整體評估
|
@@ -1762,7 +1757,6 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
1762 |
|
1763 |
def apply_special_case_adjustments(score):
|
1764 |
"""
|
1765 |
-
處理特殊情況的分數調整,著重:
|
1766 |
1. 條件組合的協同效應
|
1767 |
2. 品種特性的特殊要求
|
1768 |
3. 極端情況的處理
|
|
|
27 |
living_environment: str = "ground_floor" # "ground_floor", "with_elevator", "walk_up" - 居住環境細節
|
28 |
|
29 |
def __post_init__(self):
|
|
|
30 |
if self.barking_acceptance is None:
|
31 |
self.barking_acceptance = self.noise_tolerance
|
32 |
|
|
|
95 |
'territorial': -0.05
|
96 |
}
|
97 |
|
98 |
+
# 年齡評估
|
99 |
age_adjustments = {
|
100 |
'toddler': {'bonus_mult': 0.7, 'penalty_mult': 1.3},
|
101 |
'school_age': {'bonus_mult': 1.0, 'penalty_mult': 1.0},
|
|
|
128 |
bonus += min(0.1, skill_bonus)
|
129 |
|
130 |
|
131 |
+
# 6. 適應性評估
|
132 |
adaptability_bonus = 0.0
|
133 |
if breed_info.get('Size') == "Small" and user_prefs.living_space == "apartment":
|
134 |
adaptability_bonus += 0.08 # 小型犬更適合公寓
|
|
|
164 |
"""
|
165 |
計算額外的評估因素,結合品種特性與使用者需求的全面評估系統
|
166 |
|
|
|
167 |
1. 多功能性評估 - 品種的多樣化能力
|
168 |
2. 訓練性評估 - 學習和服從能力
|
169 |
3. 能量水平評估 - 活力和運動需求
|
|
|
227 |
|
228 |
factors['versatility'] = min(1.0, trait_score + role_score)
|
229 |
|
230 |
+
# 2. 訓練性評估
|
231 |
trainable_traits = {
|
232 |
'intelligent': 0.3,
|
233 |
'eager to please': 0.3,
|
|
|
249 |
factors['trainability'] = min(1.0, base_trainability *
|
250 |
experience_multipliers.get(user_prefs.experience_level, 1.0))
|
251 |
|
252 |
+
# 3. 能量水平評估
|
253 |
exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
|
254 |
energy_levels = {
|
255 |
'VERY HIGH': {
|
|
|
286 |
|
287 |
factors['energy_level'] = energy_score
|
288 |
|
289 |
+
# 4. 美容需求評估
|
290 |
grooming_needs = breed_info.get('Grooming Needs', 'MODERATE').upper()
|
291 |
grooming_levels = {
|
292 |
'HIGH': 1.0,
|
|
|
314 |
factors['grooming_needs'] = min(1.0, base_grooming *
|
315 |
commitment_multipliers.get(user_prefs.grooming_commitment, 1.0))
|
316 |
|
317 |
+
# 5. 社交需求評估
|
318 |
social_traits = {
|
319 |
'friendly': 0.25,
|
320 |
'social': 0.25,
|
|
|
971 |
def calculate_health_score(breed_name: str, user_prefs: UserPreferences) -> float:
|
972 |
"""
|
973 |
計算品種健康分數,加強健康問題的影響力和與使用者敏感度的連結
|
974 |
+
|
|
|
975 |
1. 根據使用者的健康敏感度調整分數
|
976 |
2. 更嚴格的健康問題評估
|
977 |
3. 考慮多重健康問題的累積效應
|
|
|
1006 |
# 輕微健康問題 - 輕微扣分
|
1007 |
minor_conditions = {
|
1008 |
'dental issues': -0.08, # 牙齒問題,需要定期護理
|
1009 |
+
'weight gain tendency': -0.08, # 易胖體質,需要控制飲食
|
1010 |
'minor allergies': -0.06, # 輕微過敏,可控制
|
1011 |
'seasonal allergies': -0.06 # 季節性過敏
|
1012 |
}
|
|
|
1077 |
|
1078 |
def calculate_noise_score(breed_name: str, user_prefs: UserPreferences) -> float:
|
1079 |
"""
|
1080 |
+
計算品種噪音分數,特別加強噪音程度與生活環境的關聯性評估,很多人棄養就是因為叫聲
|
1081 |
"""
|
1082 |
if breed_name not in breed_noise_info:
|
1083 |
return 0.5
|
|
|
1598 |
|
1599 |
def calculate_weights():
|
1600 |
"""
|
|
|
1601 |
1. 條件極端度對權重的影響
|
1602 |
2. 多重條件組合的權重調整
|
1603 |
3. 品種特性對權重分配的影響
|
|
|
1655 |
|
1656 |
def calculate_weight_adjustments(extremities):
|
1657 |
"""
|
|
|
1658 |
1. 高運動量時對耐力型犬種的偏好
|
1659 |
2. 專家級別對工作犬種的偏好
|
1660 |
3. 條件組合的整體評估
|
|
|
1757 |
|
1758 |
def apply_special_case_adjustments(score):
|
1759 |
"""
|
|
|
1760 |
1. 條件組合的協同效應
|
1761 |
2. 品種特性的特殊要求
|
1762 |
3. 極端情況的處理
|