Beispiel #1
0
def get_picks(systems):
    """Get the picks from the CSV from the given systems."""
    picks = []

    with open("ferret.csv") as input_csv:
        picks_csv = csv.reader(input_csv)

        for line_number, line in enumerate(picks_csv):
            if line_number == 0:
                Pick.initialise_data_columns(line)
                continue  # Skip first line - column headers, not a pick
            try:
                picks.append(Pick(line, systems))
            except UnwantedSystemError:
                continue  # Ignoring picks that aren't from our main EP systems.

    picks.sort(key=lambda p:
               (p.course, p.time))  # Sort picks by course then time

    picks_with_dupes = picks
    picks = []

    for single_pick in picks_with_dupes:
        for pick in picks:
            if single_pick.horse == pick.horse:
                pick.systems.add(single_pick.system)
                break
        else:
            picks.append(single_pick)

    return picks
Beispiel #2
0
    def __get_picks_info(self, sheet, column):
        player_row = 1
        first_game_row = 2
        game10_score_top_row = 22
        game10_score_bottom_row = 23
        CELL_EMPTY = 0

        player_name = str(sheet.cell(player_row, column).value)
        if player_name == "":
            return []

        picks = []
        for game_number in range(1, 11):
            top_row = first_game_row + (game_number - 1) * 2
            bottom_row = top_row + 1

            team1_picked = sheet.cell_type(top_row, column) != CELL_EMPTY
            team2_picked = sheet.cell_type(bottom_row, column) != CELL_EMPTY
            if team1_picked and team2_picked:
                print "Check spreadsheet for illegal condition (year=%d, week=%s, player=%s)" % (
                    self.year,
                    sheet.name,
                    player_name,
                )
            #assert (team1_picked and team2_picked) == False

            pick = Pick()
            pick.player_name = player_name
            pick.game_number = game_number
            pick.team1_score = None
            pick.team2_score = None
            pick.default = False

            if team1_picked:
                pick.winner = "team1"
            elif team2_picked:
                pick.winner = "team2"
            else:
                pick.winner = None

            picks.append(pick)

        team1_score = str(sheet.cell(game10_score_top_row, column).value)
        team2_score = str(sheet.cell(game10_score_bottom_row, column).value)
        default = team1_score == '' and team2_score == ''

        if default:
            for i in range(len(picks)):
                picks[i].winner = None
                picks[i].default = True
        else:
            for i in range(len(picks)):
                if picks[i].game_number == 10:
                    picks[i].team1_score = 0 if team1_score == '' else int(
                        float(team1_score))
                    picks[i].team2_score = 0 if team2_score == '' else int(
                        float(team2_score))

        return picks
Beispiel #3
0
 def start(self):
     """start chatbot"""
     try:
         # beer("debug")
         self.pick_reaction = Pick(self.list_custom_emojis(), max_repeat=7)
         self.__rtm_listen()
     except Exception as error:
         self.__handle_error(error, channel="CEG4LEXJN")
def main():
    '''Main program'''
    print('Number of picks before inicialization', Pick.count)
    # creating three picks objects
    pick1 = Pick()
    pick2 = Pick(0.7)
    pick3 = Pick(0.4, 'blue')
    pick4 = pick1
    print('Number of picks after inicialization', Pick.count)

    # explicitly delete pick objects by removing references
    del pick1
    del pick2
    del pick3
    print('Number of picks after destruction', Pick.count)

    print(pick4.size)
    print(pick4.color)
    def get_available_picks(self):
        """
        >>> state = DraftState({'qbs': [Player('qb', 100, 'qb1'), Player('qb', 90, 'qb2')], 'rbs': [Player('rb', 100, 'rb1')], 'wrs': [], 'tes': [], 'dsts': [], 'ks': []})
        >>> picks = state.get_available_picks()
        >>> for p in picks:
        ...     print p.identifier
        qb1
        rb1

        """
        avail_picks = []
        for players in self.available.itervalues():
            if len(players) > 0:
                avail_picks.append(players[0].identifier)

        return [Pick(identifier) for identifier in avail_picks]
Beispiel #6
0
def main():
    '''Main program'''
    my_pick = Pick()
    my_guitar = Guitar(my_pick)

    strings = {1: ('e', 330), 2: ('B', 247), 3: ('G', 196),
               4: ('D', 146), 5: ('A', 110), 6: ('E', 82)}
    for key, value in strings.items():
        string = GuitarString()
        string.set_number(key)
        string.set_name(value[0])
        string.set_frequency(value[1])
        my_guitar.add_strings(string)
    my_guitar.flatten_equalizer()
    my_guitar.increase_equalizer('treble', 10)
    my_guitar.decrease_equalizer('bass', 12)

    print(my_guitar.pick.size, my_guitar.pick.color)
    print()
    my_guitar.get_strings()
    print()
    my_guitar.get_equalizer()
    print()
Beispiel #7
0
def _construct(max_repeat):
    return Pick(VALUES, max_repeat)
Beispiel #8
0
    def make_decision(self, draft_state, replacement_lvls=None):
        """
        Returns a Pick object
        >>> state = draft_state.DraftState({'qb': [Player('qb', 110, 'qb1'), Player('qb', 102, 'qb2')], 'rb': [Player('rb', 121, 'rb1'), Player('rb', 50, 'rb2')], 'wr': [Player('wr', 80, 'wr1')], 'te': [Player('te', 90, 'te1')], 'dst': [Player('dst', 40, 'dst1')], 'k': [Player('k', 20, 'k1')]})
        >>> owner = state.owners[0]
        >>> owner.make_decision(state).identifier
        'rb1'
        >>> owner.strategy = "worst_dropoff"
        >>> owner.make_decision(state).identifier
        'te1'
        >>> state.available['qb'][0].value = 230
        >>> owner.make_decision(state).identifier
        'qb1'

        """

        player_to_pick = None
        my_team = draft_state.get_team(self)
        available = draft_state.available

        # Control function --> picks a random position and the best player at that position
        if self.strategy == 'control':
            choices = []
            for position, players in available.iteritems():
                if (len(players) > 0 and len(my_team[position]) <
                        self.position_maxes[position]):
                    player = players[0]
                    choices.append(player)

            player_to_pick = random.choice(choices)

        if self.strategy == 'control_weighted':
            choices = []
            random_weights = []
            for position, players in available.iteritems():
                if (len(players) > 0 and len(my_team[position]) <
                        self.position_maxes[position]):
                    player = players[0]
                    choices.append(player)
                    random_weights.append(self.position_maxes[position])
            random_weights = np.array(random_weights)
            random_weights = [
                float(r) / sum(random_weights) for r in random_weights
            ]
            player_to_pick = np.random.choice(choices, p=random_weights)

        if self.strategy == 'most_points':
            max_points = 0
            for position, players in available.iteritems():
                if (len(players) > 0 and len(my_team[position]) <
                        self.position_maxes[position]):
                    player = players[0]
                    player_val = player.value
                    if player_val > max_points:
                        max_points = player_val
                        player_to_pick = player

        # Worst dropoff to second best available
        if self.strategy == 'worst_dropoff':
            difference = 0
            for position, players in available.iteritems():
                if (len(players) > 0 and len(my_team[position]) <
                        self.position_maxes[position]):
                    player = players[0]
                    player_val = player.value
                    if len(players) == 1:
                        if player_val > difference:
                            difference = player_val
                            player_to_pick = player
                    elif len(players) > 1:
                        player_compare = players[1]
                        player_val_compare = player_compare.value
                        difference_local = player_val - player_val_compare
                        if difference_local > difference:
                            difference = difference_local
                            player_to_pick = player

        # Worst dropoff to guaranteed player
        if self.strategy == 'worst_guaranteed':
            difference = 0
            current_pick_index = self.picks.index(draft_state.pick_number)
            for position, players in available.iteritems():
                if (len(players) > 0 and len(my_team[position]) <
                        self.position_maxes[position]):
                    player = players[0]
                    player_val = player.value
                    worst_guaranteed_val = 0
                    # there is a next pick
                    if current_pick_index + 1 < len(self.picks):

                        # number of people who pick before me
                        picks_to_pass = (self.picks[current_pick_index + 1] -
                                         self.picks[current_pick_index] - 1)
                        # there will be a player available next time I pick
                        if picks_to_pass < len(players) and picks_to_pass != 0:
                            worst_guaranteed_player = players[picks_to_pass]
                            worst_guaranteed_val = worst_guaranteed_player.value
                    # if this difference is higher than the previous seen diff
                    # pick the player at this position
                    if player_val - worst_guaranteed_val > difference:
                        difference = player_val - worst_guaranteed_val
                        player_to_pick = player

        # value over replacement
        if self.strategy == 'vorp' or self.strategy == 'pos_vorp':
            highest_vorp = -float('inf')
            for position, players in available.iteritems():
                if (len(players) > 0 and len(my_team[position]) <
                        self.position_maxes[position]):
                    # print "Examining position " + position
                    player = players[0]
                    player_val = player.value
                    vorp = player_val - replacement_lvls[player.position]
                    if self.strategy == 'pos_vorp':
                        mult = self.multiplier(position, my_team)
                        vorp = mult * vorp
                    if vorp > highest_vorp:
                        player_to_pick = player
                        highest_vorp = vorp

        return Pick(player_to_pick.identifier)