Spaces:
Running
Running
Update search_history.py
Browse files- search_history.py +0 -102
search_history.py
CHANGED
@@ -8,108 +8,6 @@ class SearchHistoryComponent:
|
|
8 |
"""初始化搜索歷史組件"""
|
9 |
self.history_manager = UserHistoryManager()
|
10 |
|
11 |
-
# def format_history_html(self, history_data: Optional[List[Dict]] = None) -> str:
|
12 |
-
# try:
|
13 |
-
# if history_data is None:
|
14 |
-
# history_data = self.history_manager.get_history()
|
15 |
-
|
16 |
-
# if not history_data:
|
17 |
-
# return """
|
18 |
-
# <div style='
|
19 |
-
# text-align: center;
|
20 |
-
# padding: 40px 20px;
|
21 |
-
# color: #666;
|
22 |
-
# background: linear-gradient(to right, rgba(66, 153, 225, 0.05), rgba(72, 187, 120, 0.05));
|
23 |
-
# border-radius: 10px;
|
24 |
-
# margin: 20px 0;
|
25 |
-
# '>
|
26 |
-
# <p style='
|
27 |
-
# font-size: 1.1em;
|
28 |
-
# margin: 0;
|
29 |
-
# background: linear-gradient(90deg, #4299e1, #48bb78);
|
30 |
-
# -webkit-background-clip: text;
|
31 |
-
# -webkit-text-fill-color: transparent;
|
32 |
-
# font-weight: 600;
|
33 |
-
# '>
|
34 |
-
# No search history yet. Try making some breed recommendations!
|
35 |
-
# </p>
|
36 |
-
# </div>
|
37 |
-
# """
|
38 |
-
|
39 |
-
# html = "<div class='history-container'>"
|
40 |
-
|
41 |
-
# for entry in reversed(history_data):
|
42 |
-
# timestamp = entry.get('timestamp', 'Unknown time')
|
43 |
-
# search_type = entry.get('search_type', 'criteria')
|
44 |
-
# results = entry.get('results', [])
|
45 |
-
|
46 |
-
# html += f"""
|
47 |
-
# <div class="history-entry">
|
48 |
-
# <div class="history-header" style="border-left: 4px solid #4299e1; padding-left: 10px;">
|
49 |
-
# <span class="timestamp">🕒 {timestamp}</span>
|
50 |
-
# <span class="search-type" style="color: #4299e1; font-weight: bold; margin-left: 10px;">
|
51 |
-
# Search History
|
52 |
-
# </span>
|
53 |
-
# </div>
|
54 |
-
# """
|
55 |
-
|
56 |
-
# if search_type == "criteria":
|
57 |
-
# prefs = entry.get('preferences', {})
|
58 |
-
# html += f"""
|
59 |
-
# <div class="params-list" style="background: #f8fafc; padding: 16px; border-radius: 8px; margin-bottom: 16px;">
|
60 |
-
# <h4 style="font-size: 1.1em; font-weight: 600; color: #2D3748; margin-bottom: 12px; border-bottom: 2px solid #E2E8F0; padding-bottom: 8px;">Search Parameters:</h4>
|
61 |
-
# <ul style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; list-style: none; padding: 0;">
|
62 |
-
# <li><span class="param-label" style="font-weight: 600; color: #2D3748;">Living Space:</span> {prefs.get('living_space', 'N/A')}</li>
|
63 |
-
# <li><span class="param-label" style="font-weight: 600; color: #2D3748;">Exercise Time:</span> {prefs.get('exercise_time', 'N/A')} minutes</li>
|
64 |
-
# <li><span class="param-label" style="font-weight: 600; color: #2D3748;">Grooming:</span> {prefs.get('grooming_commitment', 'N/A')}</li>
|
65 |
-
# <li><span class="param-label" style="font-weight: 600; color: #2D3748;">Experience:</span> {prefs.get('experience_level', 'N/A')}</li>
|
66 |
-
# <li><span class="param-label" style="font-weight: 600; color: #2D3748;">Children at Home:</span> {"Yes" if prefs.get('has_children') else "No"}</li>
|
67 |
-
# <li><span class="param-label" style="font-weight: 600; color: #2D3748;">Noise Tolerance:</span> {prefs.get('noise_tolerance', 'N/A')}</li>
|
68 |
-
# </ul>
|
69 |
-
# </div>
|
70 |
-
# """
|
71 |
-
|
72 |
-
# # 結果顯示邏輯
|
73 |
-
# html += """
|
74 |
-
# <div class="results-list">
|
75 |
-
# <h4 style="font-size: 1.1em; font-weight: 600; color: #2D3748; margin-bottom: 12px; border-bottom: 2px solid #E2E8F0; padding-bottom: 8px;">Top 10 Breed Matches:</h4>
|
76 |
-
# <div class="breed-list">
|
77 |
-
# """
|
78 |
-
|
79 |
-
# if results:
|
80 |
-
# for i, result in enumerate(results[:10], 1):
|
81 |
-
# breed_name = result.get('breed', 'Unknown breed').replace('_', ' ')
|
82 |
-
# score = result.get('overall_score', result.get('final_score', 0))
|
83 |
-
# html += f"""
|
84 |
-
# <div class="breed-item" style="margin-bottom: 8px;">
|
85 |
-
# <div class="breed-info" style="display: flex; align-items: center; justify-content: space-between; padding: 8px; background: #f8fafc; border-radius: 6px;">
|
86 |
-
# <span class="breed-rank" style="background: linear-gradient(135deg, #4299e1, #48bb78); color: white; padding: 4px 10px; border-radius: 6px; font-weight: 600; min-width: 40px; text-align: center;">#{i}</span>
|
87 |
-
# <span class="breed-name" style="font-weight: 500; color: #2D3748; font-size: 1.05em; margin: 0 12px;">{breed_name}</span>
|
88 |
-
# <span class="breed-score" style="background: #F0FFF4; color: #48BB78; padding: 4px 8px; border-radius: 4px; font-weight: 600;">{score*100:.1f}%</span>
|
89 |
-
# </div>
|
90 |
-
# </div>
|
91 |
-
# """
|
92 |
-
|
93 |
-
# html += """
|
94 |
-
# </div>
|
95 |
-
# </div>
|
96 |
-
# </div>
|
97 |
-
# """
|
98 |
-
|
99 |
-
# html += "</div>"
|
100 |
-
# return html
|
101 |
-
|
102 |
-
# except Exception as e:
|
103 |
-
# print(f"Error formatting history: {str(e)}")
|
104 |
-
# print(traceback.format_exc())
|
105 |
-
# return f"""
|
106 |
-
# <div style='text-align: center; padding: 20px; color: #dc2626;'>
|
107 |
-
# Error formatting history. Please try refreshing the page.
|
108 |
-
# <br>Error details: {str(e)}
|
109 |
-
# </div>
|
110 |
-
# """
|
111 |
-
|
112 |
-
|
113 |
def format_history_html(self, history_data: Optional[List[Dict]] = None) -> str:
|
114 |
try:
|
115 |
if history_data is None:
|
|
|
8 |
"""初始化搜索歷史組件"""
|
9 |
self.history_manager = UserHistoryManager()
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def format_history_html(self, history_data: Optional[List[Dict]] = None) -> str:
|
12 |
try:
|
13 |
if history_data is None:
|