script errors

  • Thread starter Michael Linfield
  • Start date
M

Michael Linfield

require 'rubygems'
require 'ruport'
require 'ruport/util'
require 'date'
require 'optparse'


opts = OptionParser.new do |opts|
opts.on("-h", "--help", "Displays this help.") do |a|
puts opts
end
opts.on("-s", "--startdate", "Determines what start date to use.") do
|b|
@startdate = Date.new(*ParseDate.parsedate(b)[0,3])
end
opts.on("-e", "--enddate", "Determines what end date to use.") do |c|
@enddate = Date.new(*ParseDate.parsedate(c)[0,3])
end
opts.on("-o", "--output", "Specify Output format: svg|pdf|jpg") do |d|
if ARGV = svg
saveinput = GraphReport.generate{|r| r.save_as("Reportgraph.svg")}
elsif ARGV = pdf
#get pdf gem to output to pdf(ruport might have it included)
end
end
end

opts.parse!(ARGV)

result = (@startdate..@enddate).to_a
range = result.size

class GraphReport < Ruport::Report
renders_as_graph

def generate

verizondat = []
qwestdat = []
level3dat = []
attdat = []
sprintdat = []
data = File.readlines("data.csv")
head = data[0]
verizondat = data.grep(/Verizon/)
qwestdat = data.grep(/Qwest/)
level3dat = data.grep(/Level3/)
attdat = data.grep(/AT\&T/)
sprintdat = data.grep(/Sprint/)
csv = ([head] + data).join

table = Ruport::Data::Table.parse(csv)

graph = Ruport::Graph:)column_names => #the 15 graph points by average

graph.add_line verizondat.column('AVERAGE').map{|x|
x.grep(/@startdate..@enddate/).to_i}, :name=> "Verizon"
graph.add_line qwestdat.column('AVERAGE').map{|x|
x.grep(/@startdate..@enddate/).to_i}, :name=> "Qwest"
graph.add_line level3dat.column('AVERAGE').map{|x|
x.grep(/@startdate..@enddate/).to_i}, :name=> "Level3"
graph.add_line attdat.column('AVERAGE').map{|x|
x.grep(/@startdate..@enddate/).to_i}, :name=> "AT&T"
graph.add_line sprintdat.column('AVERAGE').map{|x|
x.grep(/@startdate..@enddate/).to_i}, :name=> "Sprint"
end
end

return graph



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

##############
OUTPUT:

ruby reportgraph.rb
reportgraph.rb:55: syntax error, unexpected tIDENTIFIER, expecting ')'
graph.add_line verizondat.column('AVERAGE').map{|x|
x.grep(/@startdate..@enddate/).to_i}, :name=> "Verizon"
^
reportgraph.rb:55: syntax error, unexpected ',', expecting kEND
graph.add_line verizondat.column('AVERAGE').map{|x|
x.grep(/@startdate..@enddate/).to_i}, :name=> "Verizon"

###############

all the commented objects also need fixing if anyone wants to throw
suggestions at me while i work on it over the night.

Much thanks!
 
N

Nobuyoshi Nakada

Hi,

At Tue, 4 Sep 2007 15:43:55 +0900,
Michael Linfield wrote in [ruby-talk:267464]:
graph = Ruport::Graph:)column_names => #the 15 graph points by average

The paren in this line doesn't seem closed, and you may forget
qoutes?
 
M

Michael Linfield

Nobuyoshi said:
Hi,

At Tue, 4 Sep 2007 15:43:55 +0900,
Michael Linfield wrote in [ruby-talk:267464]:
graph = Ruport::Graph:)column_names => #the 15 graph points by average

The paren in this line doesn't seem closed, and you may forget
qoutes?

lol thanks, now however i run upon a second error, line 29

result = (@startdate..@enddate)

####
OUTPUTS:

reportgraph.rb:29: bad value for range (ArgumentError)
####

fun timez.
any ideas?

Thanks!
 
N

Nobuyoshi Nakada

Hi,

At Tue, 4 Sep 2007 17:42:45 +0900,
Michael Linfield wrote in [ruby-talk:267482]:
result = (@startdate..@enddate)

####
OUTPUTS:

reportgraph.rb:29: bad value for range (ArgumentError)

Maybe, one of them (or both) is nil?
 
A

Alex Gutteridge

Nobuyoshi said:
Hi,

At Tue, 4 Sep 2007 15:43:55 +0900,
Michael Linfield wrote in [ruby-talk:267464]:
graph = Ruport::Graph:)column_names => #the 15 graph points by
average

The paren in this line doesn't seem closed, and you may forget
qoutes?

lol thanks, now however i run upon a second error, line 29

result = (@startdate..@enddate)

####
OUTPUTS:

reportgraph.rb:29: bad value for range (ArgumentError)
####

fun timez.
any ideas?

Thanks!

What options did you call the script with? Whatever, your use of
OptionParser is wrong. You are asking for date options with no
arguments where you should be asking for arguments:

opts.on("-s", "--startdate", "Determines what start date to use.") do

Should be:

opts.on("-s", "--startdate DATE", "Determines what start date to
use.") do

And the same for the end date and output options. Check the
OptionParser docs. There are other bugs in there as well: "ARGV =
svg" should surely be "d = 'svg'" for instance.

Alex Gutteridge

Bioinformatics Center
Kyoto University
 
M

Michael Linfield

Alex said:
What options did you call the script with? Whatever, your use of
OptionParser is wrong. You are asking for date options with no
arguments where you should be asking for arguments:

opts.on("-s", "--startdate", "Determines what start date to use.") do

Should be:

opts.on("-s", "--startdate DATE", "Determines what start date to
use.") do

And the same for the end date and output options. Check the
OptionParser docs. There are other bugs in there as well: "ARGV =
svg" should surely be "d = 'svg'" for instance.

well after fixing those few flaws i get a huge nomethoderror from the
method .column such as verizondat.column ...understandable because it
is actually supposed to use table.column but in fact table is tied to

table = Ruport::Data::Table.parse(csv)

which parses the data, not the grep'd array..so i guess my question now
would be how do i perform the same function except on the grep'd data?

-Thanks
 

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
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top