feat: show RDP session duration in Overview and Events (0.5.16)
Add session_duration_sec to EventSummary and a Duration column (HH:MM:SS / Nd HH:MM:SS).
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""Format and extract RDP/RDG session_duration_sec for UI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def extract_session_duration_sec(details: dict[str, Any] | None) -> int | None:
|
||||
if not isinstance(details, dict):
|
||||
return None
|
||||
raw = details.get("session_duration_sec")
|
||||
if raw is None or raw == "":
|
||||
return None
|
||||
try:
|
||||
value = int(raw)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
if value < 0:
|
||||
return None
|
||||
return value
|
||||
|
||||
|
||||
def format_session_duration(seconds: int) -> str:
|
||||
"""
|
||||
Human-readable session length for lists:
|
||||
- under 24h → HH:MM:SS (05:05:24)
|
||||
- 24h+ → Nд HH:MM:SS (1д 00:01:25)
|
||||
"""
|
||||
if seconds < 0:
|
||||
return "—"
|
||||
days, rem = divmod(int(seconds), 86_400)
|
||||
hours, rem = divmod(rem, 3600)
|
||||
minutes, secs = divmod(rem, 60)
|
||||
clock = f"{hours:02d}:{minutes:02d}:{secs:02d}"
|
||||
if days:
|
||||
return f"{days}д {clock}"
|
||||
return clock
|
||||
Reference in New Issue
Block a user