The OsLib_Schedules.rb
file in several of the BCL HVAC measures has some code to make a schedule from a set of values.
You can use this to translate a compact schedule to a ruleset schedule.
Example code:
require 'openstudio'
#this is just for testing
model = OpenStudio::Model::Model.new()
new_schedule = OpenStudio::Model::ScheduleCompact.new(model,0.5)
new_schedule.setName("Example Compact Schedule")
#createSimpleSchedule code from the OsLib_Schedules library
def createSimpleSchedule(model, options = {})
defaults = {
"name" => nil,
"winterTimeValuePairs" => {24.0 => 0.0},
"summerTimeValuePairs" => {24.0 => 1.0},
"defaultTimeValuePairs" => {24.0 => 1.0},
}
# merge user inputs with defaults
options = defaults.merge(options)
#ScheduleRuleset
sch_ruleset = OpenStudio::Model::ScheduleRuleset.new(model)
if options["name"]
sch_ruleset.setName(options["name"])
end
#Winter Design Day
winter_dsn_day = OpenStudio::Model::ScheduleDay.new(model)
sch_ruleset.setWinterDesignDaySchedule(winter_dsn_day)
winter_dsn_day = sch_ruleset.winterDesignDaySchedule
winter_dsn_day.setName("#{sch_ruleset.name} Winter Design Day")
options["winterTimeValuePairs"].each do |k,v|
hour = k.truncate
min = ((k - hour)*60).to_i
winter_dsn_day.addValue(OpenStudio::Time.new(0, hour, min, 0),v)
end
#Summer Design Day
summer_dsn_day = OpenStudio::Model::ScheduleDay.new(model)
sch_ruleset.setSummerDesignDaySchedule(summer_dsn_day)
summer_dsn_day = sch_ruleset.summerDesignDaySchedule
summer_dsn_day.setName("#{sch_ruleset.name} Summer Design Day")
options["summerTimeValuePairs"].each do |k,v|
hour = k.truncate
min = ((k - hour)*60).to_i
summer_dsn_day.addValue(OpenStudio::Time.new(0, hour, min, 0),v)
end
#All Days
week_day = sch_ruleset.defaultDaySchedule
week_day.setName("#{sch_ruleset.name} Schedule Week Day")
options["defaultTimeValuePairs"].each do |k,v|
hour = k.truncate
min = ((k - hour)*60).to_i
week_day.addValue(OpenStudio::Time.new(0, hour, min, 0),v)
end
result = sch_ruleset
return result
end #end of createSimpleSchedule
#get the value from the compact schedule
compact_sch = model.getScheduleCompactByName("Example Compact Schedule").get
compact_sch_val = compact_sch.constantValue.get
#create options and call createSimpleSchedule
options_generic_schedule = {"name" => "My Generic Ruleset Schedule",
"winterTimeValuePairs" => {24.0 => compact_sch_val},
"summerTimeValuePairs" => {24.0 => compact_sch_val},
"defaultTimeValuePairs" => {24.0 => compact_sch_val}}
generic_ruleset_schedule = createSimpleSchedule(model, options_generic_schedule)