DawnC commited on
Commit
05d2627
1 Parent(s): 1dc35ad

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +169 -43
scoring_calculation_system.py CHANGED
@@ -293,65 +293,171 @@ 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
 
@@ -511,11 +617,31 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
511
  # 計算加權總分
512
  weighted_score = sum(score * weights[category] for category, score in scores.items())
513
 
514
- # 擴大分數差異
 
 
 
 
 
515
  def amplify_score(score):
516
- # 使用指數函數擴大差異
517
- amplified = pow((score - 0.5) * 2, 3) / 8 + score
518
- return max(0.65, min(0.95, amplified)) # 限制在65%-95%範圍內
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
 
520
  final_score = amplify_score(weighted_score)
521
 
 
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
+ 計算使用者經驗與品種需求的匹配分數
361
+
362
+ 參數說明:
363
+ care_level: 品種的照顧難度 ("High", "Moderate", "Low")
364
+ user_experience: 使用者經驗等級 ("beginner", "intermediate", "advanced")
365
+ temperament: 品種的性格特徵描述
366
 
367
+ 返回:
368
+ float: 0.2-1.0 之間的匹配分數
369
+ """
370
+ # 基礎分數矩陣 - 更大的分數差異來反映經驗重要性
371
  base_scores = {
372
+ "High": {
373
+ "beginner": 0.12, # 降低起始分,反映高難度品種對新手的挑戰
374
+ "intermediate": 0.65, # 中級玩家可以應付,但仍有改善空間
375
+ "advanced": 1.0 # 資深者能完全勝任
376
+ },
377
+ "Moderate": {
378
+ "beginner": 0.35, # 適中難度對新手來說仍具挑戰
379
+ "intermediate": 0.82, # 中級玩家有很好的勝任能力
380
+ "advanced": 1.0 # 資深者完全勝任
381
+ },
382
+ "Low": {
383
+ "beginner": 0.72, # 低難度品種適合新手
384
+ "intermediate": 0.92, # 中級玩家幾乎完全勝任
385
+ "advanced": 1.0 # 資深者完全勝任
386
+ }
387
  }
388
 
389
+ # 取得基礎分數
390
  score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
391
 
392
+ # 性格特徵評估 - 根據經驗等級調整權重
393
  temperament_lower = temperament.lower()
394
+ temperament_adjustments = 0.0
395
 
396
  if user_experience == "beginner":
397
+ # 新手不適合的特徵 - 更嚴格的懲罰
398
  difficult_traits = {
399
+ 'stubborn': -0.15, # 加重固執的懲罰
400
+ 'independent': -0.12, # 加重獨立性的懲罰
401
+ 'dominant': -0.12, # 加重支配性的懲罰
402
+ 'strong-willed': -0.10, # 加重強勢的懲罰
403
+ 'protective': -0.08, # 加重保護性的懲罰
404
+ 'aloof': -0.08, # 加重冷漠的懲罰
405
+ 'energetic': -0.06 # 輕微懲罰高能量
406
  }
407
 
408
+ # 新手友善的特徵 - 提供更多獎勵
409
  easy_traits = {
410
+ 'gentle': 0.08, # 增加溫和的獎勵
411
+ 'friendly': 0.08, # 增加友善的獎勵
412
+ 'eager to please': 0.08, # 增加順從的獎勵
413
+ 'patient': 0.06, # 獎勵耐心
414
+ 'adaptable': 0.06, # 獎勵適應性
415
+ 'calm': 0.05 # 獎勵冷靜
416
  }
417
 
418
+ # 計算特徵調整
419
+ for trait, penalty in difficult_traits.items():
420
+ if trait in temperament_lower:
421
+ temperament_adjustments += penalty * 1.2 # 加重新手的懲罰
422
 
423
+ for trait, bonus in easy_traits.items():
424
+ if trait in temperament_lower:
425
+ temperament_adjustments += bonus
426
+
427
+ # 品種特殊調整
428
+ if any(term in temperament_lower for term in ['terrier', 'working', 'guard']):
429
+ temperament_adjustments -= 0.12 # 加重對特定類型品種的懲罰
430
+
431
  elif user_experience == "intermediate":
432
+ # 中級玩家的調整更加平衡
433
+ moderate_traits = {
434
+ 'intelligent': 0.05, # 獎勵聰明
435
+ 'athletic': 0.04, # 獎勵運動能力
436
+ 'versatile': 0.04, # 獎勵多功能性
437
+ 'stubborn': -0.06, # 輕微懲罰固執
438
+ 'independent': -0.05, # 輕微懲罰獨立性
439
+ 'protective': -0.04 # 輕微懲罰保護性
440
+ }
441
+
442
+ for trait, adjustment in moderate_traits.items():
443
+ if trait in temperament_lower:
444
+ temperament_adjustments += adjustment
445
+
446
  else: # advanced
447
+ # 資深玩家能夠應對挑戰性特徵
448
+ advanced_traits = {
449
+ 'stubborn': 0.04, # 反轉為優勢
450
+ 'independent': 0.04, # 反轉為優勢
451
+ 'intelligent': 0.05, # 獎勵聰明
452
+ 'protective': 0.04, # 獎勵保護性
453
+ 'strong-willed': 0.03 # 獎勵強勢
454
+ }
455
+
456
+ for trait, bonus in advanced_traits.items():
457
+ if trait in temperament_lower:
458
+ temperament_adjustments += bonus
459
 
460
+ # 確保最終分數在合理範圍內
461
  final_score = max(0.2, min(1.0, score + temperament_adjustments))
462
  return final_score
463
 
 
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
+ 將原始分數放大,創造更明顯的差異
629
+
630
+ 參數:
631
+ score: 原始分數 (0.0-1.0)
632
+
633
+ 返回:
634
+ float: 放大後的分數 (0.60-0.95)
635
+ """
636
+ # 基礎分數調整 - 將範圍集中到更有意義的區間
637
+ adjusted = (score - 0.4) * 1.67
638
+
639
+ # 使用更強的指數關係來放大差異
640
+ # 指數3可以在高分區間產生更明顯的差異
641
+ amplified = pow(adjusted, 3) / 8 + score
642
+
643
+ # 確保分數在60%-95%之間,並保持合理的分布
644
+ return max(0.60, min(0.95, amplified))
645
 
646
  final_score = amplify_score(weighted_score)
647