Update the profile via the unified drift-aware updater.
(
user_id: str,
selected_paper_ids: List[int],
papers: List[Dict],
skipped_paper_ids: Optional[List[int]] = None,
historical_selected_papers: Optional[List[Dict[str, Any]]] = None,
current_timestamp: Optional[datetime] = None,
feedback_strength_multiplier: float = 1.0,
)
| 540 | |
| 541 | |
| 542 | def update_profile_based_on_selection( |
| 543 | user_id: str, |
| 544 | selected_paper_ids: List[int], |
| 545 | papers: List[Dict], |
| 546 | skipped_paper_ids: Optional[List[int]] = None, |
| 547 | historical_selected_papers: Optional[List[Dict[str, Any]]] = None, |
| 548 | current_timestamp: Optional[datetime] = None, |
| 549 | feedback_strength_multiplier: float = 1.0, |
| 550 | ) -> Dict: |
| 551 | """Update the profile via the unified drift-aware updater.""" |
| 552 | profile = get_profile(user_id) |
| 553 | if not profile: |
| 554 | print(f"Warning: No profile found for user {user_id}") |
| 555 | return {} |
| 556 | |
| 557 | now = current_timestamp or datetime.now() |
| 558 | normalized_profile = ensure_profile_schema(profile, now=now) |
| 559 | |
| 560 | selected_papers: List[Dict[str, Any]] = [] |
| 561 | for paper_number in selected_paper_ids: |
| 562 | idx = paper_number - 1 |
| 563 | if 0 <= idx < len(papers): |
| 564 | selected_paper = dict(papers[idx]) |
| 565 | selected_paper["authors"] = normalize_authors(selected_paper.get("authors", [])) |
| 566 | selected_papers.append(selected_paper) |
| 567 | |
| 568 | skipped_papers: List[Dict[str, Any]] = [] |
| 569 | for paper_number in skipped_paper_ids or []: |
| 570 | idx = paper_number - 1 |
| 571 | if 0 <= idx < len(papers): |
| 572 | skipped_paper = dict(papers[idx]) |
| 573 | skipped_paper["authors"] = normalize_authors(skipped_paper.get("authors", [])) |
| 574 | skipped_papers.append(skipped_paper) |
| 575 | |
| 576 | updated_profile = update_profile_with_feedback( |
| 577 | normalized_profile, |
| 578 | selected_papers, |
| 579 | skipped_papers, |
| 580 | historical_selected_papers=historical_selected_papers or [], |
| 581 | current_time=now, |
| 582 | feedback_strength_multiplier=feedback_strength_multiplier, |
| 583 | ) |
| 584 | update_profile(user_id, updated_profile) |
| 585 | return updated_profile |
| 586 | |
| 587 | |
| 588 | def estimate_feedback_strength_multiplier(push_id: str, current_timestamp: datetime) -> tuple[float, Optional[float]]: |
no test coverage detected