Prev | Current Page 75 | Next

David Berube

"Practical Reporting with Ruby and Rails"

rb)
require 'gruff'
require 'active_record'
game_id_to_analyze = 5
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
CHAPTER 3 n CREATING GRAPHS WITH RUBY 45
:username => 'your_mysql_username_here',
:password => 'your_mysql_password_here',
:database => 'players_4')
class Player < ActiveRecord::Base
has_many :wins
end
class Game < ActiveRecord::Base
has_many :wins
end
class Play < ActiveRecord::Base
belongs_to :game
belongs_to :player
end
class Event < ActiveRecord::Base
belongs_to :play
end
def puts_underlined(text, underline_char="=")
puts text
puts underline_char * text.length
end
pic_dir='./all_players_graph_pics'
Dir.mkdir(pic_dir) unless File.exists?(pic_dir)
line_chart = Gruff::Line.new(1024)
index=0
columns = {}
Event.find(:all, :group=>'event DESC').each do |e|
columns[index] = e.event
index=index+1
end
line_chart.labels = columns
line_chart.legend_font_size = 10
CHAPTER 3 n CREATING GRAPHS WITH RUBY 46
line_chart.legend_box_size = 10
line_chart.


Pages:
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
pizza sopot dowcipy hotele internet pokoje w mielnie