urbanopt-scenario 0.10.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,115 +10,106 @@ require 'json'
10
10
  require 'fileutils'
11
11
 
12
12
  module URBANopt
13
- module Scenario
14
- class DISCOPostProcessor
15
- ##
16
- # DISCOPostProcessor post-processes DISCO results to selected DISCO results and
17
- # integrate them in scenario and feature reports.
18
- ##
19
- # [parameters:]
20
- # * +scenaro_report+ - _ScenarioBase_ - An object of Scenario_report class.
21
- # * +disco_results_dir_name+ - _directory name of disco results
22
- def initialize(scenario_report, disco_results_dir_name = 'disco')
23
- if !scenario_report.nil?
24
- @scenario_report = scenario_report
25
- @disco_results_dir = File.join(@scenario_report.directory_name, disco_results_dir_name)
26
- else
27
- raise 'scenario_report is not valid'
28
- end
29
-
30
- # initialize disco data
31
- @disco_data = {}
32
-
33
- # initialize disco json results
34
- @disco_json_results = {}
35
-
36
- # initialize logger
37
- @@logger ||= URBANopt::Reporting::DefaultReports.logger
38
- end
39
-
40
- # load disco data (if exists)
41
- def load_disco_data
42
-
43
- # load disco upgrade summary
44
- disco_json_filename = File.join(@disco_results_dir, 'upgrade_summary.json')
45
- if File.exist?(disco_json_filename)
46
- @disco_json_results = JSON.parse(File.read(disco_json_filename))
47
- end
48
-
49
- end
50
-
51
- # load disco data
52
- def load_data
53
- # load selected disco data
54
- load_disco_data
55
- end
56
-
57
-
58
- ##
59
- # save disco scenario fields
60
- ##
61
- def save_disco_scenario
62
- @scenario_report.scenario_power_distribution_cost = URBANopt::Reporting::DefaultReports::ScenarioPowerDistributionCost.new
63
-
64
- # RESULTS
65
-
66
- res = []
67
- # read result from JSON report
68
- res = @disco_json_results['results']
69
- @scenario_report.scenario_power_distribution_cost.results = res
70
-
71
-
72
-
73
- # OUTPUTS
74
-
75
- out = {}
76
- # read result from JSON report
77
- out[:log_file] = @disco_json_results['outputs']['log_file']
78
- out[:jobs] = []
79
- @disco_json_results['outputs']['jobs'].each do |job|
80
- out[:jobs] << job
81
- end
82
- @scenario_report.scenario_power_distribution_cost.outputs = out
83
-
84
- # VIOLATION SUMMARY
85
-
86
- vio = []
87
- # read result from JSON report
88
- vio = @disco_json_results['violation_summary']
89
- @scenario_report.scenario_power_distribution_cost.violation_summary = vio
90
-
91
- # COSTS PER EQUIPMENT
92
- cos = []
93
- # read result from JSON report
94
- cos = @disco_json_results['costs_per_equipment']
95
- @scenario_report.scenario_power_distribution_cost.costs_per_equipment = cos
96
-
97
- # EQUIPMENT
98
- equ = []
99
- # read result from JSON report
100
- equ = @disco_json_results['equipment']
101
- @scenario_report.scenario_power_distribution_cost.equipment = equ
102
-
103
- end
104
-
105
- ##
106
- # run disco post_processor
107
- ##
108
- def run
109
-
110
- # load data
111
- load_data
112
-
113
- # save additional global disco fields
114
- save_disco_scenario
115
-
116
- # save the updated scenario reports
117
- # set save_feature_reports to false since only the scenario reports should be saved
118
- # now, set save csv reports to false
119
- @scenario_report.save(file_name = 'scenario_report_disco', save_feature_reports = false, save_csv_reports = false)
120
- end
13
+ module Scenario
14
+ class DISCOPostProcessor
15
+ ##
16
+ # DISCOPostProcessor post-processes DISCO results to selected DISCO results and
17
+ # integrate them in scenario and feature reports.
18
+ ##
19
+ # [parameters:]
20
+ # * +scenaro_report+ - _ScenarioBase_ - An object of Scenario_report class.
21
+ # * +disco_results_dir_name+ - _directory name of disco results
22
+ def initialize(scenario_report, disco_results_dir_name = 'disco')
23
+ if !scenario_report.nil?
24
+ @scenario_report = scenario_report
25
+ @disco_results_dir = File.join(@scenario_report.directory_name, disco_results_dir_name)
26
+ else
27
+ raise 'scenario_report is not valid'
28
+ end
29
+
30
+ # initialize disco data
31
+ @disco_data = {}
32
+
33
+ # initialize disco json results
34
+ @disco_json_results = {}
121
35
 
36
+ # initialize logger
37
+ @@logger ||= URBANopt::Reporting::DefaultReports.logger
38
+ end
39
+
40
+ # load disco data (if exists)
41
+ def load_disco_data
42
+ # load disco upgrade summary
43
+ disco_json_filename = File.join(@disco_results_dir, 'upgrade_summary.json')
44
+ if File.exist?(disco_json_filename)
45
+ @disco_json_results = JSON.parse(File.read(disco_json_filename))
46
+ end
47
+ end
48
+
49
+ # load disco data
50
+ def load_data
51
+ # load selected disco data
52
+ load_disco_data
53
+ end
54
+
55
+ ##
56
+ # save disco scenario fields
57
+ ##
58
+ def save_disco_scenario
59
+ @scenario_report.scenario_power_distribution_cost = URBANopt::Reporting::DefaultReports::ScenarioPowerDistributionCost.new
60
+
61
+ # RESULTS
62
+
63
+ res = []
64
+ # read result from JSON report
65
+ res = @disco_json_results['results']
66
+ @scenario_report.scenario_power_distribution_cost.results = res
67
+
68
+ # OUTPUTS
69
+
70
+ out = {}
71
+ # read result from JSON report
72
+ out[:log_file] = @disco_json_results['outputs']['log_file']
73
+ out[:jobs] = []
74
+ @disco_json_results['outputs']['jobs'].each do |job|
75
+ out[:jobs] << job
122
76
  end
77
+ @scenario_report.scenario_power_distribution_cost.outputs = out
78
+
79
+ # VIOLATION SUMMARY
80
+
81
+ vio = []
82
+ # read result from JSON report
83
+ vio = @disco_json_results['violation_summary']
84
+ @scenario_report.scenario_power_distribution_cost.violation_summary = vio
85
+
86
+ # COSTS PER EQUIPMENT
87
+ cos = []
88
+ # read result from JSON report
89
+ cos = @disco_json_results['costs_per_equipment']
90
+ @scenario_report.scenario_power_distribution_cost.costs_per_equipment = cos
91
+
92
+ # EQUIPMENT
93
+ equ = []
94
+ # read result from JSON report
95
+ equ = @disco_json_results['equipment']
96
+ @scenario_report.scenario_power_distribution_cost.equipment = equ
97
+ end
98
+
99
+ ##
100
+ # run disco post_processor
101
+ ##
102
+ def run
103
+ # load data
104
+ load_data
105
+ # save additional global disco fields
106
+ save_disco_scenario
107
+
108
+ # save the updated scenario reports
109
+ # set save_feature_reports to false since only the scenario reports should be saved
110
+ # now, set save csv reports to false
111
+ @scenario_report.save(file_name = 'scenario_report_disco', save_feature_reports = false, save_csv_reports = false)
112
+ end
123
113
  end
114
+ end
124
115
  end
@@ -121,13 +121,20 @@ module URBANopt
121
121
  # retrieve all transformers
122
122
  trsfmrs = @opendss_json_results['model'].select { |d| d['class'] == 'PowerTransformer' }
123
123
  trsfmrs.each do |item|
124
- t = { 'nominal_capacity': nil, 'reactance_resistance_ratio': nil }
124
+ t = { 'nominal_capacity': nil, 'reactance_resistance_ratio': nil, 'incoming_voltage': nil, 'outgoing_voltage': nil }
125
125
  name = item['name']['value']
126
126
 
127
127
  # nominal capacity in kVA (Model.json stores it in VA)
128
128
  # TODO: assuming that all windings would have the same rated power, so grabbing first one
129
129
  begin
130
- t['nominal_capacity'] = item['windings']['value'][0]['rated_power']['value'] / 1000
130
+ t[:nominal_capacity] = item['windings']['value'][0]['rated_power']['value'] / 1000
131
+ rescue StandardError
132
+ end
133
+
134
+ # Voltage on each side of the transformer
135
+ begin
136
+ t[:incoming_voltage] = item['windings']['value'][0]['nominal_voltage']['value']
137
+ t[:outgoing_voltage] = item['windings']['value'][1]['nominal_voltage']['value']
131
138
  rescue StandardError
132
139
  end
133
140
 
@@ -137,7 +144,7 @@ module URBANopt
137
144
  reactance = item['reactances']['value'][0]['value']
138
145
  resistance = item['windings']['value'][0]['resistance']['value']
139
146
 
140
- t['reactance_resistance_ratio'] = reactance / resistance
147
+ t[:reactance_resistance_ratio] = reactance / resistance
141
148
  rescue StandardError
142
149
  end
143
150
 
@@ -155,8 +162,8 @@ module URBANopt
155
162
  if k.include? 'Transformer'
156
163
  t_key = k.sub('Transformer.', '')
157
164
  # create transformer directory
158
- transformer_dir = File.join(@scenario_report.directory_name, k)
159
- FileUtils.mkdir_p(File.join(transformer_dir, 'feature_reports'))
165
+ transformer_dir = Pathname(@scenario_report.directory_name) / k
166
+ FileUtils.mkdir_p(Pathname(transformer_dir) / 'feature_reports')
160
167
 
161
168
  # write data to csv
162
169
  # store under voltages and over voltages
@@ -164,9 +171,13 @@ module URBANopt
164
171
  over_voltage_hrs = 0
165
172
  nominal_capacity = nil
166
173
  r_r_ratio = nil
174
+ tx_incoming_voltage = nil
175
+ tx_outgoing_voltage = nil
167
176
  begin
168
- nominal_capacity = t_res[t_key]['nominal_capacity']
169
- r_r_ratio = t_res[t_key]['reactance_resistance_ratio']
177
+ nominal_capacity = t_res[t_key][:nominal_capacity]
178
+ r_r_ratio = t_res[t_key][:reactance_resistance_ratio]
179
+ tx_incoming_voltage = t_res[t_key][:incoming_voltage]
180
+ tx_outgoing_voltage = t_res[t_key][:outgoing_voltage]
170
181
  rescue StandardError
171
182
  end
172
183
 
@@ -187,7 +198,7 @@ module URBANopt
187
198
  end
188
199
 
189
200
  # save transformer CSV report
190
- File.write(File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss.csv'), transformer_csv)
201
+ File.write(Pathname(transformer_dir) / 'feature_reports' / 'default_feature_report_opendss.csv', transformer_csv)
191
202
 
192
203
  # create transformer report
193
204
  transformer_report = URBANopt::Reporting::DefaultReports::FeatureReport.new(id: k, name: k, directory_name: transformer_dir, feature_type: 'Transformer',
@@ -199,13 +210,15 @@ module URBANopt
199
210
  transformer_report.power_distribution.under_voltage_hours = under_voltage_hrs
200
211
  transformer_report.power_distribution.nominal_capacity = nominal_capacity
201
212
  transformer_report.power_distribution.reactance_resistance_ratio = r_r_ratio
213
+ transformer_report.power_distribution.tx_incoming_voltage = tx_incoming_voltage
214
+ transformer_report.power_distribution.tx_outgoing_voltage = tx_outgoing_voltage
202
215
 
203
216
  ## save transformer JSON file
204
217
  # transformer_hash
205
218
  transformer_hash = transformer_report.to_hash
206
219
  # transformer_hash.delete_if { |k, v| v.nil? }
207
220
 
208
- json_name_path = File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss.json')
221
+ json_name_path = Pathname(transformer_dir) / 'feature_reports' / 'default_feature_report_opendss.json'
209
222
 
210
223
  # save the json file
211
224
  File.open(json_name_path, 'w') do |f|
@@ -5,6 +5,6 @@
5
5
 
6
6
  module URBANopt
7
7
  module Scenario
8
- VERSION = '0.10.0'.freeze
8
+ VERSION = '0.12.0'.freeze
9
9
  end
10
10
  end
@@ -24,11 +24,11 @@ Gem::Specification.new do |spec|
24
24
  spec.required_ruby_version = '~> 2.7.0'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 2.1'
27
- spec.add_development_dependency 'rake', '~> 13.0'
28
- spec.add_development_dependency 'rspec', '~> 3.9'
27
+ spec.add_development_dependency 'rake', '~> 13.1'
28
+ spec.add_development_dependency 'rspec', '~> 3.12'
29
29
  spec.add_development_dependency 'simplecov', '~> 0.18.2'
30
30
  spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
31
- spec.add_runtime_dependency 'sqlite3', '~> 1.6'
32
- spec.add_runtime_dependency 'urbanopt-core', '~> 0.10.0'
33
- spec.add_runtime_dependency 'urbanopt-reporting', '~> 0.8.0'
31
+ spec.add_runtime_dependency 'sqlite3', '~> 1.6.0'
32
+ spec.add_runtime_dependency 'urbanopt-core', '~> 0.11.0'
33
+ spec.add_runtime_dependency 'urbanopt-reporting', '~> 0.10.0'
34
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urbanopt-scenario
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rawad El Kontar
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-07-20 00:00:00.000000000 Z
12
+ date: 2024-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -31,28 +31,28 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '13.0'
34
+ version: '13.1'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '13.0'
41
+ version: '13.1'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '3.9'
48
+ version: '3.12'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '3.9'
55
+ version: '3.12'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: simplecov
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -87,42 +87,42 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '1.6'
90
+ version: 1.6.0
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '1.6'
97
+ version: 1.6.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: urbanopt-core
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: 0.10.0
104
+ version: 0.11.0
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: 0.10.0
111
+ version: 0.11.0
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: urbanopt-reporting
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: 0.8.0
118
+ version: 0.10.0
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: 0.8.0
125
+ version: 0.10.0
126
126
  description: Library to export data point OSW files from URBANopt Scenario CSV
127
127
  email:
128
128
  - rawad.elkontar@nrel.gov
@@ -141,7 +141,6 @@ files:
141
141
  - CHANGELOG.md
142
142
  - CONTRIBUTING.md
143
143
  - Gemfile
144
- - Jenkinsfile
145
144
  - LICENSE.md
146
145
  - RDOC_MAIN.md
147
146
  - README.md
data/Jenkinsfile DELETED
@@ -1,10 +0,0 @@
1
- //Jenkins pipelines are stored in shared libraries. Please see: https://github.com/NREL/cbci_jenkins_libs
2
-
3
- @Library('cbci_shared_libs') _
4
-
5
- // Build for PR to develop branch only.
6
- if ((env.CHANGE_ID) && (env.CHANGE_TARGET) ) { // check if set
7
-
8
- urbanopt_scenario_gem()
9
-
10
- }