Ejemplo n.º 1
0
    def _calculate_owp(self):
        """
        Compute the opponent's winning percentage for each team.

        The opponent winning percentage for a team is the weighted average of a team's
        opponents unweighted winning percentage. Games that the opponents have played against
        the given team are removed. This is computed as follows, for team A:
            weights * ({team A's opponents wins} - {team A's opponents wins vs. team A}) /
                ({team A's opponents games played} - {team A's opponents games played vs. team A})

        Reference:
            https://en.wikipedia.org/wiki/Rating_Percentage_Index#Basketball_formula

        :return: 1xnteams Numpy Array of opponent's winning percentages.
        """
        opp_wins = np.dot(self.total_won[:, np.newaxis], np.ones(self.nteams)[np.newaxis, :]) - self.wins
        opp_played = np.dot(self.total_played[:, np.newaxis], np.ones(self.nteams)[np.newaxis, :]) - self.played
        weights = util.safe_divide(self.played, self.total_played[:, np.newaxis]).T
        return np.nansum(util.safe_divide(opp_wins, opp_played) * weights, axis=0)
Ejemplo n.º 2
0
 def run(self, time_limit):
     self.mongo.ensure_index([('time', ASCENDING),
                              ('media', ASCENDING),
                              ])
     N = self.mongo.find({'time': {'$gt': time_limit[0],
                                   '$lt': time_limit[1]},
                          'media': self.media,
                          }).count()
     td = time_limit[1] - time_limit[0]
     self.data = 60.0 * safe_divide(float(N), td.seconds)
Ejemplo n.º 3
0
    def _calculate_wp(self):
        """
        Compute the weighted winning percentage for each team.

        The weighted winning percentage weights home wins less than away wins, and home losses
        more than away losses. Neutral sites are unweighted (weight = 1).

        Reference:
            https://en.wikipedia.org/wiki/Rating_Percentage_Index#Basketball_formula

        :return: 1xnteams Numpy Array of weighted winning percentages.
        """
        return util.safe_divide(self.weighted_total_won, self.weighted_total_played)
Ejemplo n.º 4
0
    def _calculate_oowp(self, owp):
        """
        Compute the opponent's opponent's winning percentages for each team.

        The OOWP is the weighted average of a team's OWP. The weights represent the number of times
        the team played each opponent. Games that the opponents have played against
        the given team are removed.

        Reference:
            https://en.wikipedia.org/wiki/Rating_Percentage_Index#Basketball_formula

        :param owp: 1xnteams Numpy Array of opponent's winning percentage for each team.
        :return:
        """
        weights = util.safe_divide(self.played, self.total_played[:, np.newaxis]).T
        return np.nansum(np.dot(owp[:, np.newaxis], np.ones(self.nteams)[np.newaxis, :]) * weights, axis=0)
Ejemplo n.º 5
0
 def run(self, time_limit):
     self.mongo.ensure_index([('time', ASCENDING),
                              ('media', ASCENDING),
                              ('status', ASCENDING)])
     count = self.mongo.find({'time': {'$gt': time_limit[0],
                                       '$lt': time_limit[1]},
                              'media': self.media,
                              'status': self.status,
                              }).count()
     total = self.mongo.find({'time': {'$gt': time_limit[0],
                                       '$lt': time_limit[1]},
                              'media': self.media,
                              'status': {'$ne': '-'},
                              }).count()
     perc = safe_divide(100.0 * count, total)
     self.data = perc