Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files
scoring_calculation_system.py
CHANGED
@@ -2183,10 +2183,46 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2183 |
final_score = score * severity_multiplier
|
2184 |
return max(0.2, min(1.0, final_score))
|
2185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2186 |
def calculate_base_score(scores: dict, weights: dict) -> float:
|
2187 |
"""
|
2188 |
-
|
2189 |
-
|
|
|
|
|
2190 |
"""
|
2191 |
# 檢查關鍵指標是否有嚴重不足
|
2192 |
critical_thresholds = {
|
@@ -2204,17 +2240,39 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2204 |
# 計算基礎加權分數
|
2205 |
base_score = sum(scores[k] * weights[k] for k in scores.keys())
|
2206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2207 |
# 根據關鍵指標的不足程度進行懲罰
|
2208 |
if critical_failures:
|
2209 |
# 計算最嚴重的不足程度
|
2210 |
worst_failure = min(score for _, score in critical_failures)
|
2211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
2212 |
base_score *= (1 - penalty)
|
2213 |
|
2214 |
# 多個指標不足時的額外懲罰
|
2215 |
if len(critical_failures) > 1:
|
2216 |
-
|
|
|
|
|
|
|
2217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
2218 |
return base_score
|
2219 |
|
2220 |
def evaluate_condition_interactions(scores: dict) -> float:
|
|
|
2183 |
final_score = score * severity_multiplier
|
2184 |
return max(0.2, min(1.0, final_score))
|
2185 |
|
2186 |
+
# def calculate_base_score(scores: dict, weights: dict) -> float:
|
2187 |
+
# """
|
2188 |
+
# 計算基礎分數,加入更嚴格的評估機制。
|
2189 |
+
# 就像學校的評分系統,某些科目不及格會嚴重影響總成績。
|
2190 |
+
# """
|
2191 |
+
# # 檢查關鍵指標是否有嚴重不足
|
2192 |
+
# critical_thresholds = {
|
2193 |
+
# 'space': 0.7,
|
2194 |
+
# 'exercise': 0.7,
|
2195 |
+
# 'experience': 0.7,
|
2196 |
+
# 'noise': 0.65
|
2197 |
+
# }
|
2198 |
+
|
2199 |
+
# critical_failures = []
|
2200 |
+
# for metric, threshold in critical_thresholds.items():
|
2201 |
+
# if scores[metric] < threshold:
|
2202 |
+
# critical_failures.append((metric, scores[metric]))
|
2203 |
+
|
2204 |
+
# # 計算基礎加權分數
|
2205 |
+
# base_score = sum(scores[k] * weights[k] for k in scores.keys())
|
2206 |
+
|
2207 |
+
# # 根據關鍵指標的不足程度進行懲罰
|
2208 |
+
# if critical_failures:
|
2209 |
+
# # 計算最嚴重的不足程度
|
2210 |
+
# worst_failure = min(score for _, score in critical_failures)
|
2211 |
+
# penalty = (critical_thresholds['space'] - worst_failure) * 0.6
|
2212 |
+
# base_score *= (1 - penalty)
|
2213 |
+
|
2214 |
+
# # 多個指標不足時的額外懲罰
|
2215 |
+
# if len(critical_failures) > 1:
|
2216 |
+
# base_score *= (0.9 ** (len(critical_failures) - 1))
|
2217 |
+
|
2218 |
+
# return base_score
|
2219 |
+
|
2220 |
def calculate_base_score(scores: dict, weights: dict) -> float:
|
2221 |
"""
|
2222 |
+
計算基礎分數,特別加強:
|
2223 |
+
1. 公寓住戶高運動量的評估
|
2224 |
+
2. 確保理想匹配的最低分數
|
2225 |
+
3. 平衡空間限制與運動能力的關係
|
2226 |
"""
|
2227 |
# 檢查關鍵指標是否有嚴重不足
|
2228 |
critical_thresholds = {
|
|
|
2240 |
# 計算基礎加權分數
|
2241 |
base_score = sum(scores[k] * weights[k] for k in scores.keys())
|
2242 |
|
2243 |
+
# 特殊情況處理:公寓+高運動量
|
2244 |
+
is_apartment_with_high_exercise = (
|
2245 |
+
user_prefs.living_space == 'apartment' and
|
2246 |
+
user_prefs.exercise_time >= 120 and
|
2247 |
+
scores['exercise'] >= 0.7 # 確保運動能力符合
|
2248 |
+
)
|
2249 |
+
|
2250 |
# 根據關鍵指標的不足程度進行懲罰
|
2251 |
if critical_failures:
|
2252 |
# 計算最嚴重的不足程度
|
2253 |
worst_failure = min(score for _, score in critical_failures)
|
2254 |
+
|
2255 |
+
# 特殊情況:公寓+高運動量時降低空間限制的懲罰
|
2256 |
+
if is_apartment_with_high_exercise:
|
2257 |
+
penalty = (critical_thresholds['space'] - worst_failure) * 0.3 # 降低懲罰係數
|
2258 |
+
else:
|
2259 |
+
penalty = (critical_thresholds['space'] - worst_failure) * 0.6
|
2260 |
+
|
2261 |
base_score *= (1 - penalty)
|
2262 |
|
2263 |
# 多個指標不足時的額外懲罰
|
2264 |
if len(critical_failures) > 1:
|
2265 |
+
if is_apartment_with_high_exercise:
|
2266 |
+
base_score *= (0.95 ** (len(critical_failures) - 1)) # 降低疊加懲罰
|
2267 |
+
else:
|
2268 |
+
base_score *= (0.9 ** (len(critical_failures) - 1))
|
2269 |
|
2270 |
+
# 確保理想匹配的最低分數
|
2271 |
+
if (user_prefs.living_space == 'apartment' and
|
2272 |
+
scores['exercise'] >= 0.8 and
|
2273 |
+
scores['noise'] >= 0.7):
|
2274 |
+
base_score = max(base_score, 0.85) # 設定最低分數
|
2275 |
+
|
2276 |
return base_score
|
2277 |
|
2278 |
def evaluate_condition_interactions(scores: dict) -> float:
|