Class: Honeybee::ScheduleFixedIntervalAbridged
- Inherits:
-
ModelObject
- Object
- ModelObject
- Honeybee::ScheduleFixedIntervalAbridged
show all
- Defined in:
- lib/honeybee/schedule/fixed_interval.rb,
lib/to_openstudio/schedule/fixed_interval.rb,
lib/from_openstudio/schedule/fixed_interval.rb
Instance Attribute Summary
Attributes inherited from ModelObject
#errors, #openstudio_object, #warnings
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ModelObject
#allowable_types, clean_identifier, clean_name, #initialize, #method_missing, read_from_disk, truncate
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Honeybee::ModelObject
Class Method Details
.from_schedule_fixedinterval(schedule_fixedinterval, is_leap_year) ⇒ Object
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
|
# File 'lib/from_openstudio/schedule/fixed_interval.rb', line 38
def self.from_schedule_fixedinterval(schedule_fixedinterval, is_leap_year)
hash = {}
hash[:type] = 'ScheduleFixedIntervalAbridged'
hash[:identifier] = clean_name(schedule_fixedinterval.nameString)
unless schedule_fixedinterval.displayName.empty?
hash[:display_name] = (schedule_fixedinterval.displayName.get).force_encoding("UTF-8")
end
start_month = schedule_fixedinterval.startMonth
start_day = schedule_fixedinterval.startDay
if is_leap_year
hash[:start_date] = [start_month, start_day, 1]
else
hash[:start_date] = [start_month, start_day]
end
hash[:interpolate] = schedule_fixedinterval.interpolatetoTimestep
unless schedule_fixedinterval.scheduleTypeLimits.empty?
typ_lim = schedule_fixedinterval.scheduleTypeLimits.get
hash[:schedule_type_limit] = clean_name(typ_lim.nameString)
end
interval_length = schedule_fixedinterval.intervalLength
hash[:timestep] = 60 / interval_length.to_i
values = schedule_fixedinterval.timeSeries.values
value_array = []
for i in 0..(values.size - 1)
value_array << values[i]
end
hash[:values] = value_array
hash
end
|
Instance Method Details
#defaults ⇒ Object
37
38
39
|
# File 'lib/honeybee/schedule/fixed_interval.rb', line 37
def defaults
@@schema[:components][:schemas][:ScheduleFixedIntervalAbridged][:properties]
end
|
#find_existing_openstudio_object(openstudio_model) ⇒ Object
39
40
41
42
43
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 39
def find_existing_openstudio_object(openstudio_model)
model_schedule = openstudio_model.getScheduleFixedIntervalByName(@hash[:identifier])
return model_schedule.get unless model_schedule.empty?
nil
end
|
#full_annual_values(openstudio_model) ⇒ Object
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
128
129
130
131
132
133
134
135
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 88
def full_annual_values(openstudio_model)
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))
interval_length = 60 / timestep
dt = OpenStudio::Time.new(0, 0, interval_length, 0)
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 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
|
#interpolate ⇒ Object
67
68
69
70
71
72
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 67
def interpolate
if @hash[:interpolate]
return @hash[:interpolate]
end
defaults[:interpolate][:default]
end
|
#placeholder_value ⇒ Object
81
82
83
84
85
86
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 81
def placeholder_value
if @hash[:placeholder_value]
return @hash[:placeholder_value]
end
defaults[:placeholder_value][:default]
end
|
#start_day ⇒ Object
60
61
62
63
64
65
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 60
def start_day
if @hash[:start_date]
return @hash[:start_date][1]
end
defaults[:start_date][:default][1]
end
|
#start_month ⇒ Object
53
54
55
56
57
58
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 53
def start_month
if @hash[:start_date]
return @hash[:start_date][0]
end
defaults[:start_date][:default][0]
end
|
#timestep ⇒ Object
74
75
76
77
78
79
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 74
def timestep
if @hash[:timestep]
return @hash[:timestep]
end
defaults[:timestep][:default]
end
|
#to_openstudio(openstudio_model, schedule_csv_dir = nil, include_datetimes = nil, schedule_csvs = nil) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 45
def to_openstudio(openstudio_model, schedule_csv_dir = nil, include_datetimes = nil, schedule_csvs = nil)
if schedule_csv_dir
to_schedule_file(openstudio_model, schedule_csv_dir, include_datetimes, schedule_csvs)
else
to_schedule_fixed_interval(openstudio_model)
end
end
|
#to_schedule_file(openstudio_model, schedule_csv_dir, include_datetimes, schedule_csvs) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 177
def to_schedule_file(openstudio_model, schedule_csv_dir, include_datetimes, schedule_csvs)
schedule_key = "#{@hash[:identifier]}_#{start_month}_#{start_day}_#{timestep}"
interval_length = 60 / timestep
padded_values, date_times = full_annual_values(openstudio_model)
filename = nil
columns = nil
os_external_file = nil
schedule_csv = schedule_csvs[schedule_key]
if schedule_csv.nil?
filename = "#{@hash[:identifier]}.csv".gsub(' ', '_')
columns = []
if include_datetimes
columns << ['Date Times'].concat(date_times)
end
path = File.join(schedule_csv_dir, filename)
if !File.exist?(path)
File.open(path, 'w') {|f| f.puts ''}
end
os_external_file = OpenStudio::Model::ExternalFile.getExternalFile(openstudio_model, filename)
os_external_file = os_external_file.get
schedule_csv = {filename: filename, columns: columns, os_external_file: os_external_file}
schedule_csvs[schedule_key] = schedule_csv
else
filename = schedule_csv[:filename]
columns = schedule_csv[:columns]
os_external_file = schedule_csv[:os_external_file]
end
columns << [@hash[:identifier]].concat(padded_values)
column = columns.size rowsToSkip = 1
os_schedule_file = OpenStudio::Model::ScheduleFile.new(os_external_file, column, rowsToSkip)
os_schedule_file.setName(@hash[:identifier])
unless @hash[:display_name].nil?
os_schedule_file.setDisplayName(@hash[:display_name])
end
os_schedule_file.setInterpolatetoTimestep(interpolate)
os_schedule_file.setMinutesperItem(interval_length)
if @hash[:schedule_type_limit]
schedule_type_limit = openstudio_model.getScheduleTypeLimitsByName(@hash[:schedule_type_limit])
unless schedule_type_limit.empty?
schedule_type_limit_object = schedule_type_limit.get
os_schedule_file.setScheduleTypeLimits(schedule_type_limit_object)
end
end
os_schedule_file
end
|
#to_schedule_fixed_interval(openstudio_model) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/to_openstudio/schedule/fixed_interval.rb', line 137
def to_schedule_fixed_interval(openstudio_model)
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
os_fi_schedule.setStartMonth(1)
os_fi_schedule.setStartDay(1)
os_fi_schedule.setOutOfRangeValue(placeholder_value)
os_fi_schedule.setInterpolatetoTimestep(interpolate)
if @hash[:schedule_type_limit]
schedule_type_limit = openstudio_model.getScheduleTypeLimitsByName(@hash[:schedule_type_limit])
unless schedule_type_limit.empty?
schedule_type_limit_object = schedule_type_limit.get
os_fi_schedule.setScheduleTypeLimits(schedule_type_limit_object)
end
end
interval_length = 60 / timestep
os_fi_schedule.setIntervalLength(interval_length)
openstudio_interval_length = OpenStudio::Time.new(0, 0, interval_length)
year_description = openstudio_model.getYearDescription
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
|