Class: Honeybee::ScheduleTypeLimit

Inherits:
ModelObject show all
Defined in:
lib/honeybee/schedule/type_limit.rb,
lib/to_openstudio/schedule/type_limit.rb,
lib/from_openstudio/schedule/type_limit.rb

Constant Summary collapse

@@unit_types =
[
  'Dimensionless',
  'Temperature',
  'DeltaTemperature',
  'PrecipitationRate',
  'Angle',
  'ConvectionCoefficient',
  'ActivityLevel',
  'Velocity',
  'Capacity',
  'Power',
  'Availability',
  'Percent',
  'Control',
  'Mode'
]

Instance Attribute Summary

Attributes inherited from ModelObject

#errors, #openstudio_object, #warnings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModelObject

#allowable_types, clean_identifier, clean_name, #initialize, #method_missing, read_from_disk, truncate

Constructor Details

This class inherits a constructor from Honeybee::ModelObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Honeybee::ModelObject

Class Method Details

.from_schedule_type_limit(schedule_type_limit) ⇒ 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
# File 'lib/from_openstudio/schedule/type_limit.rb', line 55

def self.from_schedule_type_limit(schedule_type_limit)
  # create an empty hash
  hash = {}
  hash[:type] = 'ScheduleTypeLimit'
  # set hash values from OpenStudio Object
  hash[:identifier] = clean_name(schedule_type_limit.nameString)
  unless schedule_type_limit.displayName.empty?
    hash[:display_name] = (schedule_type_limit.displayName.get).force_encoding("UTF-8")
  end
  # check if boost optional object is empty
  unless schedule_type_limit.lowerLimitValue.empty?
    hash[:lower_limit] = schedule_type_limit.lowerLimitValue.get
  end
  # check if boost optional object is empty
  unless schedule_type_limit.upperLimitValue.empty?
    hash[:upper_limit] = schedule_type_limit.upperLimitValue.get
  end
  # check if boost optional object is empty
  unless schedule_type_limit.numericType.empty?
    numeric_type = schedule_type_limit.numericType.get
    hash[:numeric_type] = numeric_type.titleize
  end

  # make sure unit type always follows the capitalization of the Honeybee Enumeration
  unit_type = schedule_type_limit.unitType.titleize
  if unit_type == 'Deltatemperature'
    unit_type = 'DeltaTemperature'
  elsif unit_type == 'Precipitationrate'
    unit_type = 'PrecipitationRate'
  elsif unit_type == 'Convectioncoefficient'
    unit_type = 'ConvectionCoefficient'
  elsif unit_type == 'Activitylevel'
    unit_type = 'ActivityLevel'
  elsif unit_type == 'Controlmode'
    unit_type = 'Control'
  end
  if @@unit_types.include? unit_type
    hash[:unit_type] = unit_type
  end

  hash
end

Instance Method Details

#defaultsObject



37
38
39
# File 'lib/honeybee/schedule/type_limit.rb', line 37

def defaults
  @@schema[:components][:schemas][:ScheduleTypeLimit][:properties]
end

#find_existing_openstudio_object(openstudio_model) ⇒ Object



39
40
41
42
43
# File 'lib/to_openstudio/schedule/type_limit.rb', line 39

def find_existing_openstudio_object(openstudio_model)
  object = openstudio_model.getScheduleTypeLimitsByName(@hash[:identifier])
  return object.get if object.is_initialized
  nil
end

#to_openstudio(openstudio_model) ⇒ Object



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
# File 'lib/to_openstudio/schedule/type_limit.rb', line 45

def to_openstudio(openstudio_model)
  # create schedule type limits openstudio object
  os_type_limit = OpenStudio::Model::ScheduleTypeLimits.new(openstudio_model)
  os_type_limit.setName(@hash[:identifier])
  unless @hash[:display_name].nil?
    os_type_limit.setDisplayName(@hash[:display_name])
  end
  if @hash[:lower_limit] != nil and @hash[:lower_limit] != {:type => 'NoLimit'}
    os_type_limit.setLowerLimitValue(@hash[:lower_limit])
  end

  if @hash[:upper_limit] != nil and @hash[:upper_limit] != {:type => 'NoLimit'}
    os_type_limit.setUpperLimitValue(@hash[:upper_limit])
  end

  # assign numeric type
  if @hash[:numeric_type]
    os_type_limit.setNumericType(@hash[:numeric_type])
  else
    os_type_limit.setNumericType(defaults[:numeric_type])
  end

  # assign unit type
  if @hash[:unit_type]
    os_type_limit.setUnitType(@hash[:unit_type])
  else
    os_type_limit.setUnitType(defaults[:unit_type])
  end

  os_type_limit
end