urbanopt-scenario 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.rdoc_options +36 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +10 -0
  6. data/.travis.yml +23 -0
  7. data/CHANGELOG.md +5 -0
  8. data/Gemfile +42 -0
  9. data/Jenkinsfile +10 -0
  10. data/LICENSE.md +27 -0
  11. data/RDOC_MAIN.md +39 -0
  12. data/README.md +39 -0
  13. data/Rakefile +51 -0
  14. data/deploy_docs.sh +5 -0
  15. data/doc_templates/LICENSE.md +27 -0
  16. data/doc_templates/README.md.erb +42 -0
  17. data/doc_templates/copyright_erb.txt +31 -0
  18. data/doc_templates/copyright_js.txt +4 -0
  19. data/doc_templates/copyright_ruby.txt +29 -0
  20. data/docs/.gitignore +3 -0
  21. data/docs/.vuepress/components/InnerJsonSchema.vue +84 -0
  22. data/docs/.vuepress/components/JsonSchema.vue +12 -0
  23. data/docs/.vuepress/components/ScenarioSchema.vue +12 -0
  24. data/docs/.vuepress/components/StaticLink.vue +8 -0
  25. data/docs/.vuepress/config.js +15 -0
  26. data/docs/.vuepress/highlight.js +8 -0
  27. data/docs/.vuepress/public/custom_rdoc_styles.css +74 -0
  28. data/docs/.vuepress/utils.js +17 -0
  29. data/docs/README.md +39 -0
  30. data/docs/package-lock.json +11791 -0
  31. data/docs/package.json +22 -0
  32. data/docs/schemas/scenario-schema.md +3 -0
  33. data/lib/measures/.rubocop.yml +5 -0
  34. data/lib/measures/default_feature_reports/LICENSE.md +27 -0
  35. data/lib/measures/default_feature_reports/README.md +56 -0
  36. data/lib/measures/default_feature_reports/README.md.erb +42 -0
  37. data/lib/measures/default_feature_reports/measure.rb +731 -0
  38. data/lib/measures/default_feature_reports/measure.xml +139 -0
  39. data/lib/measures/default_feature_reports/tests/USA_CO_Golden-NREL.724666_TMY3.epw +8768 -0
  40. data/lib/measures/default_feature_reports/tests/default_feature_reports_test.rb +238 -0
  41. data/lib/measures/default_feature_reports/tests/example_model.osm +4378 -0
  42. data/lib/urbanopt-scenario.rb +31 -0
  43. data/lib/urbanopt/scenario.rb +45 -0
  44. data/lib/urbanopt/scenario/default_reports.rb +40 -0
  45. data/lib/urbanopt/scenario/default_reports/construction_cost.rb +169 -0
  46. data/lib/urbanopt/scenario/default_reports/date.rb +97 -0
  47. data/lib/urbanopt/scenario/default_reports/end_use.rb +159 -0
  48. data/lib/urbanopt/scenario/default_reports/end_uses.rb +140 -0
  49. data/lib/urbanopt/scenario/default_reports/feature_report.rb +207 -0
  50. data/lib/urbanopt/scenario/default_reports/location.rb +99 -0
  51. data/lib/urbanopt/scenario/default_reports/logger.rb +44 -0
  52. data/lib/urbanopt/scenario/default_reports/program.rb +261 -0
  53. data/lib/urbanopt/scenario/default_reports/reporting_period.rb +298 -0
  54. data/lib/urbanopt/scenario/default_reports/scenario_report.rb +276 -0
  55. data/lib/urbanopt/scenario/default_reports/schema/README.md +33 -0
  56. data/lib/urbanopt/scenario/default_reports/schema/scenario_csv_columns.txt +13 -0
  57. data/lib/urbanopt/scenario/default_reports/schema/scenario_schema.json +742 -0
  58. data/lib/urbanopt/scenario/default_reports/timeseries_csv.rb +231 -0
  59. data/lib/urbanopt/scenario/default_reports/validator.rb +97 -0
  60. data/lib/urbanopt/scenario/extension.rb +63 -0
  61. data/lib/urbanopt/scenario/logger.rb +42 -0
  62. data/lib/urbanopt/scenario/scenario_base.rb +79 -0
  63. data/lib/urbanopt/scenario/scenario_csv.rb +122 -0
  64. data/lib/urbanopt/scenario/scenario_datapoint_base.rb +162 -0
  65. data/lib/urbanopt/scenario/scenario_post_processor_base.rb +69 -0
  66. data/lib/urbanopt/scenario/scenario_post_processor_default.rb +97 -0
  67. data/lib/urbanopt/scenario/scenario_runner_base.rb +63 -0
  68. data/lib/urbanopt/scenario/scenario_runner_osw.rb +158 -0
  69. data/lib/urbanopt/scenario/simulation_dir_base.rb +90 -0
  70. data/lib/urbanopt/scenario/simulation_dir_osw.rb +261 -0
  71. data/lib/urbanopt/scenario/simulation_mapper_base.rb +47 -0
  72. data/lib/urbanopt/scenario/version.rb +35 -0
  73. data/urbanopt-scenario-gem.gemspec +36 -0
  74. metadata +227 -0
@@ -0,0 +1,122 @@
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 'urbanopt/scenario/scenario_base'
32
+ require 'urbanopt/scenario/simulation_dir_osw'
33
+
34
+ require 'csv'
35
+ require 'fileutils'
36
+
37
+ module URBANopt
38
+ module Scenario
39
+ class ScenarioCSV < ScenarioBase
40
+ ##
41
+ # ScenarioCSV is a ScenarioBase which assigns a Simulation Mapper to each Feature in a FeatureFile using a simple CSV format.
42
+ # The CSV file has three columns 1) feature_id, 2) feature_name, and 3) mapper_class_name. There is one row for each Feature.
43
+ ##
44
+ # [parameters:]
45
+ # +name+ - _String_ - Human readable scenario name.
46
+ # +root_dir+ - _String_ - Root directory for the scenario, contains Gemfile describing dependencies.
47
+ # +run_dir+ - _String_ - Directory for simulation of this scenario, deleting run directory clears the scenario.
48
+ # +feature_file+ - _URBANopt::Core::FeatureFile_ - FeatureFile containing features to simulate.
49
+ # +mapper_files_dir+ - _String_ - Directory containing all mapper class files containing MapperBase definitions.
50
+ # +csv_file+ - _String_ - Path to CSV file assigning a MapperBase class to each feature in feature_file.
51
+ # +num_header_rows+ - _Strng_ - Number of header rows to skip in CSV file.
52
+
53
+ def initialize(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
54
+ super(name, root_dir, run_dir, feature_file)
55
+
56
+ @mapper_files_dir = mapper_files_dir
57
+ @csv_file = csv_file
58
+ @num_header_rows = num_header_rows
59
+
60
+ @@logger ||= URBANopt::Scenario.logger
61
+
62
+ load_mapper_files
63
+ end
64
+
65
+ # Path to CSV file
66
+ attr_reader :csv_file #:nodoc:
67
+
68
+ # Number of header rows to skip in CSV file
69
+ attr_reader :num_header_rows #:nodoc:
70
+
71
+ # Directory containing all mapper class files
72
+ attr_reader :mapper_files_dir #:nodoc:
73
+
74
+ # Require all simulation mappers in mapper_files_dir
75
+ def load_mapper_files
76
+ Dir.glob(File.join(@mapper_files_dir, '/*.rb')).each do |f|
77
+ begin
78
+ require(f)
79
+ rescue LoadError => e
80
+ @@logger.error(e.message)
81
+ raise
82
+ end
83
+ end
84
+ end
85
+
86
+ # Gets all the simulation directories
87
+ def simulation_dirs
88
+ # DLM: TODO use HeaderConverters from CSV module
89
+
90
+ rows_skipped = 0
91
+ result = []
92
+ CSV.foreach(@csv_file) do |row|
93
+ if rows_skipped < @num_header_rows
94
+ rows_skipped += 1
95
+ next
96
+ end
97
+
98
+ break if row[0].nil?
99
+
100
+ # gets +feature_id+ , +feature_name+ and +mapper_class+ from csv_file
101
+ feature_id = row[0].chomp
102
+ feature_name = row[1].chomp
103
+ mapper_class = row[2].chomp
104
+
105
+ # gets +features+ from the feature_file.
106
+ features = []
107
+ feature = feature_file.get_feature_by_id(feature_id)
108
+ features << feature
109
+
110
+ feature_names = []
111
+ feature_names << feature_name
112
+
113
+ simulation_dir = SimulationDirOSW.new(self, features, feature_names, mapper_class)
114
+
115
+ result << simulation_dir
116
+ end
117
+
118
+ return result
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,162 @@
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
+ class ScenarioDatapoint
34
+ attr_reader :scenario, :feature_id, :feature_name, :mapper_class #:nodoc:#
35
+
36
+ ##
37
+ # ScenarioDatapoint is an agnostic description of the simulation of a Feature in a Scenario
38
+ # A Simulation Mapper will map the
39
+ ##
40
+ # [parameters:]
41
+ # +scenario+ - _ScenarioBase_ - Scenario containing this ScenarioDatapoint.
42
+ # +feature_id+ - _String_ - Unique id of the feature for this ScenarioDatapoint.
43
+ # +feature_name+ - _String_ - Human readable name of the feature for this ScenarioDatapoint.
44
+ # +mapper_class+ - _String_ - Name of Ruby class used to translate feature to simulation OSW.
45
+ def initialize(scenario, feature_id, feature_name, mapper_class)
46
+ @scenario = scenario
47
+ @feature_id = feature_id
48
+ @feature_name = feature_name
49
+ @feature = scenario.feature_file.get_feature_by_id(feature_id)
50
+ @mapper_class = mapper_class
51
+ end
52
+
53
+ attr_reader :feature #:nodoc:
54
+
55
+ ##
56
+ # Gets the type of a feature
57
+ ##
58
+ def feature_type
59
+ @feature.feature_type
60
+ end
61
+
62
+ ##
63
+ # Return the directory that this datapoint will run in.
64
+ ##
65
+ # [return:] _String_ - Directory that this datapoint will run in.
66
+ def run_dir
67
+ raise 'Feature ID not set' if @feature_id.nil?
68
+ raise 'Scenario run dir not set' if @scenario.run_dir.nil?
69
+ return File.join(@scenario.run_dir, @feature_id + '/')
70
+ end
71
+
72
+ ##
73
+ # Return the directory that this datapoint will run in.
74
+ def clear
75
+ dir = run_dir
76
+ FileUtils.rm_rf(dir) if File.exist?(dir)
77
+ FileUtils.mkdir_p(dir) if !File.exist?(dir)
78
+ end
79
+
80
+ # rubocop: disable Security/Eval #:nodoc:
81
+ # rubocop: disable Style/EvalWithLocation #:nodoc:
82
+ # Disable Sceurity/Eval since there is no user input #:nodoc:
83
+
84
+ ##
85
+ # Create run directory and generate simulation OSW, all previous contents of directory are removed
86
+ # The simulation OSW is created by evaluating the mapper_class's create_osw method
87
+ ##
88
+ # [return:] _String_ - Path to the simulation OSW.
89
+ ##
90
+ def create_osw
91
+ osw = eval("#{@mapper_class}.new.create_osw(@scenario, @feature_id, @feature_name)")
92
+ dir = run_dir
93
+ FileUtils.rm_rf(dir) if File.exist?(dir)
94
+ FileUtils.mkdir_p(dir) if !File.exist?(dir)
95
+ osw_path = File.join(dir, 'in.osw')
96
+ File.open(osw_path, 'w') do |f|
97
+ f << JSON.pretty_generate(osw)
98
+ # make sure data is written to the disk one way or the other
99
+ begin
100
+ f.fsync
101
+ rescue StandardError
102
+ f.flush
103
+ end
104
+ end
105
+ return osw_path
106
+ end
107
+ # rubocop: enable Security/Eval #:nodoc:
108
+ # rubocop: enable Style/EvalWithLocation #:nodoc:
109
+
110
+ ##
111
+ # Return true if the datapoint is out of date, false otherwise. Non-existant files are out of date.
112
+ ##
113
+ # [return:] _Boolean_ - True if the datapoint is out of date, false otherwise.
114
+ def out_of_date?
115
+ dir = run_dir
116
+ if !File.exist?(dir)
117
+ return true
118
+ end
119
+
120
+ out_osw = File.join(dir, 'out.osw')
121
+ if !File.exist?(out_osw)
122
+ return true
123
+ end
124
+ out_osw_time = File.mtime(out_osw)
125
+
126
+ # array of files that this datapoint depends on
127
+ dependencies = []
128
+
129
+ # depends on the feature file
130
+ dependencies << scenario.feature_file.path
131
+
132
+ # depends on the csv file
133
+ dependencies << scenario.csv_file
134
+
135
+ # depends on the mapper classes
136
+ Dir.glob(File.join(scenario.mapper_files_dir, '*')).each do |f|
137
+ dependencies << f
138
+ end
139
+
140
+ # depends on the root gemfile
141
+ dependencies << File.join(scenario.root_dir, 'Gemfile')
142
+ dependencies << File.join(scenario.root_dir, 'Gemfile.lock')
143
+
144
+ # todo, depends on all the measures?
145
+
146
+ # check if out of date
147
+ dependencies.each do |f|
148
+ if File.exist?(f)
149
+ if File.mtime(f) > out_osw_time
150
+ puts "File '#{f}' is newer than '#{out_osw}', datapoint out of date"
151
+ return true
152
+ end
153
+ else
154
+ puts "Dependency file '#{f}' does not exist"
155
+ end
156
+ end
157
+
158
+ return false
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,69 @@
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
+ class ScenarioPostProcessorBase
34
+ ##
35
+ # ScenarioPostProcessorBase post-processes a Scenario to create scenario level results.
36
+ ##
37
+ # [parameters:]
38
+ # +scenario_base+ - _ScenarioBase_ - An object of ScenarioBase class.
39
+ def initialize(scenario_base)
40
+ @scenario_base = scenario_base
41
+ end
42
+
43
+ attr_reader :scenario_base
44
+
45
+ ##
46
+ # Run the post processor on this Scenario.
47
+ ##
48
+ def run
49
+ raise 'run not implemented for ScenarioPostProcessorBase, override in your class'
50
+ end
51
+
52
+ ##
53
+ # Add results from a simulation_dir to this result.
54
+ ##
55
+ # [parameters:]
56
+ # +simulation_dir+ - _SimulationDirOSW_ - An object on SimulationDirOSW class.
57
+ def add_simulation_dir(simulation_dir)
58
+ raise 'add_simulation_dir not implemented for ScenarioPostProcessorBase, override in your class'
59
+ end
60
+
61
+ ##
62
+ # Save scenario result.
63
+ ##
64
+ def save
65
+ raise 'save not implemented for ScenarioPostProcessorBase, override in your class'
66
+ end
67
+ end
68
+ end
69
+ 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 'urbanopt/scenario/scenario_post_processor_base'
32
+ require 'urbanopt/scenario/default_reports'
33
+ require 'urbanopt/scenario/default_reports/logger'
34
+
35
+ require 'csv'
36
+ require 'json'
37
+ require 'fileutils'
38
+
39
+ module URBANopt
40
+ module Scenario
41
+ class ScenarioDefaultPostProcessor < ScenarioPostProcessorBase
42
+ ##
43
+ # ScenarioPostProcessorBase post-processes a scenario to create scenario level results
44
+ ##
45
+ # [parameters:]
46
+ # +scenario_base+ - _ScenarioBase_ - An object of ScenarioBase class.
47
+ def initialize(scenario_base)
48
+ super(scenario_base)
49
+ @scenario_result = URBANopt::Scenario::DefaultReports::ScenarioReport.new
50
+ @scenario_result.id = scenario_base.name
51
+ @scenario_result.name = scenario_base.name
52
+ @scenario_result.directory_name = scenario_base.run_dir
53
+
54
+ @@logger ||= URBANopt::Scenario::DefaultReports.logger
55
+ end
56
+
57
+ ##
58
+ # Run the post processor on this Scenario.This will add all the simulation_dirs.
59
+ ##
60
+ def run
61
+ # this run method adds all the simulation_dirs, you can extend it to do more custom stuff
62
+ @scenario_base.simulation_dirs.each do |simulation_dir|
63
+ add_simulation_dir(simulation_dir)
64
+ end
65
+ return @scenario_result
66
+ end
67
+
68
+ ##
69
+ # Add results from a simulation_dir to this result.
70
+ ##
71
+ # [parameters:]
72
+ # +simulation_dir+ - _SimulationDirOSW_ - An object on SimulationDirOSW class.
73
+ def add_simulation_dir(simulation_dir)
74
+ feature_reports = URBANopt::Scenario::DefaultReports::FeatureReport.from_simulation_dir(simulation_dir)
75
+
76
+ feature_reports.each do |feature_report|
77
+ if feature_report.to_hash[:simulation_status] == 'Complete'
78
+ @scenario_result.add_feature_report(feature_report)
79
+ else
80
+ @@logger.error("Feature #{feature_report.id} failed to run!")
81
+ end
82
+ end
83
+
84
+ return feature_reports
85
+ end
86
+
87
+ ##
88
+ # Save scenario result
89
+ ##
90
+ def save
91
+ @scenario_result.save
92
+
93
+ return @scenario_result
94
+ end
95
+ end
96
+ end
97
+ end