Skip to content

Commit

Permalink
Saving some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikonooooo committed Oct 21, 2023
1 parent 155a39f commit 71bafc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 42 deletions.
35 changes: 2 additions & 33 deletions src/processing/shot_detect.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
from typing import List, Tuple
from state import GameState, ShotAttempt, ShotType


def new_rim(file_path):
"""
TODO is this function used?
Accepts a strongsort text file path as an input, and outputs the coordinates
of the original rim and the new box above it. Assumption: the coordinates of
the rim do not move (constant) throughout the video.
"""
# Initialize values
left = 0
top = 0
width = 0
height = 0
with open(file_path, 'r') as file:
lines = file.readlines()
for line in lines:
# Convert each text file line into an int list
lst = [int(i) for i in line.split()]

# Rim index = 2
if lst[1] == 2:
left = lst[3]
top = lst[4]
width = lst[5]
height = lst[6]

# The top_box is simply a height above the rim_box
top_box = left, top+height, width, height
rim_box = left, top, width, height
return top_box, rim_box


def madeshot(state:GameState) -> List[Tuple[int, int]]:
# TODO revamp this method using new ball states
def madeshot(state:GameState, start:int, end:int) -> List[Tuple[int, int]]:
"""
Accepts a strongsort text file path as an input, and outputs the frame
intervals in which a shot was made. Ex: If a shot was made between the
Expand Down
19 changes: 10 additions & 9 deletions src/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ def __init__(self, ballid: int, start: int, end: int) -> None:
"last frame"

# MUTABLE
self.playerid: int = None
"shot's player"
self.type: ShotType = None
"MISSED, TWO, or THREE"

Expand All @@ -102,7 +100,6 @@ def check(self) -> bool:
assert (
self.start is not None
and self.end is not None
and self.playerid is not None
and self.type is not None
)
except:
Expand Down Expand Up @@ -274,11 +271,15 @@ def __init__(self) -> None:

self.states: list = []
"list of frames: [Frame], each frame has player, ball, and rim info"

self.players: dict = {}
"{player_0 : PlayerState, player_1 : PlayerState}"
"Global player data: {player_0 : PlayerState, player_1 : PlayerState}"

self.balls: dict = {}
"{ball_0 : BallState, ball_1 : BallState}"

self.shots

# EVERYTHING BELOW THIS POINT IS OUT-OF-DATE

self.possession_list = None
Expand Down Expand Up @@ -313,20 +314,20 @@ def update_scores(self, madeshot_list):
Updates self.score1, self.score2.
"""
madeshots = []
madeshot_lst = []
mdsh_lst = []
# Set counter to first made shot (where madeshot_list[counter][1] != 0)
counter = 0
for shot in madeshot_list:
if shot[1] != 0:
madeshot_lst.append(shot)
mdsh_lst.append(shot)

# Iterate through possession list and find who made the shot
# TODO what if madeshot_lst is empty?
for pos in self.possession_list:
if pos[2] >= madeshot_lst[counter][0]:
madeshots.append((pos[0], madeshot_lst[counter][0]))
if pos[2] >= mdsh_lst[counter][0]:
madeshots.append((pos[0], mdsh_lst[counter][0]))
counter += 1
if counter >= len(madeshot_lst):
if counter >= len(mdsh_lst):
break
# For each shot made update the player's and team's score
for shot in madeshots:
Expand Down

0 comments on commit 71bafc5

Please sign in to comment.