Ruport GraphReport

M

Michael Linfield

this is rather a followup from my other post...in the attempt to try and
graph a quick sample data i get richeous errors lol.

require 'rubygems'
require 'ruport'
require 'ruport/util'
require 'tempfile'

class GraphReport < Ruport::Report

renders_as_graph
isp1r = []
isp1 = Tempfile.new('tempisp')
isp1.puts File.readlines('maindata.csv').grep(/Blah1/)
isp1.each do |row|
isp1r << row["AVERAGE"]
isp1.close


def generate
graph = Ruport::Graph:)column_names =>
%w[24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0])
graph.add_line [isp1r], :name => "Blah1"
graph.add_line [14,54,22,54,12], :name => "bar" # Just an extra line,no
reason
return graph
end
end
end

puts GraphReport.generate{|r| r.save_as("filename.svg")}


######

theoretically this should have generated 2 lines, 0 - 24 on the bottom
of the graph, and the Blah1 grep data up the side.

instead i get some awesome errors

ruby ruporttest.rb
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:115:in
`method_missing': undefined local variable or method `generate' for
#<GraphReport:0xb7805a7c> (NameError)
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:86:in
`renderable_data'
from
/var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:171:in
`old_as'
from
/var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:383:in
`render'
from
/var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:428:in
`build'
from
/var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:382:in
`render'
from
/var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:169:in
`old_as'
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:93:in
`as'
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:107:in
`save_as'
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:107:in
`open'
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:107:in
`save_as'
from ruporttest.rb:26
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:124:in
`generate'
from ruporttest.rb:26
#####

*shrug* i cant even fathom where to begin. :(
 
A

Alex Gutteridge

this is rather a followup from my other post...in the attempt to
try and
graph a quick sample data i get richeous errors lol.

require 'rubygems'
require 'ruport'
require 'ruport/util'
require 'tempfile'

class GraphReport < Ruport::Report

renders_as_graph
isp1r = []
isp1 = Tempfile.new('tempisp')
isp1.puts File.readlines('maindata.csv').grep(/Blah1/)
isp1.each do |row|
isp1r << row["AVERAGE"]
isp1.close


def generate
graph = Ruport::Graph:)column_names =>
%w[24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0])
graph.add_line [isp1r], :name => "Blah1"
graph.add_line [14,54,22,54,12], :name => "bar" # Just an extra
line,no
reason
return graph
end
end
end

puts GraphReport.generate{|r| r.save_as("filename.svg")}


######

theoretically this should have generated 2 lines, 0 - 24 on the bottom
of the graph, and the Blah1 grep data up the side.

instead i get some awesome errors

No offence, but there are a lot of problems with the script you
posted! Check your do/end pairs and your usage of tempfile. I still
don't think you need a temporary file though, because Ruport/
FasterCSV can parse from a string.

Using this csv file:

Name,Average
Bill,2
Bob,1
Blah1,10
Jill,3
Jane,4
Blah1,20
Ada,6
Blah1,30
Ruby,7
Blah1,40
Sigfried,2
Blah1,50

Does this code help?:

require 'rubygems'
require 'ruport'
require 'ruport/util'
require 'tempfile'

class GraphReport < Ruport::Report

renders_as_graph

def generate

data = File.readlines('filename.csv') #Read in csv (into Array)
head = data[0] #Take header line
data = data.grep(/Blah/) #Grep out lines we are interested in
csv = ([head] + data).join #Combine the header and lines back
into a String

table = Ruport::Data::Table.parse(csv) #Parse into ruport

graph = Ruport::Graph() #Plot
graph.add_line table.column('Average').map{|x|x.to_i}, :name =>
"Blah1"
graph.add_line [14,54,22,54,12], :name => "bar" # Just an extra
line,no
return graph
end
end

puts GraphReport.generate{|r| r.save_as("filename.svg")}

Alex Gutteridge

Bioinformatics Center
Kyoto University
 
M

Michael Linfield

lol alright that worked out pretty nicely, but how would i align the 24
- 0 with the Times that Blah1 is set at:
EX:

Time--Average--Name
14:21 3.42 Blah1
13:45 2.12 Blah1

###
so i need to align 14:21 with 14.21 on the graph

n-e ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,470
Messages
2,571,808
Members
48,797
Latest member
PeterSimpson
Top