Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +14 -47
scoring_calculation_system.py
CHANGED
|
@@ -631,7 +631,7 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
| 631 |
return max(0.05, min(1.0, final_score))
|
| 632 |
|
| 633 |
|
| 634 |
-
def calculate_exercise_score(breed_needs: str, exercise_time: int, exercise_type: str) -> float:
|
| 635 |
"""
|
| 636 |
計算品種運動需求與使用者運動條件的匹配度。此函數特別著重:
|
| 637 |
1. 不同品種的運動耐受度差異
|
|
@@ -746,6 +746,10 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
| 746 |
final_score = (time_score * 0.7) + (type_score * 0.3)
|
| 747 |
else:
|
| 748 |
final_score = (time_score * 0.65) + (type_score * 0.35)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 749 |
|
| 750 |
# 極端情況的最終調整
|
| 751 |
if breed_needs.upper() == 'LOW' and exercise_time > breed_level['max'] * 2:
|
|
@@ -1571,43 +1575,6 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
| 1571 |
trait_penalty -= penalty * 0.5 # 專家反而因應對特殊特徵而加分
|
| 1572 |
|
| 1573 |
return max(0.2, min(1.0, base_score - trait_penalty))
|
| 1574 |
-
|
| 1575 |
-
# 第三部分:生活環境評估
|
| 1576 |
-
# def evaluate_living_conditions():
|
| 1577 |
-
# size = breed_info['Size']
|
| 1578 |
-
# exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
|
| 1579 |
-
|
| 1580 |
-
# # 空間需求矩陣
|
| 1581 |
-
# space_requirements = {
|
| 1582 |
-
# 'apartment': {
|
| 1583 |
-
# 'Small': 1.0, 'Medium': 0.4, 'Large': 0.2, 'Giant': 0.1
|
| 1584 |
-
# },
|
| 1585 |
-
# 'house_small': {
|
| 1586 |
-
# 'Small': 0.9, 'Medium': 1.0, 'Large': 0.5, 'Giant': 0.3
|
| 1587 |
-
# },
|
| 1588 |
-
# 'house_large': {
|
| 1589 |
-
# 'Small': 0.8, 'Medium': 0.9, 'Large': 1.0, 'Giant': 1.0
|
| 1590 |
-
# }
|
| 1591 |
-
# }
|
| 1592 |
-
|
| 1593 |
-
# # 基礎空間分數
|
| 1594 |
-
# space_score = space_requirements.get(user_prefs.living_space,
|
| 1595 |
-
# space_requirements['house_small'])[size]
|
| 1596 |
-
|
| 1597 |
-
# # 活動空間需求調整
|
| 1598 |
-
# if exercise_needs in ['HIGH', 'VERY HIGH']:
|
| 1599 |
-
# if user_prefs.living_space != 'house_large':
|
| 1600 |
-
# space_score *= 0.8
|
| 1601 |
-
|
| 1602 |
-
# # 院子可用性評估
|
| 1603 |
-
# yard_scores = {
|
| 1604 |
-
# 'no_yard': 0.7,
|
| 1605 |
-
# 'shared_yard': 0.85,
|
| 1606 |
-
# 'private_yard': 1.0
|
| 1607 |
-
# }
|
| 1608 |
-
# space_score *= yard_scores.get(user_prefs.yard_access, 0.8)
|
| 1609 |
-
|
| 1610 |
-
# return space_score
|
| 1611 |
|
| 1612 |
def evaluate_living_conditions() -> float:
|
| 1613 |
"""
|
|
@@ -1625,15 +1592,15 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
| 1625 |
space_requirements = {
|
| 1626 |
'apartment': {
|
| 1627 |
'Small': 1.0,
|
| 1628 |
-
'Medium': 0.
|
| 1629 |
-
'Large': 0.
|
| 1630 |
-
'Giant': 0.
|
| 1631 |
},
|
| 1632 |
'house_small': {
|
| 1633 |
'Small': 0.9,
|
| 1634 |
'Medium': 1.0,
|
| 1635 |
-
'Large': 0.8,
|
| 1636 |
-
'Giant': 0.7
|
| 1637 |
},
|
| 1638 |
'house_large': {
|
| 1639 |
'Small': 0.8,
|
|
@@ -1803,11 +1770,11 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
| 1803 |
# 空間權重調整 - 更平衡的調整方式
|
| 1804 |
if extremities['space'][0] == 'restricted':
|
| 1805 |
if extremities['exercise'][0] in ['high', 'extremely_high']:
|
| 1806 |
-
adjustments['space'] = 1.
|
| 1807 |
-
adjustments['exercise'] =
|
| 1808 |
else:
|
| 1809 |
-
adjustments['space'] = 1.6
|
| 1810 |
-
adjustments['noise'] = 1.5
|
| 1811 |
|
| 1812 |
# 運動需求權重調整 - 更合理的運動評估
|
| 1813 |
if extremities['exercise'][0] in ['extremely_high', 'extremely_low']:
|
|
|
|
| 631 |
return max(0.05, min(1.0, final_score))
|
| 632 |
|
| 633 |
|
| 634 |
+
def calculate_exercise_score(breed_needs: str, exercise_time: int, exercise_type: str, breed_size: str, living_space: str) -> float:
|
| 635 |
"""
|
| 636 |
計算品種運動需求與使用者運動條件的匹配度。此函數特別著重:
|
| 637 |
1. 不同品種的運動耐受度差異
|
|
|
|
| 746 |
final_score = (time_score * 0.7) + (type_score * 0.3)
|
| 747 |
else:
|
| 748 |
final_score = (time_score * 0.65) + (type_score * 0.35)
|
| 749 |
+
|
| 750 |
+
if breed_info['Size'] in ['Large', 'Giant'] and user_prefs.living_space == 'apartment':
|
| 751 |
+
if exercise_time >= 120:
|
| 752 |
+
final_score = min(1.0, final_score * 1.2)
|
| 753 |
|
| 754 |
# 極端情況的最終調整
|
| 755 |
if breed_needs.upper() == 'LOW' and exercise_time > breed_level['max'] * 2:
|
|
|
|
| 1575 |
trait_penalty -= penalty * 0.5 # 專家反而因應對特殊特徵而加分
|
| 1576 |
|
| 1577 |
return max(0.2, min(1.0, base_score - trait_penalty))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1578 |
|
| 1579 |
def evaluate_living_conditions() -> float:
|
| 1580 |
"""
|
|
|
|
| 1592 |
space_requirements = {
|
| 1593 |
'apartment': {
|
| 1594 |
'Small': 1.0,
|
| 1595 |
+
'Medium': 0.8,
|
| 1596 |
+
'Large': 0.7,
|
| 1597 |
+
'Giant': 0.6
|
| 1598 |
},
|
| 1599 |
'house_small': {
|
| 1600 |
'Small': 0.9,
|
| 1601 |
'Medium': 1.0,
|
| 1602 |
+
'Large': 0.8,
|
| 1603 |
+
'Giant': 0.7
|
| 1604 |
},
|
| 1605 |
'house_large': {
|
| 1606 |
'Small': 0.8,
|
|
|
|
| 1770 |
# 空間權重調整 - 更平衡的調整方式
|
| 1771 |
if extremities['space'][0] == 'restricted':
|
| 1772 |
if extremities['exercise'][0] in ['high', 'extremely_high']:
|
| 1773 |
+
adjustments['space'] = 1.3
|
| 1774 |
+
adjustments['exercise'] = 2.0
|
| 1775 |
else:
|
| 1776 |
+
adjustments['space'] = 1.6
|
| 1777 |
+
adjustments['noise'] = 1.5
|
| 1778 |
|
| 1779 |
# 運動需求權重調整 - 更合理的運動評估
|
| 1780 |
if extremities['exercise'][0] in ['extremely_high', 'extremely_low']:
|