(
profile: Dict[str, Any],
logs: List[Dict[str, Any]],
recent_pushes: List[Dict[str, Any]],
)
| 292 | |
| 293 | def _build_external_impact_summary( |
| 294 | profile: Dict[str, Any], |
| 295 | logs: List[Dict[str, Any]], |
| 296 | recent_pushes: List[Dict[str, Any]], |
| 297 | ) -> Dict[str, Any]: |
| 298 | selected_ids = { |
| 299 | int(log.get("paper_id")) |
| 300 | for log in logs |
| 301 | if str(log.get("action_type") or "") == "selected" and log.get("paper_id") is not None |
| 302 | } |
| 303 | must_read_authors = [str(author).strip() for author in ((profile or {}).get("must_read", {}) or {}).get("authors", []) if str(author).strip()] |
| 304 | |
| 305 | impact_cache: Dict[str, Dict[str, Any]] = {} |
| 306 | selected_impacts: List[Dict[str, Any]] = [] |
| 307 | skipped_impacts: List[Dict[str, Any]] = [] |
| 308 | cited_by_must_read: List[Dict[str, Any]] = [] |
| 309 | |
| 310 | for paper in recent_pushes[:25]: |
| 311 | impact = _cached_openalex_impact_signal(paper, impact_cache) |
| 312 | cited_by_count = int(impact.get("cited_by_count") or 0) |
| 313 | if cited_by_count > 0: |
| 314 | item = { |
| 315 | "title": paper.get("title", "Unknown"), |
| 316 | "cited_by_count": cited_by_count, |
| 317 | "impact_venue": impact.get("venue", ""), |
| 318 | "category": str(paper.get("category") or ""), |
| 319 | } |
| 320 | if paper.get("id") in selected_ids: |
| 321 | selected_impacts.append(item) |
| 322 | else: |
| 323 | skipped_impacts.append(item) |
| 324 | |
| 325 | if must_read_authors and impact.get("cited_by_api_url"): |
| 326 | author_matches = _fetch_citing_author_matches(impact, must_read_authors) |
| 327 | if author_matches: |
| 328 | cited_by_must_read.append( |
| 329 | { |
| 330 | "title": paper.get("title", "Unknown"), |
| 331 | "matches": author_matches, |
| 332 | "cited_by_count": cited_by_count, |
| 333 | } |
| 334 | ) |
| 335 | |
| 336 | selected_impacts.sort(key=lambda item: int(item.get("cited_by_count", 0)), reverse=True) |
| 337 | skipped_impacts.sort(key=lambda item: int(item.get("cited_by_count", 0)), reverse=True) |
| 338 | cited_by_must_read.sort( |
| 339 | key=lambda item: ( |
| 340 | int(item.get("cited_by_count", 0)), |
| 341 | len(item.get("matches") or []), |
| 342 | ), |
| 343 | reverse=True, |
| 344 | ) |
| 345 | |
| 346 | explanations: List[str] = [] |
| 347 | if selected_impacts: |
| 348 | top_selected = selected_impacts[0] |
| 349 | explanations.append( |
| 350 | f"你本周选中的论文里,外部引用积累最高的是《{top_selected['title']}》" |
| 351 | f"(cited_by={top_selected['cited_by_count']})。" |
no test coverage detected