Skip to content

Commit

Permalink
Merge pull request #217 from urbanopt/develop
Browse files Browse the repository at this point in the history
version 0.6.2
  • Loading branch information
kflemin authored Jul 1, 2021
2 parents b415bfa + d45ca99 commit fb140c9
Show file tree
Hide file tree
Showing 19 changed files with 20,311 additions and 2,039 deletions.
5 changes: 2 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ AllCops:
- gems/**/*
- measures/**/*
- spec/files/**/measures/**/*

require: rubocop-performance

inherit_from:
- http://s3.amazonaws.com/openstudio-resources/styles/rubocop_v3.yml

- http://s3.amazonaws.com/openstudio-resources/styles/rubocop_v4.yml
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# URBANopt Scenario Gem

## Version 0.6.2
Date Range: 05/15/21 - 06/30/21:

- Fixed [#214]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/214 ), update rubocop configs to v4
- Fixed [#207]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/207 ), Update Load-Flex measure gem version
- Fixed [#215]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/215 ), update rubocop to v4 #214

## Version 0.6.1
Date Range: 04-30-21 - 05/14/21

Expand Down
22,239 changes: 20,253 additions & 1,986 deletions docs/package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
"highlight.js": "^10.4.1",
"json-schema-ref-parser": "^9.0.6",
"json-schema-view-js": "git+https://[email protected]/bgschiller/json-schema-view-js.git",
"vuepress": "^1.6.0",
"webpack-dev-middleware": "^3.6.0"
},
"devDependencies": {
"braces": "^3.0.2",
"dot-prop": "^5.3.0",
"gh-pages": "^3.1.0",
"ini": "^2.0.0",
"is-svg": ">=4.3.1",
"js-yaml": "^3.14.0",
"minimist": ">=1.2.3",
"node-forge": ">=0.10.0",
"postcss": "^8.2.15",
"serialize-javascript": "^5.0.1",
"set-value": "^3.0.2",
"ssri": ">=8.0.1",
"yargs-parser": "^20.2.1",
"ini": "^2.0.0"
"vuepress": "^1.8.2",
"yargs-parser": "^20.2.1"
}
}
2 changes: 1 addition & 1 deletion lib/urbanopt/scenario/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

module URBANopt
module Scenario
@@logger = Logger.new(STDOUT)
@@logger = Logger.new($stdout)

# Definining class variable "@@logger" to log errors, info and warning messages.
def self.logger
Expand Down
10 changes: 4 additions & 6 deletions lib/urbanopt/scenario/scenario_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def initialize(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file

# Require all simulation mappers in mapper_files_dir
def load_mapper_files

# loads default values from extension gem
options = OpenStudio::Extension::RunnerConfig.default_config
# check if runner.conf file exists
Expand All @@ -94,9 +93,9 @@ def load_mapper_files

# bundle path is assigned from the runner.conf if it exists or is assigned in the root_dir
bundle_path = !options.key?(:bundle_install_path) || options[:bundle_install_path] === '' ? File.join(@root_dir, '.bundle/install/') : options[:bundle_install_path]

# checks if bundle path doesn't exist or is empty
if !Dir.exists?(bundle_path) or Dir.empty?(bundle_path)
if !Dir.exist?(bundle_path) || Dir.empty?(bundle_path)
# install bundle
OpenStudio::Extension::Runner.new(@root_dir)
end
Expand All @@ -107,8 +106,8 @@ def load_mapper_files
# for now only add openstudio and urbanopt gems to the load path
# and only those with 'urbanopt' or 'openstudio' in the before-last path position
tmp_path_arr = Pathname(ld).each_filename.to_a
if tmp_path_arr[-2].include? 'urbanopt' or tmp_path_arr[-2].include? 'openstudio'
puts "adding DIR to load path: #{ld}"
if tmp_path_arr[-2].include?('urbanopt') || tmp_path_arr[-2].include?('openstudio')
# puts "adding DIR to load path: #{ld}"
$LOAD_PATH.unshift(ld)
end
end
Expand All @@ -121,7 +120,6 @@ def load_mapper_files
@@logger.error(e.message)
raise
end

end

# Gets all the simulation directories
Expand Down
10 changes: 5 additions & 5 deletions lib/urbanopt/scenario/scenario_datapoint_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
module URBANopt
module Scenario
class ScenarioDatapoint
attr_reader :scenario, :feature_id, :feature_name, :mapper_class #:nodoc:#
attr_reader :scenario, :feature_id, :feature_name, :mapper_class, :feature #:nodoc:#

##
# ScenarioDatapoint is an agnostic description of the simulation of a Feature in a Scenario
Expand All @@ -58,9 +58,7 @@ def initialize(scenario, feature_id, feature_name, mapper_class)
@feature_name = feature_name
@feature = scenario.feature_file.get_feature_by_id(feature_id)
@mapper_class = mapper_class
end

attr_reader :feature #:nodoc:
end #:nodoc:

##
# Gets the type of a feature
Expand All @@ -83,7 +81,8 @@ def feature_location
def run_dir
raise 'Feature ID not set' if @feature_id.nil?
raise 'Scenario run dir not set' if @scenario.run_dir.nil?
return File.join(@scenario.run_dir, @feature_id + '/')

return File.join(@scenario.run_dir, "#{@feature_id}/")
end

##
Expand Down Expand Up @@ -138,6 +137,7 @@ def out_of_date?
if !File.exist?(out_osw)
return true
end

out_osw_time = File.mtime(out_osw)

# array of files that this datapoint depends on
Expand Down
8 changes: 4 additions & 4 deletions lib/urbanopt/scenario/scenario_post_processor_default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def create_scenario_db_file(file_name = @default_save_name)
feature_list = Pathname.new(@initialization_hash[:directory_name]).children.select(&:directory?) # Folders in the run/scenario directory

# get scenario CSV
scenario_csv = File.join(@initialization_hash[:root_dir], @initialization_hash[:name] + '.csv')
scenario_csv = File.join(@initialization_hash[:root_dir], "#{@initialization_hash[:name]}.csv")
if File.exist?(scenario_csv)
# csv found
feature_ids = CSV.read(scenario_csv, headers: true)
Expand Down Expand Up @@ -159,7 +159,7 @@ def create_scenario_db_file(file_name = @default_save_name)
# running sum
arr_match[:elec_val] += Float(row[7])
end
end # End elec_query
end
elec_query.close

gas_query = feature_db.query "SELECT ReportData.TimeIndex, Time.Year, Time.Month, Time.Day, Time.Hour,
Expand All @@ -182,10 +182,10 @@ def create_scenario_db_file(file_name = @default_save_name)
# running sum
arr_match[:gas_val] += Float(row[7])
end
end # End gas_query
end
gas_query.close
feature_db.close
end # End feature_list loop
end

elec_sql = []
gas_sql = []
Expand Down
12 changes: 6 additions & 6 deletions lib/urbanopt/scenario/scenario_post_processor_opendss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def load_opendss_data
# load building features data
@scenario_report.feature_reports.each do |feature_report|
# read results from opendss
opendss_csv = CSV.read(File.join(@opendss_results_dir, 'results', 'Features', feature_report.id + '.csv'))
opendss_csv = CSV.read(File.join(@opendss_results_dir, 'results', 'Features', "#{feature_report.id}.csv"))
# add results to data
@opendss_data[feature_report.id] = opendss_csv
end
Expand All @@ -102,7 +102,7 @@ def load_opendss_data
# add transformer results to @opendss_data
transformer_ids.each do |id|
# read results from transformers
transformer_csv = CSV.read(File.join(tf_results_path, id + '.csv'))
transformer_csv = CSV.read(File.join(tf_results_path, "#{id}.csv"))
# add results to data
@opendss_data[id] = transformer_csv
end
Expand Down Expand Up @@ -133,7 +133,7 @@ def merge_data(feature_report_data, opendss_data)
if row.include? 'Datetime'
row.map { |header| header.prepend('opendss_') }
end
csv << (feature_report_data[i] + row[1..-1])
csv << (feature_report_data[i] + row[1..])
end
end

Expand All @@ -142,7 +142,7 @@ def merge_data(feature_report_data, opendss_data)

# add feature reports for transformers
def save_transformers_reports
@opendss_data.keys.each do |k|
@opendss_data.each_key do |k|
if k.include? 'Transformer'

# create transformer directory
Expand Down Expand Up @@ -171,7 +171,7 @@ def save_transformers_reports
end

# save transformer CSV report
File.write(File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss' + '.csv'), transformer_csv)
File.write(File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss.csv'), transformer_csv)

# create transformer report
transformer_report = URBANopt::Reporting::DefaultReports::FeatureReport.new(id: k, name: k, directory_name: transformer_dir, feature_type: 'Transformer',
Expand All @@ -187,7 +187,7 @@ def save_transformers_reports
transformer_hash = transformer_report.to_hash
# transformer_hash.delete_if { |k, v| v.nil? }

json_name_path = File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss' + '.json')
json_name_path = File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss.json')

# save the json file
File.open(json_name_path, 'w') do |f|
Expand Down
7 changes: 4 additions & 3 deletions lib/urbanopt/scenario/scenario_runner_osw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ def run(scenario, force_clear = false, options = {})
# add each osw file to its corresponding group id +simulation_dir+ is out_of_date
if simulation_dir.out_of_date?

if feature_type == 'Building'
case feature_type
when 'Building'
building_osws << simulation_dir.in_osw_path
elsif feature_type == 'District System'
when 'District System'
district_system_osws << simulation_dir.in_osw_path
elsif feature_type == 'Transformer'
when 'Transformer'
transformer_osws << simulation_dir.in_osw_path
else
raise "ScenarioRunnerOSW does not know how to run a #{feature_type} feature"
Expand Down
14 changes: 7 additions & 7 deletions lib/urbanopt/scenario/scenario_visualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def self.create_visualization(run_dir, feature = true, feature_names = false)

run_dir.each do |folder|
# create visualization for scenarios
if feature == false
case feature
when false
name = folder.split('/')[-1]
csv_dir = File.join(folder, 'default_scenario_report.csv')
# create visualization for features
elsif feature == true
when true
index = run_dir.index(folder)
name = folder.split('/')[-1] + '-' + feature_names[index]
name = "#{folder.split('/')[-1]}-#{feature_names[index]}"
csv_dir = File.join(folder, 'feature_reports/default_feature_report.csv')
end

Expand Down Expand Up @@ -192,7 +193,6 @@ def self.create_visualization(run_dir, feature = true, feature_names = false)
monthly_sum_dec += v.to_f
i += 1
end

end
end

Expand Down Expand Up @@ -241,6 +241,6 @@ def self.create_visualization(run_dir, feature = true, feature_names = false)
file << "var scenarioData = #{JSON.pretty_generate(@all_results)};"
end
end
end # ResultVisualization
end # Scenario
end # URBANopt
end
end
end
6 changes: 1 addition & 5 deletions lib/urbanopt/scenario/simulation_dir_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ def initialize(scenario, features, feature_names)
@feature_names = feature_names
end

attr_reader :scenario #:nodoc:

attr_reader :features #:nodoc:

attr_reader :feature_names #:nodoc:
attr_reader :scenario, :features, :feature_names #:nodoc: #:nodoc: #:nodoc:

##
# Return the directory that this simulation will run in
Expand Down
4 changes: 3 additions & 1 deletion lib/urbanopt/scenario/simulation_dir_osw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ def initialize(scenario, features, feature_names, mapper_class)
end

attr_reader :mapper_class, :feature_id

##
# Return the directory that this simulation will run in.
##
def run_dir
raise 'Feature ID not set' if @feature_id.nil?
raise 'Scenario run dir not set' if scenario.run_dir.nil?
return File.join(scenario.run_dir, @feature_id + '/')

return File.join(scenario.run_dir, "#{@feature_id}/")
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/urbanopt/scenario/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@

module URBANopt
module Scenario
VERSION = '0.6.1'.freeze
VERSION = '0.6.2'.freeze
end
end
4 changes: 2 additions & 2 deletions spec/files/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ allow_local = ENV['FAVOR_LOCAL_GEMS']
#

if allow_local && File.exist?('../../../urbanopt-reporting-gem')
gem 'urbanopt-reporting', path: '../../../urbanopt-reporting-gem'
gem 'urbanopt-reporting', path: '../../../urbanopt-reporting-gem'
elsif allow_local
gem 'urbanopt-reporting', github: 'URBANopt/urbanopt-reporting-gem', branch: 'develop'
else
gem 'urbanopt-reporting', '~> 0.4.0'
gem 'urbanopt-reporting', '~> 0.4.0'
end

if allow_local && File.exist?('../../../openstudio-common-measures-gem')
Expand Down
1 change: 1 addition & 0 deletions spec/files/mappers/TestMapper1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def create_osw(scenario, features, feature_names)
if features.size != 1
raise 'TestMapper1 currently cannot simulate more than one feature'
end

feature = features[0]

feature_name = feature.name
Expand Down
2 changes: 1 addition & 1 deletion spec/urbanopt/urbanopt_scenario_reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@

it 'can create visualization for feature result' do
run_dir = [File.join(File.dirname(__FILE__), '../vis_test/baseline_scenario/1'), File.join(File.dirname(__FILE__), '../vis_test/baseline_scenario/2')]
feature_names = ["Building_1", "Building_2"]
feature_names = ['Building_1', 'Building_2']

scenario_visualization = URBANopt::Scenario::ResultVisualization.create_visualization(run_dir, true, feature_names)

Expand Down
4 changes: 2 additions & 2 deletions spec/vis_test/baseline_scenario/scenarioData.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var scenarioData = [
{
"name": "1",
"name": "1-Building_1",
"monthly_values": {
"Electricity:Facility": [
1833016.431105801,
Expand Down Expand Up @@ -1403,7 +1403,7 @@ var scenarioData = [
"complete_simulation": true
},
{
"name": "2",
"name": "2-Building_2",
"monthly_values": {
"Electricity:Facility": [
2083432.9873940796,
Expand Down
6 changes: 3 additions & 3 deletions urbanopt-scenario-gem.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.7'

spec.add_runtime_dependency 'json-schema', '~> 2.8'
spec.add_runtime_dependency 'json_pure', '~> 2.3'
spec.add_runtime_dependency 'json-schema', '~> 2.8'

spec.add_runtime_dependency 'sqlite3', '1.4.2'
spec.add_runtime_dependency 'urbanopt-core', '~> 0.6.0'
spec.add_runtime_dependency 'urbanopt-reporting', '~> 0.4.0'
spec.add_runtime_dependency 'urbanopt-core', '~> 0.6.1'
spec.add_runtime_dependency 'urbanopt-reporting', '~> 0.4.1'

# no longer need the below
# need to include all measure gems listed in mappers in project gemfiles
Expand Down

0 comments on commit fb140c9

Please sign in to comment.