Get behavior logs for a date range
(user_id: str, start_date: str, end_date: str)
| 1120 | def get_doc_engagement_stats(user_id: str, days: int = 7) -> Dict[str, Any]: |
| 1121 | """ |
| 1122 | Aggregate lightweight doc engagement proxies. |
| 1123 | """ |
| 1124 | since_timestamp = (datetime.now() - timedelta(days=max(1, int(days)))).isoformat(sep=" ") |
| 1125 | conn = get_connection() |
| 1126 | cursor = conn.cursor() |
| 1127 | cursor.execute( |
| 1128 | """ |
| 1129 | SELECT action, action_type, metadata, timestamp |
| 1130 | FROM behavior_logs |
| 1131 | WHERE user_id = ? |
| 1132 | AND timestamp >= ? |
| 1133 | AND ( |
| 1134 | (action = 'opened_report' AND action_type = 'doc_open') |
| 1135 | OR (action = 'doc_dwell_proxy' AND action_type = 'doc_engagement') |
| 1136 | ) |