interface dirextion fix
This commit is contained in:
@@ -38,6 +38,18 @@ def _observation_signature(observation: Dict[str, Any]) -> tuple[Any, ...]:
|
||||
)
|
||||
|
||||
|
||||
def _parse_observation_timestamp(value: Any) -> datetime:
|
||||
if isinstance(value, datetime):
|
||||
return value if value.tzinfo is not None else value.replace(tzinfo=timezone.utc)
|
||||
if value in (None, ""):
|
||||
return datetime.max.replace(tzinfo=timezone.utc)
|
||||
try:
|
||||
parsed = datetime.fromisoformat(str(value))
|
||||
return parsed if parsed.tzinfo is not None else parsed.replace(tzinfo=timezone.utc)
|
||||
except Exception:
|
||||
return datetime.max.replace(tzinfo=timezone.utc)
|
||||
|
||||
|
||||
def _bridge_af_packet_observation_groups(payload: Dict[str, Any]) -> Dict[str, set[str]]:
|
||||
groups: Dict[str, set[str]] = {}
|
||||
observations = payload.get("capture_observations") or []
|
||||
@@ -87,7 +99,7 @@ def _sorted_bridge_af_packet_observations(payload: Dict[str, Any]) -> Dict[str,
|
||||
grouped.setdefault(str(session_id), []).append(observation)
|
||||
|
||||
for session_id, items in grouped.items():
|
||||
items.sort(key=lambda item: str(item.get("timestamp") or ""))
|
||||
items.sort(key=lambda item: (_parse_observation_timestamp(item.get("timestamp")), str(item.get("iface") or "")))
|
||||
grouped[session_id] = items
|
||||
return grouped
|
||||
|
||||
@@ -339,7 +351,7 @@ class PacketTracker:
|
||||
return False
|
||||
|
||||
observations.append(normalized)
|
||||
observations.sort(key=lambda item: str(item.get("timestamp") or ""))
|
||||
observations.sort(key=lambda item: (_parse_observation_timestamp(item.get("timestamp")), str(item.get("iface") or "")))
|
||||
return True
|
||||
|
||||
def _merge_packet_info(self, entry: Dict[str, Any], pkt_info: Dict[str, Any], now_ts: float) -> None:
|
||||
@@ -405,8 +417,13 @@ class PacketTracker:
|
||||
return False
|
||||
|
||||
changed = False
|
||||
session_id = sorted(observation_groups.keys())[0]
|
||||
observations = observation_groups[session_id]
|
||||
session_id, observations = min(
|
||||
observation_groups.items(),
|
||||
key=lambda item: (
|
||||
_parse_observation_timestamp(item[1][0].get("timestamp") if item[1] else None),
|
||||
str(item[0]),
|
||||
),
|
||||
)
|
||||
if not observations:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user