Class: RoomConfiguration::OperatingCostsCalculator
- Inherits:
-
Object
- Object
- RoomConfiguration::OperatingCostsCalculator
- Defined in:
- app/services/room_configuration/operating_costs_calculator.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#room_configuration ⇒ Object
readonly
Returns the value of attribute room_configuration.
Class Method Summary collapse
-
.get_monthly_operation_kwh(hl_avg_comfort, hl_avg_economy) ⇒ Object
res[:avg_num_hrs_per_month] = (RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_day] + RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_end_day]).to_f*24.0 res[:avg_num_comfort_hrs_per_month] = RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_day]*RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[:comfort][:week_day] + RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_end_day]*RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[:comfort][:week_end_day] res[:avg_num_economy_hrs_per_month] = RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_days]*RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[:economy][:week_day] + RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_end_day]*RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[:economy][:week_end_day].
Instance Method Summary collapse
- #calculate_operating_costs_without_hlc ⇒ Object
- #get_operating_costs ⇒ Object
-
#initialize(room_configuration, options = {}) ⇒ OperatingCostsCalculator
constructor
A new instance of OperatingCostsCalculator.
Constructor Details
#initialize(room_configuration, options = {}) ⇒ OperatingCostsCalculator
Returns a new instance of OperatingCostsCalculator.
24 25 26 27 28 |
# File 'app/services/room_configuration/operating_costs_calculator.rb', line 24 def initialize(room_configuration, = {}) @options = @room_configuration = room_configuration @logger = [:logger] || Rails.logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'app/services/room_configuration/operating_costs_calculator.rb', line 3 def logger @logger end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
3 4 5 |
# File 'app/services/room_configuration/operating_costs_calculator.rb', line 3 def results @results end |
#room_configuration ⇒ Object (readonly)
Returns the value of attribute room_configuration.
3 4 5 |
# File 'app/services/room_configuration/operating_costs_calculator.rb', line 3 def room_configuration @room_configuration end |
Class Method Details
.get_monthly_operation_kwh(hl_avg_comfort, hl_avg_economy) ⇒ Object
res[:avg_num_hrs_per_month] = (RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_day] + RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_end_day]).to_f*24.0
res[:avg_num_comfort_hrs_per_month] = RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_day]*RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[:comfort][:week_day] + RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_end_day]*RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[:comfort][:week_end_day]
res[:avg_num_economy_hrs_per_month] = RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_days]*RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[:economy][:week_day] + RoomConfigurationConstants::AVG_DAYS_PER_MONTH[:week_end_day]*RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[:economy][:week_end_day]
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/services/room_configuration/operating_costs_calculator.rb', line 8 def self.get_monthly_operation_kwh(hl_avg_comfort, hl_avg_economy) # assumptions: # use average number of weekdays vs weekends per month, derived from averaging actual number in 4 year cycle monthly_kwh = 0.0 %i[week_day week_end_day].each do |days_type| { comfort: hl_avg_comfort, economy: hl_avg_economy }.each do |k, hl| monthly_kwh += RoomConfigurationConstants::AVG_DAYS_PER_MONTH[days_type] * RoomConfigurationConstants::HOURS_OF_OPERATION_PER_DAY[k][days_type] * (hl / RoomConfiguration::BTU_PER_HOUR_PER_WATT) / 1000.0 end end monthly_kwh end |
Instance Method Details
#calculate_operating_costs_without_hlc ⇒ Object
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 |
# File 'app/services/room_configuration/operating_costs_calculator.rb', line 45 def if @room_configuration.heating_elements.to_a.any? && @room_configuration.installation_postal_code.present? temp_data = AverageMonthlyTemperature.get_from_postal_code(@room_configuration.installation_postal_code) return { status: 'error', message: "can't calculate operating costs, temperatures error: #{temp_data[:message]}" } if temp_data[:status] != :ok # get utility rate $ cost per kwH using room's location rate_data = ElectricityRate.get_from_postal_code(@room_configuration.installation_postal_code) return { status: 'error', message: "can't calculate operating costs, electricity rate error: #{rate_data[:message]}" } if rate_data[:status] != :ok avg_cost_per_kwh = rate_data[:average_rate] kw = @room_configuration.calculate_total_kilowatts = [] = [] # here we assume a linear relationship temp diff of outside to desired ambient divided by desired ambient where desired comfort and economy is from the average and low in TEMPERATURE_OPTIONS avg_comfort_temp = RoomConfiguration::TEMPERATURE_OPTIONS.find { |to| to.first == 'Average' }.last avg_economy_temp = RoomConfiguration::TEMPERATURE_OPTIONS.find { |to| to.first == 'Low' }.last 12.times do |month| tdiffcom = avg_comfort_temp - temp_data[:average_temperatures][month] tdiffcom = 0.0 if tdiffcom < 0.0 tdiffcom = avg_comfort_temp if tdiffcom > avg_comfort_temp factorcom = tdiffcom / avg_comfort_temp tdiffeco = avg_economy_temp - temp_data[:average_temperatures][month] tdiffeco = 0.0 if tdiffeco < 0.0 tdiffeco = avg_economy_temp if tdiffeco > avg_economy_temp factoreco = tdiffeco / avg_economy_temp hrs = (RoomConfigurationConstants::AVERAGE_HOURS[:avg_num_comfort_hrs_per_month] * factorcom) + (RoomConfigurationConstants::AVERAGE_HOURS[:avg_num_economy_hrs_per_month] * factoreco) << hrs << (hrs * kw * avg_cost_per_kwh) end { status: 'ok', operating_cost_by_month: , operating_cost_annual: .sum.round(2), operating_cost_by_month_average: (.sum / 12.0).round(2), operating_cost_by_coldest_month: .max.round(2), message: "assuming default SmartStat settings, yielding average operation of #{(.sum / 365.0).round(1)} hours per day annually, and coldest month operation of #{(.max / 30.4).round(1)} hours per day, based on average monthly temperatures and electricity rates in your area." } else { status: 'error', message: 'can\'t calculate operating costs' } end end |
#get_operating_costs ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/room_configuration/operating_costs_calculator.rb', line 30 def = false = true if @room_configuration.last_heat_loss && @room_configuration.last_heat_loss['operating_cost'] if @room_configuration.allow_heat_loss_calculation? && @room_configuration.can_calculate_heat_loss? && @room_configuration.floor_type&.is_indoors? @room_configuration.calculate_heat_loss = true if @room_configuration.last_heat_loss && @room_configuration.last_heat_loss['operating_cost'] end if { status: 'ok', operating_cost_by_month: @room_configuration.last_heat_loss['operating_cost'], operating_cost_annual: @room_configuration.last_heat_loss['operating_cost'].sum.round(2), operating_cost_by_month_average: (@room_configuration.last_heat_loss['operating_cost'].sum / 12.0).round(2), operating_cost_by_coldest_month: @room_configuration.last_heat_loss['operating_cost'].max.round(2), message: "assuming default thermostat settings, and taking account the details entered for this room for insulation and openings, yielding average operation of #{(@room_configuration.last_heat_loss['operating_hrs'].sum / 365.0).round(1)} hours per day annually, and coldest month operation of #{(@room_configuration.last_heat_loss['operating_hrs'].max / 30.4).round(1)} hours per day, based on average monthly temperatures and electricity rates in your area." } else end end |