dschandra commited on
Commit
93a3e92
·
verified ·
1 Parent(s): dd08014

Create drs_logic.py

Browse files
Files changed (1) hide show
  1. utils/drs_logic.py +33 -0
utils/drs_logic.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # backend/utils/drs_logic.py
2
+ def predict_impact(ball_positions: list) -> tuple:
3
+ """
4
+ Predict the ball's impact point on the stumps or pad based on trajectory.
5
+ Returns (x, y) coordinates of the predicted impact point.
6
+ """
7
+ if not ball_positions or len(ball_positions) < 2:
8
+ return None
9
+
10
+ x1, y1 = ball_positions[-2]
11
+ x2, y2 = ball_positions[-1]
12
+
13
+ stump_y = 600 # Adjust based on video calibration
14
+ if y2 == y1:
15
+ return None
16
+
17
+ slope = (x2 - x1) / (y2 - y1)
18
+ impact_x = x1 + slope * (stump_y - y1)
19
+
20
+ return (impact_x, stump_y)
21
+
22
+ def is_drs_out(impact_point: tuple) -> bool:
23
+ """
24
+ Determine if the ball meets DRS criteria for an Out decision.
25
+ Returns True (Out) or False (Not Out).
26
+ """
27
+ if impact_point is None:
28
+ return False
29
+
30
+ x, y = impact_point
31
+ stump_x_min, stump_x_max = 400, 800 # Adjust based on video calibration
32
+
33
+ return stump_x_min <= x <= stump_x_max