Class: RemoveUnusedDefaultProfiles
- Inherits:
-
OpenStudio::Measure::ModelMeasure
- Object
- OpenStudio::Measure::ModelMeasure
- RemoveUnusedDefaultProfiles
- Defined in:
- lib/measures/RemoveUnusedDefaultProfiles/measure.rb
Overview
start the measure
Instance Method Summary collapse
-
#arguments(model) ⇒ Object
define the arguments that the user will input.
-
#name ⇒ Object
define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml.
-
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run.
Instance Method Details
#arguments(model) ⇒ Object
define the arguments that the user will input
21 22 23 24 25 26 27 |
# File 'lib/measures/RemoveUnusedDefaultProfiles/measure.rb', line 21 def arguments(model) args = OpenStudio::Measure::OSArgumentVector.new # measure does not have any arguments return args end |
#name ⇒ Object
define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml
16 17 18 |
# File 'lib/measures/RemoveUnusedDefaultProfiles/measure.rb', line 16 def name return 'RemoveUnusedDefaultProfiles' end |
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/measures/RemoveUnusedDefaultProfiles/measure.rb', line 30 def run(model, runner, user_arguments) super(model, runner, user_arguments) # use the built-in error checking if !runner.validateUserArguments(arguments(model), user_arguments) return false end # no user inputs assign to variables # reporting initial condition of model schedule_rulesets = model.getScheduleRulesets runner.registerInitialCondition("The model has #{schedule_rulesets.size} ScheduleRulesets.") # set start and end dates start_date = OpenStudio::Date.new(OpenStudio::MonthOfYear.new('January'), 1) end_date = OpenStudio::Date.new(OpenStudio::MonthOfYear.new('December'), 31) # year does matter, but I'm not setting it here # counter for removed default profiles default_profiles_removed = 0 # loop through all ScheduleRuleset objects schedule_rulesets.each do |schedule_ruleset| indices_vector = schedule_ruleset.getActiveRuleIndices(start_date, end_date) # line below lets you see the indices if for diagnostic purposes # runner.registerInfo("#{schedule_ruleset.name}: #{indices_vector}") if !indices_vector.include? -1 runner.registerInfo("#{schedule_ruleset.name} does not used the default profile, it will be replaced.") # reset values in default ScheduleDay old_default_schedule_day = schedule_ruleset.defaultDaySchedule old_default_schedule_day.clearValues # get values for new default profile rule_vector = schedule_ruleset.scheduleRules new_default_daySchedule = rule_vector.reverse[0].daySchedule new_default_daySchedule_values = new_default_daySchedule.values new_default_daySchedule_times = new_default_daySchedule.times # update values and times for default profile for i in 0..(new_default_daySchedule_values.size - 1) old_default_schedule_day.addValue(new_default_daySchedule_times[i], new_default_daySchedule_values[i]) end # note - I'm not looking at interpolatetoTimestep field. # confirm that changes were made # runner.registerInfo("Default values for #{schedule_ruleset.name}: #{old_default_schedule_day.values}") # remove rule object that has become the default. Also try to remove the ScheduleDay rule_vector.reverse[0].remove # this seems to also remove the ScheduleDay associated with the rule # new_default_daySchedule.remove default_profiles_removed += 1 end # report warning if schedule is missing type limits if schedule_ruleset.scheduleTypeLimits.empty? runner.registerWarning("#{schedule_ruleset.name} does not have a type limits assigned.") else # store schedule type limits object desired_type_limit = schedule_ruleset.scheduleTypeLimits.get # set type limit for summer and winter design day objects default_day = schedule_ruleset.defaultDaySchedule summer_design_day = schedule_ruleset.summerDesignDaySchedule winter_design_day = schedule_ruleset.winterDesignDaySchedule default_day_type_limit = default_day.setScheduleTypeLimits(desired_type_limit) summer_design_day_type_limit = summer_design_day.setScheduleTypeLimits(desired_type_limit) winter_design_type_limit = winter_design_day.setScheduleTypeLimits(desired_type_limit) if !default_day_type_limit || !summer_design_day_type_limit || !winter_design_type_limit runner.registerWarning("Failed to set type limit for default or design day for #{schedule_ruleset.name}") else puts 'did something' end # get day schedules for schedule_ruleset schedule_rules = schedule_ruleset.scheduleRules schedule_rules.each do |schedule_rule| day_schedule = schedule_rule.daySchedule day_type_limit = day_schedule.setScheduleTypeLimits(desired_type_limit) if !day_type_limit runner.registerWarning("Failed to set type limit for #{day_schedule.name}, child of #{schedule_ruleset.name}.") end end end end # reporting final condition of model runner.registerFinalCondition("#{default_profiles_removed} RuleSetSchedules had unused default profiles.") return true end |