Log user behavior
(
user_id: str,
push_id: str,
paper_id: Optional[int],
action: str,
action_type: str,
category: str = "",
metadata: Optional[Dict] = None
)
| 817 | # ============== Behavior Log Operations ============== |
| 818 | |
| 819 | def log_behavior( |
| 820 | user_id: str, |
| 821 | push_id: str, |
| 822 | paper_id: Optional[int], |
| 823 | action: str, |
| 824 | action_type: str, |
| 825 | category: str = "", |
| 826 | metadata: Optional[Dict] = None |
| 827 | ) -> int: |
| 828 | """Log user behavior""" |
| 829 | conn = get_connection() |
| 830 | cursor = conn.cursor() |
| 831 | cursor.execute(""" |
| 832 | INSERT INTO behavior_logs |
| 833 | (user_id, push_id, paper_id, action, action_type, category, metadata) |
| 834 | VALUES (?, ?, ?, ?, ?, ?, ?) |
| 835 | """, (user_id, push_id, paper_id, action, action_type, category, |
| 836 | json.dumps(metadata) if metadata else None)) |
| 837 | conn.commit() |
| 838 | log_id = cursor.lastrowid |
| 839 | conn.close() |
| 840 | return log_id |
| 841 | |
| 842 | |
| 843 | def _build_created_report_record(row: sqlite3.Row, metadata: Optional[Dict[str, Any]] = None) -> Optional[Dict[str, Any]]: |