diff --git a/BuildResidentialScheduleFile/resources/schedules.rb b/BuildResidentialScheduleFile/resources/schedules.rb index d105dde0b8..b49cec3fdd 100644 --- a/BuildResidentialScheduleFile/resources/schedules.rb +++ b/BuildResidentialScheduleFile/resources/schedules.rb @@ -923,15 +923,15 @@ def get_present_occupants(all_simulated_values, time_index) return sum end - # Define get_ev_occupant_number function # TODO # # @param all_simulated_values [TODO] TODO def get_ev_occupant_number(all_simulated_values) - if @hpxml_bldg.vehicles.nil? + if @hpxml_bldg.vehicles.to_a.empty? return 0 end + vehicle = @hpxml_bldg.vehicles[0] hours_per_year = (vehicle.hours_per_week / 7) * UnitConversions.convert(1, 'yr', 'day') @@ -940,10 +940,10 @@ def get_ev_occupant_number(all_simulated_values) occupant_away_hours_per_year[i] = all_simulated_values[i].column(5).sum() / 4 end # Only keep occupants whose 80% (the portion available for driving) away hours are sufficent to meet hours_per_year - elligible_occupant = occupant_away_hours_per_year.each_with_index.filter{|value, _| value * 0.8 > hours_per_year} + elligible_occupant = occupant_away_hours_per_year.each_with_index.filter { |value, _| value * 0.8 > hours_per_year } if elligible_occupant.empty? # if nobody has enough away hours, find the index of the occupant with the highest away hours - _, ev_occupant = occupant_away_hours_per_year.each_with_index.max_by{|value, _| value} + _, ev_occupant = occupant_away_hours_per_year.each_with_index.max_by { |value, _| value } return ev_occupant else # return the index of a random elligible occupant @@ -952,7 +952,6 @@ def get_ev_occupant_number(all_simulated_values) end end - # TODO # # @param arr [TODO] TODO @@ -1131,8 +1130,8 @@ def _get_ev_battery_schedule(away_schedule, hours_driven_per_year) discharging_schedule = [] driving_minutes_used = 0 chunk_counts = expanded_away_schedule.chunk(&:itself).map { |value, elements| [value, elements.size] } - total_away_minutes = chunk_counts.map {|value, size| value * size}.sum - extra_drive_minutes = 0 # accumulator for keeping track of extra driving minutes used due to ceil to upper integer + total_away_minutes = chunk_counts.map { |value, size| value * size }.sum + extra_drive_minutes = 0 # accumulator for keeping track of extra driving minutes used due to ceil to upper integer chunk_counts.each do |is_away, activity_minutes| if is_away == 1 current_chunk_proportion = (1.0 * activity_minutes) / total_away_minutes @@ -1169,12 +1168,13 @@ def _get_ev_battery_schedule(away_schedule, hours_driven_per_year) end def fill_ev_battery_schedule(markov_chain_simulation_result) - if @hpxml_bldg.vehicles.nil? + if @hpxml_bldg.vehicles.to_a.empty? return end + vehicle = @hpxml_bldg.vehicles[0] hours_per_year = (vehicle.hours_per_week / 7) * UnitConversions.convert(1, 'yr', 'day') - away_index = 5 # Index of away activity in the markov-chain simulator + away_index = 5 # Index of away activity in the markov-chain simulator away_schedule = markov_chain_simulation_result[@ev_occupant_number].column(away_index) charging_schedule, discharging_schedule = _get_ev_battery_schedule(away_schedule, hours_per_year) agg_charging_schedule = aggregate_array(charging_schedule, @minutes_per_step).map { |val| val.to_f / @minutes_per_step } diff --git a/BuildResidentialScheduleFile/tests/test_build_residential_schedule_file.rb b/BuildResidentialScheduleFile/tests/test_build_residential_schedule_file.rb index 90d9039ad4..20f8987d02 100644 --- a/BuildResidentialScheduleFile/tests/test_build_residential_schedule_file.rb +++ b/BuildResidentialScheduleFile/tests/test_build_residential_schedule_file.rb @@ -340,8 +340,8 @@ def test_ev_battery XMLHelper.write_file(hpxml.to_doc, @tmp_hpxml_path) @args_hash['output_csv_path'] = File.absolute_path(File.join(@tmp_output_path, 'occupancy-stochastic.csv')) - _hpxml, result = _test_measure() - sf = SchedulesFile.new(schedules_paths: _hpxml.buildings[0].header.schedules_filepaths, + hpxml, _result = _test_measure() + sf = SchedulesFile.new(schedules_paths: hpxml.buildings[0].header.schedules_filepaths, year: @year, output_path: @tmp_schedule_file_path) assert_in_epsilon(6201, sf.annual_equivalent_full_load_hrs(col_name: SchedulesFile::Columns[:EVBatteryCharging].name, schedules: sf.tmp_schedules), @tol) diff --git a/HPXMLtoOpenStudio/resources/schedules.rb b/HPXMLtoOpenStudio/resources/schedules.rb index 8e4d0e73e8..a39b20b201 100644 --- a/HPXMLtoOpenStudio/resources/schedules.rb +++ b/HPXMLtoOpenStudio/resources/schedules.rb @@ -1181,6 +1181,7 @@ def import(schedules_paths) unless valid_num_rows.include? values.length fail "Schedule has invalid number of rows (#{values.length}) for column '#{col_name}'. Must be one of: #{valid_num_rows.reverse.join(', ')}. [context: #{@schedules_path}]" end + @schedules[col_name] = values col2path[col_name] = schedules_path end