Class: Item::Materials::Checks::ControlCapacity
- Inherits:
-
BaseService
- Object
- BaseService
- Item::Materials::Checks::ControlCapacity
- Defined in:
- app/services/item/materials/checks/control_capacity.rb
Overview
Service object: control capacity.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- CAPACITY_TOLERANCE =
Capacity tolerance.
1.05
Instance Method Summary collapse
- #has_controls_and_heating_elements?(container) ⇒ Boolean
-
#process(container:, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
options:is part of the shared Item::Materials::Checks polymorphic API invoked byItem::Materials::Check#perform_checks_raw. - #qualify?(container) ⇒ Boolean
Instance Method Details
#has_controls_and_heating_elements?(container) ⇒ Boolean
17 18 19 |
# File 'app/services/item/materials/checks/control_capacity.rb', line 17 def has_controls_and_heating_elements?(container) (container.line_items.controls.present? || container.line_items.power_modules.present? || container.line_items.integration_kits.present?) && container.line_items.heating_elements.present? end |
#process(container:, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
options: is part of the shared Item::Materials::Checks polymorphic API
invoked by Item::Materials::Check#perform_checks_raw. Even though this
particular check ignores the value, the kwarg name has to stay as
options: so the bulk dispatch site keeps working.
:reek:UnusedParameters
27 28 29 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 |
# File 'app/services/item/materials/checks/control_capacity.rb', line 27 def process(container:, options: {}) # rubocop:enable Lint/UnusedMethodArgument return Result.new(status: :skipped) unless qualify?(container) material_alerts = [] # yes, so test if system load exceeds system control capacity (plus 5% fudge factor) tot_amps = container.calculate_total_amps if tot_amps > (container.control_capacity * CAPACITY_TOLERANCE) alert_name = <<-EOS Room #{container.reference_number}: total current load (#{tot_amps.round(1)} A) exceeds controls capacity (#{container.control_capacity.round(1)} A), please add relays or power modules and/or remove heating elements. EOS material_alerts << Item::Materials::Alert.new(name: alert_name, container: container) end # test if heating elements voltage is compatible with control voltage and/or with each other qty_mismatch = 0 if container.control_voltage.present? # this will be 120 or 240v, nil for dual voltage qty_mismatch = container.line_items.heating_elements.to_a.sum { |li| li.item.voltage.to_f == container.control_voltage.to_f ? 0 : li.quantity } mismatch_snippet = "control voltage (#{container.control_voltage.round} V)" else # dual voltage, see if heating elements are at least all the same voltage num_pms = container.line_items.power_modules.to_a.sum(&:quantity) # power modules allow mixing voltages, one voltage per power module num_rps = container.line_items.relay_panels.to_a.sum(&:quantity) # relay panels also allow this, any relay panel will support at least 4 voltages, which covers all of 120, 240, 277 or more volts_arr = container.line_items.heating_elements.map { |li| li.item.voltage }.uniq qtys_arr = volts_arr.map { |v| container.line_items.heating_elements.with_product_specification(:voltage, v).to_a.sum(&:quantity) }.sort largest_qty = qtys_arr.last if num_rps == 0 if num_pms > 0 if volts_arr.length > num_pms qty_mismatch = container.line_items.heating_elements.to_a.sum(&:quantity) - largest_qty mismatch_snippet = "the voltage of the other heating elements. That is, there are more heating element voltages than power modules" end else qty_mismatch = container.line_items.heating_elements.to_a.sum(&:quantity) - largest_qty mismatch_snippet = "the voltage of the other heating elements" end end end alert_name = <<-EOS Room #{container.reference_number}: #{qty_mismatch} heating element(s) do not match #{mismatch_snippet}. Please ensure that heating element voltages are compatible in this system. EOS material_alerts << Item::Materials::Alert.new(name: alert_name, container: container) if qty_mismatch > 0 Result.new(status: :ok, alerts: material_alerts) end |
#qualify?(container) ⇒ Boolean
13 14 15 |
# File 'app/services/item/materials/checks/control_capacity.rb', line 13 def qualify?(container) container.is_a?(RoomConfiguration) && has_controls_and_heating_elements?(container) end |