Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +31 -40
scoring_calculation_system.py
CHANGED
@@ -837,60 +837,51 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
837 |
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
838 |
|
839 |
# 調整權重配置
|
840 |
-
|
841 |
-
'space': 0.
|
842 |
-
'exercise': 0.
|
843 |
-
'grooming': 0.
|
844 |
-
'experience': 0.
|
845 |
-
'health': 0.
|
846 |
-
'noise': 0.
|
847 |
}
|
848 |
|
|
|
|
|
|
|
|
|
849 |
if user_prefs.has_children:
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
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 =
|
868 |
|
|
|
869 |
def amplify_score(score):
|
870 |
-
|
871 |
-
|
872 |
-
"""
|
873 |
-
# 基礎調整
|
874 |
-
adjusted = (score - 0.3) * 1.5
|
875 |
|
876 |
-
#
|
877 |
-
amplified = pow(adjusted, 2.
|
878 |
|
879 |
-
#
|
880 |
-
if amplified > 0.
|
881 |
-
amplified = 0.
|
882 |
|
883 |
-
# 擴大分數範圍(0.
|
884 |
-
final_score = max(0.
|
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()}
|
892 |
-
scores['overall'] = round(final_score, 4)
|
893 |
-
return scores
|
894 |
|
895 |
except Exception as e:
|
896 |
print(f"Error details: {str(e)}")
|
|
|
837 |
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
838 |
|
839 |
# 調整權重配置
|
840 |
+
weights = {
|
841 |
+
'space': 0.28,
|
842 |
+
'exercise': 0.18,
|
843 |
+
'grooming': 0.12,
|
844 |
+
'experience': 0.22,
|
845 |
+
'health': 0.12,
|
846 |
+
'noise': 0.08
|
847 |
}
|
848 |
|
849 |
+
# 計算基礎加權分數
|
850 |
+
weighted_score = sum(score * weights[category] for category, score in scores.items())
|
851 |
+
|
852 |
+
# 如果有孩童,將 family_safety_score 作為調整因子
|
853 |
if user_prefs.has_children:
|
854 |
+
family_safety = calculate_family_safety_score(breed_info, user_prefs.children_age)
|
855 |
+
|
856 |
+
# 使用更溫和的安全分數影響
|
857 |
+
# 0.8 是基礎保留率,確保即使最差的安全分數也只會降低 20% 的總分
|
858 |
+
safety_modifier = (family_safety * 0.2) + 0.8
|
859 |
+
|
860 |
+
# 調整基礎分數
|
861 |
+
weighted_score *= safety_modifier
|
|
|
|
|
|
|
|
|
|
|
|
|
862 |
|
863 |
+
# 加入品種額外加分的影響
|
864 |
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
865 |
+
final_weighted_score = weighted_score * (1 + breed_bonus)
|
866 |
|
867 |
+
# 最終分數放大函數也需要調整
|
868 |
def amplify_score(score):
|
869 |
+
# 基礎調整,使用更溫和的曲線
|
870 |
+
adjusted = (score - 0.3) * 1.6
|
|
|
|
|
|
|
871 |
|
872 |
+
# 使用較小的指數,避免過度放大差異
|
873 |
+
amplified = pow(adjusted, 2.5) / 4.0 + score
|
874 |
|
875 |
+
# 更寬鬆的高分處理
|
876 |
+
if amplified > 0.85:
|
877 |
+
amplified = 0.85 + (amplified - 0.85) * 0.6
|
878 |
|
879 |
+
# 擴大分數範圍(0.50-0.95)
|
880 |
+
final_score = max(0.50, min(0.95, amplified))
|
881 |
|
882 |
return round(final_score, 3)
|
883 |
|
884 |
final_score = amplify_score(final_weighted_score)
|
|
|
|
|
|
|
|
|
|
|
885 |
|
886 |
except Exception as e:
|
887 |
print(f"Error details: {str(e)}")
|