Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +33 -30
scoring_calculation_system.py
CHANGED
@@ -838,51 +838,54 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
838 |
|
839 |
# 調整權重配置
|
840 |
base_weights = {
|
841 |
-
'space': 0.25,
|
842 |
-
'exercise': 0.15,
|
843 |
-
'grooming': 0.10,
|
844 |
-
'experience': 0.20,
|
845 |
-
'health': 0.10,
|
846 |
-
'noise': 0.05
|
847 |
}
|
848 |
|
849 |
-
# 如果有孩童,加入家庭安全權重
|
850 |
if user_prefs.has_children:
|
851 |
-
|
852 |
-
#
|
853 |
-
|
854 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
855 |
else:
|
856 |
-
|
|
|
857 |
|
858 |
-
#
|
859 |
-
|
860 |
-
|
861 |
-
# 加入品種加分的影響
|
862 |
-
# breed_bonus 的影響應該要在加權總分之後,但在最終放大之前
|
863 |
-
adjusted_score = weighted_score * (1 + breed_bonus) # breed_bonus 作為乘數效果
|
864 |
|
865 |
def amplify_score(score):
|
866 |
"""
|
867 |
-
|
868 |
"""
|
869 |
-
# 基礎調整
|
870 |
-
adjusted = (score - 0.
|
871 |
|
872 |
-
#
|
873 |
-
amplified = pow(adjusted,
|
874 |
|
875 |
-
#
|
876 |
-
if amplified > 0.
|
877 |
-
amplified = 0.
|
878 |
|
879 |
-
#
|
880 |
-
final_score = max(0.
|
881 |
|
882 |
return round(final_score, 3)
|
883 |
|
884 |
-
|
885 |
-
final_score = amplify_score(adjusted_score)
|
886 |
|
887 |
# 四捨五入所有分數並回傳
|
888 |
scores = {k: round(v, 4) for k, v in scores.items()}
|
|
|
838 |
|
839 |
# 調整權重配置
|
840 |
base_weights = {
|
841 |
+
'space': 0.25,
|
842 |
+
'exercise': 0.15,
|
843 |
+
'grooming': 0.10,
|
844 |
+
'experience': 0.20,
|
845 |
+
'health': 0.10,
|
846 |
+
'noise': 0.05
|
847 |
}
|
848 |
|
|
|
849 |
if user_prefs.has_children:
|
850 |
+
# 不直接加入 family_safety 到權重中
|
851 |
+
# 而是作為一個獨立的修正因子
|
852 |
+
family_safety_score = calculate_family_safety_score(breed_info, user_prefs.children_age)
|
853 |
+
|
854 |
+
# 計算基礎加權分數
|
855 |
+
weighted_score = sum(score * base_weights[category] for category, score in scores.items())
|
856 |
+
|
857 |
+
# 將 family_safety_score 作為調整因子
|
858 |
+
# 使用較溫和的影響方式
|
859 |
+
safety_adjustment = (family_safety_score * 0.7) + 0.3 # 確保即使最低的安全分數也只會降低 70%
|
860 |
+
adjusted_score = weighted_score * safety_adjustment
|
861 |
else:
|
862 |
+
weighted_score = sum(score * base_weights[category] for category, score in scores.items())
|
863 |
+
adjusted_score = weighted_score
|
864 |
|
865 |
+
# 再加入品種加分的影響
|
866 |
+
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
867 |
+
final_weighted_score = adjusted_score * (1 + breed_bonus)
|
|
|
|
|
|
|
868 |
|
869 |
def amplify_score(score):
|
870 |
"""
|
871 |
+
修改放大函數,讓分數差異更明顯
|
872 |
"""
|
873 |
+
# 基礎調整
|
874 |
+
adjusted = (score - 0.3) * 1.5
|
875 |
|
876 |
+
# 使用較溫和的指數
|
877 |
+
amplified = pow(adjusted, 2.8) / 4.5 + score
|
878 |
|
879 |
+
# 高分區間的處理
|
880 |
+
if amplified > 0.90:
|
881 |
+
amplified = 0.90 + (amplified - 0.90) * 0.3
|
882 |
|
883 |
+
# 擴大分數範圍(0.45-0.95)
|
884 |
+
final_score = max(0.45, min(0.95, amplified))
|
885 |
|
886 |
return round(final_score, 3)
|
887 |
|
888 |
+
final_score = amplify_score(final_weighted_score)
|
|
|
889 |
|
890 |
# 四捨五入所有分數並回傳
|
891 |
scores = {k: round(v, 4) for k, v in scores.items()}
|