def shot_chart_player_game(self, id_game, id_player_team, tci): #get stats of shots from opponent team and players id_team = self.params["home"] if self.params["destiny"] == self.params[ "home"] else self.params["away"] ss = SeasonShots(self.params["competition"], self.get_season(self.params["competition"])) ts = TeamShots(id_team, self.params["competition"]) ps = ts.df.query( f"id_game == {id_game} and id_player_team == {id_player_team}") #ps = PlayerShots(ts.id_team_club, ts.competition) errores = ps.query("position.isnull()") self.set_advertencia(tci, ps, len(errores)) #get image and set stats over image image = ShotChartImage(IMAGES.BASKET_COURT) image.resize_from_width(500) image.set_data_over_image(ps, ss.df) name = f"{id_team}-{id_player_team}.png" image.save_image(IMAGES.IMAGE_ROUTE + name) #Tabla Estadísticas de tiro #Tabla Estadísticas de tiro self.pdf.set_font("Arial", "B", 14) self.pdf.set_y(75) #self.pdf.cell(self.pdf.get_string_width("Carta de tiro equipo") + 5, 15, "Carta de tiro equipo", "B: 1", 1, "L") self.pdf.image(IMAGES.IMAGE_ROUTE + name, 28, 65) image.remove_image(IMAGES.IMAGE_ROUTE + name)
def get_all_colors(self): image = ShotChartImage(IMAGES.TEST_COLOUR_MAP) list_of_colors = self.colors colors = {} for c in list_of_colors.keys(): colors[c] = 0 other_colors = {} errores = 0 for y in range(image.image.height): for x in range(image.image.width): color = image.get_color(x, y) if color in list_of_colors: colors[color] = colors[color] + 1 else: #Color not found gc = self.correct_color(color) colors[gc] = colors[gc] + 1 errores = errores + 1 if color in other_colors: other_colors[color] = other_colors[color] + 1 else: other_colors[color] = 1 print( f"Colors matched: {colors}\n colors matched: {len(colors.keys())}") # for k, v in sorted(colors.items(), key=itemgetter(1), reverse=True): # print (k, v) print( f"Other colors: {other_colors})\ntotal other colors: {len(other_colors.keys())}" ) for k, v in sorted(other_colors.items(), key=itemgetter(1), reverse=True): print(k, v) print(f"errores: {errores}")
def shot_chart_team_game(self, id_game, id_team, tci): ''' Short chart for an only game. :param id_game: :param id_team: :param tci: :return: ''' #get stats from shots from opponent team ss = SeasonShots(self.params["competition"], self.get_season(self.params["competition"])) ts = TeamShots(id_team, self.params["competition"]) data = ts.df.query(f"id_game == {id_game}") errores = data.query(f"id_game == {id_game} and position.isnull()") #print(f"Total lanzamientos equipo: {len(ts.df)}") #print(f"Total lanzmientos temporada: {len(ss.df)}") self.set_advertencia(tci, data, len(errores)) #get image and set stats over image image = ShotChartImage(IMAGES.BASKET_COURT) image.resize_from_width(500) #Set data over image image.set_data_over_image(data, ss.df) #Save image name = f"{id_team}.png" image.save_image(IMAGES.IMAGE_ROUTE + name) #self.pdf.cell(self.pdf.get_string_width("Carta de tiro equipo") + 5, 15, "Carta de tiro equipo", "B: 1", 1, "L") self.pdf.image(IMAGES.IMAGE_ROUTE + name, 28, 65) image.remove_image(IMAGES.IMAGE_ROUTE + name)
def load_images(self): if self.competition == COMPETITIONS.LF1 or self.competition == COMPETITIONS.LF2: left = ShotChartImage(IMAGES.FEB_LEFT_COLOUR_MAP) right = ShotChartImage(IMAGES.FEB_RIGHT_COLOUR_MAP) return (left, right) else: img = ShotChartImage(IMAGES.FIBA_COLOUR_MAP) return img
def shot_chart_opp_team(self, tci): #get stats from shots from opponent team ss = SeasonShots(self.params["competition"], self.get_season(self.params["competition"])) ts = AccumulatedOppShots(self.params["destiny"], self.params["competition"]) #print(f"Total lanzamientos equipo: {len(ts.df)}") #print(f"Total lanzmientos temporada: {len(ss.df)}") self.set_advertencia(tci, ts.df, ts.errores) #get image and set stats over image image = ShotChartImage(IMAGES.BASKET_COURT) image.resize_from_width(500) #Set data over image image.set_data_over_image(ts.df, ss.df) #Save image name = f"accOpp-{self.params['destiny']}.png" image.save_image(IMAGES.IMAGE_ROUTE + name) self.pdf.image(IMAGES.IMAGE_ROUTE + name, 28, 65) image.remove_image(IMAGES.IMAGE_ROUTE + name)
def shot_chart_player(self, tci): #get stats of shots from opponent team and players ss = SeasonShots(self.params["competition"], self.get_season(self.params["competition"])) ps = PlayerShots(self.params) self.set_advertencia(tci, ps.df, ps.errores) #get image and set stats over image image = ShotChartImage(IMAGES.BASKET_COURT) image.resize_from_width(500) image.set_data_over_image(ps.df, ss.df) id1 = self.params["id"] if id in self.params else self.params["id_player_team"] name = f"{id1}.shotchart.png" image.save_image(IMAGES.IMAGE_ROUTE + name) #Tabla Estadísticas de tiro self.pdf.set_font("Arial", "B", 14) self.pdf.set_y(75) self.pdf.cell(self.pdf.get_string_width("Carta de tiro equipo") + 5, 15, "Carta de tiro equipo", "B: 1", 1, "L") self.pdf.image(IMAGES.IMAGE_ROUTE + name, 28, 65) image.remove_image(IMAGES.IMAGE_ROUTE + name)
def shot_chart_team(self, id_team, tci): #get stats from shots from opponent team ss = SeasonShots(self.params["competition"], self.get_season(self.params["competition"])) ts = TeamShots(id_team, self.params["competition"]) #print(f"Total lanzamientos equipo: {len(ts.df)}") #print(f"Total lanzmientos temporada: {len(ss.df)}") self.set_advertencia(tci, ts.df, ts.errores) #get image and set stats over image image = ShotChartImage(IMAGES.BASKET_COURT) image.resize_from_width(500) #Set data over image image.set_data_over_image(ts.df, ss.df) #Save image name = "test.png" image.save_image(IMAGES.IMAGE_ROUTE + name) #self.pdf.cell(self.pdf.get_string_width("Carta de tiro equipo") + 5, 15, "Carta de tiro equipo", "B: 1", 1, "L") self.pdf.image(IMAGES.IMAGE_ROUTE + name, 28, 65) image.remove_image(IMAGES.IMAGE_ROUTE + name)
def test_create_image(self): i = ShotChartImage(IMAGES.BASKET_COURT)