Class: RunPeriod
- Inherits:
-
OpenStudio::Ruleset::ModelUserScript
- Object
- OpenStudio::Ruleset::ModelUserScript
- RunPeriod
- Defined in:
- lib/measures/RunPeriod/measure.rb
Overview
start the measure
Instance Method Summary collapse
-
#arguments(model) ⇒ Object
define the arguments that the user will input.
-
#description ⇒ Object
human readable description.
-
#modeler_description ⇒ Object
human readable description of modeling approach.
-
#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.
- #year_month_day(str) ⇒ Object
Instance Method Details
#arguments(model) ⇒ Object
define the arguments that the user will input
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 |
# File 'lib/measures/RunPeriod/measure.rb', line 57 def arguments(model) args = OpenStudio::Ruleset::OSArgumentVector.new # RunPeriodName runPeriodName = OpenStudio::Ruleset::OSArgument.makeStringArgument('runPeriodName', false) runPeriodName.setDisplayName('Run Period Name') runPeriodName.setDefaultValue('July') args << runPeriodName # make a start date argument start_date = OpenStudio::Ruleset::OSArgument.makeStringArgument('start_date', true) start_date.setDisplayName('Start date (yyyy-mm-dd or mm-dd-yyyy)') start_date.setDescription('Start date (yyyy-mm-dd or mm-dd-yyyy)') start_date.setDefaultValue('2015-7-25') args << start_date # make an end date argument end_date = OpenStudio::Ruleset::OSArgument.makeStringArgument('end_date', true) end_date.setDisplayName('End date (yyyy-mm-dd or mm-dd-yyyy)') end_date.setDescription('End date (yyyy-mm-dd or mm-dd-yyyy)') end_date.setDefaultValue('2015-7-26') args << end_date # daylightsavings daylightsavings = OpenStudio::Ruleset::OSArgument.makeBoolArgument('daylightsavings', false) daylightsavings.setDisplayName('Use Daylightsavings') daylightsavings.setDefaultValue(false) args << daylightsavings # holiday holiday = OpenStudio::Ruleset::OSArgument.makeBoolArgument('holiday', false) holiday.setDisplayName('Use Holiday and Special Days') holiday.setDefaultValue(false) args << holiday return args end |
#description ⇒ Object
human readable description
27 28 29 |
# File 'lib/measures/RunPeriod/measure.rb', line 27 def description return 'Set Run Period Object' end |
#modeler_description ⇒ Object
human readable description of modeling approach
32 33 34 |
# File 'lib/measures/RunPeriod/measure.rb', line 32 def modeler_description return 'Set Run Period Object' 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
22 23 24 |
# File 'lib/measures/RunPeriod/measure.rb', line 22 def name return 'Set Run Period Object' end |
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/measures/RunPeriod/measure.rb', line 96 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 # assign the user inputs to variables runPeriodName = runner.getStringArgumentValue('runPeriodName', user_arguments) start_date = runner.getStringArgumentValue('start_date', user_arguments) end_date = runner.getStringArgumentValue('end_date', user_arguments) daylightsavings = runner.getBoolArgumentValue('daylightsavings', user_arguments) holiday = runner.getBoolArgumentValue('holiday', user_arguments) runPeriod = model.getRunPeriod runPeriod.setName(runPeriodName) runPeriod.setUseWeatherFileDaylightSavings(daylightsavings) runPeriod.setUseWeatherFileHolidays(holiday) # set start date if date = year_month_day(start_date) start_date = OpenStudio::Date.new(OpenStudio::MonthOfYear.new(date[1]), date[2], date[0]) # actual year of start date yearDescription = model.getYearDescription yearDescription.setCalendarYear(date[0]) runPeriod.setBeginMonth(date[1]) runPeriod.setBeginDayOfMonth(date[2]) else runner.registerError("Unknown start date '#{start_date}'") raise "Unknown start date '#{start_date}'" return false end # set end date if date = year_month_day(end_date) end_date = OpenStudio::Date.new(OpenStudio::MonthOfYear.new(date[1]), date[2], date[0]) runPeriod.setEndMonth(date[1]) runPeriod.setEndDayOfMonth(date[2]) else runner.registerError("Unknown end date '#{end_date}'") raise "Unknown end date '#{end_date}'" return false end runner.registerInfo("runperiod: #{runPeriod}") # reporting final condition of model runner.registerFinalCondition('Changed run period.') # set minimum warmup days # model.getSimulationControl.setMinimumNumberofWarmupDays(20) return true end |
#year_month_day(str) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/measures/RunPeriod/measure.rb', line 36 def year_month_day(str) result = nil if match_data = /(\d+)(\D)(\d+)(\D)(\d+)/.match(str) if match_data[1].size == 4 # yyyy-mm-dd year = match_data[1].to_i month = match_data[3].to_i day = match_data[5].to_i result = [year, month, day] elsif match_data[5].size == 4 # mm-dd-yyyy year = match_data[5].to_i month = match_data[1].to_i day = match_data[3].to_i result = [year, month, day] end else puts "no match for '#{str}'" end return result end |