Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +231 -202
scoring_calculation_system.py
CHANGED
@@ -31,183 +31,104 @@ class UserPreferences:
|
|
31 |
self.barking_acceptance = self.noise_tolerance
|
32 |
|
33 |
|
34 |
-
# @staticmethod
|
35 |
-
# def calculate_breed_bonus(breed_info: dict, user_prefs: 'UserPreferences') -> float:
|
36 |
-
# """計算品種額外加分"""
|
37 |
-
# bonus = 0.0
|
38 |
-
# temperament = breed_info.get('Temperament', '').lower()
|
39 |
-
|
40 |
-
# # 1. 壽命加分(最高0.05)
|
41 |
-
# try:
|
42 |
-
# lifespan = breed_info.get('Lifespan', '10-12 years')
|
43 |
-
# years = [int(x) for x in lifespan.split('-')[0].split()[0:1]]
|
44 |
-
# longevity_bonus = min(0.05, (max(years) - 10) * 0.01)
|
45 |
-
# bonus += longevity_bonus
|
46 |
-
# except:
|
47 |
-
# pass
|
48 |
-
|
49 |
-
# # 2. 性格特徵加分(最高0.15)
|
50 |
-
# positive_traits = {
|
51 |
-
# 'friendly': 0.05,
|
52 |
-
# 'gentle': 0.05,
|
53 |
-
# 'patient': 0.05,
|
54 |
-
# 'intelligent': 0.04,
|
55 |
-
# 'adaptable': 0.04,
|
56 |
-
# 'affectionate': 0.04,
|
57 |
-
# 'easy-going': 0.03,
|
58 |
-
# 'calm': 0.03
|
59 |
-
# }
|
60 |
-
|
61 |
-
# negative_traits = {
|
62 |
-
# 'aggressive': -0.08,
|
63 |
-
# 'stubborn': -0.06,
|
64 |
-
# 'dominant': -0.06,
|
65 |
-
# 'aloof': -0.04,
|
66 |
-
# 'nervous': -0.05,
|
67 |
-
# 'protective': -0.04
|
68 |
-
# }
|
69 |
-
|
70 |
-
# personality_score = sum(value for trait, value in positive_traits.items() if trait in temperament)
|
71 |
-
# personality_score += sum(value for trait, value in negative_traits.items() if trait in temperament)
|
72 |
-
# bonus += max(-0.15, min(0.15, personality_score))
|
73 |
-
|
74 |
-
# # 3. 適應性加分(最高0.1)
|
75 |
-
# adaptability_bonus = 0.0
|
76 |
-
# if breed_info.get('Size') == "Small" and user_prefs.living_space == "apartment":
|
77 |
-
# adaptability_bonus += 0.05
|
78 |
-
# if 'adaptable' in temperament or 'versatile' in temperament:
|
79 |
-
# adaptability_bonus += 0.05
|
80 |
-
# bonus += min(0.1, adaptability_bonus)
|
81 |
-
|
82 |
-
# # 4. 家庭相容性(最高0.1)
|
83 |
-
# if user_prefs.has_children:
|
84 |
-
# family_traits = {
|
85 |
-
# 'good with children': 0.06,
|
86 |
-
# 'patient': 0.05,
|
87 |
-
# 'gentle': 0.05,
|
88 |
-
# 'tolerant': 0.04,
|
89 |
-
# 'playful': 0.03
|
90 |
-
# }
|
91 |
-
# unfriendly_traits = {
|
92 |
-
# 'aggressive': -0.08,
|
93 |
-
# 'nervous': -0.07,
|
94 |
-
# 'protective': -0.06,
|
95 |
-
# 'territorial': -0.05
|
96 |
-
# }
|
97 |
-
|
98 |
-
# # 年齡評估這樣能更細緻
|
99 |
-
# age_adjustments = {
|
100 |
-
# 'toddler': {'bonus_mult': 0.7, 'penalty_mult': 1.3},
|
101 |
-
# 'school_age': {'bonus_mult': 1.0, 'penalty_mult': 1.0},
|
102 |
-
# 'teenager': {'bonus_mult': 1.2, 'penalty_mult': 0.8}
|
103 |
-
# }
|
104 |
-
|
105 |
-
# adj = age_adjustments.get(user_prefs.children_age,
|
106 |
-
# {'bonus_mult': 1.0, 'penalty_mult': 1.0})
|
107 |
-
|
108 |
-
# family_bonus = sum(value for trait, value in family_traits.items()
|
109 |
-
# if trait in temperament) * adj['bonus_mult']
|
110 |
-
# family_penalty = sum(value for trait, value in unfriendly_traits.items()
|
111 |
-
# if trait in temperament) * adj['penalty_mult']
|
112 |
-
|
113 |
-
# bonus += min(0.15, max(-0.2, family_bonus + family_penalty))
|
114 |
-
|
115 |
-
|
116 |
-
# # 5. 專門技能加分(最高0.1)
|
117 |
-
# skill_bonus = 0.0
|
118 |
-
# special_abilities = {
|
119 |
-
# 'working': 0.03,
|
120 |
-
# 'herding': 0.03,
|
121 |
-
# 'hunting': 0.03,
|
122 |
-
# 'tracking': 0.03,
|
123 |
-
# 'agility': 0.02
|
124 |
-
# }
|
125 |
-
# for ability, value in special_abilities.items():
|
126 |
-
# if ability in temperament.lower():
|
127 |
-
# skill_bonus += value
|
128 |
-
# bonus += min(0.1, skill_bonus)
|
129 |
-
|
130 |
-
# return min(0.5, max(-0.25, bonus))
|
131 |
-
|
132 |
-
|
133 |
@staticmethod
|
134 |
-
def calculate_breed_bonus(breed_info: dict, user_prefs: UserPreferences) -> float:
|
135 |
-
"""
|
136 |
-
計算品種的額外加分,評估品種的特殊特徵對使用者需求的適配性。
|
137 |
-
|
138 |
-
這個函數考慮四個主要面向:
|
139 |
-
1. 壽命評估:考慮飼養的長期承諾
|
140 |
-
2. 性格特徵評估:評估品種性格與使用者需求的匹配度
|
141 |
-
3. 環境適應性:評估品種在特定生活環境中的表現
|
142 |
-
4. 家庭相容性:特別關注品種與家庭成員的互動
|
143 |
-
"""
|
144 |
bonus = 0.0
|
145 |
temperament = breed_info.get('Temperament', '').lower()
|
146 |
-
description = breed_info.get('Description', '').lower()
|
147 |
|
148 |
-
#
|
149 |
try:
|
150 |
lifespan = breed_info.get('Lifespan', '10-12 years')
|
151 |
years = [int(x) for x in lifespan.split('-')[0].split()[0:1]]
|
152 |
-
|
153 |
-
|
154 |
-
# 根據壽命長短給予不同程度的獎勵或懲罰
|
155 |
-
if avg_years < 8:
|
156 |
-
bonus -= 0.08 # 短壽命可能帶來情感負擔
|
157 |
-
elif avg_years < 10:
|
158 |
-
bonus -= 0.04 # 稍短壽命輕微降低評分
|
159 |
-
elif avg_years > 13:
|
160 |
-
bonus += 0.06 # 長壽命適度加分
|
161 |
-
elif avg_years > 15:
|
162 |
-
bonus += 0.08 # 特別長壽的品種獲得更多加分
|
163 |
except:
|
164 |
pass
|
165 |
|
166 |
-
#
|
167 |
positive_traits = {
|
168 |
-
'friendly': 0.
|
169 |
-
'gentle': 0.
|
170 |
-
'patient': 0.
|
171 |
-
'intelligent': 0.
|
172 |
-
'adaptable': 0.
|
173 |
-
'affectionate': 0.
|
174 |
-
'easy-going': 0.
|
175 |
-
'calm': 0.
|
176 |
}
|
177 |
|
178 |
negative_traits = {
|
179 |
-
'aggressive': -0.
|
180 |
-
'stubborn': -0.
|
181 |
-
'dominant': -0.
|
182 |
-
'aloof': -0.
|
183 |
-
'nervous': -0.
|
184 |
-
'protective': -0.
|
185 |
}
|
186 |
|
187 |
-
|
188 |
-
personality_score
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
if negative_count > 1:
|
206 |
-
personality_score *= (1 - (negative_count - 1) * 0.15)
|
207 |
-
|
208 |
-
bonus += max(-0.25, min(0.25, personality_score))
|
209 |
|
210 |
-
|
|
|
211 |
adaptability_bonus = 0.0
|
212 |
if breed_info.get('Size') == "Small" and user_prefs.living_space == "apartment":
|
213 |
adaptability_bonus += 0.08 # 小型犬更適合公寓
|
@@ -235,56 +156,164 @@ def calculate_breed_bonus(breed_info: dict, user_prefs: UserPreferences) -> floa
|
|
235 |
|
236 |
bonus += min(0.15, adaptability_bonus)
|
237 |
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
'school_age': {
|
262 |
-
'bonus_mult': 1.0,
|
263 |
-
'penalty_mult': 1.0
|
264 |
-
},
|
265 |
-
'teenager': {
|
266 |
-
'bonus_mult': 1.2, # 提高正面特質的獎勵
|
267 |
-
'penalty_mult': 0.8 # 降低負面特質的懲罰
|
268 |
-
}
|
269 |
-
}
|
270 |
|
271 |
-
|
272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
|
284 |
-
|
285 |
|
286 |
-
|
287 |
-
|
288 |
|
289 |
|
290 |
# @staticmethod
|
|
|
31 |
self.barking_acceptance = self.noise_tolerance
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
@staticmethod
|
35 |
+
def calculate_breed_bonus(breed_info: dict, user_prefs: 'UserPreferences') -> float:
|
36 |
+
"""計算品種額外加分"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
bonus = 0.0
|
38 |
temperament = breed_info.get('Temperament', '').lower()
|
|
|
39 |
|
40 |
+
# 1. 壽命加分(最高0.05)
|
41 |
try:
|
42 |
lifespan = breed_info.get('Lifespan', '10-12 years')
|
43 |
years = [int(x) for x in lifespan.split('-')[0].split()[0:1]]
|
44 |
+
longevity_bonus = min(0.05, (max(years) - 10) * 0.01)
|
45 |
+
bonus += longevity_bonus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
except:
|
47 |
pass
|
48 |
|
49 |
+
# 2. 性格特徵加分(最高0.15)
|
50 |
positive_traits = {
|
51 |
+
'friendly': 0.05,
|
52 |
+
'gentle': 0.05,
|
53 |
+
'patient': 0.05,
|
54 |
+
'intelligent': 0.04,
|
55 |
+
'adaptable': 0.04,
|
56 |
+
'affectionate': 0.04,
|
57 |
+
'easy-going': 0.03,
|
58 |
+
'calm': 0.03
|
59 |
}
|
60 |
|
61 |
negative_traits = {
|
62 |
+
'aggressive': -0.08,
|
63 |
+
'stubborn': -0.06,
|
64 |
+
'dominant': -0.06,
|
65 |
+
'aloof': -0.04,
|
66 |
+
'nervous': -0.05,
|
67 |
+
'protective': -0.04
|
68 |
}
|
69 |
|
70 |
+
personality_score = sum(value for trait, value in positive_traits.items() if trait in temperament)
|
71 |
+
personality_score += sum(value for trait, value in negative_traits.items() if trait in temperament)
|
72 |
+
bonus += max(-0.15, min(0.15, personality_score))
|
73 |
+
|
74 |
+
# 3. 適應性加分(最高0.1)
|
75 |
+
adaptability_bonus = 0.0
|
76 |
+
if breed_info.get('Size') == "Small" and user_prefs.living_space == "apartment":
|
77 |
+
adaptability_bonus += 0.05
|
78 |
+
if 'adaptable' in temperament or 'versatile' in temperament:
|
79 |
+
adaptability_bonus += 0.05
|
80 |
+
bonus += min(0.1, adaptability_bonus)
|
81 |
+
|
82 |
+
# 4. 家庭相容性(最高0.1)
|
83 |
+
if user_prefs.has_children:
|
84 |
+
family_traits = {
|
85 |
+
'good with children': 0.06,
|
86 |
+
'patient': 0.05,
|
87 |
+
'gentle': 0.05,
|
88 |
+
'tolerant': 0.04,
|
89 |
+
'playful': 0.03
|
90 |
+
}
|
91 |
+
unfriendly_traits = {
|
92 |
+
'aggressive': -0.08,
|
93 |
+
'nervous': -0.07,
|
94 |
+
'protective': -0.06,
|
95 |
+
'territorial': -0.05
|
96 |
+
}
|
97 |
+
|
98 |
+
# 年齡評估這樣能更細緻
|
99 |
+
age_adjustments = {
|
100 |
+
'toddler': {'bonus_mult': 0.7, 'penalty_mult': 1.3},
|
101 |
+
'school_age': {'bonus_mult': 1.0, 'penalty_mult': 1.0},
|
102 |
+
'teenager': {'bonus_mult': 1.2, 'penalty_mult': 0.8}
|
103 |
+
}
|
104 |
+
|
105 |
+
adj = age_adjustments.get(user_prefs.children_age,
|
106 |
+
{'bonus_mult': 1.0, 'penalty_mult': 1.0})
|
107 |
+
|
108 |
+
family_bonus = sum(value for trait, value in family_traits.items()
|
109 |
+
if trait in temperament) * adj['bonus_mult']
|
110 |
+
family_penalty = sum(value for trait, value in unfriendly_traits.items()
|
111 |
+
if trait in temperament) * adj['penalty_mult']
|
112 |
+
|
113 |
+
bonus += min(0.15, max(-0.2, family_bonus + family_penalty))
|
114 |
+
|
115 |
|
116 |
+
# 5. 專門技能加分(最高0.1)
|
117 |
+
skill_bonus = 0.0
|
118 |
+
special_abilities = {
|
119 |
+
'working': 0.03,
|
120 |
+
'herding': 0.03,
|
121 |
+
'hunting': 0.03,
|
122 |
+
'tracking': 0.03,
|
123 |
+
'agility': 0.02
|
124 |
+
}
|
125 |
+
for ability, value in special_abilities.items():
|
126 |
+
if ability in temperament.lower():
|
127 |
+
skill_bonus += value
|
128 |
+
bonus += min(0.1, skill_bonus)
|
|
|
|
|
|
|
|
|
129 |
|
130 |
+
|
131 |
+
# 6. 適應性評估 - 根據具體環境給予更細緻的評分
|
132 |
adaptability_bonus = 0.0
|
133 |
if breed_info.get('Size') == "Small" and user_prefs.living_space == "apartment":
|
134 |
adaptability_bonus += 0.08 # 小型犬更適合公寓
|
|
|
156 |
|
157 |
bonus += min(0.15, adaptability_bonus)
|
158 |
|
159 |
+
return min(0.5, max(-0.25, bonus))
|
160 |
+
|
161 |
+
|
162 |
+
# @staticmethod
|
163 |
+
# def calculate_breed_bonus(breed_info: dict, user_prefs: UserPreferences) -> float:
|
164 |
+
# """
|
165 |
+
# 計算品種的額外加分,評估品種的特殊特徵對使用者需求的適配性。
|
166 |
+
|
167 |
+
# 這個函數考慮四個主要面向:
|
168 |
+
# 1. 壽命評估:考慮飼養的長期承諾
|
169 |
+
# 2. 性格特徵評估:評估品種性格與使用者需求的匹配度
|
170 |
+
# 3. 環境適應性:評估品種在特定生活環境中的表現
|
171 |
+
# 4. 家庭相容性:特別關注品種與家庭成員的互動
|
172 |
+
# """
|
173 |
+
# bonus = 0.0
|
174 |
+
# temperament = breed_info.get('Temperament', '').lower()
|
175 |
+
# description = breed_info.get('Description', '').lower()
|
176 |
+
|
177 |
+
# # 壽命評估 - 重新設計以反映更實際的考量
|
178 |
+
# try:
|
179 |
+
# lifespan = breed_info.get('Lifespan', '10-12 years')
|
180 |
+
# years = [int(x) for x in lifespan.split('-')[0].split()[0:1]]
|
181 |
+
# avg_years = float(years[0])
|
182 |
|
183 |
+
# # 根據壽命長短給予不同程度的獎勵或懲罰
|
184 |
+
# if avg_years < 8:
|
185 |
+
# bonus -= 0.08 # 短壽命可能帶來情感負擔
|
186 |
+
# elif avg_years < 10:
|
187 |
+
# bonus -= 0.04 # 稍短壽命輕微降低評分
|
188 |
+
# elif avg_years > 13:
|
189 |
+
# bonus += 0.06 # 長壽命適度加分
|
190 |
+
# elif avg_years > 15:
|
191 |
+
# bonus += 0.08 # 特別長壽的品種獲得更多加分
|
192 |
+
# except:
|
193 |
+
# pass
|
194 |
+
|
195 |
+
# # 性格特徵評估 - 擴充並細化評分標準
|
196 |
+
# positive_traits = {
|
197 |
+
# 'friendly': 0.08, # 提高友善性的重要性
|
198 |
+
# 'gentle': 0.08, # 溫和性格更受歡迎
|
199 |
+
# 'patient': 0.07, # 耐心是重要特質
|
200 |
+
# 'intelligent': 0.06, # 聰明但不過分重要
|
201 |
+
# 'adaptable': 0.06, # 適應性佳的特質
|
202 |
+
# 'affectionate': 0.06, # 親密性很重要
|
203 |
+
# 'easy-going': 0.05, # 容易相處的性格
|
204 |
+
# 'calm': 0.05 # 冷靜的特質
|
205 |
+
# }
|
206 |
+
|
207 |
+
# negative_traits = {
|
208 |
+
# 'aggressive': -0.15, # 嚴重懲罰攻擊性
|
209 |
+
# 'stubborn': -0.10, # 固執性格不易處理
|
210 |
+
# 'dominant': -0.10, # 支配性可能造成問題
|
211 |
+
# 'aloof': -0.08, # 冷漠性格影響互動
|
212 |
+
# 'nervous': -0.08, # 緊張性格需要更多關注
|
213 |
+
# 'protective': -0.06 # 過度保護可能有風險
|
214 |
+
# }
|
215 |
+
|
216 |
+
# # 性格評分計算 - 加入累積效應
|
217 |
+
# personality_score = 0
|
218 |
+
# positive_count = 0
|
219 |
+
# negative_count = 0
|
220 |
+
|
221 |
+
# for trait, value in positive_traits.items():
|
222 |
+
# if trait in temperament:
|
223 |
+
# personality_score += value
|
224 |
+
# positive_count += 1
|
225 |
+
|
226 |
+
# for trait, value in negative_traits.items():
|
227 |
+
# if trait in temperament:
|
228 |
+
# personality_score += value
|
229 |
+
# negative_count += 1
|
230 |
+
|
231 |
+
# # 多重特徵的累積效應
|
232 |
+
# if positive_count > 2:
|
233 |
+
# personality_score *= (1 + (positive_count - 2) * 0.1)
|
234 |
+
# if negative_count > 1:
|
235 |
+
# personality_score *= (1 - (negative_count - 1) * 0.15)
|
236 |
+
|
237 |
+
# bonus += max(-0.25, min(0.25, personality_score))
|
238 |
+
|
239 |
+
# # 適應性評估 - 根據具體環境給予更細緻的評分
|
240 |
+
# adaptability_bonus = 0.0
|
241 |
+
# if breed_info.get('Size') == "Small" and user_prefs.living_space == "apartment":
|
242 |
+
# adaptability_bonus += 0.08 # 小型犬更適合公寓
|
243 |
+
|
244 |
+
# # 環境適應性評估
|
245 |
+
# if 'adaptable' in temperament or 'versatile' in temperament:
|
246 |
+
# if user_prefs.living_space == "apartment":
|
247 |
+
# adaptability_bonus += 0.10 # 適應性在公寓環境更重要
|
248 |
+
# else:
|
249 |
+
# adaptability_bonus += 0.05 # 其他環境仍有加分
|
250 |
+
|
251 |
+
# # 氣候適應性
|
252 |
+
# description = breed_info.get('Description', '').lower()
|
253 |
+
# climate = user_prefs.climate
|
254 |
+
# if climate == 'hot':
|
255 |
+
# if 'heat tolerant' in description or 'warm climate' in description:
|
256 |
+
# adaptability_bonus += 0.08
|
257 |
+
# elif 'thick coat' in description or 'cold climate' in description:
|
258 |
+
# adaptability_bonus -= 0.10
|
259 |
+
# elif climate == 'cold':
|
260 |
+
# if 'thick coat' in description or 'cold climate' in description:
|
261 |
+
# adaptability_bonus += 0.08
|
262 |
+
# elif 'heat tolerant' in description or 'short coat' in description:
|
263 |
+
# adaptability_bonus -= 0.10
|
264 |
+
|
265 |
+
# bonus += min(0.15, adaptability_bonus)
|
266 |
+
|
267 |
+
# # 家庭相容性評估 - 特別關注有孩童的家庭
|
268 |
+
# if user_prefs.has_children:
|
269 |
+
# family_traits = {
|
270 |
+
# 'good with children': 0.12, # 提高與孩童相處的重要性
|
271 |
+
# 'patient': 0.10,
|
272 |
+
# 'gentle': 0.10,
|
273 |
+
# 'tolerant': 0.08,
|
274 |
+
# 'playful': 0.06
|
275 |
+
# }
|
276 |
|
277 |
+
# unfriendly_traits = {
|
278 |
+
# 'aggressive': -0.15, # 加重攻擊性的懲罰
|
279 |
+
# 'nervous': -0.12, # 緊張特質可能有風險
|
280 |
+
# 'protective': -0.10, # 過度保護性需要注意
|
281 |
+
# 'territorial': -0.08 # 地域性可能造成問題
|
282 |
+
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
|
284 |
+
# # 根據孩童年齡調整評分權重
|
285 |
+
# age_adjustments = {
|
286 |
+
# 'toddler': {
|
287 |
+
# 'bonus_mult': 0.6, # 降低正面特質的獎勵
|
288 |
+
# 'penalty_mult': 1.5 # 加重負面特質的懲罰
|
289 |
+
# },
|
290 |
+
# 'school_age': {
|
291 |
+
# 'bonus_mult': 1.0,
|
292 |
+
# 'penalty_mult': 1.0
|
293 |
+
# },
|
294 |
+
# 'teenager': {
|
295 |
+
# 'bonus_mult': 1.2, # 提高正面特質的獎勵
|
296 |
+
# 'penalty_mult': 0.8 # 降低負面特質的懲罰
|
297 |
+
# }
|
298 |
+
# }
|
299 |
+
|
300 |
+
# adj = age_adjustments.get(user_prefs.children_age,
|
301 |
+
# {'bonus_mult': 1.0, 'penalty_mult': 1.0})
|
302 |
|
303 |
+
# # 計算家庭相容性分數
|
304 |
+
# family_score = 0
|
305 |
+
# for trait, value in family_traits.items():
|
306 |
+
# if trait in temperament:
|
307 |
+
# family_score += value * adj['bonus_mult']
|
308 |
|
309 |
+
# for trait, value in unfriendly_traits.items():
|
310 |
+
# if trait in temperament:
|
311 |
+
# family_score += value * adj['penalty_mult']
|
312 |
|
313 |
+
# bonus += min(0.20, max(-0.30, family_score))
|
314 |
|
315 |
+
# # 確保總體加分在合理範圍內,但允許更大的變化
|
316 |
+
# return min(0.5, max(-0.35, bonus))
|
317 |
|
318 |
|
319 |
# @staticmethod
|