Пример #1
0
    def parse_player(self, games):
        print("\nAnalysing " + self._name)
        # add player and ball objects from games
        for game in games:
            # game._framesToParse = misc.get_game_frames(self,game)

            for player in game.players:
                if player._name == self._name:
                    # get position stuff
                    player._framesToParse = misc.get_game_frames(self, game)
                    self.playerObjects.append(player)
                    self.ballObjects.append(game.ball)

                    AHit.analyse_game_hits(game)
                    APosition.analyse_game_possession(game)

        # add positions,velocities,hits, ball position, team colours
        # for position in player.positions:
        # self.positions.append(position)
        # for velocity in player.velocities:
        # self.velocities.append(velocity)
        # for hit in player.hits:
        # self.hits.append(hit)
        # for position in ball.positions:
        # self.ballPositions.append(position)

        position, speed = self.analyse_player_positions_and_speed()
        hits = self.analyse_player_hits()
        possession = self.analyse_player_possession()

        self.position = position
        self.speed = speed
        self.possession = possession
        self.hits = hits
Пример #2
0
    def __init__(self,dataOptions,typeOptions):
        # data accepting
        (games,teams,players) = dataOptions
        for x in typeOptions[0]:
            self.plotBy = x
            self.plotByData = typeOptions[0][x]
            
        self.plotOvertime,self.plotHeat,self.normaliseHeat,self.plotLine,self.plotBall = typeOptions[1]
        
        # get frames to parse for each game.
        for game in games:
            game._frames_to_parse = misc.get_game_frames(self,game)
            print('Got '+str(len(game._frames_to_parse))+' frames for a game')
        
        
        # player/team._name:data
        subPlotRows = 1
        subPlotColumns = 1
        subPlotNumber = 1
        
        if players:
        # if there are players selected
            print('Plotting '+str(players))
            noOfPlots = len(players)
            subPlotRows = math.floor(math.sqrt(noOfPlots))
            subPlotColumns = math.ceil(noOfPlots/subPlotRows)
            print('Plotting a '+str(subPlotColumns)+'x'+str(subPlotRows)+' grid.')

            fig = plt.figure(figsize=(subPlotColumns*4,subPlotRows*4))
            # plot players separately
            for playerName in players:
                print('Plot '+str(subPlotNumber))
                ax = fig.add_subplot(subPlotRows,subPlotColumns,subPlotNumber,projection='3d')     
                ax.set_title(playerName)
                
                subPlotNumber += 1

            
                positionsToPlot = []
                for game in games:
                    # print(game)
                    for player in game.players:
                        try:
                            if player._name == playerName:
                                # print(player._name)
                                # try to add positions,ask forgiveness.
                                for x in game._frames_to_parse:
                                    try:
                                        positionsToPlot.append(misc.make_orange_side(player.positions[x],player))
                                    except TypeError:
                                        # print('type error')
                                        # print(x)
                                        pass
                                print('Added '+str(len(game._frames_to_parse))+' frames of positions for '+player._name)
                        except AttributeError:
                            print(player.name+' has no ._name')
                
                self.create_axes(ax)
                if self.plotLine:
                    self.plot_line(ax,positionsToPlot)
                if self.plotHeat:
                    self.plot_heat(ax,positionsToPlot)
            plt.show()
                
        elif teams:
            print('Plotting '+str(teams))
            noOfPlots = len(teams)
            subPlotRows = math.floor(math.sqrt(noOfPlots))
            subPlotColumns = math.ceil(noOfPlots/subPlotRows)
            print('Plotting a '+str(subPlotColumns)+'x'+str(subPlotRows)+' grid.')
            
            fig = plt.figure(figsize=(subPlotColumns*4,subPlotRows*4))
            
            # plot teams separately
            for teamName in teams:
                print('Plot '+str(teamName))
                ax = fig.add_subplot(subPlotRows,subPlotColumns,subPlotNumber,projection='3d')     
                ax.set_title(teamName)
                
                subPlotNumber += 1

            
                positionsToPlot = []
                for game in games:
                    # print(game)
                    for team in game.teams:
                        if team._name == teamName:
                            # print(player._name)
                            # try to add positions,ask forgiveness.
                            for player in team.players:
                                for x in game._frames_to_parse:
                                    try:
                                        positionsToPlot.append(player.positions[x])
                                    except TypeError:
                                        # print('type error')
                                        # print(x)
                                        pass
                                print('Added '+str(len(game._frames_to_parse))+' frames of positions for '+player._name)
                            print('Added '+str(len(positionsToPlot))+' total frames for '+teamName)
                
                self.create_axes(ax)
                if self.plotLine:
                    self.plot_line(ax,positionsToPlot)
                if self.plotHeat:
                    self.plot_heat(ax,positionsToPlot)
            plt.show()