(history, newer_id=None, older_id=None)
| 21679 | return None |
| 21680 | |
| 21681 | def _normalize_social_diff_records(history, newer_id=None, older_id=None): |
| 21682 | if not history: |
| 21683 | return {"error": "Nessuno snapshot disponibile"} |
| 21684 | if newer_id or older_id: |
| 21685 | by_id = {row.get("snapshot_id"): row for row in history if isinstance(row, dict) and row.get("snapshot_id")} |
| 21686 | newer = by_id.get(newer_id) if newer_id else None |
| 21687 | older = by_id.get(older_id) if older_id else None |
| 21688 | if newer is None and newer_id: |
| 21689 | return {"error": "snapshot newer_id non trovato"} |
| 21690 | if older is None and older_id: |
| 21691 | return {"error": "snapshot older_id non trovato"} |
| 21692 | if newer is None: |
| 21693 | newer = history[-1] |
| 21694 | if older is None: |
| 21695 | older = history[-2] if len(history) >= 2 else None |
| 21696 | if not older: |
| 21697 | return {"error": "Serve almeno 2 snapshot per calcolare il diff", "available": [row.get("snapshot_id") for row in history]} |
| 21698 | return { |
| 21699 | "newer": newer, |
| 21700 | "older": older, |
| 21701 | "diff": core._social_snapshot_diff(older, newer) |
| 21702 | } |
| 21703 | if len(history) < 2: |
| 21704 | return {"error": "Serve almeno 2 snapshot per calcolare il diff", "available": len(history)} |
| 21705 | return { |
| 21706 | "older": history[-2], |
| 21707 | "newer": history[-1], |
| 21708 | "diff": core._social_snapshot_diff(history[-2], history[-1]), |
| 21709 | "baseline_id": history[-2].get("snapshot_id"), |
| 21710 | "latest_id": history[-1].get("snapshot_id"), |
| 21711 | } |
| 21712 | |
| 21713 | def _social_watch_worker(watch_id, target, platform, interval_seconds, iterations): |
| 21714 | while True: |
no test coverage detected