-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combining player objects #65
Comments
What I ended up doing is convert the key to a string that would be consistent across queries and pre-collected info that I might want to use later on. from collections import defaultdict
import nfldb
def tally_points(db, y, w, ph):
q = nfldb.Query(db)
player_score = defaultdict(int)
player_metadata = {}
q.game(season_year=y, week=w, season_type=ph)
for pp in q.as_aggregate():
p_id = str(pp.player)
player_metadata[p_id] = [pp.player.team, pp.player.position]
player_score[p_id] += 1.0*pp.kicking_xpmade
q.play_player(kicking_fgm=1)
for pp in q.as_play_players():
p_id = str(pp.player)
player_metadata[p_id] = [pp.player.team, pp.player.position]
fg_length = getattr(pp, 'kicking_fgm_yds')
if fg_length < 40:
player_score[p_id] += 3.0
elif fg_length < 50:
player_score[p_id] += 4.0
else:
player_score[p_id] += 5.0
return player_score, player_metadata
if __name__ == '__main__':
db = nfldb.connect()
player_points, p_info = tally_points(db, 2014, 6, 'Regular')
for player in player_points:
if player == 'Dan Bailey (DAL, K)':
print type(player), player, player_points[player], p_info[player][0], p_info[player][1]
print '-'*25
for player in player_points:
if player == 'Nick Folk (NYJ, K)':
print type(player), player, player_points[player], p_info[player][0], p_info[player][1]
print '-'*25
for player in player_points:
if player == 'Graham Gano (CAR, K)':
print type(player), player, player_points[player], p_info[player][0], p_info[player][1]
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doing something like the following results in having multiple "keys" in my points dictionary that are the same type and appear to be the same key (but aren't).
With Bailey kicking 3FGs & 3XP and Folk kicking 1FG & 1 XP I would expect the output to be
Is there a way to merge these
pp.player
objects like I am trying to do or should I be using something else as the key in myplayer_score
dictionary? If I use something else, can I still retain all of thepp.player
objects properties so that I could still access all of that player info from the object?gist
The text was updated successfully, but these errors were encountered: