Skip to content
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

Jacksonville 3 Letter Abbreviation #35

Closed
ToddAtWSU opened this issue Sep 16, 2018 · 4 comments
Closed

Jacksonville 3 Letter Abbreviation #35

ToddAtWSU opened this issue Sep 16, 2018 · 4 comments

Comments

@ToddAtWSU
Copy link

So I have a script that uses a team's full name (i.e. Jacksonville) and grabs it's 3 letter abbreviation. For Jacksonville, this returns JAC, but the games use JAX which means I can never find Jacksonville in a game. Here is some relevant code showing my issue.

nflTeams = nflgame.teams
#teams is a list of full names I read in from a file earlier in the code, names include "Jacksonville" and "New England"
for team in teams:
    # Loop through all NFL teams i.e. all 32 teams
    for nflTeam in nflTeams:
        # Check if this NFL team is our fantasy team
        if team == nflTeam[1]:
            # We have found our team, now loop through all
            # games since games use team abbreviations
            for game in week:
            # Here nflTeam[0] will have "JAC" and game.away or game.home will have "JAX"
                if nflTeam[0] == game.away:
                # Some code here...
                elif nflTeam[0] == game.home:
                # More code here...

So should both of these use JAX or JAC and not one and the other?

@ochawkeye
Copy link
Collaborator

That code doesn't run...how is it supposed to show your issue? :P

So should both of these use JAX or JAC and not one and the other?

This is another case where we can't control what the NFL gives us. Case in point:

import nflgame

for year in range(2009, 2019):
    for abbreviation in ['JAC', 'JAX']:

        try:
            games = nflgame.games(year, week=1, kind='REG', home=abbreviation, away=abbreviation)
            for game in games:
                print year, game
        except TypeError:
            continue
2009 JAC (12) at IND (14)
2010 DEN (17) at JAC (24)
2011 TEN (14) at JAC (16)
2012 JAC (23) at MIN (26)
2013 KC (28) at JAC (2)
2014 JAC (17) at PHI (34)
2015 CAR (20) at JAC (9)
2016 GB (27) at JAC (23)
2017 JAX (29) at HOU (7)
2018 JAX (20) at NYG (15)

I do notice that at some pont I must have changed my ..\nflgame\__init__.py to the following:

teams = [
...
    ['JAX', 'Jacksonville', 'Jaguars', 'Jacksonville Jaguars', 'JAC'],
...

but I don't think that should matter. since using the nflgame.standard_team() function can normalize our team name to whatever nflgame might be expecting to see for the abbreviation.

nflTeams = nflgame.teams
#teams is a list of full names I read in from a file earlier in the code, names include "Jacksonville" and "New England"
for team in teams:
    # Loop through all NFL teams i.e. all 32 teams
    for nflTeam in nflTeams:
        # Check if this NFL team is our fantasy team
        if team == nflTeam[1]:
            # We have found our team, now loop through all
            # games since games use team abbreviations
            for game in week:
            # Here nflTeam[0] will have "JAC" and game.away or game.home will have "JAX"
                if nflTeam[0] == nflgame.standard_team(game.away):
                # Some code here...
                elif nflTeam[0] == nflgame.standard_team(game.home):
                # More code here...

@reddigari
Copy link

reddigari commented Sep 26, 2018

I'm encountering a similar problem updating a (new) nfldb database with this fork of nflgame. Running nfldb-update raises this error:

psycopg2.IntegrityError: insert or update on table "play" violates foreign key constraint "play_pos_team_fkey"
DETAIL:  Key (pos_team)=(JAX) is not present in table "team".

I'd rather not fidget with the nfldb code; is there a quick-fix I can do on the nflgame side to re-write the JSON data to play nicely with the database?

@derek-adair
Copy link
Owner

Ya... this threw me for a loop when i first got into this project. I think it is a valid point to have something check all abbreviations and return a normalized and consistent format.

As for how this affects nfldb really not sure how to advise you there.

@derek-adair
Copy link
Owner

derek-adair commented Oct 22, 2018

Closing as a known issue with a acceptable workaround.

Workaround: handle it manually

for year in range(2009, 2019):
    for abbreviation in ['JAC', 'JAX']:

        try:
            games = nflgame.games(year, week=1, kind='REG', home=abbreviation, away=abbreviation)
            for game in games:
                print year, game
        except TypeError:
            continue

This is very likely to change and/or go away when we start work on #46.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants