Files
StreamLens/analyzer/models/flow_stats.py
noisedestroyers 36a576dc2c Enhanced Textual TUI with proper API usage and documentation
- Fixed DataTable row selection and event handling
- Added explicit column keys to prevent auto-generated keys
- Implemented row-to-flow mapping for reliable selection tracking
- Converted left metrics panel to horizontal top bar
- Fixed all missing FlowStats/EnhancedAnalysisData attributes
- Created comprehensive Textual API documentation in Documentation/textual/
- Added validation checklist to prevent future API mismatches
- Preserved cursor position during data refreshes
- Fixed RowKey type handling and event names

The TUI now properly handles flow selection, displays metrics in a compact top bar,
and correctly correlates selected rows with the details pane.
2025-07-27 18:37:55 -04:00

86 lines
3.6 KiB
Python

"""
Data structures for flow and frame type statistics
"""
from dataclasses import dataclass, field
from typing import Dict, List, Set, Tuple
@dataclass
class FrameTypeStats:
"""Statistics for a specific frame type within a flow"""
frame_type: str
count: int = 0
total_bytes: int = 0
timestamps: List[float] = field(default_factory=list)
frame_numbers: List[int] = field(default_factory=list)
inter_arrival_times: List[float] = field(default_factory=list)
avg_inter_arrival: float = 0.0
std_inter_arrival: float = 0.0
outlier_frames: List[int] = field(default_factory=list)
outlier_details: List[Tuple[int, float]] = field(default_factory=list)
@dataclass
class EnhancedAnalysisData:
"""Enhanced analysis data from specialized decoders"""
# CH10 Timing Analysis
avg_clock_drift_ppm: float = 0.0
max_clock_drift_ppm: float = 0.0
timing_quality: str = "Unknown" # excellent, good, moderate, poor
timing_stability: str = "Unknown" # stable, variable
anomaly_rate: float = 0.0 # Percentage of frames with timing anomalies
avg_confidence_score: float = 0.0
# CH10 Frame Quality
avg_frame_quality: float = 0.0
sequence_gaps: int = 0
rtc_sync_errors: int = 0
format_errors: int = 0
overflow_errors: int = 0
# CH10 Data Analysis
channel_count: int = 0
analog_channels: int = 0
pcm_channels: int = 0
tmats_frames: int = 0
# General Enhanced Data
has_internal_timing: bool = False
primary_data_type: str = "Unknown"
decoder_type: str = "Standard" # Standard, Chapter10_Enhanced, PTP_Enhanced, etc.
# Decoded Frame Data Storage
sample_decoded_fields: Dict[str, any] = field(default_factory=dict) # Sample of actual decoded fields for display
available_field_names: List[str] = field(default_factory=list) # List of all available field names from decoder
field_count: int = 0 # Total number of fields decoded
frame_types: Set[str] = field(default_factory=set) # Set of unique frame types encountered
timing_accuracy: float = 0.0 # Timing accuracy percentage
signal_quality: float = 0.0 # Signal quality percentage
@dataclass
class FlowStats:
"""Statistics for a source-destination IP pair"""
src_ip: str
dst_ip: str
src_port: int = 0 # Source port (0 if not applicable/unknown)
dst_port: int = 0 # Destination port (0 if not applicable/unknown)
transport_protocol: str = "Unknown" # TCP, UDP, ICMP, IGMP, etc.
traffic_classification: str = "Unknown" # Unicast, Multicast, Broadcast
frame_count: int = 0
timestamps: List[float] = field(default_factory=list)
frame_numbers: List[int] = field(default_factory=list)
inter_arrival_times: List[float] = field(default_factory=list)
avg_inter_arrival: float = 0.0
std_inter_arrival: float = 0.0
outlier_frames: List[int] = field(default_factory=list)
outlier_details: List[Tuple[int, float]] = field(default_factory=list) # (frame_number, time_delta)
total_bytes: int = 0
protocols: Set[str] = field(default_factory=set)
detected_protocol_types: Set[str] = field(default_factory=set) # Enhanced protocol detection (CH10, PTP, IENA, etc)
frame_types: Dict[str, FrameTypeStats] = field(default_factory=dict) # Per-frame-type statistics
enhanced_analysis: EnhancedAnalysisData = field(default_factory=EnhancedAnalysisData) # Enhanced decoder analysis
first_seen: float = 0.0 # Timestamp of the first frame in this flow
last_seen: float = 0.0 # Timestamp of the last frame in this flow
duration: float = 0.0 # Duration of the flow in seconds
jitter: float = 0.0 # Network jitter measurement