Exemple #1
0
    def print(self, distribution: Dict[Player, float]):
        palette = sns.color_palette(None, len(distribution))
        labels = []
        sizes = []
        colors = []

        i = 0
        for player in sorted(distribution.keys(), key=lambda item: item.value):
            likelihood = distribution[player]
            if likelihood != 0:
                labels.append(get_name(player))
                sizes.append(likelihood)
                colors.append(palette[i])
            i += 1

        sizes_sum = sum(sizes)
        sizes = saferound([size / sizes_sum for size in sizes],
                          self.__PRECISION)

        wedges, names, percentages = plt.pie(sizes,
                                             labels=labels,
                                             colors=colors,
                                             autopct='%1.1f%%')
        kw = dict(arrowprops=dict(arrowstyle="-"), zorder=0, va="center")
        previous_angle = None
        for i, it in enumerate(zip(wedges, names, percentages, sizes)):
            wedge, name, percentage, size = it
            if size < self.__THRESHOLD_LIKELIHOOD:
                name.update({'visible': False})
                percentage.update({'visible': False})
                angle = (wedge.theta2 - wedge.theta1) / 2 + wedge.theta1
                text_angle = angle
                if previous_angle is not None and self.__angle_distance(
                        angle,
                        previous_angle) < self.__THRESHOLD_MIN_ANGLE_INC:
                    text_angle = (previous_angle +
                                  self.__THRESHOLD_MIN_ANGLE_INC + 360) % 360
                x, y = np.cos(np.deg2rad(angle)), np.sin(np.deg2rad(angle))
                x_text = (1 + self.__THRESHOLD_LINE_LENGTH) * np.cos(
                    np.deg2rad(text_angle))
                y_text = (1 + self.__THRESHOLD_LINE_LENGTH) * np.sin(
                    np.deg2rad(text_angle))
                horizontalalignment = {-1: "right", 1: "left"}[int(np.sign(x))]
                plt.annotate(name.get_text() + ": " + percentage.get_text(),
                             xy=(x, y),
                             xytext=(x_text, y_text),
                             horizontalalignment=horizontalalignment,
                             **kw)
                previous_angle = angle

        if self.__file_name is None:
            plt.show()
        else:
            plt.savefig(self.__file_name)
            plt.clf()
Exemple #2
0
    def print(self, distribution: Dict[Player, float]):
        distribution = {
            player: value * self.__multiplier
            for player, value in distribution.items()
        }
        distribution = saferound(distribution, self.__precision)
        sorted_distribution = []
        for player, likelihood in distribution.items():
            sorted_distribution.append((get_name(player), likelihood))

        sorted_distribution.sort(key=lambda x: x[1], reverse=True)
        for row in sorted_distribution:
            player_name = row[0]
            likelihood = row[1]
            print(player_name + ": " + str(likelihood))
Exemple #3
0
# Show at which frames each player occurs in a given episode.
from Data.PlayerData import get_name
from Layers.Appearance.VideoParser import VideoParser, ParsedVideo

SEASON = 17
EPISODE = 5

parsed_video = VideoParser.load_parsed_video(SEASON, EPISODE)
player_occurrences = parsed_video.player_occurrences
alive_players = parsed_video.alive_players

for player, occurrences in player_occurrences.items():
    if player in alive_players:
        print(get_name(player))
        print(sorted(list(occurrences)))

total_face_frames = 0
for player, occurrences in player_occurrences.items():
    if player in alive_players:
        total_face_frames += len(occurrences)

for player, occurrences in player_occurrences.items():
    if player in alive_players:
        print(get_name(player))
        print(len(occurrences) / total_face_frames)