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
def analyse_player_hits(self): self.hits = [] for player in self.playerObjects: for hit in player.hits: if hit.frameNo in player._framesToParse: self.hits.append(hit) print("Found hits: " + str(len(self.hits))) keyNames = ["half", "third", "height", "shot", "goal", "pass_", "dribble", "save"] _hits = {item: {} for item in keyNames} for hit in self.hits: for key in _hits: value = getattr(hit, key) try: # print(key) # print(value) _hits[key][value] += 1 except KeyError: _hits[key][value] = 1 # _hits[key].append(getattr(hit,key)) totalHits = len(self.hits) # hits = {} # for key1,value1 in _hits.items(): # hits[key1] = {} # for key2,value2 in value1.items(): # # convert raw numbers to % # newValue = value2/totalHits # hits[key1][key2] = newValue hits = _hits hits["total"] = totalHits print("Raw Hit data:") print(hits) averageHitDistance = AHit.get_average_hit_distance(self.hits) hits["aveHitDistance"] = averageHitDistance averageShotDistance = AHit.get_average_shot_distance(self.hits) hits["aveShotDistance"] = averageShotDistance averagePassDistance = AHit.get_average_hit_distance(list(hit for hit in self.hits if hit.pass_)) hits["avePassDistance"] = averagePassDistance averageDribbleDistance, averageDribbleHits = AHit.get_average_dribble_distance(self.hits) hits["aveDribbleDistance"] = averageDribbleDistance hits["aveDribbleHits"] = averageDribbleHits # print(hits) return hits