Sorry, this content is no longer available

Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
1

data type error in Ruby

asked 8 years ago

dalin_si's avatar

updated 7 years ago

Hi, i want to modify the COP of CoilCoolingDXSingleSpeed according to a csv file:

arr_of_arrs = CSV.read('C:\Users\sdl06\Documents\essence-144\144assumption\PTAC_Efficiency.csv')

coils.each do |coil|
   arr_of_arrs.each do |arr|
      if coil.name.get.casecmp(arr[0])==0
         coil.setRatedCOP(arr[1].to_f)
      end
   end
end

However, I got error like that:

TypeError: Expected argument 1 of type boost::optional< double >, but got String "3.98"
        in SWIG method 'setRatedCOP'

I know that is data type error, but I don't know how to transfer Float to Double. Any suggestion? Thanks!

Preview: (hide)

Comments

1

Well arr[1].to_f should convert the value to a float but SWIG thinks it is being pass a string, so that is odd. I would try:

puts "#{arr[1].to_f}, #{arr[1].to_f.class}"

If the argument is a float and SWIG rejects it then I would try:

coil.setRatedCOP(OpenStudio::OptionalDouble.new(arr[1].to_f))

We have standardized away from methods taking OptionalDouble values as input but these still remain in the older APIs.

macumber's avatar macumber  ( 8 years ago )

This is a known issue for CoilCoolingDXSingleSpeed.

ericringold's avatar ericringold  ( 8 years ago )

@macumber Thx! I figured out

dalin_si's avatar dalin_si  ( 8 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 8 years ago

dalin_si's avatar

Ok, now I figured out

only one adding one line:

cop = OpenStudio::OptionalDouble.new(arr[1].to_f)

to transfer Float to OpenStudio::OptionalDouble

then:

coil.setRatedCOP(cop)
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 8 years ago

Seen: 167 times

Last updated: Feb 13 '17