mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-11 02:12:04 +03:00
docs: add comprehensive docstrings to stats module
- Add detailed docstring to RttStats class documenting all attributes - Add comprehensive docstring to rtt_stats() function with Args, Returns, and Note sections - Document jitter calculation behavior for edge cases (fewer than 2 samples)
This commit is contained in:
parent
3a0f95c793
commit
874163f839
1 changed files with 27 additions and 0 deletions
|
|
@ -4,6 +4,18 @@ from typing import NamedTuple
|
|||
|
||||
|
||||
class RttStats(NamedTuple):
|
||||
"""Statistics computed from RTT samples.
|
||||
|
||||
Attributes:
|
||||
sent: Number of probes sent.
|
||||
received: Number of probes received.
|
||||
loss_pct: Percentage of lost probes (0-100).
|
||||
min_ms: Minimum RTT in milliseconds, or None if no samples.
|
||||
avg_ms: Average RTT in milliseconds, or None if no samples.
|
||||
max_ms: Maximum RTT in milliseconds, or None if no samples.
|
||||
mdev_ms: Mean deviation of RTT in milliseconds, or None if no samples.
|
||||
jitter_ms: Jitter (average inter-packet delay variation) in milliseconds, or None.
|
||||
"""
|
||||
sent: int
|
||||
received: int
|
||||
loss_pct: float
|
||||
|
|
@ -15,6 +27,21 @@ class RttStats(NamedTuple):
|
|||
|
||||
|
||||
def rtt_stats(samples: list[float | None]) -> RttStats:
|
||||
"""Compute RTT statistics from a list of samples.
|
||||
|
||||
Args:
|
||||
samples: A list of RTT measurements in milliseconds, where None represents
|
||||
a lost/timeout probe.
|
||||
|
||||
Returns:
|
||||
A RttStats named tuple containing sent/received counts, loss percentage,
|
||||
min/avg/max RTT, mean deviation, and jitter. All timing fields are None
|
||||
if no samples were received.
|
||||
|
||||
Note:
|
||||
Jitter is computed as the average absolute difference between consecutive
|
||||
non-None samples. If fewer than two valid samples exist, jitter is 0.0.
|
||||
"""
|
||||
sent = len(samples)
|
||||
got = [s for s in samples if s is not None]
|
||||
received = len(got)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue