DawnC commited on
Commit
4bb5524
1 Parent(s): b794bde

Update recommendation_html_format.py

Browse files
Files changed (1) hide show
  1. recommendation_html_format.py +32 -10
recommendation_html_format.py CHANGED
@@ -54,19 +54,41 @@ def format_recommendation_html(recommendations: List[Dict], is_description_searc
54
  print(f"Error in convert_to_display_score: {str(e)}")
55
  return 70
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  def _generate_progress_bar(score: float) -> float:
58
- """生成非線性的進度條寬度"""
59
- if score <= 0.3:
60
- width = 30 + (score / 0.3) * 20
61
- elif score <= 0.6:
62
- width = 50 + ((score - 0.3) / 0.3) * 20
63
- elif score <= 0.8:
64
- width = 70 + ((score - 0.6) / 0.2) * 15
 
 
 
 
65
  else:
66
- width = 85 + ((score - 0.8) / 0.2) * 15
67
-
 
 
68
  import random
69
- width += random.uniform(-2, 2)
 
70
  return min(100, max(20, width))
71
 
72
  html_content = "<div class='recommendations-container'>"
 
54
  print(f"Error in convert_to_display_score: {str(e)}")
55
  return 70
56
 
57
+ # def _generate_progress_bar(score: float) -> float:
58
+ # """生成非線性的進度條寬度"""
59
+ # if score <= 0.3:
60
+ # width = 30 + (score / 0.3) * 20
61
+ # elif score <= 0.6:
62
+ # width = 50 + ((score - 0.3) / 0.3) * 20
63
+ # elif score <= 0.8:
64
+ # width = 70 + ((score - 0.6) / 0.2) * 15
65
+ # else:
66
+ # width = 85 + ((score - 0.8) / 0.2) * 15
67
+
68
+ # import random
69
+ # width += random.uniform(-2, 2)
70
+ # return min(100, max(20, width))
71
+
72
  def _generate_progress_bar(score: float) -> float:
73
+ """生成更線性的進度條寬度"""
74
+ # 基礎轉換
75
+ base_width = score * 100
76
+
77
+ # 微調以避免視覺上的偏差
78
+ if score > 0.9:
79
+ # 高分區間略微壓縮
80
+ width = 90 + (score - 0.9) * 100
81
+ elif score > 0.7:
82
+ # 中高分區間稍微展開
83
+ width = 70 + (score - 0.7) * 100
84
  else:
85
+ # 維持線性關係
86
+ width = base_width
87
+
88
+ # 加入細微的隨機變化使顯示更自然
89
  import random
90
+ width += random.uniform(-1, 1)
91
+
92
  return min(100, max(20, width))
93
 
94
  html_content = "<div class='recommendations-container'>"