urbanopt-scenario 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rdoc_options +36 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +42 -0
- data/Jenkinsfile +10 -0
- data/LICENSE.md +27 -0
- data/RDOC_MAIN.md +39 -0
- data/README.md +39 -0
- data/Rakefile +51 -0
- data/deploy_docs.sh +5 -0
- data/doc_templates/LICENSE.md +27 -0
- data/doc_templates/README.md.erb +42 -0
- data/doc_templates/copyright_erb.txt +31 -0
- data/doc_templates/copyright_js.txt +4 -0
- data/doc_templates/copyright_ruby.txt +29 -0
- data/docs/.gitignore +3 -0
- data/docs/.vuepress/components/InnerJsonSchema.vue +84 -0
- data/docs/.vuepress/components/JsonSchema.vue +12 -0
- data/docs/.vuepress/components/ScenarioSchema.vue +12 -0
- data/docs/.vuepress/components/StaticLink.vue +8 -0
- data/docs/.vuepress/config.js +15 -0
- data/docs/.vuepress/highlight.js +8 -0
- data/docs/.vuepress/public/custom_rdoc_styles.css +74 -0
- data/docs/.vuepress/utils.js +17 -0
- data/docs/README.md +39 -0
- data/docs/package-lock.json +11791 -0
- data/docs/package.json +22 -0
- data/docs/schemas/scenario-schema.md +3 -0
- data/lib/measures/.rubocop.yml +5 -0
- data/lib/measures/default_feature_reports/LICENSE.md +27 -0
- data/lib/measures/default_feature_reports/README.md +56 -0
- data/lib/measures/default_feature_reports/README.md.erb +42 -0
- data/lib/measures/default_feature_reports/measure.rb +731 -0
- data/lib/measures/default_feature_reports/measure.xml +139 -0
- data/lib/measures/default_feature_reports/tests/USA_CO_Golden-NREL.724666_TMY3.epw +8768 -0
- data/lib/measures/default_feature_reports/tests/default_feature_reports_test.rb +238 -0
- data/lib/measures/default_feature_reports/tests/example_model.osm +4378 -0
- data/lib/urbanopt-scenario.rb +31 -0
- data/lib/urbanopt/scenario.rb +45 -0
- data/lib/urbanopt/scenario/default_reports.rb +40 -0
- data/lib/urbanopt/scenario/default_reports/construction_cost.rb +169 -0
- data/lib/urbanopt/scenario/default_reports/date.rb +97 -0
- data/lib/urbanopt/scenario/default_reports/end_use.rb +159 -0
- data/lib/urbanopt/scenario/default_reports/end_uses.rb +140 -0
- data/lib/urbanopt/scenario/default_reports/feature_report.rb +207 -0
- data/lib/urbanopt/scenario/default_reports/location.rb +99 -0
- data/lib/urbanopt/scenario/default_reports/logger.rb +44 -0
- data/lib/urbanopt/scenario/default_reports/program.rb +261 -0
- data/lib/urbanopt/scenario/default_reports/reporting_period.rb +298 -0
- data/lib/urbanopt/scenario/default_reports/scenario_report.rb +276 -0
- data/lib/urbanopt/scenario/default_reports/schema/README.md +33 -0
- data/lib/urbanopt/scenario/default_reports/schema/scenario_csv_columns.txt +13 -0
- data/lib/urbanopt/scenario/default_reports/schema/scenario_schema.json +742 -0
- data/lib/urbanopt/scenario/default_reports/timeseries_csv.rb +231 -0
- data/lib/urbanopt/scenario/default_reports/validator.rb +97 -0
- data/lib/urbanopt/scenario/extension.rb +63 -0
- data/lib/urbanopt/scenario/logger.rb +42 -0
- data/lib/urbanopt/scenario/scenario_base.rb +79 -0
- data/lib/urbanopt/scenario/scenario_csv.rb +122 -0
- data/lib/urbanopt/scenario/scenario_datapoint_base.rb +162 -0
- data/lib/urbanopt/scenario/scenario_post_processor_base.rb +69 -0
- data/lib/urbanopt/scenario/scenario_post_processor_default.rb +97 -0
- data/lib/urbanopt/scenario/scenario_runner_base.rb +63 -0
- data/lib/urbanopt/scenario/scenario_runner_osw.rb +158 -0
- data/lib/urbanopt/scenario/simulation_dir_base.rb +90 -0
- data/lib/urbanopt/scenario/simulation_dir_osw.rb +261 -0
- data/lib/urbanopt/scenario/simulation_mapper_base.rb +47 -0
- data/lib/urbanopt/scenario/version.rb +35 -0
- data/urbanopt-scenario-gem.gemspec +36 -0
- metadata +227 -0
@@ -0,0 +1,231 @@
|
|
1
|
+
# *********************************************************************************
|
2
|
+
# URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
|
3
|
+
# contributors. All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
# are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice, this list
|
9
|
+
# of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer in the documentation and/or other
|
13
|
+
# materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of the copyright holder nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without specific
|
17
|
+
# prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
22
|
+
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
24
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
27
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
28
|
+
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
# *********************************************************************************
|
30
|
+
|
31
|
+
require 'csv'
|
32
|
+
require 'pathname'
|
33
|
+
require 'json-schema'
|
34
|
+
require 'urbanopt/scenario/default_reports/validator'
|
35
|
+
require 'urbanopt/scenario/default_reports/logger'
|
36
|
+
|
37
|
+
module URBANopt
|
38
|
+
module Scenario
|
39
|
+
module DefaultReports
|
40
|
+
##
|
41
|
+
# TimeseriesCSV include timesries reults reported in a CSV file.
|
42
|
+
##
|
43
|
+
class TimeseriesCSV
|
44
|
+
attr_accessor :path, :first_report_datetime, :column_names #:nodoc:
|
45
|
+
|
46
|
+
##
|
47
|
+
# TimeseriesCSV class initializes timeseries csv attributes: +:path+ , +:first_report_datetime+ , +:column_names+
|
48
|
+
##
|
49
|
+
# +hash+ - _Hash_ - A hash which may contain a deserialized timeseries_csv.
|
50
|
+
##
|
51
|
+
def initialize(hash = {})
|
52
|
+
hash.delete_if { |k, v| v.nil? }
|
53
|
+
hash = defaults.merge(hash)
|
54
|
+
|
55
|
+
@run_dir = ''
|
56
|
+
|
57
|
+
@path = hash[:path]
|
58
|
+
@first_report_datetime = hash[:first_report_datetime]
|
59
|
+
@column_names = hash[:column_names]
|
60
|
+
|
61
|
+
# hash of column_name to array of values, does not get serialized to hash
|
62
|
+
@mutex = Mutex.new
|
63
|
+
@data = nil
|
64
|
+
|
65
|
+
# initialize class variables @@validator and @@schema
|
66
|
+
@@validator ||= Validator.new
|
67
|
+
@@schema ||= @@validator.schema
|
68
|
+
|
69
|
+
# initialize @@logger
|
70
|
+
@@logger ||= URBANopt::Scenario::DefaultReports.logger
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Assigns default values if values does not exist.
|
75
|
+
##
|
76
|
+
def defaults
|
77
|
+
hash = {}
|
78
|
+
hash[:path] = nil
|
79
|
+
hash[:column_names] = []
|
80
|
+
return hash
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Gets run directory.
|
85
|
+
##
|
86
|
+
# [parameters:]
|
87
|
+
# +name+ - _String_ - The name of the scenario (+directory_name+).
|
88
|
+
##
|
89
|
+
def run_dir_name(name)
|
90
|
+
@run_dir = name
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Converts to a Hash equivalent for JSON serialization.
|
95
|
+
##
|
96
|
+
# - Exclude attributes with nil values.
|
97
|
+
# - Validate reporting_period hash properties against schema.
|
98
|
+
##
|
99
|
+
def to_hash
|
100
|
+
result = {}
|
101
|
+
directory_path = Pathname.new File.expand_path(@run_dir.to_s, File.dirname(__FILE__)) if @run_dir
|
102
|
+
csv_path = Pathname.new @path if @path
|
103
|
+
|
104
|
+
relative_path = csv_path.to_s.sub(directory_path.to_s, '')
|
105
|
+
|
106
|
+
result[:path] = relative_path if @path
|
107
|
+
result[:first_report_datetime] = @first_report_datetime if @first_report_datetime
|
108
|
+
result[:column_names] = @column_names if @column_names
|
109
|
+
|
110
|
+
# validate timeseries_csv properties against schema
|
111
|
+
if @@validator.validate(@@schema[:definitions][:TimeseriesCSV][:properties], result).any?
|
112
|
+
raise "scenario_report properties does not match schema: #{@@validator.validate(@@schema[:definitions][:TimeseriesCSV][:properties], result)}"
|
113
|
+
end
|
114
|
+
|
115
|
+
return result
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Loads data from the CSV file.
|
120
|
+
##
|
121
|
+
def load_data
|
122
|
+
@mutex.synchronize do
|
123
|
+
if @data.nil?
|
124
|
+
@data = {}
|
125
|
+
@column_names = []
|
126
|
+
CSV.foreach(@path) do |row|
|
127
|
+
if @column_names.empty?
|
128
|
+
@column_names = row
|
129
|
+
@column_names.each do |column_name|
|
130
|
+
@data[column_name] = []
|
131
|
+
end
|
132
|
+
else
|
133
|
+
row.each_with_index do |value, i|
|
134
|
+
@data[@column_names[i]] << value.to_f
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Gets data for each column name in the CSV file.
|
144
|
+
##
|
145
|
+
# [parameters:]
|
146
|
+
# +column_name+ - _String_ - The header of each column in the CSV file.
|
147
|
+
##
|
148
|
+
def get_data(column_name)
|
149
|
+
load_data
|
150
|
+
return @data[column_name]
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Saves data to the the scenario report CSV file.
|
155
|
+
##
|
156
|
+
# [parameters:]
|
157
|
+
# +path+ - _String_ - The path of the scenario report CSV (default_scenario_report.csv).
|
158
|
+
##
|
159
|
+
def save_data(path)
|
160
|
+
File.open(path, 'w') do |f|
|
161
|
+
f.puts @column_names.join(',')
|
162
|
+
n = @data[@column_names[0]].size
|
163
|
+
|
164
|
+
(0..n).each do |i|
|
165
|
+
line = []
|
166
|
+
@column_names.each do |column_name|
|
167
|
+
line << @data[column_name][i]
|
168
|
+
end
|
169
|
+
f.puts line.join(',')
|
170
|
+
end
|
171
|
+
begin
|
172
|
+
f.fsync
|
173
|
+
rescue StandardError
|
174
|
+
f.flush
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
##
|
180
|
+
# Merges timeseries csv to each other.
|
181
|
+
##
|
182
|
+
# - initialize first_report_datetime with the incoming first_report_datetime if its nil.
|
183
|
+
# - checks if first_report_datetime are identical.
|
184
|
+
# - merge the column names
|
185
|
+
# - merge the column data
|
186
|
+
##
|
187
|
+
# [parameters:]
|
188
|
+
# +other+ - _TimeseriesCSV_ - An object of TimeseriesCSV class.
|
189
|
+
##
|
190
|
+
def add_timeseries_csv(other)
|
191
|
+
@path = other.path
|
192
|
+
|
193
|
+
# initialize first_report_datetime with the incoming first_report_datetime if its nil.
|
194
|
+
if @first_report_datetime.nil?
|
195
|
+
@first_report_datetime = other.first_report_datetime
|
196
|
+
end
|
197
|
+
|
198
|
+
# checks if first_report_datetime are identical.
|
199
|
+
if @first_report_datetime != other.first_report_datetime
|
200
|
+
raise "first_report_datetime '#{@first_report_datetime}' does not match other.first_report_datetime '#{other.first_report_datetime}'"
|
201
|
+
end
|
202
|
+
|
203
|
+
# merge the column names
|
204
|
+
@column_names = @column_names.concat(other.column_names).uniq
|
205
|
+
|
206
|
+
# merge the column data
|
207
|
+
other.column_names.each do |column_name|
|
208
|
+
new_values = other.get_data(column_name)
|
209
|
+
|
210
|
+
if @data.nil?
|
211
|
+
@data = {}
|
212
|
+
end
|
213
|
+
|
214
|
+
current_values = @data[column_name]
|
215
|
+
if current_values
|
216
|
+
if current_values.size != new_values.size
|
217
|
+
raise 'Values of different sizes in add_timeseries_csv'
|
218
|
+
end
|
219
|
+
new_values.each_with_index do |value, i|
|
220
|
+
new_values[i] = value + current_values[i]
|
221
|
+
end
|
222
|
+
@data[column_name] = new_values
|
223
|
+
else
|
224
|
+
@data[column_name] = new_values
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# *********************************************************************************
|
2
|
+
# URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
|
3
|
+
# contributors. All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
# are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice, this list
|
9
|
+
# of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer in the documentation and/or other
|
13
|
+
# materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of the copyright holder nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without specific
|
17
|
+
# prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
22
|
+
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
24
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
27
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
28
|
+
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
# *********************************************************************************
|
30
|
+
|
31
|
+
require 'json'
|
32
|
+
|
33
|
+
module URBANopt
|
34
|
+
module Scenario
|
35
|
+
module DefaultReports
|
36
|
+
class Validator
|
37
|
+
@@schema = nil
|
38
|
+
|
39
|
+
# initialize the root directory
|
40
|
+
def initialize
|
41
|
+
super
|
42
|
+
|
43
|
+
@root_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..'))
|
44
|
+
|
45
|
+
@instance_lock = Mutex.new
|
46
|
+
@@schema ||= schema
|
47
|
+
end
|
48
|
+
|
49
|
+
# Return the absolute path of the default reports files
|
50
|
+
def files_dir
|
51
|
+
File.absolute_path(File.join(@root_dir, 'lib/urbanopt/scenario/default_reports/'))
|
52
|
+
end
|
53
|
+
|
54
|
+
# return path to schema file
|
55
|
+
def schema_file
|
56
|
+
File.join(files_dir, 'schema/scenario_schema.json')
|
57
|
+
end
|
58
|
+
|
59
|
+
# return schema
|
60
|
+
def schema
|
61
|
+
@instance_lock.synchronize do
|
62
|
+
if @@schema.nil?
|
63
|
+
File.open(schema_file, 'r') do |f|
|
64
|
+
@@schema = JSON.parse(f.read, symbolize_names: true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
@@schema
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# validate data against schema
|
74
|
+
##
|
75
|
+
# [parameters:]
|
76
|
+
# +schema+ - _Hash_ - A hash of the JSON scenario_schema.
|
77
|
+
# +data+ - _Hash_ - A hash of the data to be validated against scenario_schema.
|
78
|
+
##
|
79
|
+
def validate(schema, data)
|
80
|
+
JSON::Validator.fully_validate(schema, data)
|
81
|
+
end
|
82
|
+
|
83
|
+
# check if the schema is valid
|
84
|
+
def schema_valid?
|
85
|
+
metaschema = JSON::Validator.validator_for_name('draft6').metaschema
|
86
|
+
JSON::Validator.validate(metaschema, @@schema)
|
87
|
+
end
|
88
|
+
|
89
|
+
# return detailed schema validation errors
|
90
|
+
def schema_validation_errors
|
91
|
+
metaschema = JSON::Validator.validator_for_name('draft6').metaschema
|
92
|
+
JSON::Validator.fully_validate(metaschema, @@schema)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# *********************************************************************************
|
2
|
+
# URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
|
3
|
+
# contributors. All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
# are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice, this list
|
9
|
+
# of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer in the documentation and/or other
|
13
|
+
# materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of the copyright holder nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without specific
|
17
|
+
# prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
22
|
+
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
24
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
27
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
28
|
+
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
# *********************************************************************************
|
30
|
+
|
31
|
+
require 'openstudio/extension'
|
32
|
+
|
33
|
+
module URBANopt
|
34
|
+
module Scenario
|
35
|
+
class Extension < OpenStudio::Extension::Extension
|
36
|
+
def initialize
|
37
|
+
super
|
38
|
+
@root_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Returns the absolute path of the measures or nil if there is none, can be used when configuring OSWs.
|
43
|
+
def measures_dir
|
44
|
+
return File.absolute_path(File.join(@root_dir, 'lib', 'measures'))
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Relevant files such as weather data, design days, etc.
|
49
|
+
# Return the absolute path of the files or nil if there is none, used when configuring OSWs
|
50
|
+
def files_dir
|
51
|
+
return nil
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Doc templates are common files like copyright files which are used to update measures and other code.
|
56
|
+
# Doc templates will only be applied to measures in the current repository.
|
57
|
+
# Return the absolute path of the doc templates dir or nil if there is none.
|
58
|
+
def doc_templates_dir
|
59
|
+
return File.absolute_path(File.join(@root_dir, 'doc_templates'))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# *********************************************************************************
|
2
|
+
# URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
|
3
|
+
# contributors. All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
# are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice, this list
|
9
|
+
# of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer in the documentation and/or other
|
13
|
+
# materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of the copyright holder nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without specific
|
17
|
+
# prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
22
|
+
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
24
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
27
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
28
|
+
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
# *********************************************************************************
|
30
|
+
|
31
|
+
require 'logger'
|
32
|
+
|
33
|
+
module URBANopt
|
34
|
+
module Scenario
|
35
|
+
@@logger = Logger.new(STDOUT)
|
36
|
+
|
37
|
+
# Definining class variable "@@logger" to log errors, info and warning messages.
|
38
|
+
def self.logger
|
39
|
+
@@logger
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# *********************************************************************************
|
2
|
+
# URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
|
3
|
+
# contributors. All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
# are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice, this list
|
9
|
+
# of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright notice, this
|
12
|
+
# list of conditions and the following disclaimer in the documentation and/or other
|
13
|
+
# materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of the copyright holder nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without specific
|
17
|
+
# prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
22
|
+
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
24
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
27
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
28
|
+
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
# *********************************************************************************
|
30
|
+
|
31
|
+
module URBANopt
|
32
|
+
module Scenario
|
33
|
+
# ScenarioBase is a simulation method agnostic description of a Scenario.
|
34
|
+
class ScenarioBase
|
35
|
+
##
|
36
|
+
# Initialize ScenarioBase attributes: +name+ , +root directory+ , +run directory+ and +feature_file+
|
37
|
+
##
|
38
|
+
# [parameters:]
|
39
|
+
# +name+ - _String_ - Human readable scenario name.
|
40
|
+
# +root_dir+ - _String_ - Root directory for the scenario, contains Gemfile describing dependencies.
|
41
|
+
# +run_dir+ - _String_ - Directory for simulation of this scenario, deleting run directory clears the scenario.
|
42
|
+
# +feature_file+ - _FeatureFile_ - An instance of +URBANopt::Core::FeatureFile+ containing features for simulation.
|
43
|
+
def initialize(name, root_dir, run_dir, feature_file)
|
44
|
+
@name = name
|
45
|
+
@root_dir = root_dir
|
46
|
+
@run_dir = run_dir
|
47
|
+
@feature_file = feature_file
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Name of the Scenario.
|
52
|
+
attr_reader :name #:nodoc:
|
53
|
+
|
54
|
+
##
|
55
|
+
# Root directory containing Gemfile.
|
56
|
+
attr_reader :root_dir #:nodoc:
|
57
|
+
|
58
|
+
##
|
59
|
+
# Directory to run this Scenario.
|
60
|
+
attr_reader :run_dir #:nodoc:
|
61
|
+
|
62
|
+
##
|
63
|
+
# An instance of +URBANopt::Core::FeatureFile+ associated with this Scenario.
|
64
|
+
attr_reader :feature_file #:nodoc:
|
65
|
+
|
66
|
+
# An array of SimulationDirBase objects.
|
67
|
+
def simulation_dirs
|
68
|
+
raise 'simulation_dirs not implemented for ScenarioBase, override in your class'
|
69
|
+
end
|
70
|
+
|
71
|
+
# Removes all simulation input and output files by removing this Scenario's +run_dir+ .
|
72
|
+
def clear
|
73
|
+
Dir.glob(File.join(@run_dir, '/*')).each do |f|
|
74
|
+
FileUtils.rm_rf(f)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|