backend / utils /drs_logic.py
dschandra's picture
Create drs_logic.py
93a3e92 verified
raw
history blame
968 Bytes
# backend/utils/drs_logic.py
def predict_impact(ball_positions: list) -> tuple:
"""
Predict the ball's impact point on the stumps or pad based on trajectory.
Returns (x, y) coordinates of the predicted impact point.
"""
if not ball_positions or len(ball_positions) < 2:
return None
x1, y1 = ball_positions[-2]
x2, y2 = ball_positions[-1]
stump_y = 600 # Adjust based on video calibration
if y2 == y1:
return None
slope = (x2 - x1) / (y2 - y1)
impact_x = x1 + slope * (stump_y - y1)
return (impact_x, stump_y)
def is_drs_out(impact_point: tuple) -> bool:
"""
Determine if the ball meets DRS criteria for an Out decision.
Returns True (Out) or False (Not Out).
"""
if impact_point is None:
return False
x, y = impact_point
stump_x_min, stump_x_max = 400, 800 # Adjust based on video calibration
return stump_x_min <= x <= stump_x_max