Class: URBANopt::Scenario::DefaultReports::FeatureReport
- Inherits:
-
Object
- Object
- URBANopt::Scenario::DefaultReports::FeatureReport
- Defined in:
- lib/urbanopt/scenario/default_reports/feature_report.rb
Overview
FeatureReport generates two types of reports in a simulation_dir. The default_feature_reports measure writes a ‘default_feature_reports.json’ file containing information on all features in the simulation. It also writes a ‘default_feature_reports.csv’ containing timeseries data for all features in the simulation. The DefaultPostProcessor reads these feature reports and aggregates them to create a ScenarioReport.
Instance Attribute Summary collapse
-
#construction_costs ⇒ Object
Returns the value of attribute construction_costs.
-
#design_parameters ⇒ Object
Returns the value of attribute design_parameters.
-
#directory_name ⇒ Object
Returns the value of attribute directory_name.
-
#distributed_generation ⇒ Object
Returns the value of attribute distributed_generation.
-
#feature_type ⇒ Object
Returns the value of attribute feature_type.
-
#id ⇒ Object
Returns the value of attribute id.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#program ⇒ Object
Returns the value of attribute program.
-
#reporting_periods ⇒ Object
Returns the value of attribute reporting_periods.
-
#simulation_status ⇒ Object
Returns the value of attribute simulation_status.
-
#timeseries_csv ⇒ Object
Returns the value of attribute timeseries_csv.
-
#timesteps_per_hour ⇒ Object
Returns the value of attribute timesteps_per_hour.
Class Method Summary collapse
-
.from_simulation_dir(simulation_dir) ⇒ Object
Return an Array of FeatureReports for the simulation_dir as multiple Features can be simulated together in a single simulation directory.
Instance Method Summary collapse
-
#defaults ⇒ Object
Assign default values if values does not exist.
-
#initialize(hash = {}) ⇒ FeatureReport
constructor
Each FeatureReport object corresponds to a single Feature.
-
#to_hash ⇒ Object
Convert to a Hash equivalent for JSON serialization.
Constructor Details
#initialize(hash = {}) ⇒ FeatureReport
Each FeatureReport object corresponds to a single Feature.
- parameters:
-
hash- Hash - A hash which may contain a deserialized feature_report.
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 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 62 def initialize(hash = {}) hash.delete_if { |k, v| v.nil? } hash = defaults.merge(hash) @id = hash[:id] @name = hash[:name] @directory_name = hash[:directory_name] @feature_type = hash[:feature_type] @timesteps_per_hour = hash[:timesteps_per_hour] @simulation_status = hash[:simulation_status] @timeseries_csv = TimeseriesCSV.new(hash[:timeseries_csv]) @timeseries_csv.run_dir_name(@directory_name) @location = Location.new(hash[:location]) @program = Program.new(hash[:program]) # design_parameters to add later @construction_costs = [] hash[:construction_costs].each do |cc| @constructiion_costs << ConstructionCost.new(cc) end @reporting_periods = [] hash[:reporting_periods].each do |rp| @reporting_periods << ReportingPeriod.new(rp) end @distributed_generation = DistributedGeneration.new(hash[:distributed_generation] || {}) # initialize class variables @@validator and @@schema @@validator ||= Validator.new @@schema ||= @@validator.schema end |
Instance Attribute Details
#construction_costs ⇒ Object
Returns the value of attribute construction_costs.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def construction_costs @construction_costs end |
#design_parameters ⇒ Object
Returns the value of attribute design_parameters.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def design_parameters @design_parameters end |
#directory_name ⇒ Object
Returns the value of attribute directory_name.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def directory_name @directory_name end |
#distributed_generation ⇒ Object
Returns the value of attribute distributed_generation.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def distributed_generation @distributed_generation end |
#feature_type ⇒ Object
Returns the value of attribute feature_type.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def feature_type @feature_type end |
#id ⇒ Object
Returns the value of attribute id.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def id @id end |
#location ⇒ Object
Returns the value of attribute location.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def name @name end |
#program ⇒ Object
Returns the value of attribute program.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def program @program end |
#reporting_periods ⇒ Object
Returns the value of attribute reporting_periods.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def reporting_periods @reporting_periods end |
#simulation_status ⇒ Object
Returns the value of attribute simulation_status.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def simulation_status @simulation_status end |
#timeseries_csv ⇒ Object
Returns the value of attribute timeseries_csv.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def timeseries_csv @timeseries_csv end |
#timesteps_per_hour ⇒ Object
Returns the value of attribute timesteps_per_hour.
54 55 56 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 54 def timesteps_per_hour @timesteps_per_hour end |
Class Method Details
.from_simulation_dir(simulation_dir) ⇒ Object
Return an Array of FeatureReports for the simulation_dir as multiple Features can be simulated together in a single simulation directory.
-
Ensure that
simulation_dirinclude only one feature. -
Read in the reports written by measure if they exist.
- parameters:
-
simulation_dir- SimulationDirOSW - A simulation directory from an OSW simulation, must include ‘default_feature_reports’ measure.
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 116 def self.from_simulation_dir(simulation_dir) result = [] # simulation dir can include only one feature features = simulation_dir.features if features.size != 1 raise 'FeatureReport cannot support multiple features per OSW' end # read in the reports written by measure default_feature_reports_json = nil default_feature_reports_csv = nil simulation_status = simulation_dir.simulation_status if simulation_status == 'Complete' || simulation_status == 'Failed' # read in the scenario reports JSON and CSV Dir.glob(File.join(simulation_dir.run_dir, '*_default_feature_reports/')).each do |dir| scenario_reports_json_path = File.join(dir, 'default_feature_reports.json') if File.exist?(scenario_reports_json_path) File.open(scenario_reports_json_path, 'r') do |file| default_feature_reports_json = JSON.parse(file.read, symbolize_names: true) end end scenario_reports_csv_path = File.join(dir, 'default_feature_reports.csv') if File.exist?(scenario_reports_csv_path) default_feature_reports_csv = scenario_reports_csv_path end end end # if we loaded the json if default_feature_reports_json # && default_feature_reports_json[:feature_reports] # default_feature_reports_json.each do |feature_report| # result << FeatureReport.new(feature_report) # end result << FeatureReport.new(default_feature_reports_json) # should we keep it as an array !? or each each report can only include 1 feature else # we did not find a report features.each do |feature| hash = {} hash[:id] = feature.id hash[:name] = feature.name hash[:directory_name] = simulation_dir.run_dir hash[:simulation_status] = simulation_status result << FeatureReport.new(hash) end end # validate feature_report json against schema if @@validator.validate(@@schema[:definitions][:FeatureReport][:properties], default_feature_reports_json).any? raise "default_feature_report_json properties does not match schema: #{@@validator.validate(@@schema[:definitions][:FeatureReport][:properties], default_feature_reports_json)}" end return result end |
Instance Method Details
#defaults ⇒ Object
Assign default values if values does not exist.
97 98 99 100 101 102 103 104 105 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 97 def defaults hash = {} hash[:timeseries_csv] = {} hash[:location] = {} hash[:program] = {} hash[:construction_costs] = [] hash[:reporting_periods] = [] return hash end |
#to_hash ⇒ Object
Convert to a Hash equivalent for JSON serialization
-
Exclude attributes with nil values.
-
Validate feature_report hash properties against schema.
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 |
# File 'lib/urbanopt/scenario/default_reports/feature_report.rb', line 181 def to_hash result = {} result[:id] = @id if @id result[:name] = @name if @name result[:directory_name] = @directory_name if @directory_name result[:feature_type] = @feature_type if @feature_type result[:timesteps_per_hour] = @timesteps_per_hour if @timesteps_per_hour result[:simulation_status] = @simulation_status if @simulation_status result[:timeseries_csv] = @timeseries_csv.to_hash result[:location] = @location.to_hash if @location result[:program] = @program.to_hash result[:construction_costs] = [] @construction_costs.each { |cc| result[:construction_costs] << cc.to_hash } result[:reporting_periods] = [] @reporting_periods.each { |rp| result[:reporting_periods] << rp.to_hash } result[:distributed_generation] = @distributed_generation.to_hash if @distributed_generation # validate feature_report properties against schema if @@validator.validate(@@schema[:definitions][:FeatureReport][:properties], result).any? raise "feature_report properties does not match schema: #{@@validator.validate(@@schema[:definitions][:FeatureReport][:properties], result)}" end return result end |