选择书源 Args: sources: 书源列表 strategy: 选择策略(domain_diversity 或 top_n) Returns: (选中的书源, 统计信息)
(
self,
sources: List[Dict],
strategy: str = 'domain_diversity'
)
| 209 | return selected, stats |
| 210 | |
| 211 | def select( |
| 212 | self, |
| 213 | sources: List[Dict], |
| 214 | strategy: str = 'domain_diversity' |
| 215 | ) -> Tuple[List[Dict], Dict]: |
| 216 | """ |
| 217 | 选择书源 |
| 218 | |
| 219 | Args: |
| 220 | sources: 书源列表 |
| 221 | strategy: 选择策略(domain_diversity 或 top_n) |
| 222 | |
| 223 | Returns: |
| 224 | (选中的书源, 统计信息) |
| 225 | """ |
| 226 | print(f'\n=== 智能选择开始 ===') |
| 227 | print(f'候选书源:{len(sources)} 个') |
| 228 | print(f'目标数量:{self.target_count} 个') |
| 229 | print(f'选择策略:{strategy}') |
| 230 | print(f'域名限制:每域名最多 {self.max_per_domain} 个\n') |
| 231 | |
| 232 | # 步骤 1:按评分排序 |
| 233 | print('步骤 1:按评分排序...') |
| 234 | sorted_sources = self.sort_by_score(sources) |
| 235 | print(f'✓ 排序完成') |
| 236 | |
| 237 | # 步骤 2:选择 |
| 238 | print(f'\n步骤 2:使用 {strategy} 策略选择...') |
| 239 | if strategy == 'domain_diversity': |
| 240 | selected, stats = self.select_with_domain_diversity(sorted_sources) |
| 241 | elif strategy == 'top_n': |
| 242 | selected, stats = self.select_top_n(sorted_sources) |
| 243 | else: |
| 244 | raise ValueError(f'未知策略:{strategy}') |
| 245 | |
| 246 | print(f'✓ 选择完成:{len(selected)} 个书源') |
| 247 | |
| 248 | # 步骤 3:打印统计 |
| 249 | print('\n=== 选择统计 ===') |
| 250 | print(f'候选书源:{stats["total_candidates"]} 个') |
| 251 | print(f'选中书源:{stats["selected"]} 个') |
| 252 | print(f'唯一域名:{stats["unique_domains"]} 个') |
| 253 | print(f'平均评分:{stats["avg_score"]:.1f}') |
| 254 | print(f'评分范围:{stats["min_score"]:.1f} - {stats["max_score"]:.1f}') |
| 255 | |
| 256 | if strategy == 'domain_diversity': |
| 257 | print(f'总域名数:{stats["total_domains"]} 个') |
| 258 | print(f'域名限制跳过:{stats["skipped_by_domain"]} 个') |
| 259 | |
| 260 | print('\n=== 智能选择完成 ===\n') |
| 261 | |
| 262 | return selected, stats |
| 263 | |
| 264 | |
| 265 | def main(): |
no test coverage detected