Exemplo n.º 1
0
 def __init__(self, play_track):
     Track.__init__(self,
                    id=play_track['nid'],
                    url=PlayMusic.track_url(play_track),
                    name=play_track['title'],
                    artist=play_track['artist'],
                    album=play_track['album'],
                    album_artist=play_track['albumArtist'],
                    duration=int(play_track['durationMillis']) / 1000,
                    track_num=play_track['trackNumber'])
Exemplo n.º 2
0
 def __init__(self, rdio_track):
     Track.__init__(self,
                    id=rdio_track['key'],
                    url=rdio_track['shortUrl'],
                    name=rdio_track['name'],
                    artist=rdio_track['artist'],
                    album=rdio_track['album'],
                    album_artist=rdio_track.get('albumArtist'),
                    duration=rdio_track['duration'],
                    track_num=rdio_track['trackNum'],
                    available=rdio_track['canStream'])
Exemplo n.º 3
0
 def __init__(self, rdio_track):
     Track.__init__(self,
                    id=rdio_track['key'],
                    url=rdio_track['shortUrl'],
                    name=rdio_track['name'],
                    artist=rdio_track['artist'],
                    album=rdio_track['album'],
                    album_artist=rdio_track.get('albumArtist'),
                    duration=rdio_track['duration'],
                    track_num=rdio_track['trackNum'],
                    available=rdio_track['canStream'])
Exemplo n.º 4
0
 def __init__(self, play_track):
     Track.__init__(
         self,
         id=play_track["nid"],
         url=PlayMusic.track_url(play_track),
         name=play_track["title"],
         artist=play_track["artist"],
         album=play_track["album"],
         album_artist=play_track["albumArtist"],
         duration=int(play_track["durationMillis"]) / 1000,
         track_num=play_track["trackNumber"],
     )
Exemplo n.º 5
0
    def create_track(self, tournament, gender):
        """Creates a new track for a given tournament and gender. Starts off
        with an empty scoreboard and mappings for the player stats.

        :param tournament: The tournament to create the track for.
        :param gender: The gender of the track to create.
        :return: The newly created track.
        """
        stats = HashTable()

        for player_name, player_profile in self.circuit.get_players(gender):
            season_stats: SeasonStats = self.get_stats(gender).find(
                player_name)
            tournament_stats = TournamentStats(player_profile, season_stats)
            season_stats.tournament_stats.insert(tournament.type.name,
                                                 tournament_stats)
            stats.insert(player_name, tournament_stats)

        winning_score = get_winning_score(gender)
        forfeit_score = get_forfeit_score(gender)

        previous_stats = None
        previous_season_scoreboard = None

        if tournament.previous is not None:
            previous_stats = tournament.previous.get_track(gender).stats
            previous_season_scoreboard = tournament.previous.season.get_scoreboard(
                gender)

        track_round = 1
        remaining = stats.clone()
        scoreboard = List()

        return Track(gender, track_round, stats, remaining, winning_score,
                     forfeit_score, scoreboard, previous_stats,
                     previous_season_scoreboard)
Exemplo n.º 6
0
    def play_round(self, track: Track):
        """Plays a round in the tournament for a track.

        :param track: The track that is playing this round.
        """
        if track.round > MAX_ROUNDS:
            print('This track is already complete')
            return

        print('Playing the %s\'s track' % track.name)
        winners = HashTable()
        winner = None
        matches = List()
        track.update_previous_winners()

        if self.previous is not None and next_bool(
                'Should we seed the round for you?', True):
            if track.round == 1:
                self.seed_automatic_first(track, matches)
            else:
                self.seed_automatic_next(track, matches)
        else:
            input_type = next_input_type('How should data be entered?')
            if input_type == FILE:
                matches = self.seed_file(track)
            else:
                self.seed_manual(track, matches)

        # Run each match.
        for match in matches:
            # Find the winner and add them to the next batch.
            winner, winner_score, loser, loser_score = match.run(
                track.winning_score, track.remaining)
            winners.insert(winner.player.name, winner)
            winner: TournamentStats = winner
            loser: TournamentStats = loser

            # Update the winner profile.
            winner.win()
            winner.add_score(winner_score, loser_score)

            # Update the loser profile.
            loser.loss()
            loser.add_score(loser_score, winner_score)

            apply_multiplier(track.name, winner, loser_score)
            self.update_points(loser, track)

        if track.round == MAX_ROUNDS:
            print('Tournament %s successfully complete for the %s\'s track' %
                  (self.type.name, track.name))
            print('Winner for the final round: %s' % winner.player.name)
            track.round += 1
            self.update_points(winner, track)
            self.print_scoreboard(track.name)
            return

        print('Winners for round %d:' % track.round)

        for name, stats in winners:
            print('- %s' % name)

        track.remaining = winners
        track.round += 1
Exemplo n.º 7
0
def load_track(tournament, gender, track_round):
    """Loads a track from file.

    :param tournament: The tournament this track is part of.
    :param gender: The gender of players on this track.
    :param track_round: The round the track is starting from.
    :return: The track loaded from file.
    """
    stats = HashTable()
    remaining = HashTable()
    sorter = Sorter(lambda a, b: b.round_achieved - a.round_achieved)

    with open('%s/%s/%s/%s.csv' % (OUTPUT, tournament.season.name,
                                   tournament.type.name, gender)) as the_file:
        for line in the_file:
            # Parse player stats.
            csv = parse_csv_line(line)
            player_name = csv[0]
            round_achieved = int(csv[1])
            multiplier = float(csv[2])
            points = float(csv[3])
            wins = int(csv[4])
            losses = int(csv[5])
            scores = load_scores(csv[6])
            opponent_scores = List()

            for score in csv[7:]:
                opponent_scores.append(int(score))

            # Create the players' tournament stats profile.
            season_stats: SeasonStats = tournament.season.get_stats(
                gender).find(player_name)
            tournament_stats = TournamentStats(season_stats.player,
                                               season_stats, round_achieved,
                                               multiplier, points, wins,
                                               losses, scores, opponent_scores)
            tournament_stats.season.tournament_stats.insert(
                tournament.type.name, tournament_stats)

            # Add this profile to the tournament players.
            stats.insert(player_name, tournament_stats)

            if not tournament.complete and track_round <= round_achieved:
                remaining.insert(player_name, tournament_stats)

            if tournament.complete or track_round > round_achieved:
                sorter.consume(tournament_stats)

    scoreboard = sorter.sort()

    if not tournament.complete:
        linked_scoreboard = List()
        for stats in scoreboard:
            linked_scoreboard.append(stats)
        scoreboard = linked_scoreboard

    winning_score = get_winning_score(gender)
    forfeit_score = get_forfeit_score(gender)

    previous_stats = None
    previous_season_scoreboard = None

    if tournament.previous is not None:
        previous_stats = tournament.previous.get_track(gender).stats
        previous_season_scoreboard = tournament.previous.season.get_scoreboard(
            gender)

    return Track(gender, track_round, stats, remaining, winning_score,
                 forfeit_score, scoreboard, previous_stats,
                 previous_season_scoreboard)