-
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
How to query TIME #190
Comments
Raw SQL stuff is completely Greek to me, but the quarter can be accessed from the Not sure how well this stuff translates from Python to SQL, but here's what it looks like in Python. import nfldb
db = nfldb.connect()
q = nfldb.Query(db)
q.game(season_year=2016, week=1, season_type='Regular', team='SD')
q.play(receiving_tar__ge=1)
for play in q.as_plays():
print play
print play.time
print play.time.phase, play.time.minutes, play.time.seconds
print '-'*225
|
BINGO..time.phase worked ...thank you ! Now..any idea how I can execute a sql statement to SHOW what those subfields are that I can use in SQL queries ? I might run into this with other time fields, field position, etc...ie. any other composite data fields. |
Just so you know "304" refers to 304 seconds into the quarter, not 3:04. so Q1,304 counting towards 900 would be 5 minutes, 4 seconds into the quarter. |
Yes..thank you for the clarification iliketowel...5 min 4 secs into the 2nd quarter.. Also..clarification on what worked for me..it was (time).phase (time needs parentheses around it otherwise it thinks time is a tablename.) so..added and (time).phase in ('Q2','Q3') to my query to find out who was targeted most in 2nd half. Thanks guys ! |
I converted the time using a query like this below. If you cut and paste the query below into a text editor it should appear better. But you can play around with it to see how I had to use case statements and left/right functions to trim off all of the stuff except the numerical number in the subquery, and then added 15 if it was the 2nd quarter, 30 if 3rd, 45 if 4th. I just used a random game in the where clause to display the functionality select --* |
This should work even better and should be exactly what you're looking for: select * |
I lost Keenan Allen from my fantasy team this week so I want to see the other SD WRs targets BY QUARTER to see who got the most action after Allen went out. I see quarter is an element of the TIME field on the play table but I don't know how to refer to the subelements of it..how can I change the query below to return the QUARTER instead of a field value like (Q1,304) which is what is returned now (which I assume means it occured in 1st quarter..3 minutes and 4 seconds into the game ?) . I've done some googling and tried (time).game_phase but get an error column "game_phase" not found in data type game_time
PS: I'm an oracle db guy with background in SQL and none in POSTGRESQL nor Python hence my attempt at doing it this way !
select pp.team,
player.full_name,
time,
sum (ap.receiving_tar) Targets,
sum(pp.receiving_rec) as Receptions
from
player,
play p,
agg_play ap,
play_player pp,
game g
where 1=1
and g.season_year>=2016
and g.season_type='Regular'
and g.gsis_id = ap.gsis_id
and g.gsis_id=p.gsis_id
and p.play_id=ap.play_id
and p.drive_id=ap.drive_id
and p.play_id=pp.play_id
and p.gsis_id=pp.gsis_id
and pp.player_id=Player.player_id
and ap.receiving_tar >0
and player.position in ('WR')
and pp.team='SD'
group by pp.team
,player.full_name,
time
order by full_name desc
The text was updated successfully, but these errors were encountered: