mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-11 01:02:10 +03:00
docs: add comprehensive docstrings to compare module
- Add docstring to Change dataclass explaining all attributes - Add docstring to ReportDiff dataclass describing the collection of changes - Add docstring to load_report() documenting args, returns, and exceptions
This commit is contained in:
parent
c07fbfabd3
commit
e6cbe1b4ab
1 changed files with 31 additions and 0 deletions
|
|
@ -10,6 +10,15 @@ from netsleuth.exporter import badge
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Change:
|
class Change:
|
||||||
|
"""A single metric change between two reports.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
label: Human-readable description of what changed.
|
||||||
|
before: Value before the change.
|
||||||
|
after: Value after the change.
|
||||||
|
delta: Numeric difference (after - before), or None if not applicable.
|
||||||
|
"""
|
||||||
|
|
||||||
label: str
|
label: str
|
||||||
before: Any = None
|
before: Any = None
|
||||||
after: Any = None
|
after: Any = None
|
||||||
|
|
@ -18,6 +27,16 @@ class Change:
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ReportDiff:
|
class ReportDiff:
|
||||||
|
"""Collection of changes between two network diagnostic reports.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
identity: Changes in network identity (IP, ASN, country, etc.).
|
||||||
|
latency: Changes in latency metrics for reference hosts.
|
||||||
|
speed: Changes in speedtest results.
|
||||||
|
new_findings: Findings present in the newer report but not the older.
|
||||||
|
resolved_findings: Findings present in the older report but cleared in the newer.
|
||||||
|
"""
|
||||||
|
|
||||||
identity: list[Change] = field(default_factory=list)
|
identity: list[Change] = field(default_factory=list)
|
||||||
latency: list[Change] = field(default_factory=list)
|
latency: list[Change] = field(default_factory=list)
|
||||||
speed: list[Change] = field(default_factory=list)
|
speed: list[Change] = field(default_factory=list)
|
||||||
|
|
@ -26,6 +45,18 @@ class ReportDiff:
|
||||||
|
|
||||||
|
|
||||||
def load_report(path: Path) -> dict:
|
def load_report(path: Path) -> dict:
|
||||||
|
"""Load a JSON report from disk.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
path: Path to the JSON report file.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Parsed report dictionary.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
FileNotFoundError: If the report file does not exist.
|
||||||
|
json.JSONDecodeError: If the file contains invalid JSON.
|
||||||
|
"""
|
||||||
return json.loads(Path(path).read_text(encoding="utf-8"))
|
return json.loads(Path(path).read_text(encoding="utf-8"))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue