lib/to_openstudio/schedule/fixed_interval.rb in honeybee-openstudio-2.34.8 vs lib/to_openstudio/schedule/fixed_interval.rb in honeybee-openstudio-2.34.9

- old
+ new

@@ -83,21 +83,72 @@ return @hash[:placeholder_value] end defaults[:placeholder_value][:default] end + def full_annual_values(openstudio_model) + # get start and end date times + yd = openstudio_model.getYearDescription + date_time = OpenStudio::DateTime.new(yd.makeDate(1, 1), OpenStudio::Time.new(0,0,0)) + start_date_time = OpenStudio::DateTime.new(yd.makeDate(start_month, start_day), OpenStudio::Time.new(0,0,0)) + end_date_time = OpenStudio::DateTime.new(yd.makeDate(12, 31), OpenStudio::Time.new(1,0,0)) + + # get timestep + interval_length = 60 / timestep + dt = OpenStudio::Time.new(0, 0, interval_length, 0) + + # get values and date times + values = @hash[:values] + num_values = values.size + i_values = 0 + padded_values = [] + date_times = [] + pv = placeholder_value + + while date_time < end_date_time + date = date_time.date + time = date_time.time + date_times << "#{date.dayOfMonth} #{date.monthOfYear.valueName} #{time.hours.to_s.rjust(2,'0')}:#{time.minutes.to_s.rjust(2,'0')}" + + if date_time < start_date_time + padded_values << pv + elsif i_values < num_values + padded_values << values[i_values] + i_values += 1 + else + padded_values << pv + end + + date_time += dt + end + + # if there are still more values to add, this indicates a reversed period + if i_values + 1 < num_values + overwrite_index = 0 + while i_values != num_values + padded_values[overwrite_index] = values[i_values] + i_values += 1 + overwrite_index += 1 + end + end + + return padded_values, date_times + end + def to_schedule_fixed_interval(openstudio_model) # create the new schedule os_fi_schedule = OpenStudio::Model::ScheduleFixedInterval.new(openstudio_model) os_fi_schedule.setName(@hash[:identifier]) unless @hash[:display_name].nil? os_fi_schedule.setDisplayName(@hash[:display_name]) end - # assign start date - os_fi_schedule.setStartMonth(start_month) - os_fi_schedule.setStartDay(start_day) + # assign start date and the out of range value + os_fi_schedule.setStartMonth(1) + os_fi_schedule.setStartDay(1) + os_fi_schedule.setOutOfRangeValue(placeholder_value) + # assign the interpolate value os_fi_schedule.setInterpolatetoTimestep(interpolate) # assign the schedule type limit if @hash[:schedule_type_limit] @@ -113,56 +164,25 @@ os_fi_schedule.setIntervalLength(interval_length) openstudio_interval_length = OpenStudio::Time.new(0, 0, interval_length) # assign the values as a timeseries year_description = openstudio_model.getYearDescription - start_date = year_description.makeDate(start_month, start_day) - timeseries = OpenStudio::TimeSeries.new(start_date, openstudio_interval_length, OpenStudio.createVector(@hash[:values]), '') + start_date = year_description.makeDate(1, 1) + all_values, date_times = full_annual_values(openstudio_model) + timeseries = OpenStudio::TimeSeries.new(start_date, openstudio_interval_length, OpenStudio.createVector(all_values), '') os_fi_schedule.setTimeSeries(timeseries) os_fi_schedule end def to_schedule_file(openstudio_model, schedule_csv_dir, include_datetimes, schedule_csvs) # in order to combine schedules in the same csv file they must have the same key schedule_key = "#{@hash[:identifier]}_#{start_month}_#{start_day}_#{timestep}" - # get start and end date times - yd = openstudio_model.getYearDescription - date_time = OpenStudio::DateTime.new(yd.makeDate(1, 1), OpenStudio::Time.new(0,0,0)) - start_date_time = OpenStudio::DateTime.new(yd.makeDate(start_month, start_day), OpenStudio::Time.new(0,0,0)) - end_date_time = OpenStudio::DateTime.new(yd.makeDate(12, 31), OpenStudio::Time.new(1,0,0)) - - # get timestep + # get the list of values for the whole year interval_length = 60 / timestep - dt = OpenStudio::Time.new(0, 0, interval_length, 0) - - # get values and date times - values = @hash[:values] - num_values = values.size - i_values = 0 - padded_values = [] - date_times = [] - pv = placeholder_value - - while date_time < end_date_time - date = date_time.date - time = date_time.time - date_times << "#{date.dayOfMonth} #{date.monthOfYear.valueName} #{time.hours.to_s.rjust(2,'0')}:#{time.minutes.to_s.rjust(2,'0')}" - - if date_time < start_date_time - padded_values << pv - elsif i_values < num_values - padded_values << values[i_values] - i_values += 1 - else - padded_values << pv - end - - date_time += dt - end - + padded_values, date_times = full_annual_values(openstudio_model) # find or create the schedule csv object which will hold the filename and columns filename = nil columns = nil os_external_file = nil