Guest User

Untitled

a guest
May 1st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. require 'rubygems' #1
  2. require 'activerecord'
  3. # Begin ActiveRecord configuration
  4. ActiveRecord::Base.establish_connection( #2
  5. :adapter => "mysql",
  6. :host => "localhost",
  7. :database => "paper",
  8. :username => "root",
  9. :password => "" #,
  10. #:socket => "/var/run/mysqld/mysqld.sock" #/var/lib/gems/1.8/gems/activerecord-2.1.0/lib/active_record/vendor/mysql.rb
  11. )
  12. # Begin ActiveRecord classes
  13. class Product < ActiveRecord::Base #3
  14. has_many :purchases
  15. end
  16. class Purchase < ActiveRecord::Base
  17. belongs_to :store
  18. end
  19. class Store < ActiveRecord::Base
  20. end
  21. # Begin logic
  22. myproducts = Product.find(:all) #4
  23. #require 'pp'
  24. #pp myproducts
  25.  
  26. require 'scruffy'
  27. graph = Scruffy::Graph.new #1
  28. graph.title = "Comparison of Product Sales"
  29. stores = Store.find(:all, :select=>"id, location")
  30. myproducts.each do |product| #2
  31. counts = stores.collect do |store|
  32. Purchase.count "id", :store_id=>store.id, :product_id=>product.id
  33. end
  34. graph.add :line, product.name, counts #3
  35. end
  36. graph.point_markers =
  37. Store.find(:all).map! {|store| store.location}
  38. graph.render :as => 'PNG', :to => 'productsales.png',
  39. :width => 720,
  40. :theme => Scruffy::Themes::Keynote.new
Add Comment
Please, Sign In to add comment