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

Function _update_drift_state

scripts/drift_engine.py:1380–1409  ·  view source on GitHub ↗

鏇存柊鍥涢樁娈垫紓绉绘祦绋嬶細 stable -> shifting -> recovered -> stable 姝e悜婕傜Щ鎻愬崌 score锛屾仮澶嶈繃绋嬮檷浣?score銆?

(
    profile: Dict[str, Any],
    date: Optional[str],
    score_delta: float = 0.2,
)

Source from the content-addressed store, hash-verified

1378
1379def _update_drift_state(
1380 profile: Dict[str, Any],
1381 date: Optional[str],
1382 score_delta: float = 0.2,
1383) -> Dict[str, Any]:
1384 """
1385 鏇存柊鍥涢樁娈垫紓绉绘祦绋嬶細
1386 stable -> shifting -> recovered -> stable
1387 姝e悜婕傜Щ鎻愬崌 score锛屾仮澶嶈繃绋嬮檷浣?score銆? """
1388 drift_state = profile.get("drift_state", {}) or {}
1389 old_score = float(drift_state.get("score", 0) or 0)
1390 old_status = str(drift_state.get("status") or "stable")
1391 new_score = max(0.0, min(1.0, old_score + score_delta))
1392
1393 if score_delta >= 0:
1394 status = "shifting" if new_score >= DRIFT_SHIFT_THRESHOLD else "stable"
1395 else:
1396 if old_status == "shifting":
1397 status = "stable" if new_score <= DRIFT_STABLE_THRESHOLD else "recovered"
1398 elif old_status == "recovered":
1399 status = "stable" if new_score <= DRIFT_STABLE_THRESHOLD else "recovered"
1400 else:
1401 status = "stable"
1402
1403 final_score = 0.0 if status == "stable" else round(new_score, 2)
1404 return {
1405 "status": status,
1406 "score": final_score,
1407 "last_drift_date": date,
1408 }
1409
1410
1411def to_display_drift_status(status: Optional[str]) -> str:
1412 normalized = str(status or "stable").strip() or "stable"

Callers 5

topic_weight_decayFunction · 0.85
must_read_replaceFunction · 0.85
keyword_emergenceFunction · 0.85
direction_addFunction · 0.85
direction_removeFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected