Module: OpenStudio::Metadata::Helpers

Included in:
Creator
Defined in:
lib/openstudio/metadata/helpers.rb

Instance Method Summary collapse

Instance Method Details

#create_ems_str(name) ⇒ Object

Format with no spaces or ‘-’ (can be used as EMS var name)

Parameters:

  • name (String)


43
44
45
# File 'lib/openstudio/metadata/helpers.rb', line 43

def create_ems_str(name)
  return name.gsub(/[\s-]/, '_').to_s
end

#create_mapping_output_uuid(emsName, uuid) ⇒ Object



173
174
175
176
177
178
179
180
181
# File 'lib/openstudio/metadata/helpers.rb', line 173

def create_mapping_output_uuid(emsName, uuid)
  json = {}
  json[:id] = haystack_format_as_ref(uuid)
  json[:source] = 'Ptolemy'
  json[:name] = ''
  json[:type] = ''
  json[:variable] = emsName
  return json
end

#create_mapping_timevars(outvar_time, uuid) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/openstudio/metadata/helpers.rb', line 139

def create_mapping_timevars(outvar_time, uuid)
  # this function will use the uuid generated from create_point_timevars(), to make a mapping.
  # the uuid is unique to be used for mapping purpose; uuid is the belt to connect point_json and mapping_json
  # the mapping_json below contains all the necessary tags
  mapping_json = {}
  mapping_json[:id] = uuid
  mapping_json[:source] = 'EnergyPlus'
  mapping_json[:name] = 'EMS'
  mapping_json[:type] = outvar_time.nameString
  mapping_json[:variable] = ''

  return mapping_json
end

#create_output_meter(model, meter_name, reporting_frequency: 'timestep') ⇒ Object



110
111
112
113
114
115
# File 'lib/openstudio/metadata/helpers.rb', line 110

def create_output_meter(model, meter_name, reporting_frequency: 'timestep')
  meter = OpenStudio::Model::OutputMeter.new(model)
  meter.setName(meter_name)
  meter.setReportingFrequency(reporting_frequency)
  return meter
end

#create_output_variable_and_ems_sensor(system_node_property:, node:, ems_name:, model:, reporting_frequency: 'timestep', bcvtb: true) ⇒ Object

Create both an output variable and an energy management system sensor and register them to the model

Parameters:

  • system_node_property (String)

    One of the ‘System Node Properties’, see E+ IO reference node list outputs

  • node (OpenStudio::Model::Node)

    Node of interest

  • ems_name (String)

    Desired name for EMS variable

  • model (OpenStudio::Model::Model)
  • reporting_frequency (String) (defaults to: 'timestep')

    See E+ IO reference reporting frequency for options

  • bcvtb (Boolean) (defaults to: true)

    Flag to export OutputVariable to bcvtb



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/openstudio/metadata/helpers.rb', line 91

def create_output_variable_and_ems_sensor(system_node_property:, node:, ems_name:, model:, reporting_frequency: 'timestep', bcvtb: true)
  name = create_ems_str(ems_name)
  output_variable = OpenStudio::Model::OutputVariable.new(system_node_property, model)
  output_variable.setKeyValue(node.name.to_s)
  output_variable.setReportingFrequency(reporting_frequency)
  output_variable.setName(name)
  output_variable.setExportToBCVTB(bcvtb)

  # EMS sensors are used to declare an Erl variable that is linked to E+ output variables or meters
  sensor = OpenStudio::Model::EnergyManagementSystemSensor.new(model, output_variable)

  # The key reference for the specified output variable
  sensor.setKeyName(node.handle.to_s)

  # Unique name for the sensor that becomes the name of a variable for us in Erl programs.
  sensor.setName("EMS_#{name}")
  return output_variable
end

#create_point_timevars(outvar_time, siteRef) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/openstudio/metadata/helpers.rb', line 117

def create_point_timevars(outvar_time, siteRef)
  # this function will add haystack tag to the time-variables created by user.
  # the time-variables are also written to variables.cfg file to coupling energyplus
  # the uuid is unique to be used for mapping purpose
  # the point_json generated here caontains the tags for the tim-variables
  point_json = {}
  # id = outvar_time.keyValue.to_s + outvar_time.name.to_s
  uuid = haystack_create_uuid
  point_json[:id] = uuid
  # point_json[:source] = create_str("EnergyPlus")
  # point_json[:type] = "Output:Variable"
  # point_json[:name] = create_str(outvar_time.name.to_s)
  # point_json[:variable] = create_str(outvar_time.name)
  point_json[:dis] = haystack_format_as_str(outvar_time.nameString)
  point_json[:siteRef] = haystack_format_as_ref(siteRef)
  point_json[:point] = 'm:'
  point_json[:cur] = 'm:'
  point_json[:curStatus] = 's:disabled'

  return point_json, uuid
end

#create_point_uuid(type, id, siteRef, equipRef, floorRef, where, what, measurement, kind, unit) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/openstudio/metadata/helpers.rb', line 153

def create_point_uuid(type, id, siteRef, equipRef, floorRef, where, what, measurement, kind, unit)
  point_json = {}
  uuid = haystack_create_uuid
  point_json[:id] = uuid
  point_json[:dis] = haystack_format_as_str(id)
  point_json[:siteRef] = haystack_format_as_ref(siteRef)
  point_json[:equipRef] = haystack_format_as_ref(equipRef)
  point_json[:floorRef] = haystack_format_as_ref(floorRef)
  point_json[:point] = 'm:'
  point_json[type.to_s] = 'm:'
  point_json[measurement.to_s] = 'm:'
  point_json[where.to_s] = 'm:'
  point_json[what.to_s] = 'm:'
  point_json[:kind] = haystack_format_as_str(kind)
  point_json[:unit] = haystack_format_as_str(unit)
  point_json[:cur] = 'm:'
  point_json[:curStatus] = 's:disabled'
  return point_json, uuid
end

#haystack_create_uuidString

Create a UUID and format as a Haystack ref (ie, “r:xxxxx”)

Returns:

  • (String)


51
52
53
# File 'lib/openstudio/metadata/helpers.rb', line 51

def haystack_create_uuid
  return "r:#{OpenStudio.removeBraces(OpenStudio.createUUID)}"
end

#haystack_format_as_num(str) ⇒ String

Return string formatted for numbers (ie, “n:xxxxx”)

Parameters:

  • []

    str An object which can be converted to a string

Returns:

  • (String)


78
79
80
# File 'lib/openstudio/metadata/helpers.rb', line 78

def haystack_format_as_num(str)
  return "n:#{str}"
end

#haystack_format_as_ref(id) ⇒ String

Return string formatted for Ref (ie, “r:xxxxx”) with uuid of object

Parameters:

  • id (OpenStudio::UUID)

Returns:

  • (String)


60
61
62
# File 'lib/openstudio/metadata/helpers.rb', line 60

def haystack_format_as_ref(id)
  return "r:#{OpenStudio.removeBraces(id)}"
end

#haystack_format_as_str(str) ⇒ String

Return string formatted for strings (ie, “s:xxxxx”)

Parameters:

  • []

    str An object which can be converted to a string

Returns:

  • (String)


69
70
71
# File 'lib/openstudio/metadata/helpers.rb', line 69

def haystack_format_as_str(str)
  return "s:#{str}"
end