Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +137 -39
scoring_calculation_system.py
CHANGED
@@ -294,78 +294,176 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
294 |
return base_score
|
295 |
|
296 |
|
297 |
-
def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
298 |
-
|
299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
"""
|
309 |
-
# 基礎分數矩陣 -
|
310 |
base_scores = {
|
311 |
"High": {
|
312 |
-
"beginner": 0.
|
313 |
-
"intermediate": 0.65, #
|
314 |
-
"advanced": 1.0
|
315 |
},
|
316 |
"Moderate": {
|
317 |
-
"beginner": 0.
|
318 |
-
"intermediate": 0.82,
|
319 |
-
"advanced": 1.0
|
320 |
},
|
321 |
"Low": {
|
322 |
-
"beginner": 0.
|
323 |
-
"intermediate": 0.92,
|
324 |
-
"advanced": 1.0
|
325 |
}
|
326 |
}
|
327 |
|
328 |
# 取得基礎分數
|
329 |
score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
330 |
|
331 |
-
# 性格特徵評估 - 根據經驗等級調整權重
|
332 |
temperament_lower = temperament.lower()
|
333 |
temperament_adjustments = 0.0
|
334 |
|
335 |
if user_experience == "beginner":
|
336 |
-
#
|
337 |
difficult_traits = {
|
338 |
-
'stubborn': -0.
|
339 |
-
'independent': -0.
|
340 |
-
'dominant': -0.
|
341 |
-
'strong-willed': -0.
|
342 |
-
'protective': -0.
|
343 |
-
'aloof': -0.
|
344 |
-
'energetic': -0.
|
345 |
}
|
346 |
|
347 |
-
#
|
348 |
easy_traits = {
|
349 |
-
'gentle': 0.
|
350 |
-
'friendly': 0.
|
351 |
-
'eager to please': 0.
|
352 |
-
'patient': 0.
|
353 |
-
'adaptable': 0.
|
354 |
-
'calm': 0.
|
355 |
}
|
356 |
|
357 |
-
#
|
358 |
for trait, penalty in difficult_traits.items():
|
359 |
if trait in temperament_lower:
|
360 |
-
temperament_adjustments += penalty
|
361 |
|
362 |
for trait, bonus in easy_traits.items():
|
363 |
if trait in temperament_lower:
|
364 |
temperament_adjustments += bonus
|
365 |
|
366 |
-
#
|
367 |
if any(term in temperament_lower for term in ['terrier', 'working', 'guard']):
|
368 |
-
temperament_adjustments -= 0.
|
369 |
|
370 |
elif user_experience == "intermediate":
|
371 |
# 中級玩家的調整更加平衡
|
|
|
294 |
return base_score
|
295 |
|
296 |
|
297 |
+
# def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
298 |
+
# """
|
299 |
+
# 計算使用者經驗與品種需求的匹配分數
|
300 |
+
|
301 |
+
# 參數說明:
|
302 |
+
# care_level: 品種的照顧難度 ("High", "Moderate", "Low")
|
303 |
+
# user_experience: 使用者經驗等級 ("beginner", "intermediate", "advanced")
|
304 |
+
# temperament: 品種的性格特徵描述
|
305 |
+
|
306 |
+
# 返回:
|
307 |
+
# float: 0.2-1.0 之間的匹配分數
|
308 |
+
# """
|
309 |
+
# # 基礎分數矩陣 - 更大的分數差異來反映經驗重要性
|
310 |
+
# base_scores = {
|
311 |
+
# "High": {
|
312 |
+
# "beginner": 0.12, # 降低起始分,反映高難度品種對新手的挑戰
|
313 |
+
# "intermediate": 0.65, # 中級玩家可以應付,但仍有改善空間
|
314 |
+
# "advanced": 1.0 # 資深者能完全勝任
|
315 |
+
# },
|
316 |
+
# "Moderate": {
|
317 |
+
# "beginner": 0.35, # 適中難度對新手來說仍具挑戰
|
318 |
+
# "intermediate": 0.82, # 中級玩家有很好的勝任能力
|
319 |
+
# "advanced": 1.0 # 資深者完全勝任
|
320 |
+
# },
|
321 |
+
# "Low": {
|
322 |
+
# "beginner": 0.72, # 低難度品種適合新手
|
323 |
+
# "intermediate": 0.92, # 中級玩家幾乎完全勝任
|
324 |
+
# "advanced": 1.0 # 資深者完全勝任
|
325 |
+
# }
|
326 |
+
# }
|
327 |
+
|
328 |
+
# # 取得基礎分數
|
329 |
+
# score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
330 |
|
331 |
+
# # 性格特徵評估 - 根據經驗等級調整權重
|
332 |
+
# temperament_lower = temperament.lower()
|
333 |
+
# temperament_adjustments = 0.0
|
334 |
+
|
335 |
+
# if user_experience == "beginner":
|
336 |
+
# # 新手不適合的特徵 - 更嚴格的懲罰
|
337 |
+
# difficult_traits = {
|
338 |
+
# 'stubborn': -0.15, # 加重固執的懲罰
|
339 |
+
# 'independent': -0.12, # 加重獨立性的懲罰
|
340 |
+
# 'dominant': -0.12, # 加重支配性的懲罰
|
341 |
+
# 'strong-willed': -0.10, # 加重強勢的懲罰
|
342 |
+
# 'protective': -0.08, # 加重保護性的懲罰
|
343 |
+
# 'aloof': -0.08, # 加重冷漠的懲罰
|
344 |
+
# 'energetic': -0.06 # 輕微懲罰高能量
|
345 |
+
# }
|
346 |
+
|
347 |
+
# # 新手友善的特徵 - 提供更多獎勵
|
348 |
+
# easy_traits = {
|
349 |
+
# 'gentle': 0.08, # 增加溫和的獎勵
|
350 |
+
# 'friendly': 0.08, # 增加友善的獎勵
|
351 |
+
# 'eager to please': 0.08, # 增加順從的獎勵
|
352 |
+
# 'patient': 0.06, # 獎勵耐心
|
353 |
+
# 'adaptable': 0.06, # 獎勵適應性
|
354 |
+
# 'calm': 0.05 # 獎勵冷靜
|
355 |
+
# }
|
356 |
+
|
357 |
+
# # 計算特徵調整
|
358 |
+
# for trait, penalty in difficult_traits.items():
|
359 |
+
# if trait in temperament_lower:
|
360 |
+
# temperament_adjustments += penalty * 1.2 # 加重新手的懲罰
|
361 |
+
|
362 |
+
# for trait, bonus in easy_traits.items():
|
363 |
+
# if trait in temperament_lower:
|
364 |
+
# temperament_adjustments += bonus
|
365 |
+
|
366 |
+
# # 品種特殊調整
|
367 |
+
# if any(term in temperament_lower for term in ['terrier', 'working', 'guard']):
|
368 |
+
# temperament_adjustments -= 0.12 # 加重對特定類型品種的懲罰
|
369 |
+
|
370 |
+
# elif user_experience == "intermediate":
|
371 |
+
# # 中級玩家的調整更加平衡
|
372 |
+
# moderate_traits = {
|
373 |
+
# 'intelligent': 0.05, # 獎勵聰明
|
374 |
+
# 'athletic': 0.04, # 獎勵運動能力
|
375 |
+
# 'versatile': 0.04, # 獎勵多功能性
|
376 |
+
# 'stubborn': -0.06, # 輕微懲罰固執
|
377 |
+
# 'independent': -0.05, # 輕微懲罰獨立性
|
378 |
+
# 'protective': -0.04 # 輕微懲罰保護性
|
379 |
+
# }
|
380 |
+
|
381 |
+
# for trait, adjustment in moderate_traits.items():
|
382 |
+
# if trait in temperament_lower:
|
383 |
+
# temperament_adjustments += adjustment
|
384 |
+
|
385 |
+
# else: # advanced
|
386 |
+
# # 資深玩家能夠應對挑戰性特徵
|
387 |
+
# advanced_traits = {
|
388 |
+
# 'stubborn': 0.04, # 反轉為優勢
|
389 |
+
# 'independent': 0.04, # 反轉為優勢
|
390 |
+
# 'intelligent': 0.05, # 獎勵聰明
|
391 |
+
# 'protective': 0.04, # 獎勵保護性
|
392 |
+
# 'strong-willed': 0.03 # 獎勵強勢
|
393 |
+
# }
|
394 |
+
|
395 |
+
# for trait, bonus in advanced_traits.items():
|
396 |
+
# if trait in temperament_lower:
|
397 |
+
# temperament_adjustments += bonus
|
398 |
|
399 |
+
# # 確保最終分數在合理範圍內
|
400 |
+
# final_score = max(0.2, min(1.0, score + temperament_adjustments))
|
401 |
+
# return final_score
|
402 |
+
|
403 |
+
|
404 |
+
def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
405 |
+
"""
|
406 |
+
計算經驗分數,加強不同經驗等級的區別
|
407 |
"""
|
408 |
+
# 基礎分數矩陣 - 調整分數範圍,讓差異更明顯
|
409 |
base_scores = {
|
410 |
"High": {
|
411 |
+
"beginner": 0.15, # 從0.12降到0.15,對新手更嚴格
|
412 |
+
"intermediate": 0.65, # 保持不變
|
413 |
+
"advanced": 1.0
|
414 |
},
|
415 |
"Moderate": {
|
416 |
+
"beginner": 0.45, # 從0.35提高到0.45,增加區別
|
417 |
+
"intermediate": 0.82,
|
418 |
+
"advanced": 1.0
|
419 |
},
|
420 |
"Low": {
|
421 |
+
"beginner": 0.85, # 從0.72提高到0.85,更適合新手
|
422 |
+
"intermediate": 0.92,
|
423 |
+
"advanced": 1.0
|
424 |
}
|
425 |
}
|
426 |
|
427 |
# 取得基礎分數
|
428 |
score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
429 |
|
|
|
430 |
temperament_lower = temperament.lower()
|
431 |
temperament_adjustments = 0.0
|
432 |
|
433 |
if user_experience == "beginner":
|
434 |
+
# 調整新手的懲罰力度
|
435 |
difficult_traits = {
|
436 |
+
'stubborn': -0.25, # 從-0.15加重到-0.25
|
437 |
+
'independent': -0.20, # 從-0.12加重到-0.20
|
438 |
+
'dominant': -0.20,
|
439 |
+
'strong-willed': -0.18,
|
440 |
+
'protective': -0.15,
|
441 |
+
'aloof': -0.15,
|
442 |
+
'energetic': -0.12 # 從-0.06加重到-0.12
|
443 |
}
|
444 |
|
445 |
+
# 新手友善特徵的獎勵略微減少,避免過度補償
|
446 |
easy_traits = {
|
447 |
+
'gentle': 0.06,
|
448 |
+
'friendly': 0.06,
|
449 |
+
'eager to please': 0.06,
|
450 |
+
'patient': 0.04,
|
451 |
+
'adaptable': 0.04,
|
452 |
+
'calm': 0.04
|
453 |
}
|
454 |
|
455 |
+
# 新手的特徵懲罰不再乘以1.2,而是直接使用更重的懲罰值
|
456 |
for trait, penalty in difficult_traits.items():
|
457 |
if trait in temperament_lower:
|
458 |
+
temperament_adjustments += penalty
|
459 |
|
460 |
for trait, bonus in easy_traits.items():
|
461 |
if trait in temperament_lower:
|
462 |
temperament_adjustments += bonus
|
463 |
|
464 |
+
# 特定品種類型的懲罰加重
|
465 |
if any(term in temperament_lower for term in ['terrier', 'working', 'guard']):
|
466 |
+
temperament_adjustments -= 0.20
|
467 |
|
468 |
elif user_experience == "intermediate":
|
469 |
# 中級玩家的調整更加平衡
|