Class: BTAP::Measures::OSMeasures::BTAPModelUserScript
- Inherits:
-
OpenStudio::Ruleset::ModelUserScript
- Object
- OpenStudio::Ruleset::ModelUserScript
- BTAP::Measures::OSMeasures::BTAPModelUserScript
- Defined in:
- lib/openstudio-standards/btap/measures.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#argument_array_of_arrays ⇒ Object
if and E+ measure replace OpenStudio::Ruleset::ModelUserScript with OpenStudio::Ruleset::WorkspaceUserScript Array containing information of all inputs required by measure.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #argument_getter(model, runner, user_arguments) ⇒ Object
-
#argument_setter(args) ⇒ Object
end method run.
- #arguments(model, argument_array_of_arrays) ⇒ Object
-
#generate_ruby_macro(model, runner) ⇒ Object
this method will output the ruby macro to perform the change.
-
#name ⇒ Object
if and E+ measure replace OpenStudio::Ruleset::ModelUserScript with OpenStudio::Ruleset::WorkspaceUserScript.
- #run(model, runner, user_arguments) ⇒ Object
- #set_user_arguments_and_apply(model, argument_values, runner) ⇒ Object
Instance Attribute Details
#argument_array_of_arrays ⇒ Object
if and E+ measure replace OpenStudio::Ruleset::ModelUserScript with OpenStudio::Ruleset::WorkspaceUserScript Array containing information of all inputs required by measure.
33 34 35 |
# File 'lib/openstudio-standards/btap/measures.rb', line 33 def argument_array_of_arrays @argument_array_of_arrays end |
#file ⇒ Object
Returns the value of attribute file.
34 35 36 |
# File 'lib/openstudio-standards/btap/measures.rb', line 34 def file @file end |
Instance Method Details
#argument_getter(model, runner, user_arguments) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/openstudio-standards/btap/measures.rb', line 209 def argument_getter(model, runner,user_arguments) @arg_table = [] unless @argument_array_of_hashes == nil @argument_array_of_hashes.each do |row| name = row["variable_name"] case row["type"] when "BOOL" value = runner.getBoolArgumentValue(name, user_arguments) instance_variable_set("@#{name}",value) @arg_table << [name,value] when "STRING" value = runner.getStringArgumentValue(name, user_arguments) instance_variable_set("@#{name}",value) @arg_table << [name,value] when "INTEGER" value = runner.getIntegerArgumentValue(name, user_arguments) instance_variable_set("@#{name}",value) @arg_table << [name,value] if ( not row["min_value"].nil? and instance_variable_get("@#{name}") < row["min_value"] ) or ( not row["max_value"].nil? and instance_variable_get("@#{name}") > row["max_value"] ) runner.registerError("#{row["display_name"]} must be greater than or equal to #{row["min_value"]} and less than or equal to #{row["max_value"]}. You entered #{instance_variable_get("@#{name}")}.") return false end when "FLOAT" value = runner.getDoubleArgumentValue(name, user_arguments) instance_variable_set("@#{name}",value) @arg_table << [name,value] if ( not row["min_value"].nil? and instance_variable_get("@#{name}") < row["min_value"] ) or ( not row["max_value"].nil? and instance_variable_get("@#{name}") > row["max_value"] ) runner.registerError("#{row["display_name"]} must be greater than or equal to #{row["min_value"]} and less than or equal to #{row["max_value"]}. You entered #{instance_variable_get("@#{name}")}.") return false end when "STRINGCHOICE" @arg_table << [name,runner.getBoolArgumentValue(name, user_arguments)] instance_variable_set("@#{name}", runner.getStringArgumentValue(name, user_arguments) ) when "WSCHOICE" @arg_table << [name,runner.getBoolArgumentValue(name, user_arguments)] instance_variable_set("@#{name}", runner.getOptionalWorkspaceObjectChoiceValue(name, user_arguments,model) ) when "PATH" @arg_table << [name,runner.getBoolArgumentValue(name, user_arguments)] instance_variable_set("@#{name}", runner.getPathArgument(name, user_arguments) ) end #end case end #end do end return @arg_table end |
#argument_setter(args) ⇒ Object
end method run
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/openstudio-standards/btap/measures.rb', line 162 def argument_setter(args) #***boilerplate code starts. Do not edit... # this converts the 2D array to a array hash for better readability and makes # column data accessible by name. @argument_array_of_hashes = [] @argument_array_of_arrays[1..-1].each do |row| # [1..-1] skips the first row hsh = {}; @argument_array_of_arrays[0].each_with_index{ |header, idx| hsh[header] = row[idx] } @argument_array_of_hashes << hsh end #iterate through array of hashes and make arguments based on type and set # max and min values where applicable. @argument_array_of_hashes.each do |row| arg = nil case row["type"] when "BOOL" arg = OpenStudio::Ruleset::OSArgument::makeBoolArgument(row["variable_name"],row["required"],row["model_dependant"]) when "STRING" arg = OpenStudio::Ruleset::OSArgument::makeStringArgument(row["variable_name"],row["required"],row["model_dependant"]) when "INTEGER" arg = OpenStudio::Ruleset::OSArgument::makeIntegerArgument(row["variable_name"],row["required"],row["model_dependant"]) arg.setMaxValue( row["max_value"].to_i ) unless row["min_value"].nil? arg.setMaxValue( row["max_value"].to_i ) unless row["max_value"].nil? when "FLOAT" arg = OpenStudio::Ruleset::OSArgument::makeDoubleArgument(row["variable_name"],row["required"],row["model_dependant"]) arg.setMaxValue( row["max_value"].to_f ) unless row["min_value"].nil? arg.setMaxValue( row["max_value"].to_f ) unless row["max_value"].nil? when "STRINGCHOICE" # #add string choices one by one. chs = OpenStudio::StringVector.new row["string_choice_array"].each {|choice| chs << choice} arg = OpenStudio::Ruleset::OSArgument::makeChoiceArgument(row["variable_name"], chs,row["required"],row["model_dependant"]) when "PATH" arg = OpenStudio::Ruleset::OSArgument::makePathArgument("alternativeModelPath",true,"osm") when "WSCHOICE" arg = OpenStudio::Ruleset::makeChoiceArgumentOfWorkspaceObjects( row["variable_name"], row["os_object_type"].to_IddObjectType , model, row["required"]) end # #common argument aspects. unless arg.nil? arg.setDisplayName(row["display_name"]) arg.setDefaultValue(row["default_value"]) unless row["default_value"].nil? args << arg end end return args end |
#arguments(model, argument_array_of_arrays) ⇒ Object
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/openstudio-standards/btap/measures.rb', line 55 def arguments(model,argument_array_of_arrays) #IF and E+ measure replace model with workspace as the argument #Create an argument vector args = OpenStudio::Ruleset::OSArgumentVector.new @argument_array_of_arrays = argument_array_of_arrays #***boilerplate code starts. Do not edit... # this converts the 2D array to a array hash for better readability and makes # column data accessible by name. @argument_array_of_hashes = [] @argument_array_of_arrays[1..-1].each do |row| # [1..-1] skips the first row hsh = {}; @argument_array_of_arrays[0].each_with_index{ |header, idx| hsh[header] = row[idx] } @argument_array_of_hashes << hsh end #iterate through array of hashes and make arguments based on type and set # max and min values where applicable. @argument_array_of_hashes.each do |row| arg = nil case row["type"] when "BOOL" arg = OpenStudio::Ruleset::OSArgument::makeBoolArgument(row["variable_name"],row["required"],row["model_dependant"]) when "STRING" arg = OpenStudio::Ruleset::OSArgument::makeStringArgument(row["variable_name"],row["required"],row["model_dependant"]) when "INTEGER" arg = OpenStudio::Ruleset::OSArgument::makeIntegerArgument(row["variable_name"],row["required"],row["model_dependant"]) arg.setMaxValue( row["max_value"].to_i ) unless row["min_value"].nil? arg.setMaxValue( row["max_value"].to_i ) unless row["max_value"].nil? when "FLOAT" arg = OpenStudio::Ruleset::OSArgument::makeDoubleArgument(row["variable_name"],row["required"],row["model_dependant"]) arg.setMaxValue( row["max_value"].to_f ) unless row["min_value"].nil? arg.setMaxValue( row["max_value"].to_f ) unless row["max_value"].nil? when "STRINGCHOICE" # #add string choices one by one. chs = OpenStudio::StringVector.new row["string_choice_array"].each {|choice| chs << choice} arg = OpenStudio::Ruleset::OSArgument::makeChoiceArgument(row["variable_name"], chs,row["required"],row["model_dependant"]) when "PATH" arg = OpenStudio::Ruleset::OSArgument::makePathArgument("alternativeModelPath",true,"osm") when "WSCHOICE" arg = OpenStudio::Ruleset::makeChoiceArgumentOfWorkspaceObjects( row["variable_name"], row["os_object_type"].to_IddObjectType , model, row["required"]) end # #common argument aspects. unless arg.nil? arg.setDisplayName(row["display_name"]) arg.setDefaultValue(row["default_value"]) unless row["default_value"].nil? args << arg end end return args end |
#generate_ruby_macro(model, runner) ⇒ Object
this method will output the ruby macro to perform the change.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/openstudio-standards/btap/measures.rb', line 44 def generate_ruby_macro(model,runner) if @file == nil or @file == "" @file = "Enter_Path_To_#{self.class.name}_measure.rb_File!" end BTAP::runner_register("MACRO", "\##{self.class.name} Measure Start", runner) BTAP::runner_register("MACRO", "require \"#{@file}\"", runner) BTAP::runner_register("MACRO", "argument_values = #{@arg_table}", runner) BTAP::runner_register("MACRO", "#{self.class.name}.new.set_user_arguments_and_apply(model,argument_values,runner)",runner) BTAP::runner_register("MACRO", "\##{self.class.name} Measure End", runner) end |
#name ⇒ Object
if and E+ measure replace OpenStudio::Ruleset::ModelUserScript with OpenStudio::Ruleset::WorkspaceUserScript
39 40 41 |
# File 'lib/openstudio-standards/btap/measures.rb', line 39 def name "BTAPModelUserScript" end |
#run(model, runner, user_arguments) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/openstudio-standards/btap/measures.rb', line 145 def run(model, runner, user_arguments) #IF and E+ measure replace model with workspace as the argument #Boilerplate start super(model, runner, user_arguments) BTAP::runner_register("INFO", "Initial model being modified by #{self.class.name}",runner) if not runner.validateUserArguments(self.arguments(model),user_arguments) return false end #Set argument to instance variables. self.argument_getter(model, runner,user_arguments) #will run the childs method measure_code result = self.measure_code(model,runner) generate_ruby_macro(model,runner) return result end |
#set_user_arguments_and_apply(model, argument_values, runner) ⇒ Object
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 |
# File 'lib/openstudio-standards/btap/measures.rb', line 110 def set_user_arguments_and_apply(model,argument_values,runner) = "Settting Arguments" runner.nil? ? puts() : runner.registerInfo() #create argument map user_arguments = OpenStudio::Ruleset::OSArgumentMap.new #get argument list arguments = self.arguments(model) #go through each argument arguments.each do |argument| found = false #go through each passed argument_values argument_values.each do |pair| #when a match is found. if argument.name == pair[0] clone_argument = argument.clone unless clone_argument.setValue(pair[1]) = "Could not set #{argument.name} to #{pair[1]}" runner.nil? ? puts() : runner.registerError() else = "Set #{argument.name} to #{pair[1]}" runner.nil? ? puts() : runner.registerInfo() end user_arguments[pair[0]] = clone_argument #log message = " Argument set to #{user_arguments}" runner.nil? ? puts() : runner.registerInfo() end found = true end puts ("Warning: value for argument #{argument.name} not set!.") if found == false end self.run(model, runner, user_arguments) end |