예제 #1
0
def run():
    salaries = load_salaries('salaries/dk_nba_salaries_2015_11_07.csv')
    results = load_results('results/contest-standings-13876064.csv')
    numentries = len(results)
    prize_map = get_prize_map(numentries)
    scores_mean = analyze_results(
        results, lambda x: numpy.mean(x) / len(results)
    )
    scores_own = analyze_results(
        results, lambda x: len(x) / float(len(results))
    )
    scores_weighted = analyze_results(
        results,
        lambda x: sum([get_weighted_score(y, prize_map) for y in x])
                  / float(len(x))
    )
    sorted_mean = sorted(scores_mean.items(), key=lambda x: x[1],
                         reverse=False)
    sorted_own = sorted(scores_own.items(), key=lambda x: x[1], reverse=True)
    sorted_weighted = sorted(scores_weighted.items(), key=lambda x: x[1],
                             reverse=True)

    print 'Sorted by score:'
    print '\tPlayer\t\tScore\tOwn\tWeighted'
    for player, score in sorted_mean[:30]:
        if player in salaries:
            print ('\t%s\t%.4f\t%.2f\t%.4f\t%s'
                   % (player[:15], score, scores_own[player] * 100,
                      scores_weighted[player], salaries[player]))
        else:
            print ('\t%s\t%.4f\t%.2f\t%.4f'
                   % (player[:15], score, scores_own[player] * 100,
                      scores_weighted[player]))

    print 'Sorted by ownership:'
    print '\tPlayer\t\tScore\tOwn\tWeighted'
    for player, own in sorted_own[:30]:
        if player in salaries:
            print ('\t%s\t%.4f\t%.2f\t%.4f\t%s'
                   % (player[:15], scores_mean[player], own * 100,
                      scores_weighted[player], salaries[player]))
        else:
            print ('\t%s\t%.4f\t%.2f\t%.4f'
                   % (player[:15], scores_mean[player], own * 100,
                      scores_weighted[player]))

    print 'Sorted by weighted score:'
    print '\tPlayer\t\tScore\tOwn\tWeighted'
    for player, weighted_score in sorted_weighted[:50]:
        if player in salaries:
            print ('\t%s\t%.4f\t%.2f\t%.4f\t%s'
                   % (player[:15], scores_mean[player],
                      scores_own[player] * 100, weighted_score,
                      salaries[player]))
        else:
            print ('\t%s\t%.4f\t%.2f\t%.4f'
                   % (player[:15], scores_mean[player],
                      scores_own[player] * 100, weighted_score))
예제 #2
0
def run_weighted(ids, filename, verbose=False):
    print "Calculated weighted scores..."
    salaries = load_salaries(filename)
    weighted_scores = get_weighted_scores(ids)
    sorted_scores = sorted(weighted_scores.items(), key=lambda x: x[1],
                           reverse=True)
    for player, score in sorted_scores:
        if player in salaries:
            print ('\t%s\t%.4f\t%d\t%s' % (player[:15], score[0], score[1],
                                           salaries[player]))
        elif verbose:
            print '\t%s\t%.4f\t%d' % (player[:15], score[0], score[1])
예제 #3
0
def run_deltas(curr_ids, prev_ids, filename, verbose=False):
    print "Calculating deltas..."
    scores_curr = get_weighted_scores(curr_ids)
    scores_prev = get_weighted_scores(prev_ids)
    deltas = {}
    for player in scores_curr:
        if player in scores_curr and player in scores_prev:
            deltas[player] = (scores_curr[player][0] - scores_prev[player][0],
                              scores_curr[player][1])
    salaries = load_salaries(filename)
    sorted_deltas = sorted(deltas.items(), key=lambda x: x[1], reverse=True)
    for player, delta in sorted_deltas:
        if delta[0] > 0:
            if player in salaries:
                print ('\t%s\t%.4f\t%d\t%s' % (player[:15], delta[0], delta[1],
                                               salaries[player]))
            elif verbose:
                print '\t%s\t%.4f\t%d' % (player[:15], delta[0], delta[1])
    return deltas
예제 #4
0
                       for player in sorted(players)]
        print '%s %s' % (score, salary)
        print '\t%s' % (', '.join(player_strs[:4]))
        print '\t%s' % (', '.join(player_strs[-4:]))

if __name__=='__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-s', '--salaries', type=str)
    parser.add_argument('-p', '--prefill', type=str,
                        help=('Quoted list of comma-separated player names'
                              ' (e.g. "Stephen Curry, James Harden")'))
    parser.add_argument('-i', '--ignore', type=str,
                        help=('Quoted list of comma-separated player names'
                              ' (e.g. "Stephen Curry, James Harden")'))
    parser.add_argument('-m', '--min_score', type=float)
    args = parser.parse_args()

    if args.salaries:
        print 'Loading score data...'
        scores = get_scores_with_freq(get_ids(limit=7), min_games=3)
        salaries = load_salaries(args.salaries)
        prefill_players = ([x.strip() for x in args.prefill.split(',')]
                           if args.prefill else [])
        ignore_players = ([x.strip() for x in args.ignore.split(',')]
                          if args.ignore else [])
        min_score = args.min_score if args.min_score != None else -1
        generate(scores, salaries, prefill_players=prefill_players,
                 ignore_players=ignore_players, min_score=min_score)
    else:
        print 'Unable to run script: requires a --salaries argument'
예제 #5
0
    parser.add_argument('-s', '--salaries', type=str)
    parser.add_argument('-p',
                        '--prefill',
                        type=str,
                        help=('Quoted list of comma-separated player names'
                              ' (e.g. "Stephen Curry, James Harden")'))
    parser.add_argument('-i',
                        '--ignore',
                        type=str,
                        help=('Quoted list of comma-separated player names'
                              ' (e.g. "Stephen Curry, James Harden")'))
    parser.add_argument('-m', '--min_score', type=float)
    args = parser.parse_args()

    if args.salaries:
        print 'Loading score data...'
        scores = get_scores_with_freq(get_ids(limit=7), min_games=3)
        salaries = load_salaries(args.salaries)
        prefill_players = ([x.strip() for x in args.prefill.split(',')]
                           if args.prefill else [])
        ignore_players = ([x.strip() for x in args.ignore.split(',')]
                          if args.ignore else [])
        min_score = args.min_score if args.min_score != None else -1
        generate(scores,
                 salaries,
                 prefill_players=prefill_players,
                 ignore_players=ignore_players,
                 min_score=min_score)
    else:
        print 'Unable to run script: requires a --salaries argument'
예제 #6
0
    salary_means = {}
    for result in results[start:end]:
        for position in positions.keys():
            positions[position].append(result[position_index_map[position]])
    for position, players in positions.iteritems():
        pos_salaries = [salaries[player][0] for player in players]
        salary_means[position] = numpy.mean(pos_salaries)
    return salary_means

def run_and_plot(intervals, salaries):
    POSITIONS = ['PG', 'SG', 'SF', 'PF', 'C', 'F', 'G', 'UTIL']
    data = []
    for i, end in enumerate(intervals[1:]):
        start = intervals[i]
        print start, end
        data.append(run('results/contest-standings-13876064.csv',
                        salaries, start=start, end=end))
    lines = {}
    for pos in POSITIONS:
        lines[pos], = plt.plot(intervals[1:], [x[pos] for x in data], label=pos)
    plt.legend([lines[pos] for pos in POSITIONS], POSITIONS)
    plt.show()

if __name__=='__main__':
    salaries = load_salaries('salaries/dk_nba_salaries_2015_11_07.csv')
    for salary in sorted(salaries.items(), key=lambda x: x[1][0], reverse=True)[:20]:
        print salary
    run_and_plot(range(0, 1001, 100), salaries)
    run_and_plot(range(0, 10001, 1000), salaries)
    run_and_plot(range(0, 100001, 10000), salaries)