BurntSushi / nfldb

A library to manage and update NFL data in a relational database.
The Unlicense
1.07k stars 263 forks source link

Fix Home|Away Turnovers #281

Closed joeycortez42 closed 6 years ago

joeycortez42 commented 6 years ago

Modified version of #197.

Fixed home_turnovers and away_turnovers mapping from timeout mapping. Added command line option to update game turnovers.

flipperbw commented 6 years ago

Not sure what stats_home and stats_away are but they do not exist, and makes this change fail.

joeycortez42 commented 6 years ago

@flipperbw What happens when you run this in a python file?

import nflgame
game = nflgame.one(2017, 1, 'CIN', 'BAL')
print game.home, game.stats_home.turnovers, 'turnovers'
print game.away, game.stats_away.turnovers, 'turnovers'
flipperbw commented 6 years ago

I wound up using #197 (with some fixes of its own, some typos there). So I'm not sure, but can't really go back to check. It said this though:

Traceback (most recent call last):
  File "/usr/local/bin/nfldb-update", line 42, in <module>
    nfldb.update.run(**vars(args))
  File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 574, in run
    doit()
  File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 564, in doit
    update_games(db, batch_size=batch_size)
  File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 414, in update_games
    update_current_week_schedule(db)
  File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 321, in update_current_week_schedule
    g = game_from_id(cursor, gsis_id)
  File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 58, in game_from_id
    return game_from_schedule(cursor, gsis_id)
  File "/usr/local/lib/python2.7/dist-packages/nfldb/update.py", line 105, in game_from_schedule
    return nfldb.Game._from_schedule(cursor.connection, s)
  File "/usr/local/lib/python2.7/dist-packages/nfldb/types.py", line 2164, in _from_schedule
    return Game._from_nflgame(db, _Game())
  File "/usr/local/lib/python2.7/dist-packages/nfldb/types.py", line 2115, in _from_nflgame
    dbg.home_turnovers = int(g.stats_home.turnovers)
AttributeError: '_Game' object has no attribute 'stats_home'
joeycortez42 commented 6 years ago

@flipperbw I got the same thing trying to update after this weeks games. But I ran it again and it worked. I feel like there is a cache issue with nfldb and nflgame. I'm going to modify the pull request to fix this.

Thanks!

jayhova3g commented 6 years ago

@nokemono42 Were you able to fix the suspected cache issue with nfldb and nflgame? I'm using #287 and I'm still getting the following errors:

nfldb-update Namespace(batch_size=5, interval=None, player_interval=43200, simulate=None, update_schedules=False, update_turnovers=False)

STARTING NFLDB UPDATE AT 2017-12-18 07:26:58.227374 Connecting to nfldb... done. Setting timezone to UTC... done. Locking write access to tables... done. Updating season phase, year and week... done. Bulk inserting data for 48 games... Sending batch of data to database. Sending batch of data to database. Sending batch of data to database. Sending batch of data to database. Sending batch of data to database. Sending batch of data to database. Sending batch of data to database. Sending batch of data to database. Sending batch of data to database. Sending batch of data to database. done. Updating schedule JSON database... Last updated: 2017-12-18 13:24:01.532627 done. Updating schedule for (Regular, 2017, 15) Traceback (most recent call last): File "/usr/local/bin/nfldb-update", line 42, in nfldb.update.run(**vars(args)) File "/Users/cyclone/Library/Python/2.7/lib/python/site-packages/nfldb/update.py", line 575, in run doit() File "/Users/cyclone/Library/Python/2.7/lib/python/site-packages/nfldb/update.py", line 565, in doit update_games(db, batch_size=batch_size) File "/Users/cyclone/Library/Python/2.7/lib/python/site-packages/nfldb/update.py", line 414, in update_games update_current_week_schedule(db) File "/Users/cyclone/Library/Python/2.7/lib/python/site-packages/nfldb/update.py", line 321, in update_current_week_schedule g = game_from_id(cursor, gsis_id) File "/Users/cyclone/Library/Python/2.7/lib/python/site-packages/nfldb/update.py", line 58, in game_from_id return game_from_schedule(cursor, gsis_id) File "/Users/cyclone/Library/Python/2.7/lib/python/site-packages/nfldb/update.py", line 105, in game_from_schedule return nfldb.Game._from_schedule(cursor.connection, s) File "/Users/cyclone/Library/Python/2.7/lib/python/site-packages/nfldb/types.py", line 2162, in _from_schedule return Game._from_nflgame(db, _Game()) File "/Users/cyclone/Library/Python/2.7/lib/python/site-packages/nfldb/types.py", line 2114, in _from_nflgame dbg.home_turnovers = int(g.stats_home.turnovers) AttributeError: '_Game' object has no attribute 'stats_home'

joeycortez42 commented 6 years ago

@jayhova3g #287 Addresses this issue. I have been running it for a few weeks now with no problem.

jayhova3g commented 6 years ago

Thank you for responding. I think I had an configuration error on my computer. I deleted and reinstalled #287. I haven't had anymore issues.