Last active
August 29, 2015 14:06
-
-
Save ochawkeye/f5d1781966d73a771765 to your computer and use it in GitHub Desktop.
Fuzzy matching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import, division, print_function | |
import nfldb | |
def nfldb_pp_func(db, nflgame_name): | |
""" | |
nflgame player name -> nfldb play player | |
P.Manning, DEN -> Peyton Manning (DEN, QB) | |
""" | |
print('-' * 79) | |
print('Trying to match: %s' % nflgame_name) | |
player_name, team_name = [x.strip() for x in nflgame_name.split(',')] | |
matches = nfldb.player_search(db, player_name, team=team_name, limit=5) | |
for (player, dist) in matches: | |
print('Similarity score: %d, Player: %s' % (dist, player)) | |
print('=' * 79) | |
positions = ['QB', 'RB', 'WR', 'TE', 'K'] | |
for (player, dist) in matches: | |
if str(player.position) in positions: | |
return player | |
if __name__ == '__main__': | |
db = nfldb.connect() | |
tough_names = ['M.Lynch, SEA', 'T.Smith, BAL', 'M.Colston, NO', | |
'D.McFadden, OAK', 'D.Sproles, PHI', ] | |
for name in tough_names: | |
print('%s -> %s' % (name, nfldb_pp_func(db, name))) | |
print('*' * 79) | |
very_tough_names = ['C.Patterson, MIN', 'E.Sanders, DEN', | |
'D.Williams, CAR', 'B.Pierce, BAL', | |
'R.Wilson, SEA', ] | |
for name in very_tough_names: | |
print('%s -> %s' % (name, nfldb_pp_func(db, name))) | |
''' | |
------------------------------------------------------------------------------- | |
Trying to match: M.Lynch, SEA | |
Similarity score: 7, Player: Max Unger (SEA, C) | |
Similarity score: 8, Player: Marshawn Lynch (SEA, RB) | |
Similarity score: 8, Player: Jon Ryan (SEA, P) | |
Similarity score: 9, Player: Mike Taylor (SEA, OLB) | |
Similarity score: 9, Player: K.J. Wright (SEA, OLB) | |
=============================================================================== | |
M.Lynch, SEA -> Marshawn Lynch (SEA, RB) | |
------------------------------------------------------------------------------- | |
Trying to match: T.Smith, BAL | |
Similarity score: 6, Player: Torrey Smith (BAL, WR) | |
Similarity score: 6, Player: Jimmy Smith (BAL, CB) | |
Similarity score: 6, Player: Daryl Smith (BAL, ILB) | |
Similarity score: 6, Player: Steve Smith (BAL, WR) | |
Similarity score: 7, Player: Ray Rice (BAL, RB) | |
=============================================================================== | |
T.Smith, BAL -> Torrey Smith (BAL, WR) | |
------------------------------------------------------------------------------- | |
Trying to match: M.Colston, NO | |
Similarity score: 7, Player: Marques Colston (NO, WR) | |
Similarity score: 7, Player: Nick Toon (NO, WR) | |
Similarity score: 8, Player: Tim Lelito (NO, G) | |
Similarity score: 8, Player: Kyle Knox (NO, LB) | |
Similarity score: 9, Player: Marcus Ball (NO, DB) | |
=============================================================================== | |
M.Colston, NO -> Marques Colston (NO, WR) | |
------------------------------------------------------------------------------- | |
Trying to match: D.McFadden, OAK | |
Similarity score: 5, Player: D.J. Hayden (OAK, CB) | |
Similarity score: 6, Player: Darren McFadden (OAK, RB) | |
Similarity score: 8, Player: Donald Penn (OAK, T) | |
Similarity score: 9, Player: T.J. Carrie (OAK, CB) | |
Similarity score: 9, Player: Derek Carr (OAK, QB) | |
=============================================================================== | |
D.McFadden, OAK -> Darren McFadden (OAK, RB) | |
------------------------------------------------------------------------------- | |
Trying to match: D.Sproles, PHI | |
Similarity score: 6, Player: Darren Sproles (PHI, RB) | |
Similarity score: 6, Player: Nick Foles (PHI, QB) | |
Similarity score: 8, Player: Donnie Jones (PHI, P) | |
Similarity score: 8, Player: Nate Allen (PHI, SS) | |
Similarity score: 8, Player: Trent Cole (PHI, OLB) | |
=============================================================================== | |
D.Sproles, PHI -> Darren Sproles (PHI, RB) | |
******************************************************************************* | |
------------------------------------------------------------------------------- | |
Trying to match: C.Patterson, MIN | |
Similarity score: 8, Player: Adrian Peterson (MIN, RB) | |
Similarity score: 8, Player: Tom Johnson (MIN, DT) | |
Similarity score: 9, Player: Rhett Ellison (MIN, TE) | |
Similarity score: 9, Player: Brian Robison (MIN, DE) | |
Similarity score: 9, Player: Joe Berger (MIN, G) | |
=============================================================================== | |
C.Patterson, MIN -> Adrian Peterson (MIN, RB) | |
------------------------------------------------------------------------------- | |
Trying to match: E.Sanders, DEN | |
Similarity score: 7, Player: C.J. Anderson (DEN, RB) | |
Similarity score: 7, Player: T.J. Ward (DEN, SS) | |
Similarity score: 8, Player: Emmanuel Sanders (DEN, WR) | |
Similarity score: 9, Player: Isaiah Burse (DEN, WR) | |
Similarity score: 9, Player: Wes Welker (DEN, WR) | |
=============================================================================== | |
E.Sanders, DEN -> C.J. Anderson (DEN, RB) | |
------------------------------------------------------------------------------- | |
Trying to match: D.Williams, CAR | |
Similarity score: 6, Player: Jason Williams (CAR, LB) | |
Similarity score: 6, Player: Garry Williams (CAR, T) | |
Similarity score: 8, Player: Brandon Williams (CAR, TE) | |
Similarity score: 8, Player: DeAngelo Williams (CAR, RB) | |
Similarity score: 9, Player: Colin Jones (CAR, DB) | |
=============================================================================== | |
D.Williams, CAR -> Brandon Williams (CAR, TE) | |
------------------------------------------------------------------------------- | |
Trying to match: B.Pierce, BAL | |
Similarity score: 6, Player: Ray Rice (BAL, RB) | |
Similarity score: 7, Player: Sam Koch (BAL, P) | |
Similarity score: 7, Player: Bernard Pierce (BAL, RB) | |
Similarity score: 8, Player: Zach Orr (BAL, LB) | |
Similarity score: 8, Player: Jah Reid (BAL, T) | |
=============================================================================== | |
B.Pierce, BAL -> Ray Rice (BAL, RB) | |
------------------------------------------------------------------------------- | |
Trying to match: R.Wilson, SEA | |
Similarity score: 6, Player: Luke Willson (SEA, TE) | |
Similarity score: 7, Player: Russell Wilson (SEA, QB) | |
Similarity score: 7, Player: Jon Ryan (SEA, P) | |
Similarity score: 9, Player: J.R. Sweezy (SEA, G) | |
Similarity score: 9, Player: Mike Morgan (SEA, OLB) | |
=============================================================================== | |
R.Wilson, SEA -> Luke Willson (SEA, TE) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment