Class: HeatingSystemCalculator::HeatingSystem

Inherits:
Object
  • Object
show all
Defined in:
app/services/heating_system_calculator/heating_system.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HeatingSystem

Returns a new instance of HeatingSystem.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/heating_system_calculator/heating_system.rb', line 6

def initialize(options = {})
  @heated_area = options[:heated_area]
  @room_configuration = options[:room_configuration]
  @room_configuration.present? ? pre_process_from_room(@room_configuration) : pre_process_from_options(options)
  @error = { error_status: :missing_catalog, error_message: 'Catalog is missing.' } if @catalog.nil?
  @error = { error_status: :missing_room_type, error_message: 'Room/Area type is missing.' } if @room_type.nil?
  if @room_type and @room_type.environment.downcase.index('indoor') and @sub_floor_type.nil?
    @error = { error_status: :missing_sub_floor_type,
               error_message: 'Sub Floor type is missing.' }
  end
  @error = { error_status: :missing_floor_type, error_message: 'Floor/Surface type is missing.' } if @floor_type.nil?
  @error = { error_status: :missing_heating_system, error_message: 'Heating System Type is missing.' } if @heating_system_product_line.nil?
  @heating_system_type_name = @heating_system_product_line.heating_system_type_name
  @use_in_stock_only = options[:use_in_stock_only]
  @membrane_recommended = options[:membrane_recommended]
  @membrane_type = options[:membrane_type]
end

Instance Attribute Details

#cable_spacingObject (readonly)

Returns the value of attribute cable_spacing.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def cable_spacing
  @cable_spacing
end

#catalogObject (readonly)

Returns the value of attribute catalog.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def catalog
  @catalog
end

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def error
  @error
end

#floor_typeObject (readonly)

Returns the value of attribute floor_type.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def floor_type
  @floor_type
end

#heating_system_product_lineObject (readonly)

Returns the value of attribute heating_system_product_line.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def heating_system_product_line
  @heating_system_product_line
end

#heating_system_type_nameObject (readonly)

Returns the value of attribute heating_system_type_name.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def heating_system_type_name
  @heating_system_type_name
end

Returns the value of attribute membrane_recommended.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def membrane_recommended
  @membrane_recommended
end

#membrane_typeObject (readonly)

Returns the value of attribute membrane_type.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def membrane_type
  @membrane_type
end

#room_typeObject (readonly)

Returns the value of attribute room_type.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def room_type
  @room_type
end

#sub_floor_typeObject (readonly)

Returns the value of attribute sub_floor_type.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def sub_floor_type
  @sub_floor_type
end

#use_in_stock_onlyObject (readonly)

Returns the value of attribute use_in_stock_only.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def use_in_stock_only
  @use_in_stock_only
end

#voltageObject (readonly)

Returns the value of attribute voltage.



3
4
5
# File 'app/services/heating_system_calculator/heating_system.rb', line 3

def voltage
  @voltage
end

Instance Method Details

#calculate_voltage_from_heated_areaObject



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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/services/heating_system_calculator/heating_system.rb', line 44

def calculate_voltage_from_heated_area
  area = @heated_area.heated_area_sqft
  # test area and criteria keys to see if we need 120V or 240V system
  if ['Snow Melt Mat','Snow Melt PowerMat','Snow Melt OmniMat','Snow Melt EcoMat', 'Snow Melt Cable', 'Slab Heat Mat', 'Slab Heat Cable'].include?(@heating_system_type_name)
    sm_threshold_area = 40.0
    if ['Snow Melt Mat','Snow Melt PowerMat','Snow Melt OmniMat','Snow Melt EcoMat', 'Slab Heat Mat'].include?(@heating_system_type_name)
      controlsvoltage = 120
      threshold = 10.0 if ['Snow Melt Mat','Snow Melt PowerMat','Snow Melt OmniMat','Snow Melt EcoMat'].include?(@heating_system_type_name) # ugly but it works I guess, smallest 240v SMM is 10 ft long
      threshold = 40.0 if ['Slab Heat Mat'].include?(@heating_system_type_name) # ugly but it works I guess, smallest 240v SHM is 40 ft long
      smallest_bigger_dim = 99_999_999.0
      @heated_area.zones.each do |z|
        z_bigger_dim = [z[:length].to_f, z[:width].to_f].max
        smallest_bigger_dim = z_bigger_dim if z_bigger_dim < smallest_bigger_dim
      end
      controlsvoltage = 240 if smallest_bigger_dim >= threshold # prefer 240V if threshold met
      controlsvoltage = 240 if area >= sm_threshold_area # prefer 240V if threshold met
    elsif ['Snow Melt Cable', 'Slab Heat Cable'].include?(@heating_system_type_name)
      controlsvoltage = 120
      smallest_zone_area = 99_999_999.0
      tot_zone_area = 0.0
      @heated_area.zones.each do |z|
        tot_zone_area += z[:sqft].to_f
        smallest_zone_area = z[:sqft].to_f if z[:sqft].to_f < smallest_zone_area
      end
      if ['Slab Heat Cable'].include?(@heating_system_type_name)
        # ugly but it works I guess, smallest 240 SHC cable length using cable spacing of 5
        controlsvoltage = 240 if smallest_zone_area >= 323.0 * @cable_spacing / 12.0
      elsif ['Snow Melt Cable'].include?(@heating_system_type_name)
        # for SMC use 120V if total area is smaller than sm_threshold_area and 240V if bigger
        controlsvoltage = 240 if tot_zone_area >= sm_threshold_area
      end
    end
  elsif ['TempZone Cable'].include?(@heating_system_type_name)
    # for TempZone Cable 3 inch spacing or unknown, use area threshold of 118 sq.ft.
    amax = 118.0
    # for TempZone Cable 4 inch spacing or more, use area threshold of 128 sq.ft.
    amax = 128.0 if @cable_spacing.round >= 4
    controlsvoltage = if area <= amax
                        120
                      else
                        240
                      end
  elsif ['TempZone Thin Cable'].include?(@heating_system_type_name)
    # for TempZone Thin Cable 3 inch spacing or unknown, use area threshold of 145 sq.ft.
    amax = 145.0
    # for TempZone Thin Cable 4 inch spacing or more, use area threshold of 195 sq.ft.
    amax = 195.0 if @cable_spacing.round >= 4
    controlsvoltage = if area <= amax
                        120
                      else
                        240
                      end
  else
    # for TempZone and Environ Flex Rolls and Mats, or no criteria keys, just use area threshold of 115 sq.ft.
    controlsvoltage = if area <= 115.0
                        120
                      else
                        240
                      end
  end
  Voltage.where(id: controlsvoltage).first
end

#pre_process_from_options(options) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'app/services/heating_system_calculator/heating_system.rb', line 34

def pre_process_from_options(options)
  @catalog = options[:catalog]
  @room_type = options[:room_type]
  @sub_floor_type = options[:sub_floor_type]
  @floor_type = options[:floor_type]
  @heating_system_product_line = options[:heating_system_product_line]
  @cable_spacing = options[:cable_spacing]
  @voltage = options[:voltage] || calculate_voltage_from_heated_area
end

#pre_process_from_room(room_configuration) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/services/heating_system_calculator/heating_system.rb', line 24

def pre_process_from_room(room_configuration)
  @catalog = room_configuration.customer.catalog
  @room_type = room_configuration.room_type
  @sub_floor_type = room_configuration.sub_floor_type
  @floor_type = room_configuration.floor_type
  @heating_system_product_line = room_configuration.get_heating_system_type
  @cable_spacing = room_configuration.cable_spacing
  @voltage = room_configuration.voltage || calculate_voltage_from_heated_area
end