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

Function get_recent_drift_updates

skills/storage-helper/scripts/db_ops.py:1667–1714  ·  view source on GitHub ↗

Return recent drift-update behavior logs for a user. Args: user_id: User ID days: Lookback days Returns: Parsed drift update records ordered from old to new.

(user_id: str, days: int = 7)

Source from the content-addressed store, hash-verified

1665
1666
1667def get_recent_drift_updates(user_id: str, days: int = 7) -> List[Dict[str, Any]]:
1668 """
1669 Return recent drift-update behavior logs for a user.
1670
1671 Args:
1672 user_id: User ID
1673 days: Lookback days
1674
1675 Returns:
1676 Parsed drift update records ordered from old to new.
1677 """
1678 since_timestamp = (datetime.now() - timedelta(days=max(1, int(days)))).isoformat(sep=" ")
1679
1680 conn = get_connection()
1681 cursor = conn.cursor()
1682 cursor.execute(
1683 """
1684 SELECT id, user_id, push_id, paper_id, action, action_type, category, timestamp, metadata
1685 FROM behavior_logs
1686 WHERE user_id = ?
1687 AND action = 'profile_updated'
1688 AND action_type = 'drift_update'
1689 AND timestamp >= ?
1690 ORDER BY timestamp ASC, id ASC
1691 """,
1692 (user_id, since_timestamp),
1693 )
1694 rows = cursor.fetchall()
1695 conn.close()
1696
1697 results: List[Dict[str, Any]] = []
1698 for row in rows:
1699 record = dict(row)
1700 metadata = _load_json_metadata(record.get("metadata"))
1701 record["metadata"] = metadata
1702 if "drift_status" in metadata:
1703 record["drift_status"] = metadata.get("drift_status")
1704 if "drift_score" in metadata:
1705 record["drift_score"] = metadata.get("drift_score")
1706 if "adaptive_alpha" in metadata:
1707 record["adaptive_alpha"] = metadata.get("adaptive_alpha")
1708 if "top_shift_topics" in metadata:
1709 record["top_shift_topics"] = metadata.get("top_shift_topics")
1710 if "explanation" in metadata:
1711 record["explanation"] = metadata.get("explanation")
1712 results.append(record)
1713
1714 return results
1715
1716
1717def get_recent_reading_signal(

Callers 1

generate_weekly_reportFunction · 0.85

Calls 8

_load_json_metadataFunction · 0.85
nowMethod · 0.80
cursorMethod · 0.80
getMethod · 0.80
get_connectionFunction · 0.70
executeMethod · 0.45
fetchallMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected