urbanopt-scenario 0.3.0.pre1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +3 -3
- data/.gitignore +2 -0
- data/CHANGELOG.md +60 -2
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +33 -17
- data/Jenkinsfile +1 -1
- data/LICENSE.md +1 -1
- data/RDOC_MAIN.md +2 -2
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/docs/.vuepress/components/InnerJsonSchema.vue +7 -15
- data/docs/.vuepress/config.js +13 -9
- data/docs/.vuepress/highlight.js +1 -1
- data/docs/.vuepress/json-schema-deref-loader.js +22 -0
- data/docs/README.md +2 -2
- data/docs/package-lock.json +2384 -2323
- data/docs/package.json +12 -8
- data/lib/urbanopt-scenario.rb +1 -1
- data/lib/urbanopt/scenario.rb +2 -1
- data/lib/urbanopt/scenario/default_reports.rb +3 -8
- data/lib/urbanopt/scenario/extension.rb +6 -4
- data/lib/urbanopt/scenario/logger.rb +1 -1
- data/lib/urbanopt/scenario/scenario_base.rb +5 -5
- data/lib/urbanopt/scenario/scenario_csv.rb +29 -17
- data/lib/urbanopt/scenario/scenario_datapoint_base.rb +12 -5
- data/lib/urbanopt/scenario/scenario_post_processor_base.rb +3 -3
- data/lib/urbanopt/scenario/scenario_post_processor_default.rb +121 -11
- data/lib/urbanopt/scenario/scenario_post_processor_opendss.rb +13 -14
- data/lib/urbanopt/scenario/scenario_runner_base.rb +8 -7
- data/lib/urbanopt/scenario/scenario_runner_osw.rb +29 -13
- data/lib/urbanopt/scenario/scenario_visualization.rb +235 -0
- data/lib/urbanopt/scenario/simulation_dir_base.rb +4 -4
- data/lib/urbanopt/scenario/simulation_dir_osw.rb +6 -13
- data/lib/urbanopt/scenario/simulation_mapper_base.rb +4 -4
- data/lib/urbanopt/scenario/version.rb +2 -2
- data/package-lock.json +3 -0
- data/urbanopt-scenario-gem.gemspec +11 -10
- metadata +80 -57
- data/doc_templates/LICENSE.md +0 -27
- data/doc_templates/README.md.erb +0 -42
- data/doc_templates/copyright_erb.txt +0 -31
- data/doc_templates/copyright_js.txt +0 -4
- data/doc_templates/copyright_ruby.txt +0 -29
- data/docs/.vuepress/components/ScenarioSchema.vue +0 -12
- data/docs/schemas/scenario-schema.md +0 -3
- data/lib/measures/.rubocop.yml +0 -5
- data/lib/measures/default_feature_reports/LICENSE.md +0 -27
- data/lib/measures/default_feature_reports/README.md +0 -56
- data/lib/measures/default_feature_reports/README.md.erb +0 -42
- data/lib/measures/default_feature_reports/measure.rb +0 -1006
- data/lib/measures/default_feature_reports/measure.xml +0 -143
- data/lib/measures/default_feature_reports/tests/USA_CO_Golden-NREL.724666_TMY3.epw +0 -8768
- data/lib/measures/default_feature_reports/tests/default_feature_reports_test.rb +0 -238
- data/lib/measures/default_feature_reports/tests/example_model.osm +0 -4378
- data/lib/urbanopt/scenario/default_reports/construction_cost.rb +0 -169
- data/lib/urbanopt/scenario/default_reports/date.rb +0 -97
- data/lib/urbanopt/scenario/default_reports/distributed_generation.rb +0 -379
- data/lib/urbanopt/scenario/default_reports/end_use.rb +0 -159
- data/lib/urbanopt/scenario/default_reports/end_uses.rb +0 -140
- data/lib/urbanopt/scenario/default_reports/feature_report.rb +0 -267
- data/lib/urbanopt/scenario/default_reports/generator.rb +0 -92
- data/lib/urbanopt/scenario/default_reports/location.rb +0 -99
- data/lib/urbanopt/scenario/default_reports/logger.rb +0 -44
- data/lib/urbanopt/scenario/default_reports/power_distribution.rb +0 -102
- data/lib/urbanopt/scenario/default_reports/program.rb +0 -266
- data/lib/urbanopt/scenario/default_reports/reporting_period.rb +0 -305
- data/lib/urbanopt/scenario/default_reports/scenario_report.rb +0 -317
- data/lib/urbanopt/scenario/default_reports/schema/README.md +0 -33
- data/lib/urbanopt/scenario/default_reports/schema/scenario_csv_columns.txt +0 -32
- data/lib/urbanopt/scenario/default_reports/schema/scenario_schema.json +0 -857
- data/lib/urbanopt/scenario/default_reports/solar_pv.rb +0 -93
- data/lib/urbanopt/scenario/default_reports/storage.rb +0 -105
- data/lib/urbanopt/scenario/default_reports/timeseries_csv.rb +0 -299
- data/lib/urbanopt/scenario/default_reports/validator.rb +0 -97
- data/lib/urbanopt/scenario/default_reports/wind.rb +0 -92
data/docs/package.json
CHANGED
@@ -10,17 +10,21 @@
|
|
10
10
|
},
|
11
11
|
"author": "NREL",
|
12
12
|
"dependencies": {
|
13
|
-
"highlight.js": "^
|
14
|
-
"json-schema-ref-parser": "^
|
13
|
+
"highlight.js": "^10.2.1",
|
14
|
+
"json-schema-ref-parser": "^9.0.6",
|
15
15
|
"json-schema-view-js": "git+https://git@github.com/bgschiller/json-schema-view-js.git",
|
16
|
-
"vuepress": "^1.
|
16
|
+
"vuepress": "^1.6.0",
|
17
17
|
"webpack-dev-middleware": "^3.6.0"
|
18
18
|
},
|
19
19
|
"devDependencies": {
|
20
|
-
"braces": "
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
20
|
+
"braces": "^3.0.2",
|
21
|
+
"dot-prop": "^5.3.0",
|
22
|
+
"gh-pages": "^3.1.0",
|
23
|
+
"js-yaml": "^3.14.0",
|
24
|
+
"minimist": ">=1.2.3",
|
25
|
+
"node-forge": ">=0.10.0",
|
26
|
+
"serialize-javascript": "^5.0.1",
|
27
|
+
"set-value": "^3.0.2",
|
28
|
+
"yargs-parser": "^20.2.1"
|
25
29
|
}
|
26
30
|
}
|
data/lib/urbanopt-scenario.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
data/lib/urbanopt/scenario.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -42,5 +42,6 @@ require 'urbanopt/scenario/scenario_runner_osw'
|
|
42
42
|
require 'urbanopt/scenario/simulation_dir_base'
|
43
43
|
require 'urbanopt/scenario/simulation_dir_osw'
|
44
44
|
require 'urbanopt/scenario/simulation_mapper_base'
|
45
|
+
require 'urbanopt/scenario/scenario_visualization'
|
45
46
|
|
46
47
|
require 'urbanopt/scenario/default_reports'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -31,10 +31,5 @@
|
|
31
31
|
##
|
32
32
|
# Retrieve all default_reports classes.
|
33
33
|
##
|
34
|
-
|
35
|
-
require 'urbanopt/
|
36
|
-
require 'urbanopt/scenario/default_reports/logger'
|
37
|
-
require 'urbanopt/scenario/default_reports/program'
|
38
|
-
require 'urbanopt/scenario/default_reports/reporting_period'
|
39
|
-
require 'urbanopt/scenario/default_reports/scenario_report'
|
40
|
-
require 'urbanopt/scenario/default_reports/timeseries_csv'
|
34
|
+
|
35
|
+
require 'urbanopt/reporting/default_reports'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -39,14 +39,15 @@ module URBANopt
|
|
39
39
|
end
|
40
40
|
|
41
41
|
##
|
42
|
-
#
|
42
|
+
# [return:] Absolute path of the measures or nil if there is none, can be used when configuring OSWs.
|
43
43
|
def measures_dir
|
44
44
|
return File.absolute_path(File.join(@root_dir, 'lib', 'measures'))
|
45
45
|
end
|
46
46
|
|
47
47
|
##
|
48
48
|
# Relevant files such as weather data, design days, etc.
|
49
|
-
|
49
|
+
##
|
50
|
+
# [return:] Absolute path of the files or nil if there is none, used when configuring OSWs
|
50
51
|
def files_dir
|
51
52
|
return nil
|
52
53
|
end
|
@@ -54,7 +55,8 @@ module URBANopt
|
|
54
55
|
##
|
55
56
|
# Doc templates are common files like copyright files which are used to update measures and other code.
|
56
57
|
# Doc templates will only be applied to measures in the current repository.
|
57
|
-
|
58
|
+
##
|
59
|
+
# [return:] Absolute path of the doc templates dir or nil if there is none.
|
58
60
|
def doc_templates_dir
|
59
61
|
return File.absolute_path(File.join(@root_dir, 'doc_templates'))
|
60
62
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -36,10 +36,10 @@ module URBANopt
|
|
36
36
|
# Initialize ScenarioBase attributes: +name+ , +root directory+ , +run directory+ and +feature_file+
|
37
37
|
##
|
38
38
|
# [parameters:]
|
39
|
-
# +name+ - _String_ - Human readable scenario name.
|
40
|
-
# +root_dir+ - _String_ - Root directory for the scenario, contains Gemfile describing dependencies.
|
41
|
-
# +run_dir+ - _String_ - Directory for simulation of this scenario, deleting run directory clears the scenario.
|
42
|
-
# +feature_file+ - _FeatureFile_ - An instance of +URBANopt::Core::FeatureFile+ containing features for simulation.
|
39
|
+
# * +name+ - _String_ - Human readable scenario name.
|
40
|
+
# * +root_dir+ - _String_ - Root directory for the scenario, contains Gemfile describing dependencies.
|
41
|
+
# * +run_dir+ - _String_ - Directory for simulation of this scenario, deleting run directory clears the scenario.
|
42
|
+
# * +feature_file+ - _FeatureFile_ - An instance of +URBANopt::Core::FeatureFile+ containing features for simulation.
|
43
43
|
def initialize(name, root_dir, run_dir, feature_file)
|
44
44
|
@name = name
|
45
45
|
@root_dir = root_dir
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -42,17 +42,15 @@ module URBANopt
|
|
42
42
|
# The CSV file has three columns 1) feature_id, 2) feature_name, and 3) mapper_class_name. There is one row for each Feature.
|
43
43
|
##
|
44
44
|
# [parameters:]
|
45
|
-
# +name+ - _String_ - Human readable scenario name.
|
46
|
-
# +root_dir+ - _String_ - Root directory for the scenario, contains Gemfile describing dependencies.
|
47
|
-
# +run_dir+ - _String_ - Directory for simulation of this scenario, deleting run directory clears the scenario.
|
48
|
-
# +feature_file+ - _URBANopt::Core::FeatureFile_ - FeatureFile containing features to simulate.
|
49
|
-
# +mapper_files_dir+ - _String_ - Directory containing all mapper class files containing MapperBase definitions.
|
50
|
-
# +csv_file+ - _String_ - Path to CSV file assigning a MapperBase class to each feature in feature_file.
|
51
|
-
# +num_header_rows+ -
|
52
|
-
|
45
|
+
# * +name+ - _String_ - Human readable scenario name.
|
46
|
+
# * +root_dir+ - _String_ - Root directory for the scenario, contains Gemfile describing dependencies.
|
47
|
+
# * +run_dir+ - _String_ - Directory for simulation of this scenario, deleting run directory clears the scenario.
|
48
|
+
# * +feature_file+ - _URBANopt::Core::FeatureFile_ - FeatureFile containing features to simulate.
|
49
|
+
# * +mapper_files_dir+ - _String_ - Directory containing all mapper class files containing MapperBase definitions.
|
50
|
+
# * +csv_file+ - _String_ - Path to CSV file assigning a MapperBase class to each feature in feature_file.
|
51
|
+
# * +num_header_rows+ - _String_ - Number of header rows to skip in CSV file.
|
53
52
|
def initialize(name, root_dir, run_dir, feature_file, mapper_files_dir, csv_file, num_header_rows)
|
54
53
|
super(name, root_dir, run_dir, feature_file)
|
55
|
-
|
56
54
|
@mapper_files_dir = mapper_files_dir
|
57
55
|
@csv_file = csv_file
|
58
56
|
@num_header_rows = num_header_rows
|
@@ -73,13 +71,27 @@ module URBANopt
|
|
73
71
|
|
74
72
|
# Require all simulation mappers in mapper_files_dir
|
75
73
|
def load_mapper_files
|
76
|
-
Dir.glob(File.join(@mapper_files_dir, '/*.rb'))
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
74
|
+
dirs = Dir.glob(File.join(@mapper_files_dir, '/*.rb'))
|
75
|
+
# order is not guaranteed...attempt to add Baseline first, then High Efficiency
|
76
|
+
ordered_dirs = []
|
77
|
+
bindex = dirs.find_index { |i| i.include? 'Baseline.rb' }
|
78
|
+
if bindex
|
79
|
+
ordered_dirs << dirs[bindex]
|
80
|
+
dirs.delete_at(bindex)
|
81
|
+
end
|
82
|
+
hindex = dirs.find_index { |i| i.include? 'HighEfficiency.rb' }
|
83
|
+
if hindex
|
84
|
+
ordered_dirs << dirs[hindex] if hindex
|
85
|
+
dirs.delete_at(hindex)
|
86
|
+
end
|
87
|
+
# then the rest
|
88
|
+
ordered_dirs += dirs
|
89
|
+
|
90
|
+
ordered_dirs.each do |f|
|
91
|
+
require(f)
|
92
|
+
rescue LoadError => e
|
93
|
+
@@logger.error(e.message)
|
94
|
+
raise
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -38,10 +38,10 @@ module URBANopt
|
|
38
38
|
# A Simulation Mapper will map the
|
39
39
|
##
|
40
40
|
# [parameters:]
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
41
|
+
# * +scenario+ - _ScenarioBase_ - Scenario containing this ScenarioDatapoint.
|
42
|
+
# * +feature_id+ - _String_ - Unique id of the feature for this ScenarioDatapoint.
|
43
|
+
# * +feature_name+ - _String_ - Human readable name of the feature for this ScenarioDatapoint.
|
44
|
+
# * +mapper_class+ - _String_ - Name of Ruby class used to translate feature to simulation OSW.
|
45
45
|
def initialize(scenario, feature_id, feature_name, mapper_class)
|
46
46
|
@scenario = scenario
|
47
47
|
@feature_id = feature_id
|
@@ -59,6 +59,13 @@ module URBANopt
|
|
59
59
|
@feature.feature_type
|
60
60
|
end
|
61
61
|
|
62
|
+
##
|
63
|
+
# Gets the type of a feature
|
64
|
+
##
|
65
|
+
def feature_location
|
66
|
+
@feature.feature_location
|
67
|
+
end
|
68
|
+
|
62
69
|
##
|
63
70
|
# Return the directory that this datapoint will run in.
|
64
71
|
##
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -35,7 +35,7 @@ module URBANopt
|
|
35
35
|
# ScenarioPostProcessorBase post-processes a Scenario to create scenario level results.
|
36
36
|
##
|
37
37
|
# [parameters:]
|
38
|
-
# +scenario_base+ - _ScenarioBase_ - An object of ScenarioBase class.
|
38
|
+
# * +scenario_base+ - _ScenarioBase_ - An object of ScenarioBase class.
|
39
39
|
def initialize(scenario_base)
|
40
40
|
@scenario_base = scenario_base
|
41
41
|
end
|
@@ -53,7 +53,7 @@ module URBANopt
|
|
53
53
|
# Add results from a simulation_dir to this result.
|
54
54
|
##
|
55
55
|
# [parameters:]
|
56
|
-
# +simulation_dir+ - _SimulationDirOSW_ - An object on SimulationDirOSW class.
|
56
|
+
# * +simulation_dir+ - _SimulationDirOSW_ - An object on SimulationDirOSW class.
|
57
57
|
def add_simulation_dir(simulation_dir)
|
58
58
|
raise 'add_simulation_dir not implemented for ScenarioPostProcessorBase, override in your class'
|
59
59
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -29,12 +29,12 @@
|
|
29
29
|
# *********************************************************************************
|
30
30
|
|
31
31
|
require 'urbanopt/scenario/scenario_post_processor_base'
|
32
|
-
require 'urbanopt/
|
33
|
-
require 'urbanopt/scenario/default_reports/logger'
|
32
|
+
require 'urbanopt/reporting/default_reports'
|
34
33
|
|
35
34
|
require 'csv'
|
36
35
|
require 'json'
|
37
36
|
require 'fileutils'
|
37
|
+
require 'sqlite3'
|
38
38
|
|
39
39
|
module URBANopt
|
40
40
|
module Scenario
|
@@ -43,14 +43,15 @@ module URBANopt
|
|
43
43
|
# ScenarioPostProcessorBase post-processes a scenario to create scenario level results
|
44
44
|
##
|
45
45
|
# [parameters:]
|
46
|
-
# +scenario_base+ - _ScenarioBase_ - An object of ScenarioBase class.
|
46
|
+
# * +scenario_base+ - _ScenarioBase_ - An object of ScenarioBase class.
|
47
47
|
def initialize(scenario_base)
|
48
48
|
super(scenario_base)
|
49
49
|
|
50
|
-
initialization_hash = { directory_name: scenario_base.run_dir, name: scenario_base.name, id: scenario_base.name }
|
51
|
-
@scenario_result = URBANopt::
|
50
|
+
@initialization_hash = { directory_name: scenario_base.run_dir, name: scenario_base.name, id: scenario_base.name, root_dir: scenario_base.root_dir }
|
51
|
+
@scenario_result = URBANopt::Reporting::DefaultReports::ScenarioReport.new(@initialization_hash)
|
52
|
+
@default_save_name = 'default_scenario_report'
|
52
53
|
|
53
|
-
@@logger ||= URBANopt::
|
54
|
+
@@logger ||= URBANopt::Reporting::DefaultReports.logger
|
54
55
|
end
|
55
56
|
|
56
57
|
##
|
@@ -68,9 +69,9 @@ module URBANopt
|
|
68
69
|
# Add results from a simulation_dir to this result.
|
69
70
|
##
|
70
71
|
# [parameters:]
|
71
|
-
# +simulation_dir+ - _SimulationDirOSW_ - An object on SimulationDirOSW class.
|
72
|
+
# * +simulation_dir+ - _SimulationDirOSW_ - An object on SimulationDirOSW class.
|
72
73
|
def add_simulation_dir(simulation_dir)
|
73
|
-
feature_reports = URBANopt::
|
74
|
+
feature_reports = URBANopt::Reporting::DefaultReports::FeatureReport.from_simulation_dir(simulation_dir)
|
74
75
|
|
75
76
|
feature_reports.each do |feature_report|
|
76
77
|
if feature_report.to_hash[:simulation_status] == 'Complete'
|
@@ -83,12 +84,121 @@ module URBANopt
|
|
83
84
|
return feature_reports
|
84
85
|
end
|
85
86
|
|
87
|
+
# Create database file with scenario-level results
|
88
|
+
# Sum values for each timestep across all features. Save to new table in a new database
|
89
|
+
##
|
90
|
+
# [parameters:]
|
91
|
+
# * +file_name+ - _String_ - Assign a name to the saved scenario results file
|
92
|
+
def create_scenario_db_file(file_name = @default_save_name)
|
93
|
+
new_db_file = File.join(@initialization_hash[:directory_name], "#{file_name}.db")
|
94
|
+
scenario_db = SQLite3::Database.open new_db_file
|
95
|
+
scenario_db.execute "CREATE TABLE IF NOT EXISTS ReportData(
|
96
|
+
TimeIndex INTEGER,
|
97
|
+
Year VARCHAR(255),
|
98
|
+
Month VARCHAR(255),
|
99
|
+
Day VARCHAR(255),
|
100
|
+
Hour VARCHAR(255),
|
101
|
+
Minute VARCHAR(255),
|
102
|
+
Dst INTEGER,
|
103
|
+
FuelType VARCHAR(255),
|
104
|
+
Value INTEGER,
|
105
|
+
FuelUnits VARCHAR(255)
|
106
|
+
)"
|
107
|
+
|
108
|
+
values_arr = []
|
109
|
+
feature_list = Pathname.new(@initialization_hash[:directory_name]).children.select(&:directory?) # Folders in the run/scenario directory
|
110
|
+
|
111
|
+
# get scenario CSV
|
112
|
+
scenario_csv = File.join(@initialization_hash[:root_dir], @initialization_hash[:name] + '.csv')
|
113
|
+
if File.exist?(scenario_csv)
|
114
|
+
# csv found
|
115
|
+
feature_ids = CSV.read(scenario_csv, headers: true)
|
116
|
+
feature_list = []
|
117
|
+
# loop through building feature ids from scenario csv
|
118
|
+
feature_ids['Feature Id'].each do |feature|
|
119
|
+
if Dir.exist?(File.join(@initialization_hash[:directory_name], feature))
|
120
|
+
feature_list << File.join(@initialization_hash[:directory_name], feature)
|
121
|
+
else
|
122
|
+
puts "warning: did not find a directory for datapoint #{feature}...skipping"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
else
|
126
|
+
raise "Couldn't find scenario CSV: #{scenario_csv}"
|
127
|
+
end
|
128
|
+
feature_1_name = File.basename(feature_list[0]) # Get name of first feature, so we can read eplusout.sql from there
|
129
|
+
uo_output_sql_file = File.join(@initialization_hash[:directory_name], feature_1_name, 'eplusout.sql')
|
130
|
+
feature_list.each do |feature| # Loop through each feature in the scenario
|
131
|
+
feature_db = SQLite3::Database.open uo_output_sql_file
|
132
|
+
# Doing "db.results_as_hash = true" is prettier, but in this case significantly slower.
|
133
|
+
|
134
|
+
elec_query = feature_db.query "SELECT ReportData.TimeIndex, Time.Year, Time.Month, Time.Day, Time.Hour,
|
135
|
+
Time.Minute, Time.Dst, ReportData.Value
|
136
|
+
FROM ReportData
|
137
|
+
INNER JOIN Time ON Time.TimeIndex=ReportData.TimeIndex
|
138
|
+
INNER JOIN ReportDataDictionary AS rddi ON rddi.ReportDataDictionaryIndex=ReportData.ReportDataDictionaryIndex
|
139
|
+
WHERE rddi.IndexGroup == 'Facility:Electricity'
|
140
|
+
AND rddi.ReportingFrequency == 'Zone Timestep'
|
141
|
+
AND Time.Year > 1900
|
142
|
+
ORDER BY ReportData.TimeIndex"
|
143
|
+
|
144
|
+
elec_query.each do |row| # Add up all the values for electricity usage across all Features at this timestep
|
145
|
+
# row[0] == TimeIndex, row[1] == Value
|
146
|
+
|
147
|
+
arr_match = values_arr.find { |v| v[:time_index] == row[0] }
|
148
|
+
if arr_match.nil?
|
149
|
+
# add new row to value_arr
|
150
|
+
values_arr << { time_index: row[0], year: row[1], month: row[2], day: row[3], hour: row[4], minute: row[5], dst: row[6], elec_val: Float(row[7]), gas_val: 0 }
|
151
|
+
else
|
152
|
+
# running sum
|
153
|
+
arr_match[:elec_val] += Float(row[7])
|
154
|
+
end
|
155
|
+
end # End elec_query
|
156
|
+
elec_query.close
|
157
|
+
|
158
|
+
gas_query = feature_db.query "SELECT ReportData.TimeIndex, Time.Year, Time.Month, Time.Day, Time.Hour,
|
159
|
+
Time.Minute, Time.Dst, ReportData.Value
|
160
|
+
FROM ReportData
|
161
|
+
INNER JOIN Time ON Time.TimeIndex=ReportData.TimeIndex
|
162
|
+
INNER JOIN ReportDataDictionary AS rddi ON rddi.ReportDataDictionaryIndex=ReportData.ReportDataDictionaryIndex
|
163
|
+
WHERE rddi.IndexGroup == 'Facility:Gas'
|
164
|
+
AND rddi.ReportingFrequency == 'Zone Timestep'
|
165
|
+
AND Time.Year > 1900
|
166
|
+
ORDER BY ReportData.TimeIndex"
|
167
|
+
|
168
|
+
gas_query.each do |row|
|
169
|
+
# row[0] == TimeIndex, row[1] == Value
|
170
|
+
arr_match = values_arr.find { |v| v[:time_index] == row[0] }
|
171
|
+
if arr_match.nil?
|
172
|
+
# add new row to value_arr
|
173
|
+
values_arr << { time_index: row[0], year: row[1], month: row[2], day: row[3], hour: row[4], minute: row[5], dst: row[6], gas_val: Float(row[7]), elec_val: 0 }
|
174
|
+
else
|
175
|
+
# running sum
|
176
|
+
arr_match[:gas_val] += Float(row[7])
|
177
|
+
end
|
178
|
+
end # End gas_query
|
179
|
+
gas_query.close
|
180
|
+
feature_db.close
|
181
|
+
end # End feature_list loop
|
182
|
+
|
183
|
+
elec_sql = []
|
184
|
+
gas_sql = []
|
185
|
+
values_arr.each do |i|
|
186
|
+
elec_sql << "(#{i[:time_index]}, #{i[:year]}, #{i[:month]}, #{i[:day]}, #{i[:hour]}, #{i[:minute]}, #{i[:dst]}, 'Electricity', #{i[:elec_val]}, 'J')"
|
187
|
+
gas_sql << "(#{i[:time_index]}, #{i[:year]}, #{i[:month]}, #{i[:day]}, #{i[:hour]}, #{i[:minute]}, #{i[:dst]}, 'Gas', #{i[:gas_val]}, 'J')"
|
188
|
+
end
|
189
|
+
|
190
|
+
# Put summed Values into the database
|
191
|
+
scenario_db.execute("INSERT INTO ReportData VALUES #{elec_sql.join(', ')}")
|
192
|
+
scenario_db.execute("INSERT INTO ReportData VALUES #{gas_sql.join(', ')}")
|
193
|
+
scenario_db.close
|
194
|
+
end
|
195
|
+
|
86
196
|
##
|
87
197
|
# Save scenario result
|
88
198
|
##
|
89
199
|
# [parameters:]
|
90
|
-
# +file_name+ - _String_ - Assign a name to the saved scenario results file
|
91
|
-
def save(file_name =
|
200
|
+
# * +file_name+ - _String_ - Assign a name to the saved scenario results file
|
201
|
+
def save(file_name = @default_save_name)
|
92
202
|
@scenario_result.save
|
93
203
|
|
94
204
|
return @scenario_result
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# *********************************************************************************
|
2
|
-
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
2
|
+
# URBANopt (tm), Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
|
3
3
|
# contributors. All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -29,8 +29,7 @@
|
|
29
29
|
# *********************************************************************************
|
30
30
|
|
31
31
|
# require 'urbanopt/scenario/scenario_post_processor_base'
|
32
|
-
require 'urbanopt/
|
33
|
-
require 'urbanopt/scenario/default_reports/logger'
|
32
|
+
require 'urbanopt/reporting/default_reports'
|
34
33
|
|
35
34
|
require 'csv'
|
36
35
|
require 'json'
|
@@ -44,8 +43,8 @@ module URBANopt
|
|
44
43
|
# OpenDSSPostProcessor post-processes OpenDSS results to selected OpenDSS results and integrate them in scenario and feature reports.
|
45
44
|
##
|
46
45
|
# [parameters:]
|
47
|
-
# +scenario_report+ - _ScenarioBase_ - An object of Scenario_report class.
|
48
|
-
# +opendss_results_dir_name+ - _directory name of opendss results
|
46
|
+
# * +scenario_report+ - _ScenarioBase_ - An object of Scenario_report class.
|
47
|
+
# * +opendss_results_dir_name+ - _directory name of opendss results
|
49
48
|
def initialize(scenario_report, opendss_results_dir_name = 'opendss')
|
50
49
|
if !scenario_report.nil?
|
51
50
|
@scenario_report = scenario_report
|
@@ -64,7 +63,7 @@ module URBANopt
|
|
64
63
|
@feature_reports_data = {}
|
65
64
|
|
66
65
|
# initialize logger
|
67
|
-
@@logger ||= URBANopt::
|
66
|
+
@@logger ||= URBANopt::Reporting::DefaultReports.logger
|
68
67
|
end
|
69
68
|
|
70
69
|
# load opendss data
|
@@ -166,9 +165,9 @@ module URBANopt
|
|
166
165
|
File.write(File.join(transformer_dir, 'feature_reports', 'default_feature_report_opendss' + '.csv'), transformer_csv)
|
167
166
|
|
168
167
|
# create transformer report
|
169
|
-
transformer_report = URBANopt::
|
170
|
-
|
171
|
-
|
168
|
+
transformer_report = URBANopt::Reporting::DefaultReports::FeatureReport.new(id: k, name: k, directory_name: transformer_dir, feature_type: 'Transformer',
|
169
|
+
timesteps_per_hour: @scenario_report.timesteps_per_hour,
|
170
|
+
simulation_status: 'complete')
|
172
171
|
|
173
172
|
# assign results to transfomrer report
|
174
173
|
transformer_report.power_distribution.over_voltage_hours = over_voltage_hrs
|
@@ -203,9 +202,9 @@ module URBANopt
|
|
203
202
|
# Save csv report method
|
204
203
|
##
|
205
204
|
# [parameters:]
|
206
|
-
# +feature_report+ - _feature report object_ - An onject of the feature report
|
207
|
-
# +updated_feature_report_csv+ - _CSV_ - An updated feature report csv
|
208
|
-
# +file_name+ - _String_ - Assigned name to save the file with no extension
|
205
|
+
# * +feature_report+ - _feature report object_ - An onject of the feature report
|
206
|
+
# * +updated_feature_report_csv+ - _CSV_ - An updated feature report csv
|
207
|
+
# * +file_name+ - _String_ - Assigned name to save the file with no extension
|
209
208
|
def save_csv(feature_report, updated_feature_report_csv, file_name = 'default_feature_report')
|
210
209
|
File.write(File.join(feature_report.directory_name, 'feature_reports', "#{file_name}.csv"), updated_feature_report_csv)
|
211
210
|
end
|
@@ -214,7 +213,7 @@ module URBANopt
|
|
214
213
|
# create opendss json report results
|
215
214
|
##
|
216
215
|
# [parameters:]
|
217
|
-
# +feature_report+ - _feature report object_ - An onject of the feature report
|
216
|
+
# * +feature_report+ - _feature report object_ - An onject of the feature report
|
218
217
|
def add_summary_results(feature_report)
|
219
218
|
under_voltage_hrs = 0
|
220
219
|
over_voltage_hrs = 0
|
@@ -259,7 +258,7 @@ module URBANopt
|
|
259
258
|
updated_feature_csv = merge_data(@feature_reports_data[id], @opendss_data[id])
|
260
259
|
|
261
260
|
# save fetaure reports
|
262
|
-
feature_report.
|
261
|
+
feature_report.save_json_report('default_feature_report_opendss')
|
263
262
|
|
264
263
|
# resave updated csv report
|
265
264
|
save_csv(feature_report, updated_feature_csv, 'default_feature_report_opendss')
|