From 71bafc571db2c66ec7ac94741d5b0fbce7985e5a Mon Sep 17 00:00:00 2001 From: Michael Ngo Date: Sat, 21 Oct 2023 12:07:48 -0400 Subject: [PATCH] Saving some stuff --- src/processing/shot_detect.py | 35 ++--------------------------------- src/state.py | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/src/processing/shot_detect.py b/src/processing/shot_detect.py index e38bd507..a79e82c2 100644 --- a/src/processing/shot_detect.py +++ b/src/processing/shot_detect.py @@ -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 diff --git a/src/state.py b/src/state.py index 2b2a0c02..611b3c52 100644 --- a/src/state.py +++ b/src/state.py @@ -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" @@ -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: @@ -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 @@ -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: