Prev | Current Page 69 | Next

David Berube

"Practical Reporting with Ruby and Rails"

This allows you to analyze the average time it takes the player
to achieve each goal. Note that the games table is included only for compatibility with the
CHAPTER 3 n CREATING GRAPHS WITH RUBY 39
previous database, since you have data for only one game. (This allows you to easily
expand if you??™re asked to create a similar report for a different game.)
Now that you have the data loaded into your MySQL database, you can create a
simple bar chart for each player, as shown in Listing 3-4.
Listing 3-4. Creating Player Bar Charts (player_bar_charts.rb)
require 'gruff'
require 'active_record'
game_id_to_analyze = 5
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'root', # This is the default username and password
:password => '', # for MySQL, but note that if you have a
# different username and password,
# you should change it.
:database => 'players_4')
class Player < ActiveRecord::Base
has_many :plays
end
class Game < ActiveRecord::Base
has_many :plays
end
class Play < ActiveRecord::Base
belongs_to :game
belongs_to :player
end
class Event < ActiveRecord::Base
belongs_to :plays
end
columns = Event.


Pages:
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
LMC Matisse Limp Bizkit Sarah McLachlan Milk Inc.