Module: HeatlossCalculationsHelper

Defined in:
app/helpers/heatloss_calculations_helper.rb

Instance Method Summary collapse

Instance Method Details



57
58
59
# File 'app/helpers/heatloss_calculations_helper.rb', line 57

def ceiling_heat_loss_edit_link
  link_to edit_icon_hlc( ceiling_heat_loss_present? ), ceiling_heat_loss_details_my_room_path(@room), data: { turbo: true, turbo_stream: true }, class: "btn btn-my-account-card transparent border-0 p-0 block-ui-on-click"
end

#ceiling_heat_loss_headerObject



53
54
55
# File 'app/helpers/heatloss_calculations_helper.rb', line 53

def ceiling_heat_loss_header
  "#{check_mark_hlc( ceiling_heat_loss_present? )} <span class='step-number'>Step 3:</span> Ceiling".html_safe
end

#ceiling_heat_loss_present?Boolean

BEGIN CEILING

Returns:

  • (Boolean)


49
50
51
# File 'app/helpers/heatloss_calculations_helper.rb', line 49

def ceiling_heat_loss_present?
  @room.ceiling.present? and !@room.ceiling.new_record?
end

#check_mark_hlc(done) ⇒ Object

BEGIN COMMON HELPER



18
19
20
# File 'app/helpers/heatloss_calculations_helper.rb', line 18

def check_mark_hlc(done)
  fa_icon('circle-check', :style => "").html_safe if done
end

#edit_icon_hlc(done) ⇒ Object



22
23
24
# File 'app/helpers/heatloss_calculations_helper.rb', line 22

def edit_icon_hlc(done)
  done ? fa_icon('pen-to-square', text: "Edit") : fa_icon('plus', text: "Add")
end

#heat_loss_charts_data(room, heat_loss) ⇒ Hash

Generates data for heat loss charts Stimulus controller

Parameters:

  • room (RoomConfiguration)

    the room with heat loss data

  • heat_loss (Hash)

    the calculated heat loss data

Returns:

  • (Hash)

    data for chart rendering (values are Ruby arrays, not JSON)



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
# File 'app/helpers/heatloss_calculations_helper.rb', line 65

def heat_loss_charts_data(room, heat_loss)
  # Build highlight months (months where loss exceeds heat supply)
  highlight_months = heat_loss['loss_exceeds_heat_supply']
    .each_with_index
    .select { |o, _i| o['exceeds'] }
    .map { |_o, i| i }

  # Pie chart data
  pie_data = heat_loss['hlc_by_object'].map do |o|
    { name: o['name'], y: o['heat_loss'].round, color: o['color'] }
  end

  {
    pie_data: pie_data,
    hl_averages: heat_loss['hlc_averages'].map { |o| o['heat_loss'].round },
    hl_ranges: heat_loss['hlc_ranges'].map { |o| [o['range'][0].round, o['range'][1].round] },
    heat_supplied: heat_loss['heat_supplied'].map { |o| o['heat_supplied'].round },
    heat_supply_ranges: heat_loss['heat_supplied'].map { |o| [(o['heat_supplied'] * 0.875).round, (o['heat_supplied'] * 1.125).round] },
    highlight_months: highlight_months,
    desired_temps: heat_loss['avg_temperatures'].map { |_o| room.desired_temperature.round },
    ambient_temps: heat_loss['ambient_temperatures'].map { |o| o['temperature'].round },
    ambient_temp_ranges: heat_loss['ambient_temperature_ranges'].map { |o| [o['range'][0].round, o['range'][1].round] },
    avg_temps: heat_loss['avg_temperatures'].map { |o| o['temperature'].round },
    avg_temp_ranges: heat_loss['avg_temperature_ranges'].map { |o| [o['range'][0].round, o['range'][1].round] }
  }
end

#report_hlc_room_error_js(objects = [@room]) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/heatloss_calculations_helper.rb', line 3

def report_hlc_room_error_js(objects=[@room])
  errors = []
  if flash[:error].present?
    errors << flash[:error]
    flash[:error] = nil
  end
  objects.select{|record| record.errors.any? }.each do |record|
    errors += record.errors.full_messages
    record.errors.clear
  end
  report_message_js errors.compact.uniq
end

#room_heat_loss_details_headerObject

BEGIN ROOM GENERAL



28
29
30
31
# File 'app/helpers/heatloss_calculations_helper.rb', line 28

def room_heat_loss_details_header
  done = @room.installation_postal_code.present? and @room.area > 0.0
  "#{check_mark_hlc(done)} <span class='step-number'>Step 1:</span> Room/Area".html_safe
end


43
44
45
# File 'app/helpers/heatloss_calculations_helper.rb', line 43

def under_floor_heat_loss_edit_link
  link_to edit_icon_hlc( under_floor_heat_loss_present? ), under_floor_heat_loss_details_my_room_path(@room), data: { turbo: true, turbo_stream: true }, class: "btn btn-my-account-card transparent border-0 p-0 block-ui-on-click"
end

#under_floor_heat_loss_headerObject



39
40
41
# File 'app/helpers/heatloss_calculations_helper.rb', line 39

def under_floor_heat_loss_header
  "#{check_mark_hlc( under_floor_heat_loss_present? )} <span class='step-number'>Step 2:</span> Under Floor".html_safe
end

#under_floor_heat_loss_present?Boolean

BEGIN UNDERFLOOR

Returns:

  • (Boolean)


35
36
37
# File 'app/helpers/heatloss_calculations_helper.rb', line 35

def under_floor_heat_loss_present?
  @room.under_floor.present? and !@room.under_floor.new_record?
end