Class: URBANopt::RNM::PostProcessor
- Inherits:
-
Object
- Object
- URBANopt::RNM::PostProcessor
- Defined in:
- lib/urbanopt/rnm/post_processor.rb
Instance Method Summary collapse
-
#calculate_stats ⇒ Object
Calculate report statistics from raw results.
-
#generate_feature_file ⇒ Object
Generate new GeoJSON file.
-
#generate_report ⇒ Object
Generate Scenario report.
-
#get_scenario ⇒ Object
Load Scenario Report.
-
#initialize(results, scenario_dir, feature_file, reopt: false) ⇒ PostProcessor
constructor
Initialize Post-Processor.
-
#post_process ⇒ Object
Post Process report and feature file.
Constructor Details
#initialize(results, scenario_dir, feature_file, reopt: false) ⇒ PostProcessor
Initialize Post-Processor
- parameters:
-
results
- Hash - Hash of RNM-US results returned from the API -
scenario
- String - Path to scenario_dir
17 18 19 20 21 22 23 24 25 |
# File 'lib/urbanopt/rnm/post_processor.rb', line 17 def initialize(results, scenario_dir, feature_file, reopt: false) @results = results @scenario_dir = scenario_dir @results_dir = File.join(@scenario_dir, 'rnm-us', 'results') @report_filename = 'scenario_report_rnm.json' @geojson_filename = 'feature_file_rnm.json' @feature_file = feature_file @reopt = reopt end |
Instance Method Details
#calculate_stats ⇒ Object
Calculate report statistics from raw results
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 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 174 175 176 177 178 179 180 |
# File 'lib/urbanopt/rnm/post_processor.rb', line 90 def calculate_stats # calculate statistics and append to scenario report stats = {} # demand generation planning stats['demand_generation_planning'] = [] @results['Demand/generation and number of consumers/distributed generators'].each do |item| rec = {} puts "ITEM VOLTAGE LEVEL: #{item['Voltage level']}, item type: #{item['Type'].strip}" case item['Voltage level'] when 'LV' rec['type'] = "Low Voltage (LV) #{item['Type'].strip}" when 'MV' rec['type'] = "Medium Voltage (MV) #{item['Type'].strip}" else rec['type'] = item['Voltage level'] + item['Type'].strip end if item['Type'].strip == 'Consumers' # consumers rec['peak_demand_kw'] = item['Peak demand/generation (kW)'] elsif item['Type'].include? 'generators' # generators rec['max_generation_kw'] = item['Peak demand/generation (kW)'] else rec['peak_demand_generation_kw'] = item['Peak demand/generation (kW)'] end rec['number_of_nodes_in_network'] = item['Number'] stats['demand_generation_planning'] << rec end # lines LV and MV stats['electrical_lines_length'] = {} km_to_mi = 0.621371 @results['Length of overhead and underground electrical lines'].each do |item| case item['Voltage level'] when 'Lines LV' stats['electrical_lines_length']['low_voltage'] = {} stats['electrical_lines_length']['low_voltage']['overhead_mi'] = (item['Overhead (km)'] * km_to_mi).round(4) stats['electrical_lines_length']['low_voltage']['underground_mi'] = (item['Underground (km)'] * km_to_mi).round(4) when 'Lines MV' stats['electrical_lines_length']['medium_voltage'] = {} stats['electrical_lines_length']['medium_voltage']['overhead_mi'] = (item['Overhead (km)'] * km_to_mi).round(4) stats['electrical_lines_length']['medium_voltage']['underground_mi'] = (item['Underground (km)'] * km_to_mi).round(4) end end transformer_capacity = 0 @results['Substations and distribution transformers'].each do |item| transformer_capacity += item['Size (kVA)'] * item['Number'] end stats['distribution_transformers_capacity_kva'] = transformer_capacity # costs stats['costs'] = {} stats['costs']['investment'] = {} stats['costs']['yearly_maintenance'] = {} @results['Summary'].each do |item| case item['Level'] when 'LV' stats['costs']['investment']['low_voltage_network'] = item['Investment cost'] stats['costs']['yearly_maintenance']['low_voltage_network'] = item['Preventive maintenance (yearly)'] when 'MV' stats['costs']['investment']['medium_voltage_network'] = item['Investment cost'] stats['costs']['yearly_maintenance']['medium_voltage_network'] = item['Preventive maintenance (yearly)'] when 'Dist.Transf.' stats['costs']['investment']['distribution_transformers'] = item['Investment cost'] stats['costs']['yearly_maintenance']['distribution_transformers'] = item['Preventive maintenance (yearly)'] when 'HV/MV Subest.' stats['costs']['investment']['primary_substations'] = item['Investment cost'] stats['costs']['yearly_maintenance']['primary_substations'] = item['Preventive maintenance (yearly)'] end end # cost totals inv_tot = 0 stats['costs']['investment'].each do |key, val| inv_tot += val end stats['costs']['investment']['total'] = inv_tot maint_tot = 0 stats['costs']['yearly_maintenance'].each do |key, val| maint_tot += val end stats['costs']['yearly_maintenance']['total'] = maint_tot # reliability indexes stats['reliability_indexes'] = {} # sum of interruptions duration / num customers. 6 would be too high stats['reliability_indexes']['SAIDI'] = @results['Reliability indexes'][0]['ASIDI'] # num interruptions / num customers. should be < 1 stats['reliability_indexes']['SAIFI'] = @results['Reliability indexes'][0]['ASIFI'] return stats end |
#generate_feature_file ⇒ Object
Generate new GeoJSON file
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/urbanopt/rnm/post_processor.rb', line 72 def generate_feature_file # get results GeoJSON file and read in results = JSON.parse(File.read(File.join(@results_dir, 'GeoJSON', 'Distribution_system.json'))) # merge the two files results['features'].each do |feature| @feature_file['features'].append(feature) end # save back to scenario directory as features_and_rnm.json File.open(File.join(@scenario_dir, @geojson_filename), 'w') do |f| f.write(JSON.pretty_generate(@feature_file)) end end |
#generate_report ⇒ Object
Generate Scenario report
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/urbanopt/rnm/post_processor.rb', line 39 def generate_report # calculate rnm statistics rnm_stats = calculate_stats # get scenario scenario = get_scenario # merge stats with scenario report (before feature_reports section) scenario['scenario_report']['rnm_results'] = rnm_stats # save back to scenario directory as scenario_report_rnm.json File.open(File.join(@scenario_dir, @report_filename), 'w') do |f| f.write(JSON.pretty_generate(scenario)) end end |
#get_scenario ⇒ Object
Load Scenario Report
59 60 61 62 63 64 65 66 67 |
# File 'lib/urbanopt/rnm/post_processor.rb', line 59 def get_scenario if @reopt # get reopt scenario report return JSON.parse(File.read(File.join(@scenario_dir, 'feature_optimization.json'))) else # get default scenario report return JSON.parse(File.read(File.join(@scenario_dir, 'default_scenario_report.json'))) end end |
#post_process ⇒ Object
Post Process report and feature file
30 31 32 33 34 |
# File 'lib/urbanopt/rnm/post_processor.rb', line 30 def post_process generate_report generate_feature_file puts "RNM results were added to scenario report and feature file. New files can be found in #{@results_dir}" end |