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 ⇒ Object
Returns the value of attribute argument_array.
-
#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(model, args) ⇒ Object
end method run.
-
#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 ⇒ Object
Returns the value of attribute argument_array.
127 128 129 |
# File 'lib/openstudio-standards/btap/measures.rb', line 127 def argument_array @argument_array end |
#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.
126 127 128 |
# File 'lib/openstudio-standards/btap/measures.rb', line 126 def argument_array_of_arrays @argument_array_of_arrays end |
#file ⇒ Object
Returns the value of attribute file.
128 129 130 |
# File 'lib/openstudio-standards/btap/measures.rb', line 128 def file @file end |
Instance Method Details
#argument_getter(model, runner, user_arguments) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/openstudio-standards/btap/measures.rb', line 245 def argument_getter(model, runner,user_arguments) @arg_table = [] unless @argument_array == nil @argument_array.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(model, args) ⇒ Object
end method run
202 203 204 205 206 207 208 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 |
# File 'lib/openstudio-standards/btap/measures.rb', line 202 def argument_setter(model,args) #***boilerplate code starts. Do not edit... #iterate through array of hashes and make arguments based on type and set # max and min values where applicable. @argument_array.each do |row| #strip out first char that contains the @ symbol row.variable_name[0] = '' 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.
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/openstudio-standards/btap/measures.rb', line 139 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
133 134 135 136 |
# File 'lib/openstudio-standards/btap/measures.rb', line 133 def name "BTAPModelUserScript" OSMArgument.new end |
#run(model, runner, user_arguments) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/openstudio-standards/btap/measures.rb', line 185 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
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/openstudio-standards/btap/measures.rb', line 150 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 |