只有hello包实现多跳,还没加入业务数据
具体的还要看opencode和gpt记录接着优化
This commit is contained in:
62
sim/analysis_tools/reliability_analysis.py
Normal file
62
sim/analysis_tools/reliability_analysis.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""
|
||||
Reliability Analysis Tools.
|
||||
|
||||
Functions for analyzing packet delivery reliability.
|
||||
"""
|
||||
|
||||
from typing import Dict, Any
|
||||
|
||||
|
||||
def analyze_loss_breakdown(loss_data: Dict[str, int]) -> Dict[str, Any]:
|
||||
"""
|
||||
Analyze packet loss breakdown.
|
||||
|
||||
Args:
|
||||
loss_data: Dictionary with loss counts by type
|
||||
|
||||
Returns:
|
||||
Dictionary with loss analysis
|
||||
"""
|
||||
total_loss = sum(loss_data.values())
|
||||
|
||||
if total_loss == 0:
|
||||
return {
|
||||
"total_loss": 0,
|
||||
"rates": {},
|
||||
"primary_cause": "none",
|
||||
}
|
||||
|
||||
rates = {k: round(v / total_loss * 100, 2) for k, v in loss_data.items() if v > 0}
|
||||
|
||||
# Find primary cause
|
||||
primary_cause = (
|
||||
max(loss_data.items(), key=lambda x: x[1])[0] if loss_data else "none"
|
||||
)
|
||||
|
||||
return {
|
||||
"total_loss": total_loss,
|
||||
"rates": rates,
|
||||
"primary_cause": primary_cause,
|
||||
}
|
||||
|
||||
|
||||
def calculate_pdr_metrics(total_sent: int, total_received: int) -> Dict[str, Any]:
|
||||
"""
|
||||
Calculate PDR metrics.
|
||||
|
||||
Args:
|
||||
total_sent: Total packets sent
|
||||
total_received: Total packets received
|
||||
|
||||
Returns:
|
||||
Dictionary with PDR analysis
|
||||
"""
|
||||
pdr = total_received / total_sent if total_sent > 0 else 0
|
||||
|
||||
return {
|
||||
"total_sent": total_sent,
|
||||
"total_received": total_received,
|
||||
"pdr": round(pdr * 100, 2),
|
||||
"delivered": total_received,
|
||||
"lost": total_sent - total_received,
|
||||
}
|
||||
Reference in New Issue
Block a user