Пример #1
0
    def get_average_position(dict):
        allPlayerPositions = []
        for player in dict:
            if player.team.colour == 'blue':
                for position in dict[player]:
                    position = misc.make_orange_side(position,player)
                    allPlayerPositions.append(position)
            else:
                allPlayerPositions += dict[player]
                
        values = allPlayerPositions
        try:
            (x,y,z) = zip(*values)
            x = list(x)
            y = list(y)
            z = list(z)
        except TypeError:
            print(values[:10])
            print('Cannot unzip values')
            return None
        except ValueError:
            print(values[:10])
            print('Cannot unzip values')
            return None
        i=0
        while i <(len(x)):
            if (x[i] is None) or (y[i] is None) and (z[i] is None):
                # print(x)
                # print(x[i],y[i],z[i])
                x.pop(i)
                y.pop(i)
                z.pop(i)
            else: i+=1
                
        try:
            a = (s.mean(x), s.mean(y), s.mean(z))
        except TypeError:
            for no in range(len(x)):
                if not isinstance(x[no],int):
                    print(no)
                    print(x[no])
                    # print(x[:10])
            
        # a = (s.median(x),s.median(y),np.percentile(z,70))
        # v = ((s.pstdev(x,a[0])-1800)*5,(s.pstdev(y,a[1])-2400)*5,(s.pstdev(z,a[2])-50)*5)
        #variance is too much with this data.
        
        #return separate 25,75% ranges.
        v = []
        for axis in (x,y):
            v.append([np.percentile(axis,25),np.percentile(axis,75)])
        v.append([np.percentile(z,25),np.percentile(z,90)])

        
        return(a,v)
Пример #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()