Module: HeatlossCalculationsHelper

Defined in:
app/helpers/heatloss_calculations_helper.rb

Overview

View helper: heatloss calculations.

Instance Method Summary collapse

Instance Method Details



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

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

#ceiling_heat_loss_headerObject



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

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)


46
47
48
# File 'app/helpers/heatloss_calculations_helper.rb', line 46

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)



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

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



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

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



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

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


41
42
43
# File 'app/helpers/heatloss_calculations_helper.rb', line 41

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: { controller: 'ui-blocker', turbo: true, turbo_stream: true }, class: "btn btn-my-account-card transparent border-0 p-0"
end

#under_floor_heat_loss_headerObject



37
38
39
# File 'app/helpers/heatloss_calculations_helper.rb', line 37

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)


33
34
35
# File 'app/helpers/heatloss_calculations_helper.rb', line 33

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