MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / must_read_replace

Function must_read_replace

scripts/drift_engine.py:986–1042  ·  view source on GitHub ↗

蹇呰浣滆€?鏈烘瀯婕傜Щ锛氭浛鎹㈤儴鍒嗗繀璇讳綔鑰呭拰鏈烘瀯

(
    profile: Dict[str, Any],
    params: Dict[str, Any],
    selected_papers: Optional[List[Dict]] = None,
    date: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

984
985def must_read_replace(
986 profile: Dict[str, Any],
987 params: Dict[str, Any],
988 selected_papers: Optional[List[Dict]] = None,
989 date: Optional[str] = None,
990) -> Tuple[Dict[str, Any], Dict[str, Any]]:
991 """
992 蹇呰浣滆€?鏈烘瀯婕傜Щ锛氭浛鎹㈤儴鍒嗗繀璇讳綔鑰呭拰鏈烘瀯
993 """
994 updated = copy.deepcopy(profile)
995 must_read = updated.get("must_read", {})
996
997 replace_ratio = params.get("replace_ratio", 0.5)
998
999 # 鏇挎崲浣滆€?
1000 old_authors = list(must_read.get("authors", []))
1001 if old_authors and random.random() < replace_ratio:
1002 keep_count = max(0, int(len(old_authors) * (1 - replace_ratio)))
1003 new_authors_pool = params.get("new_authors_pool", [])
1004
1005 # 淇濈暀閮ㄥ垎鏃т綔鑰?
1006 kept_authors = random.sample(old_authors, keep_count) if keep_count > 0 else []
1007
1008 # 娣诲姞鏂颁綔鑰?
1009 new_authors_count = len(old_authors) - keep_count
1010 new_authors = random.sample(new_authors_pool, min(new_authors_count, len(new_authors_pool)))
1011
1012 must_read["authors"] = kept_authors + new_authors
1013
1014 # 鏇挎崲鏈烘瀯
1015 old_institutions = list(must_read.get("institutions", []))
1016 if old_institutions and random.random() < replace_ratio:
1017 keep_count = max(0, int(len(old_institutions) * (1 - replace_ratio)))
1018 new_institutions_pool = params.get("new_institutions_pool", [])
1019
1020 kept_institutions = random.sample(old_institutions, keep_count) if keep_count > 0 else []
1021 new_institutions_count = len(old_institutions) - keep_count
1022 new_institutions = random.sample(
1023 new_institutions_pool, min(new_institutions_count, len(new_institutions_pool))
1024 )
1025
1026 must_read["institutions"] = kept_institutions + new_institutions
1027
1028 updated["must_read"] = must_read
1029
1030 # 鏇存柊 drift_state
1031 updated["drift_state"] = _update_drift_state(profile, date, score_delta=0.2)
1032
1033 drift_event = {
1034 "method": "must_read_replace",
1035 "authors_before": old_authors,
1036 "authors_after": list(must_read.get("authors", [])),
1037 "institutions_before": old_institutions,
1038 "institutions_after": list(must_read.get("institutions", [])),
1039 }
1040
1041 return updated, drift_event
1042
1043

Callers

nothing calls this directly

Calls 2

_update_drift_stateFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected