Skip to content

Commit

Permalink
No EV bug fix and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeee committed Nov 21, 2024
1 parent 2204599 commit 41ec1db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions BuildResidentialScheduleFile/resources/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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
Expand All @@ -952,7 +952,6 @@ def get_ev_occupant_number(all_simulated_values)
end
end


# TODO
#
# @param arr [TODO] TODO
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions HPXMLtoOpenStudio/resources/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41ec1db

Please sign in to comment.