""" Simplified swing analyzer - contains only essential functions Cleaned up to remove unused functions per user requirements """ import numpy as np # One-liner frame mapping replacement def to_processed_idx(original_idx, sample_rate): return int(round(original_idx / max(1, sample_rate))) def segment_swing_pose_based(pose_data, detections=None, sample_rate=1, frame_shape=None, **kwargs): """Legacy function - use analyze_swing_dtl for new analysis""" from .segmentation import segment_swing return segment_swing(pose_data, detections, sample_rate, frame_shape, **kwargs) def analyze_trajectory(frames, detections, swing_phases, sample_rate=1, fps=30.0): """ Simple trajectory analysis - just track ball movement after impact Args: frames: Video frames detections: Ball detections swing_phases: Swing phase data sample_rate: Frame sampling rate fps: Actual video FPS """ trajectory_data = {} # Simple phase assignment without complex calculations for phase_name, frames_in_phase in swing_phases.items(): # Skip non-phase keys like timing_unreliable if not isinstance(frames_in_phase, list): continue for frame_idx in frames_in_phase: trajectory_data[frame_idx] = { "phase": phase_name, "ball_detected": False } # Mark frames where ball is detected ball_detections = [d for d in detections if d.class_name == "sports ball"] for detection in ball_detections: frame_idx = to_processed_idx(detection.frame_idx, sample_rate) if frame_idx in trajectory_data: trajectory_data[frame_idx]["ball_detected"] = True return trajectory_data