Class: TariffSelectionGeneric
- Inherits:
-
OpenStudio::Measure::EnergyPlusMeasure
- Object
- OpenStudio::Measure::EnergyPlusMeasure
- TariffSelectionGeneric
- Defined in:
- lib/measures/tariff_selection_generic/measure.rb
Overview
start the measure
Instance Method Summary collapse
-
#arguments(workspace) ⇒ Object
define the arguments that the user will input.
-
#description ⇒ Object
human readable description.
-
#modeler_description ⇒ Object
human readable description of modeling approach.
-
#name ⇒ Object
define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml.
-
#run(workspace, runner, user_arguments) ⇒ Object
define what happens when the measure is run.
Instance Method Details
#arguments(workspace) ⇒ Object
define the arguments that the user will input
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/measures/tariff_selection_generic/measure.rb', line 28 def arguments(workspace) args = OpenStudio::Measure::OSArgumentVector.new # possible tariffs meters = {} # list files in resources directory and bin by meter of tariff object tariff_files = Dir.entries("#{File.dirname(__FILE__)}/resources") tariff_files.each do |tar| next if !tar.include?('.idf') # load the idf file containing the electric tariff tar_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/resources/#{tar}") tar_file = OpenStudio::IdfFile.load(tar_path) # in OpenStudio PAT in 1.1.0 and earlier all resource files are moved up a directory. # below is a temporary workaround for this before issuing an error. if tar_file.empty? tar_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/#{tar}") tar_file = OpenStudio::IdfFile.load(tar_path) end if tar_file.empty? puts "Unable to find the file #{tar}" else tar_file = tar_file.get # get the tariff object and the requested meter tariff_object = tar_file.getObjectsByType('UtilityCost:Tariff'.to_IddObjectType) if tariff_object.size > 1 puts "Only expected one tariff object in #{tar} but got #{tariff_object.size}" elsif tariff_object == 0 puts "Expected on tariff object in #{tar} but got #{tariff_object.size}" else tariff_name = tariff_object[0].getString(0).get tariff_meter = tariff_object[0].getString(1).get end # populate hash with tariff object meters[{ file_name: tar.gsub('.idf', ''), obj_name: tariff_name }] = tariff_meter end end # make an argument for each meter value found in the hash meters.values.uniq.each do |meter| choices = meters.select { |key, value| value == meter } # make a choice argument for tariff chs = [] chs_display = [] choices.each do |k, v| chs << k[:file_name] chs_display << k[:obj_name] end # TODO: - these will need to be unique names tar = OpenStudio::Measure::OSArgument.makeChoiceArgument(meter, chs, chs_display, true) tar.setDisplayName("Select a Tariff for #{meter}.") tar.setDefaultValue(chs[0]) args << tar end return args end |
#description ⇒ Object
human readable description
18 19 20 |
# File 'lib/measures/tariff_selection_generic/measure.rb', line 18 def description return 'This measure will add pre defined tariffs from IDF files in the resrouce directory for this measure.' end |
#modeler_description ⇒ Object
human readable description of modeling approach
23 24 25 |
# File 'lib/measures/tariff_selection_generic/measure.rb', line 23 def modeler_description return 'The measure works by cloning objects in from an external file into the current IDF file. Change functionality by changing the resource files. This measure may also adjust the simulation timestep.' end |
#name ⇒ Object
define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml
13 14 15 |
# File 'lib/measures/tariff_selection_generic/measure.rb', line 13 def name return ' Tariff Selection-Generic' end |
#run(workspace, runner, user_arguments) ⇒ Object
define what happens when the measure is run
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/measures/tariff_selection_generic/measure.rb', line 94 def run(workspace, runner, user_arguments) super(workspace, runner, user_arguments) args = runner.getArgumentValues(arguments(workspace), user_arguments) args = Hash[args.collect{ |k, v| [k.to_s, v] }] if !args then return false end # reporting initial condition of model starting_tariffs = workspace.getObjectsByType('UtilityCost:Tariff'.to_IddObjectType) runner.registerInitialCondition("The model started with #{starting_tariffs.size} tariff objects.") # loop though args to make tariff for each one args.each do |k, v| # load the idf file containing the electric tariff tar_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/resources/#{v}.idf") tar_file = OpenStudio::IdfFile.load(tar_path) # in OpenStudio PAT in 1.1.0 and earlier all resource files are moved up a directory. # below is a temporary workaround for this before issuing an error. if tar_file.empty? tar_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/#{v}.idf") tar_file = OpenStudio::IdfFile.load(tar_path) end if tar_file.empty? runner.registerError("Unable to find the file #{v}.idf") return false else tar_file = tar_file.get end # add everything from the file workspace.addObjects(tar_file.objects) # let the user know what happened runner.registerInfo("added a #{k} tariff from #{v}.idf") end # set the simulation timestep to 15min (4 per hour) to match the demand window of the tariffs if !workspace.getObjectsByType('Timestep'.to_IddObjectType).empty? initial_timestep = workspace.getObjectsByType('Timestep'.to_IddObjectType)[0].getString(0) if initial_timestep.to_s != '4' workspace.getObjectsByType('Timestep'.to_IddObjectType)[0].setString(0, '4') runner.registerInfo("Changing the simulation timestep to 4 timesteps per hour from #{initial_timestep} per hour to match the demand window of the tariffs") end else # add a timestep object to the workspace new_object_string = " Timestep, 4; !- Number of Timesteps per Hour " idfObject = OpenStudio::IdfObject.load(new_object_string) object = idfObject.get wsObject = workspace.addObject(object) new_object = wsObject.get runner.registerInfo('No timestep object found. Added a new timestep object set to 4 timesteps per hour') end # report final condition of model finishing_tariffs = workspace.getObjectsByType('UtilityCost:Tariff'.to_IddObjectType) runner.registerFinalCondition("The model finished with #{finishing_tariffs.size} tariff objects.") return true end |