Class: BTAPModelMeasure

Inherits:
OpenStudio::Measure::ModelMeasure
  • Object
show all
Includes:
BTAPMeasureHelper
Defined in:
lib/openstudio-standards/utilities/template_measure/measure.rb

Overview

start the measure

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BTAPMeasureHelper

#arguments, #get_hash_of_arguments, #valid_float?, #validate_and_get_arguments_in_hash

Constructor Details

#initializeBTAPModelMeasure

Use the constructor to set global variables



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
# File 'lib/openstudio-standards/utilities/template_measure/measure.rb', line 30

def initialize
  super()
  # Set to true if you want to package the arguments as json.
  @use_json_package = false
  # Set to true if you want to want to allow strings and doubles in stringdouble types. Set to false to force to use doubles. The latter is used for certain
  # continuous optimization algorithms. You may have to re-examine your input in PAT as this fundamentally changes the measure.
  @use_string_double = true

  # Put in this array of hashes all the input variables that you need in your measure. Your choice of types are Sting, Double,
  # StringDouble, and Choice. Optional fields are valid strings, max_double_value, and min_double_value. This will
  # create all the variables, validate the ranges and types you need,  and make them available in the 'run' method as a hash after
  # you run 'arguments = validate_and_get_arguments_in_hash(model, runner, user_arguments)'
  @measure_interface_detailed = [
    {
      'name' => 'a_string_argument',
      'type' => 'String',
      'display_name' => 'A String Argument (string)',
      'default_value' => 'The Default Value',
      'is_required' => true
    },
    {
      'name' => 'a_double_argument',
      'type' => 'Double',
      'display_name' => 'A Double numeric Argument (double)',
      'default_value' => 0,
      'max_double_value' => 100.0,
      'min_double_value' => 0.0,
      'is_required' => true
    },
    {
      'name' => 'a_string_double_argument',
      'type' => 'StringDouble',
      'display_name' => 'A String Double numeric Argument (double)',
      'default_value' => 23.0,
      'max_double_value' => 100.0,
      'min_double_value' => 0.0,
      'valid_strings' => ['Baseline', 'NA'],
      'is_required' => true
    },
    {
      'name' => 'a_choice_argument',
      'type' => 'Choice',
      'display_name' => 'A Choice String Argument ',
      'default_value' => 'choice_1',
      'choices' => ['choice_1', 'choice_2'],
      'is_required' => true
    },
    {
      'name' => 'a_bool_argument',
      'type' => 'Bool',
      'display_name' => 'A Boolean Argument ',
      'default_value' => false,
      'is_required' => true
    }
  ]
end

Instance Attribute Details

#use_json_packageObject

Returns the value of attribute use_json_package.



7
8
9
# File 'lib/openstudio-standards/utilities/template_measure/measure.rb', line 7

def use_json_package
  @use_json_package
end

#use_string_doubleObject

Returns the value of attribute use_string_double.



7
8
9
# File 'lib/openstudio-standards/utilities/template_measure/measure.rb', line 7

def use_string_double
  @use_string_double
end

Instance Method Details

#descriptionObject

human readable description



20
21
22
# File 'lib/openstudio-standards/utilities/template_measure/measure.rb', line 20

def description
  return 'This template measure is used to ensure consistency in detailed BTAP measures.'
end

#modeler_descriptionObject

human readable description of modeling approach



25
26
27
# File 'lib/openstudio-standards/utilities/template_measure/measure.rb', line 25

def modeler_description
  return 'This template measure is used to ensure consistency in BTAP measures.'
end

#nameObject

human readable name



12
13
14
15
16
17
# File 'lib/openstudio-standards/utilities/template_measure/measure.rb', line 12

def name
  # BEFORE YOU DO anything.. please generate a new <uid>224561f4-8ccc-4f60-8118-34b85359d6f7</uid> and add this to the measure.xml file
  # You can generate a new UUID using the ruby command
  # ruby -e 'require "securerandom";  puts SecureRandom.uuid '
  return 'BTAPTemplateMeasure'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/openstudio-standards/utilities/template_measure/measure.rb', line 88

def run(model, runner, user_arguments)
  # Runs parent run method.
  super(model, runner, user_arguments)
  # Gets arguments from interfaced and puts them in a hash with there display name. This also does a check on ranges to
  # ensure that the values inputted are valid based on your @measure_interface array of hashes.
  arguments = validate_and_get_arguments_in_hash(model, runner, user_arguments)
  # puts JSON.pretty_generate(arguments)
  return false if arguments == false

  # You can now access the input argument by the name.
  # arguments['a_string_argument']
  # arguments['a_double_argument']
  # etc......
  # So write your measure code here!

  # Do something.
  return true
end