urbanopt-scenario 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,140 @@
|
|
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/default_reports/end_use'
|
32
|
+
require 'urbanopt/scenario/default_reports/validator'
|
33
|
+
require 'json-schema'
|
34
|
+
|
35
|
+
module URBANopt
|
36
|
+
module Scenario
|
37
|
+
module DefaultReports
|
38
|
+
##
|
39
|
+
# Enduses class inlclude results for each fuel type.
|
40
|
+
##
|
41
|
+
class EndUses
|
42
|
+
attr_accessor :electricity, :natural_gas, :additional_fuel, :district_cooling, :district_heating, :water # :nodoc:
|
43
|
+
##
|
44
|
+
# EndUses class intialize end_uses(fuel type) attributes: +:electricity+ , +:natural_gas+ , +:additional_fuel+ ,
|
45
|
+
# +:district_cooling+ , +:district_heating+ , +:water+
|
46
|
+
##
|
47
|
+
# [parameters:]
|
48
|
+
# +hash+ - _Hash_ - A hash which may contain a deserialized end_uses.
|
49
|
+
##
|
50
|
+
def initialize(hash = {})
|
51
|
+
hash.delete_if { |k, v| v.nil? }
|
52
|
+
hash = defaults.merge(hash)
|
53
|
+
|
54
|
+
@electricity = EndUse.new(hash[:electricity])
|
55
|
+
@natural_gas = EndUse.new(hash[:natural_gas])
|
56
|
+
@additional_fuel = EndUse.new(hash[:additional_fuel])
|
57
|
+
@district_cooling = EndUse.new(hash[:district_cooling])
|
58
|
+
@district_heating = EndUse.new(hash[:district_heating])
|
59
|
+
@water = EndUse.new(hash[:water])
|
60
|
+
|
61
|
+
# initialize class variables @@validator and @@schema
|
62
|
+
@@validator ||= Validator.new
|
63
|
+
@@schema ||= @@validator.schema
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Converts to a Hash equivalent for JSON serialization.
|
68
|
+
##
|
69
|
+
# - Exclude attributes with nil values.
|
70
|
+
# - Validate end_uses hash properties against schema.
|
71
|
+
##
|
72
|
+
def to_hash
|
73
|
+
result = {}
|
74
|
+
|
75
|
+
electricity_hash = @electricity.to_hash if @electricity.to_hash
|
76
|
+
electricity_hash.delete_if { |k, v| v.nil? }
|
77
|
+
result[:electricity] = electricity_hash if @electricity
|
78
|
+
|
79
|
+
natural_gas_hash = @natural_gas.to_hash if @natural_gas
|
80
|
+
natural_gas_hash.delete_if { |k, v| v.nil? }
|
81
|
+
result[:natural_gas] = natural_gas_hash if @natural_gas
|
82
|
+
|
83
|
+
additional_fuel_hash = @additional_fuel.to_hash if @additional_fuel
|
84
|
+
additional_fuel_hash.delete_if { |k, v| v.nil? }
|
85
|
+
result[:additional_fuel] = additional_fuel_hash if @additional_fuel
|
86
|
+
|
87
|
+
district_cooling_hash = @district_cooling.to_hash if @district_cooling
|
88
|
+
district_cooling_hash.delete_if { |k, v| v.nil? }
|
89
|
+
result[:district_cooling] = district_cooling_hash if @district_cooling
|
90
|
+
|
91
|
+
district_heating_hash = @district_heating.to_hash if @district_heating
|
92
|
+
district_heating_hash.delete_if { |k, v| v.nil? }
|
93
|
+
result[:district_heating] = district_heating_hash if @district_heating
|
94
|
+
|
95
|
+
water_hash = @water.to_hash if @water
|
96
|
+
water_hash.delete_if { |k, v| v.nil? }
|
97
|
+
result[:water] = water_hash if @water
|
98
|
+
|
99
|
+
# validate end_uses properties against schema
|
100
|
+
if @@validator.validate(@@schema[:definitions][:EndUses][:properties], result).any?
|
101
|
+
raise "end_uses properties does not match schema: #{@@validator.validate(@@schema[:definitions][:EndUses][:properties], result)}"
|
102
|
+
end
|
103
|
+
|
104
|
+
return result
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Assigns default values if values do not exist.
|
109
|
+
##
|
110
|
+
def defaults
|
111
|
+
hash = {}
|
112
|
+
hash[:electricity] = EndUse.new.to_hash
|
113
|
+
hash[:natural_gas] = EndUse.new.to_hash
|
114
|
+
hash[:additional_fuel] = EndUse.new.to_hash
|
115
|
+
hash[:district_cooling] = EndUse.new.to_hash
|
116
|
+
hash[:district_heating] = EndUse.new.to_hash
|
117
|
+
hash[:water] = EndUse.new.to_hash
|
118
|
+
|
119
|
+
return hash
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Aggregates the values of each EndUse attribute.
|
124
|
+
##
|
125
|
+
# [Parameters:]
|
126
|
+
# +new_end_uses+ - _EndUses_ - An object of EndUses class.
|
127
|
+
##
|
128
|
+
def merge_end_uses!(new_end_uses)
|
129
|
+
# modify the existing_period by summing up the results ; # sum results only if they exist
|
130
|
+
@electricity.merge_end_use!(new_end_uses.electricity)
|
131
|
+
@natural_gas.merge_end_use!(new_end_uses.natural_gas)
|
132
|
+
@additional_fuel.merge_end_use!(new_end_uses.additional_fuel)
|
133
|
+
@district_cooling.merge_end_use!(new_end_uses.district_cooling)
|
134
|
+
@district_heating.merge_end_use!(new_end_uses.district_heating)
|
135
|
+
return self
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,207 @@
|
|
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/default_reports/construction_cost'
|
32
|
+
require 'urbanopt/scenario/default_reports/program'
|
33
|
+
require 'urbanopt/scenario/default_reports/location'
|
34
|
+
require 'urbanopt/scenario/default_reports/reporting_period'
|
35
|
+
require 'urbanopt/scenario/default_reports/timeseries_csv'
|
36
|
+
require 'urbanopt/scenario/default_reports/validator'
|
37
|
+
require 'json-schema'
|
38
|
+
|
39
|
+
require 'json'
|
40
|
+
|
41
|
+
module URBANopt
|
42
|
+
module Scenario
|
43
|
+
module DefaultReports
|
44
|
+
##
|
45
|
+
# FeatureReport generates two types of reports in a simulation_dir.
|
46
|
+
# The default_feature_reports measure writes a 'default_feature_reports.json' file containing
|
47
|
+
# information on all features in the simulation. It also writes a 'default_feature_reports.csv'
|
48
|
+
# containing timeseries data for all features in the simulation.
|
49
|
+
# The DefaultPostProcessor reads these feature reports and aggregates them to create a ScenarioReport.
|
50
|
+
##
|
51
|
+
class FeatureReport
|
52
|
+
attr_accessor :id, :name, :directory_name, :feature_type, :timesteps_per_hour, :simulation_status,
|
53
|
+
:timeseries_csv, :location, :program, :design_parameters, :construction_costs, :reporting_periods # :nodoc:
|
54
|
+
##
|
55
|
+
# Each FeatureReport object corresponds to a single Feature.
|
56
|
+
##
|
57
|
+
# [parameters:]
|
58
|
+
# +hash+ - _Hash_ - A hash which may contain a deserialized feature_report.
|
59
|
+
##
|
60
|
+
def initialize(hash = {})
|
61
|
+
hash.delete_if { |k, v| v.nil? }
|
62
|
+
hash = defaults.merge(hash)
|
63
|
+
|
64
|
+
@id = hash[:id]
|
65
|
+
@name = hash[:name]
|
66
|
+
@directory_name = hash[:directory_name]
|
67
|
+
@feature_type = hash[:feature_type]
|
68
|
+
@timesteps_per_hour = hash[:timesteps_per_hour]
|
69
|
+
@simulation_status = hash[:simulation_status]
|
70
|
+
@timeseries_csv = TimeseriesCSV.new(hash[:timeseries_csv])
|
71
|
+
@timeseries_csv.run_dir_name(@directory_name)
|
72
|
+
@location = Location.new(hash[:location])
|
73
|
+
@program = Program.new(hash[:program])
|
74
|
+
# design_parameters to add later
|
75
|
+
@construction_costs = []
|
76
|
+
hash[:construction_costs].each do |cc|
|
77
|
+
@constructiion_costs << ConstructionCost.new(cc)
|
78
|
+
end
|
79
|
+
|
80
|
+
@reporting_periods = []
|
81
|
+
hash[:reporting_periods].each do |rp|
|
82
|
+
@reporting_periods << ReportingPeriod.new(rp)
|
83
|
+
end
|
84
|
+
|
85
|
+
# initialize class variables @@validator and @@schema
|
86
|
+
@@validator ||= Validator.new
|
87
|
+
@@schema ||= @@validator.schema
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Assign default values if values does not exist.
|
92
|
+
##
|
93
|
+
def defaults
|
94
|
+
hash = {}
|
95
|
+
hash[:timeseries_csv] = {}
|
96
|
+
hash[:location] = {}
|
97
|
+
hash[:program] = {}
|
98
|
+
hash[:construction_costs] = []
|
99
|
+
hash[:reporting_periods] = []
|
100
|
+
return hash
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Return an Array of FeatureReports for the simulation_dir as multiple Features can be simulated together in a single simulation directory.
|
105
|
+
##
|
106
|
+
# - Ensure that +simulation_dir+ include only one feature.
|
107
|
+
# - Read in the reports written by measure if they exist.
|
108
|
+
##
|
109
|
+
# [parameters:]
|
110
|
+
# +simulation_dir+ - _SimulationDirOSW_ - A simulation directory from an OSW simulation, must include 'default_feature_reports' measure.
|
111
|
+
##
|
112
|
+
def self.from_simulation_dir(simulation_dir)
|
113
|
+
result = []
|
114
|
+
|
115
|
+
# simulation dir can include only one feature
|
116
|
+
features = simulation_dir.features
|
117
|
+
if features.size != 1
|
118
|
+
raise 'FeatureReport cannot support multiple features per OSW'
|
119
|
+
end
|
120
|
+
|
121
|
+
# read in the reports written by measure
|
122
|
+
default_feature_reports_json = nil
|
123
|
+
default_feature_reports_csv = nil
|
124
|
+
|
125
|
+
simulation_status = simulation_dir.simulation_status
|
126
|
+
if simulation_status == 'Complete' || simulation_status == 'Failed'
|
127
|
+
|
128
|
+
# read in the scenario reports JSON and CSV
|
129
|
+
Dir.glob(File.join(simulation_dir.run_dir, '*_default_feature_reports/')).each do |dir|
|
130
|
+
scenario_reports_json_path = File.join(dir, 'default_feature_reports.json')
|
131
|
+
if File.exist?(scenario_reports_json_path)
|
132
|
+
File.open(scenario_reports_json_path, 'r') do |file|
|
133
|
+
default_feature_reports_json = JSON.parse(file.read, symbolize_names: true)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
scenario_reports_csv_path = File.join(dir, 'default_feature_reports.csv')
|
137
|
+
if File.exist?(scenario_reports_csv_path)
|
138
|
+
default_feature_reports_csv = scenario_reports_csv_path
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
# if we loaded the json
|
145
|
+
if default_feature_reports_json # && default_feature_reports_json[:feature_reports]
|
146
|
+
# default_feature_reports_json.each do |feature_report|
|
147
|
+
# result << FeatureReport.new(feature_report)
|
148
|
+
# end
|
149
|
+
result << FeatureReport.new(default_feature_reports_json) # should we keep it as an array !? or each each report can only include 1 feature
|
150
|
+
|
151
|
+
else
|
152
|
+
# we did not find a report
|
153
|
+
features.each do |feature|
|
154
|
+
hash = {}
|
155
|
+
hash[:id] = feature.id
|
156
|
+
hash[:name] = feature.name
|
157
|
+
hash[:directory_name] = simulation_dir.run_dir
|
158
|
+
hash[:simulation_status] = simulation_status
|
159
|
+
result << FeatureReport.new(hash)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# validate feature_report json against schema
|
164
|
+
if @@validator.validate(@@schema[:definitions][:FeatureReport][:properties], default_feature_reports_json).any?
|
165
|
+
raise "default_feature_report_json properties does not match schema: #{@@validator.validate(@@schema[:definitions][:FeatureReport][:properties], default_feature_reports_json)}"
|
166
|
+
end
|
167
|
+
|
168
|
+
return result
|
169
|
+
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# Convert to a Hash equivalent for JSON serialization
|
173
|
+
##
|
174
|
+
# - Exclude attributes with nil values.
|
175
|
+
# - Validate feature_report hash properties against schema.
|
176
|
+
##
|
177
|
+
def to_hash
|
178
|
+
result = {}
|
179
|
+
result[:id] = @id if @id
|
180
|
+
result[:name] = @name if @name
|
181
|
+
result[:directory_name] = @directory_name if @directory_name
|
182
|
+
result[:feature_type] = @feature_type if @feature_type
|
183
|
+
result[:timesteps_per_hour] = @timesteps_per_hour if @timesteps_per_hour
|
184
|
+
result[:simulation_status] = @simulation_status if @simulation_status
|
185
|
+
result[:timeseries_csv] = @timeseries_csv.to_hash
|
186
|
+
|
187
|
+
result[:location] = @location.to_hash if @location
|
188
|
+
|
189
|
+
result[:program] = @program.to_hash
|
190
|
+
|
191
|
+
result[:construction_costs] = []
|
192
|
+
@construction_costs.each { |cc| result[:construction_costs] << cc.to_hash }
|
193
|
+
|
194
|
+
result[:reporting_periods] = []
|
195
|
+
@reporting_periods.each { |rp| result[:reporting_periods] << rp.to_hash }
|
196
|
+
|
197
|
+
# validate feature_report properties against schema
|
198
|
+
if @@validator.validate(@@schema[:definitions][:FeatureReport][:properties], result).any?
|
199
|
+
raise "feature_report properties does not match schema: #{@@validator.validate(@@schema[:definitions][:FeatureReport][:properties], result)}"
|
200
|
+
end
|
201
|
+
|
202
|
+
return result
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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/default_reports/validator'
|
32
|
+
require 'json-schema'
|
33
|
+
require 'json'
|
34
|
+
|
35
|
+
module URBANopt
|
36
|
+
module Scenario
|
37
|
+
module DefaultReports
|
38
|
+
##
|
39
|
+
# Location include all location information.
|
40
|
+
##
|
41
|
+
class Location
|
42
|
+
attr_accessor :latitude, :longitude, :surface_elevation, :weather_filename #:nodoc:
|
43
|
+
##
|
44
|
+
# Location class intialize location attributes: +:latitude+ , +:longitude+ , +:surface_elevation+ , +:weather_filename+
|
45
|
+
##
|
46
|
+
# [parameters:]
|
47
|
+
# +hash+ - _Hash_ - A hash which may contain a deserialized location.
|
48
|
+
##
|
49
|
+
def initialize(hash = {})
|
50
|
+
hash.delete_if { |k, v| v.nil? }
|
51
|
+
hash = defaults.merge(hash)
|
52
|
+
|
53
|
+
@latitude = hash[:latitude]
|
54
|
+
@longitude = hash[:longitude]
|
55
|
+
@surface_elevation = hash[:surface_elevation]
|
56
|
+
@weather_filename = hash[:weather_filename]
|
57
|
+
|
58
|
+
# initialize class variables @@validator and @@schema
|
59
|
+
@@validator ||= Validator.new
|
60
|
+
@@schema ||= @@validator.schema
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Convert to a Hash equivalent for JSON serialization.
|
65
|
+
##
|
66
|
+
# - Exclude attributes with nil values.
|
67
|
+
# - Validate location hash properties against schema.
|
68
|
+
##
|
69
|
+
def to_hash
|
70
|
+
result = {}
|
71
|
+
result[:latitude] = @latitude if @latitude
|
72
|
+
result[:longitude] = @longitude if @longitude
|
73
|
+
result[:surface_elevation] = @surface_elevation if @surface_elevation
|
74
|
+
result[:weather_filename] = @weather_filename if @weather_filename
|
75
|
+
|
76
|
+
# validate location properties against schema
|
77
|
+
if @@validator.validate(@@schema[:definitions][:Location][:properties], result).any?
|
78
|
+
raise "end_uses properties does not match schema: #{@@validator.validate(@@schema[:definitions][:Location][:properties], result)}"
|
79
|
+
end
|
80
|
+
|
81
|
+
return result
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Assign default values if values does not exist
|
86
|
+
##
|
87
|
+
def defaults
|
88
|
+
hash = {}
|
89
|
+
hash[:latitude] = nil
|
90
|
+
hash[:longitude] = nil
|
91
|
+
hash[:surface_elevation] = nil
|
92
|
+
hash[:weather_filename] = nil
|
93
|
+
|
94
|
+
return hash
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
+
module DefaultReports
|
36
|
+
@@logger = Logger.new(STDOUT)
|
37
|
+
##
|
38
|
+
# Definining class variable "@@logger" to log errors, info and warning messages.
|
39
|
+
def self.logger
|
40
|
+
@@logger
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|