First time here? Check out the Help page!
1 | initial version |
You can put your zones.csv
into a resources
subfolder indeed, this way it will stay with your measure (it seems that you can only have measure.rb
and measure.xml
at the root of your measure folder).
In your zones.csv
:
ZoneName
Zone 1
Zone 2
Zone 3
then in your measure:
require 'csv'
# File.dirname(__FILE__) points to the location of the current file, so your `measure.rb`
zones = CSV.table(File.dirname(__FILE__) + '/resources/zones.csv')
#
At this point if you check the headers:
[1] (main)> zones.headers
=> [:zonename]
Then you can do a bunch of stuff, like you can loop on each and grab the thermal zone associated with it
zones.each do |row|
zonename = row[:zonename]
zone = model.getThermalZoneByName(zonename)
if zone.empty?
puts "couldn't find zone named #{zonename}"
else
zone = zone.get
# Do something else
end
end
Or if it's easier you can always load all the zone name in a more familiar array object:
# Create empty array to store the zone names
zone_names = []
zones.each{|zone| zone_names << zone[:zonename]}
2 | No.2 Revision |
You can put your zones.csv
into a resources
subfolder indeed, this way it will stay with your measure (it seems that you can only have measure.rb
and measure.xml
at the root of your measure folder).
In your zones.csv
:
ZoneName
Zone 1
Zone 2
Zone 3
then in your measure:
require 'csv'
# File.dirname(__FILE__) points to the location of the current file, so your `measure.rb`
zones = CSV.table(File.dirname(__FILE__) + '/resources/zones.csv')
#
At this point if you check the headers:
[1] (main)> zones.headers
=> [:zonename]
Then you can do a bunch of stuff, like you can loop on each and grab the thermal zone associated with it
zones.each do |row|
zonename = row[:zonename]
zone = model.getThermalZoneByName(zonename)
if zone.empty?
puts "couldn't find zone named #{zonename}"
else
zone = zone.get
# Do something else
end
end
Or if it's easier you can always load all the zone name in a more familiar array object:
# Create empty array to store the zone names
zone_names = []
zones.each{|zone| zones.each{|row| zone_names << zone[:zonename]}
row[:zonename]}