Get the latest push information for a user Args: user_id: User ID Returns: Push information with papers list
(user_id: str)
| 1298 | previous_weight = previous_directions.get(direction, 0.0) |
| 1299 | delta = current_weight - previous_weight |
| 1300 | |
| 1301 | changes.append({ |
| 1302 | "direction": direction, |
| 1303 | "current_weight": current_weight, |
| 1304 | "previous_weight": previous_weight, |
| 1305 | "delta": delta, |
| 1306 | "trend": "up" if delta > 0.001 else ("down" if delta < -0.001 else "stable") |
| 1307 | }) |
| 1308 | |
| 1309 | changes.sort(key=lambda x: abs(x["delta"]), reverse=True) |
| 1310 | return changes |
| 1311 | |
| 1312 | |
| 1313 | # ============== Recent Push Operations ============== |
| 1314 | |
| 1315 | def get_recent_pushes(user_id: str, limit: int = 50) -> List[Dict]: |
| 1316 | """ |
| 1317 | Get recently pushed papers for a user |
| 1318 | |
| 1319 | Args: |
| 1320 | user_id: User ID |
| 1321 | limit: Maximum number of papers to return |
| 1322 | |
| 1323 | Returns: |
| 1324 | List of papers with push information |
| 1325 | """ |
| 1326 | conn = get_connection() |
| 1327 | cursor = conn.cursor() |
| 1328 | |
| 1329 | # Get papers pushed in the last 7 days |
| 1330 | since_date = (datetime.now() - timedelta(days=7)).date().isoformat() |
| 1331 | |
| 1332 | cursor.execute(""" |
| 1333 | SELECT p.*, bl.push_id, bl.timestamp as pushed_at, bl.metadata |
| 1334 | FROM papers p |
| 1335 | JOIN behavior_logs bl ON p.id = bl.paper_id |
| 1336 | WHERE bl.user_id = ? |
| 1337 | AND bl.action = 'pushed' |
| 1338 | AND date(bl.timestamp) >= ? |
| 1339 | ORDER BY bl.timestamp DESC |
| 1340 | LIMIT ? |
| 1341 | """, (user_id, since_date, limit)) |
| 1342 | |
| 1343 | rows = cursor.fetchall() |
| 1344 | conn.close() |
| 1345 | |
| 1346 | return [_build_paper_dict(row) for row in rows] |
| 1347 | |
| 1348 | |
| 1349 | def get_latest_push(user_id: str) -> Optional[Dict]: |
| 1350 | """ |
| 1351 | Get the latest push information for a user |
| 1352 | |
| 1353 | Args: |
| 1354 | user_id: User ID |
| 1355 | |
| 1356 | Returns: |
| 1357 | Push information with papers list |