18
19
20
21
22
23
24
25
26
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
|
# File 'app/services/item/materials/checks/control_capacity.rb', line 18
def process(container:, options:{})
return Result.new(status: :skipped) unless qualify?(container)
material_alerts = []
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
qty_mismatch = 0
if container.control_voltage.present? qty_mismatch = container.line_items.heating_elements.to_a.sum{|li| (li.item.voltage.to_f != container.control_voltage.to_f) ? li.quantity : 0 }
mismatch_snippet = "control voltage (#{container.control_voltage.round} V)"
else num_pms = container.line_items.power_modules.to_a.sum{|li| li.quantity} num_rps = container.line_items.relay_panels.to_a.sum{|li| li.quantity} volts_arr = container.line_items.heating_elements.collect{|li| li.item.voltage}.uniq
qtys_arr = volts_arr.map{|v| container.line_items.heating_elements.with_product_specification(:voltage, v).to_a.sum{|li| li.quantity}}.sort_by{|q| q}
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{|li| li.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{|li| li.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
|