Closed albertlyu closed 10 years ago
rails generate model Shot play_id:integer player_id:integer team_id:integer game_id:integer half:integer points_type:integer detail_id:integer zone_id:integer distance:integer x_coord:float y_coord:float made:boolean
The above model generator creates the following initial migration script for creating the shots
table:
class CreateShots < ActiveRecord::Migration
def change
create_table :shots do |t|
t.integer :play_id
t.integer :player_id
t.integer :team_id
t.integer :game_id
t.integer :half
t.integer :points_type
t.integer :detail_id
t.integer :zone_id
t.integer :distance
t.float :x_coord
t.float :y_coord
t.boolean :made
t.timestamps
end
end
end
So these new tables should look something like this:
I think this is a more permanent solution to the issue raised up in #41 than optimizing the queries. The queries against the
plays
table are taking the longest because every row is being checked to see ifx_coord
is null. That's extremely inefficient for a non-indexed column.So let's create and populate a new
shots
table, only with shots that havex_coord
andy_coord
available.Additionally, from #46, add a
zone_id
for a shot's zone. We'll also create lookup tables forzones
anddetails
with the descriptions of zone and detail in each table (detail being the shot type such as 'Jump Shot,' event being example 'Field Goal Missed.').