示例#1
0
 def pretty_print(self):
     """Print stage, either cup match pairs or league table."""
     if self.type == StageType.Cup:
         for round in self.rounds:
             for match in round:
                 print match
     else:
         for i in range(len(self.groups_club_names)):
             print "Group", (i + 1)
             table = LeagueTable.create_league_table(self.rounds, self.groups_club_names[i], self.setup.pointsperwin)
             print "%-20s %3s %3s %3s %3s %3s %3s %3s %3s" % ("Name", "P", "W", "D", "L", "F", "A", "T", "P")
             LeagueTable.print_league_table(table)
示例#2
0
    def get_winners(self):
        """Get stage winners.

        If the stage was a cup, returns winning clubs of match pairs.
        If the stage was a league, returns top x clubs of the league, x
        being the number of promotions in stage setup.
        If the stage was not yet finished, will probably fail.
        """
        retval = []
        if self.type == StageType.Cup:
            if self.setup.matchrules.replays != Match.TiebreakerType.Off:
                for m in self.rounds[0]:
                    w = m.get_winner_name()
                    if w != "unknown" and w != "draw":
                        retval.append(w)
                for m in self.rounds[1]:
                    w = m.get_winner_name()
                    if w == "draw":
                        raise ValueError("Replay match was a draw!")
                    if w != "unknown":
                        retval.append(w)
            else:
                if self.setup.rounds == 1:
                    for m in self.rounds[0]:
                        w = m.get_winner_name()
                        if w != "unknown":
                            retval.append(w)
                elif self.setup.rounds == 2:
                    ms = zip(self.rounds[0], self.rounds[1])
                    for m1, m2 in ms:
                        w = Match.double_match_result(m1.mr, m2.mr, self.setup.matchrules)
                        if w == Match.MatchResultType.Club1:
                            retval.append(m2.club1.name)
                        elif w == Match.MatchResultType.Club2:
                            retval.append(m2.club2.name)
                        else:
                            raise ValueError("Match.double_match_result() returned draw!")
                else:
                    raise ValueError("Only up to two rounds per knockout stage supported at the moment")
        else:
            for group in self.groups_club_names:
                table = LeagueTable.create_league_table(self.rounds, group, self.setup.pointsperwin)
                if len(self.promotions) > 0:
                    retval.extend(table.get_top(self.promotions[0].num / self.setup.groups))  # TODO - only returns top x
        return retval
示例#3
0
    def get_relegations(self):
        """Return relegated club names.

        If cup, will return an empty list (TODO). If league, will return names
        of bottom x clubs in the league, x being as defined somewhere (probably
        nowhere).
        """
        if self.type == StageType.League:
            clubs = []
            ret = []
            for group in self.groups_club_names:
                table = LeagueTable.create_league_table(self.rounds, group, self.setup.pointsperwin)
                if len(self.relegations) > 0:
                    clubs.extend(table.get_bottom(self.relegations[0].num / self.setup.groups))  # TODO - only returns bottom x
            for club in clubs:
                ret.append((self.relegations[0].tournament, self.relegations[0].stage, club))
            return ret
        else:
            return []
示例#4
0
    def get_staying(self):
        """Return the clubs not promoted or relegated.

        If cup, will return an empty list. Otherwise, will return the clubs not
        listed in promotions or relegations.
        """
        if self.type == StageType.League:
            proms = self.get_promotions()
            rels = self.get_relegations()
            exc_clubnames = []
            for t, s, c in proms + rels:
                exc_clubnames.append(c)
            all = []
            for group in self.groups_club_names:
                table = LeagueTable.create_league_table(self.rounds, group, self.setup.pointsperwin)
                all += table.get_all()
            ret = []
            for club in all:
                if club not in exc_clubnames:
                    ret.append(club)
            return ret
        else:
            return []