Prev | Current Page 76 | Next

David Berube

"Practical Reporting with Ruby and Rails"

title = "Chart of All Players"
line_chart.minimum_value = 0
line_chart.maximum_value = 110
Player.find(:all).each do |player|
total_games = Play.count(:conditions=>['game_id = ? AND player_id = ?',
game_id_to_analyze, player.id]).to_f
total_wins = Play.count(:conditions=>['game_id = ? AND player_id = ? AND won=1',
game_id_to_analyze, player.id]).to_f
sql = "SELECT event, avg(time) as average_time
FROM events as e
INNER JOIN
plays as p
ON e.play_id=p.id
WHERE p.game_id='#{game_id_to_analyze}'
AND
p.player_id='#{player.id}'
GROUP
BY e.event DESC;"
data = []
Event.find_by_sql(sql).each do |row|
data << (row.average_time.to_i/1000)
end
line_chart.data(player.name, data )
end
line_chart.write("all_players.png")
Save this script as all_players.rb. You can run the script as follows:
ruby all_players.rb
The output from the script is shown in Figure 3-5. This example packs a lot of information
into the chart for demonstration purposes. You can design your own charts to
contain less information and be easier to read.


Pages:
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
drukarki fiskalne kraków willa karmazyn międzyzdroje www.books61.hobbitstory.com terapia magnetyczna Informacje o hostingu