Exemple #1
0
def run(lineups=20, exposure=0.3):
    roster_list, player_list = [], []
    create_upload_file()
    player_map = map_pids(DEFAULT_ARGS['pids'])
    max_exposure = lineups * exposure
    exposure = None

    for _ in range(lineups):
        args = DEFAULT_ARGS.copy()
        if exposure:
            args['banned'] = DEFAULT_ARGS['banned'] + [
                name for name, freq in exposure.items() if freq > max_exposure
            ]
        roster = optimizer_run('NFL', [], Namespace(**args))

        # discard and replace duplicate lineups
        if roster in roster_list:
            while roster in roster_list:
                args['banned'].append(random.choice(roster.players).name)
                roster = optimizer_run('NFL', [], Namespace(**args))

        roster_list.append(roster)
        player_list += [p.name for p in roster.players]

        update_upload_csv(player_map, roster.sorted_players()[:])
        exposure = Counter(player_list)

    unique = len(set([str(r.players) for r in roster_list]))
    if unique != lineups:
        raise Exception(
            'Duplication error in logic. Expected {} and got {} lineups'.
            format(lineups, unique))
def run(lineups=20, exposure=0.4, min_avg=7):
    DEFAULT_ARGS['min_avg'] = min_avg
    roster_list, player_list = [], []
    create_upload_file()
    player_map = map_pids(DEFAULT_ARGS['pids'])
    max_exposure = lineups * exposure
    exposure = None

    for _ in range(lineups):
        args = DEFAULT_ARGS.copy()
        if exposure:
            args['banned'] = DEFAULT_ARGS['banned'] + [
                name for name, freq in exposure.items()
                if freq > max_exposure
            ]
        roster = optimizer_run('NBA', [], Namespace(**args))

        # discard and replace duplicate lineups
        if is_duplicate(roster, roster_list):
            while is_duplicate(roster, roster_list):
                args['banned'].append(
                    random.choice(roster.players).name
                )
                roster = optimizer_run('NBA', [], Namespace(**args))

        roster_list.append(roster)
        player_list += [p.name for p in roster.players]

        update_upload_csv(
            player_map,
            roster.sorted_players()[:]
        )
        exposure = Counter(player_list)

    unique = len(set([str(r.players) for r in roster_list]))
    if unique != lineups:
        raise Exception(
            'Duplication error in logic. Expected {} and got {} lineups'
            .format(lineups, unique)
        )

    scores = [r.projected() for r in roster_list]
    print('Generated {} lineups.'.format(lineups))
    print('Maximum score: {}'.format(numpy.max(scores)))
    print('Minimum score: {}'.format(numpy.min(scores)))
    print('Average score: {}'.format(numpy.average(scores)))
    print('Median score: {}'.format(numpy.median(scores)))
Exemple #3
0
def run(lineups=20, exposure=0.4, min_avg=7):
    DEFAULT_ARGS['min_avg'] = min_avg
    roster_list, player_list = [], []
    create_upload_file()
    player_map = map_pids(DEFAULT_ARGS['pids'])
    max_exposure = lineups * exposure
    exposure = None

    for _ in range(lineups):
        args = DEFAULT_ARGS.copy()
        if exposure:
            args['banned'] = DEFAULT_ARGS['banned'] + [
                name for name, freq in exposure.items()
                if freq > max_exposure
            ]
        roster = optimizer_run('NFL', [], Namespace(**args))

        # discard and replace duplicate lineups
        if is_duplicate(roster, roster_list):
            while is_duplicate(roster, roster_list):
                args['banned'].append(
                    random.choice(roster.players).name
                )
                roster = optimizer_run('NFL', [], Namespace(**args))

        roster_list.append(roster)
        player_list += [p.name for p in roster.players]

        update_upload_csv(
            player_map,
            roster.sorted_players()[:]
        )
        exposure = Counter(player_list)

    unique = len(set([str(r.players) for r in roster_list]))
    if unique != lineups:
        raise Exception(
            'Duplication error in logic. Expected {} and got {} lineups'
            .format(lineups, unique)
        )

    scores = [r.projected() for r in roster_list]
    print('Generated {} lineups.'.format(lineups))
    print('Maximum score: {}'.format(numpy.max(scores)))
    print('Minimum score: {}'.format(numpy.min(scores)))
    print('Average score: {}'.format(numpy.average(scores)))
    print('Median score: {}'.format(numpy.median(scores)))