Spaces:
Running
Running
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +25 -72
scoring_calculation_system.py
CHANGED
@@ -293,68 +293,6 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
293 |
return base_score
|
294 |
|
295 |
|
296 |
-
# def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
297 |
-
# """飼養經驗需求計算"""
|
298 |
-
# # 初始化 temperament_adjustments,確保所有路徑都有值
|
299 |
-
# temperament_adjustments = 0.0
|
300 |
-
|
301 |
-
# # 降低初學者的基礎分數
|
302 |
-
# base_scores = {
|
303 |
-
# "High": {"beginner": 0.15, "intermediate": 0.70, "advanced": 1.0},
|
304 |
-
# "Moderate": {"beginner": 0.40, "intermediate": 0.85, "advanced": 1.0},
|
305 |
-
# "Low": {"beginner": 0.75, "intermediate": 0.95, "advanced": 1.0}
|
306 |
-
# }
|
307 |
-
|
308 |
-
# score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
309 |
-
|
310 |
-
# # 擴展性格特徵評估
|
311 |
-
# temperament_lower = temperament.lower()
|
312 |
-
|
313 |
-
# if user_experience == "beginner":
|
314 |
-
# # 增加更多特徵評估
|
315 |
-
# difficult_traits = {
|
316 |
-
# 'stubborn': -0.12,
|
317 |
-
# 'independent': -0.10,
|
318 |
-
# 'dominant': -0.10,
|
319 |
-
# 'strong-willed': -0.08,
|
320 |
-
# 'protective': -0.06,
|
321 |
-
# 'energetic': -0.05
|
322 |
-
# }
|
323 |
-
|
324 |
-
# easy_traits = {
|
325 |
-
# 'gentle': 0.06,
|
326 |
-
# 'friendly': 0.06,
|
327 |
-
# 'eager to please': 0.06,
|
328 |
-
# 'patient': 0.05,
|
329 |
-
# 'adaptable': 0.05,
|
330 |
-
# 'calm': 0.04
|
331 |
-
# }
|
332 |
-
|
333 |
-
# # 更精確的特徵影響計算
|
334 |
-
# temperament_adjustments = sum(value for trait, value in easy_traits.items() if trait in temperament_lower)
|
335 |
-
# temperament_adjustments += sum(value for trait, value in difficult_traits.items() if trait in temperament_lower)
|
336 |
-
|
337 |
-
# # 品種特定調整
|
338 |
-
# if "terrier" in breed_info['Description'].lower():
|
339 |
-
# temperament_adjustments -= 0.1 # 梗類犬對新手不友善
|
340 |
-
|
341 |
-
# elif user_experience == "intermediate":
|
342 |
-
# # 中級飼主的調整較溫和
|
343 |
-
# if any(trait in temperament_lower for trait in ['gentle', 'friendly', 'patient']):
|
344 |
-
# temperament_adjustments += 0.03
|
345 |
-
# if any(trait in temperament_lower for trait in ['stubborn', 'independent']):
|
346 |
-
# temperament_adjustments -= 0.02
|
347 |
-
|
348 |
-
# else: # advanced
|
349 |
-
# # 資深飼主能處理更具挑戰性的犬種
|
350 |
-
# if any(trait in temperament_lower for trait in ['stubborn', 'independent', 'dominant']):
|
351 |
-
# temperament_adjustments += 0.02 # 反而可能是優點
|
352 |
-
# if any(trait in temperament_lower for trait in ['protective', 'energetic']):
|
353 |
-
# temperament_adjustments += 0.03
|
354 |
-
|
355 |
-
# final_score = max(0.2, min(1.0, score + temperament_adjustments))
|
356 |
-
# return final_score
|
357 |
-
|
358 |
def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
359 |
"""
|
360 |
計算使用者經驗與品種需求的匹配分數
|
@@ -616,19 +554,34 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
616 |
|
617 |
# 計算加權總分
|
618 |
weighted_score = sum(score * weights[category] for category, score in scores.items())
|
619 |
-
|
620 |
-
# # 擴大分數差異
|
621 |
-
# def amplify_score(score):
|
622 |
-
# # 使用指數函數擴大差異
|
623 |
-
# amplified = pow((score - 0.5) * 2, 3) / 8 + score
|
624 |
-
# return max(0.65, min(0.95, amplified)) # 限制在65%-95%範圍內
|
625 |
|
626 |
def amplify_score(score):
|
627 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
628 |
adjusted = (score - 0.35) * 1.8
|
629 |
-
|
630 |
-
#
|
631 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
|
633 |
final_score = amplify_score(weighted_score)
|
634 |
|
|
|
293 |
return base_score
|
294 |
|
295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
297 |
"""
|
298 |
計算使用者經驗與品種需求的匹配分數
|
|
|
554 |
|
555 |
# 計算加權總分
|
556 |
weighted_score = sum(score * weights[category] for category, score in scores.items())
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
|
558 |
def amplify_score(score):
|
559 |
+
"""
|
560 |
+
優化分數放大函數,產生更自然的分數分布
|
561 |
+
|
562 |
+
改進:
|
563 |
+
- 使用更自然的指數關係
|
564 |
+
- 加入細微的隨機變化
|
565 |
+
- 避免過多的整數和半數
|
566 |
+
"""
|
567 |
+
# 基礎調整
|
568 |
adjusted = (score - 0.35) * 1.8
|
569 |
+
|
570 |
+
# 使用 3.2 次方使曲線更平滑
|
571 |
+
amplified = pow(adjusted, 3.2) / 5.8 + score
|
572 |
+
|
573 |
+
# 加入細微的隨機變化(約±0.3%)
|
574 |
+
import random
|
575 |
+
random_adjustment = random.uniform(-0.003, 0.003)
|
576 |
+
|
577 |
+
# 特別處理高分區間,使其更分散
|
578 |
+
if amplified > 0.95:
|
579 |
+
amplified = 0.95 + (amplified - 0.95) * 0.6
|
580 |
+
|
581 |
+
final_score = max(0.55, min(0.98, amplified + random_adjustment))
|
582 |
+
|
583 |
+
# 避免過多的 .0 和 .5 結尾
|
584 |
+
return round(final_score + random.uniform(-0.001, 0.001), 3)
|
585 |
|
586 |
final_score = amplify_score(weighted_score)
|
587 |
|