urbanopt-scenario 0.3.0 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +3 -3
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +61 -0
  5. data/CONTRIBUTING.md +1 -1
  6. data/Gemfile +33 -17
  7. data/Jenkinsfile +1 -1
  8. data/LICENSE.md +1 -1
  9. data/RDOC_MAIN.md +2 -2
  10. data/README.md +1 -1
  11. data/Rakefile +1 -1
  12. data/docs/.vuepress/components/InnerJsonSchema.vue +7 -15
  13. data/docs/.vuepress/config.js +13 -9
  14. data/docs/.vuepress/highlight.js +1 -1
  15. data/docs/.vuepress/json-schema-deref-loader.js +22 -0
  16. data/docs/README.md +2 -2
  17. data/docs/package-lock.json +2384 -2323
  18. data/docs/package.json +12 -8
  19. data/lib/urbanopt-scenario.rb +1 -1
  20. data/lib/urbanopt/scenario.rb +2 -1
  21. data/lib/urbanopt/scenario/default_reports.rb +3 -8
  22. data/lib/urbanopt/scenario/extension.rb +6 -4
  23. data/lib/urbanopt/scenario/logger.rb +1 -1
  24. data/lib/urbanopt/scenario/scenario_base.rb +5 -5
  25. data/lib/urbanopt/scenario/scenario_csv.rb +29 -17
  26. data/lib/urbanopt/scenario/scenario_datapoint_base.rb +12 -5
  27. data/lib/urbanopt/scenario/scenario_post_processor_base.rb +3 -3
  28. data/lib/urbanopt/scenario/scenario_post_processor_default.rb +120 -11
  29. data/lib/urbanopt/scenario/scenario_post_processor_opendss.rb +13 -14
  30. data/lib/urbanopt/scenario/scenario_runner_base.rb +8 -7
  31. data/lib/urbanopt/scenario/scenario_runner_osw.rb +29 -13
  32. data/lib/urbanopt/scenario/scenario_visualization.rb +235 -0
  33. data/lib/urbanopt/scenario/simulation_dir_base.rb +4 -4
  34. data/lib/urbanopt/scenario/simulation_dir_osw.rb +6 -9
  35. data/lib/urbanopt/scenario/simulation_mapper_base.rb +4 -4
  36. data/lib/urbanopt/scenario/version.rb +2 -2
  37. data/package-lock.json +3 -0
  38. data/urbanopt-scenario-gem.gemspec +10 -6
  39. metadata +78 -52
  40. data/doc_templates/LICENSE.md +0 -27
  41. data/doc_templates/README.md.erb +0 -42
  42. data/doc_templates/copyright_erb.txt +0 -31
  43. data/doc_templates/copyright_js.txt +0 -4
  44. data/doc_templates/copyright_ruby.txt +0 -29
  45. data/docs/.vuepress/components/ScenarioSchema.vue +0 -12
  46. data/docs/schemas/scenario-schema.md +0 -3
  47. data/lib/measures/.rubocop.yml +0 -5
  48. data/lib/measures/default_feature_reports/LICENSE.md +0 -27
  49. data/lib/measures/default_feature_reports/README.md +0 -26
  50. data/lib/measures/default_feature_reports/README.md.erb +0 -42
  51. data/lib/measures/default_feature_reports/measure.rb +0 -1013
  52. data/lib/measures/default_feature_reports/measure.xml +0 -160
  53. data/lib/urbanopt/scenario/default_reports/construction_cost.rb +0 -169
  54. data/lib/urbanopt/scenario/default_reports/date.rb +0 -97
  55. data/lib/urbanopt/scenario/default_reports/distributed_generation.rb +0 -379
  56. data/lib/urbanopt/scenario/default_reports/end_use.rb +0 -159
  57. data/lib/urbanopt/scenario/default_reports/end_uses.rb +0 -140
  58. data/lib/urbanopt/scenario/default_reports/feature_report.rb +0 -267
  59. data/lib/urbanopt/scenario/default_reports/generator.rb +0 -92
  60. data/lib/urbanopt/scenario/default_reports/location.rb +0 -99
  61. data/lib/urbanopt/scenario/default_reports/logger.rb +0 -44
  62. data/lib/urbanopt/scenario/default_reports/power_distribution.rb +0 -102
  63. data/lib/urbanopt/scenario/default_reports/program.rb +0 -265
  64. data/lib/urbanopt/scenario/default_reports/reporting_period.rb +0 -304
  65. data/lib/urbanopt/scenario/default_reports/scenario_report.rb +0 -317
  66. data/lib/urbanopt/scenario/default_reports/schema/README.md +0 -33
  67. data/lib/urbanopt/scenario/default_reports/schema/scenario_csv_columns.txt +0 -34
  68. data/lib/urbanopt/scenario/default_reports/schema/scenario_schema.json +0 -857
  69. data/lib/urbanopt/scenario/default_reports/solar_pv.rb +0 -93
  70. data/lib/urbanopt/scenario/default_reports/storage.rb +0 -105
  71. data/lib/urbanopt/scenario/default_reports/timeseries_csv.rb +0 -299
  72. data/lib/urbanopt/scenario/default_reports/validator.rb +0 -97
  73. data/lib/urbanopt/scenario/default_reports/wind.rb +0 -92
@@ -10,17 +10,21 @@
10
10
  },
11
11
  "author": "NREL",
12
12
  "dependencies": {
13
- "highlight.js": "^9.15.6",
14
- "json-schema-ref-parser": "^6.1.0",
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.2.0",
16
+ "vuepress": "^1.6.0",
17
17
  "webpack-dev-middleware": "^3.6.0"
18
18
  },
19
19
  "devDependencies": {
20
- "braces": ">=2.3.1",
21
- "gh-pages": "^2.0.1",
22
- "js-yaml": ">=3.13.1",
23
- "serialize-javascript": ">=2.1.1",
24
- "set-value": ">=2.0.1"
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
  }
@@ -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,
@@ -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
- require 'urbanopt/scenario/default_reports/construction_cost'
35
- require 'urbanopt/scenario/default_reports/feature_report'
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
- # Returns the absolute path of the measures or nil if there is none, can be used when configuring OSWs.
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
- # Return the absolute path of the files or nil if there is none, used when configuring OSWs
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
- # Return the absolute path of the doc templates dir or nil if there is none.
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+ - _Strng_ - Number of header rows to skip in CSV file.
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')).each do |f|
77
- begin
78
- require(f)
79
- rescue LoadError => e
80
- @@logger.error(e.message)
81
- raise
82
- end
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
- # +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.
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/scenario/default_reports'
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::Scenario::DefaultReports::ScenarioReport.new(initialization_hash)
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::Scenario::DefaultReports.logger
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::Scenario::DefaultReports::FeatureReport.from_simulation_dir(simulation_dir)
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,120 @@ 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_list.each do |feature| # Loop through each feature in the scenario
129
+ uo_output_sql_file = File.join(@initialization_hash[:directory_name], File.basename(feature), 'eplusout.sql')
130
+ feature_db = SQLite3::Database.open uo_output_sql_file
131
+ # Doing "db.results_as_hash = true" is prettier, but in this case significantly slower.
132
+
133
+ elec_query = feature_db.query "SELECT ReportData.TimeIndex, Time.Year, Time.Month, Time.Day, Time.Hour,
134
+ Time.Minute, Time.Dst, ReportData.Value
135
+ FROM ReportData
136
+ INNER JOIN Time ON Time.TimeIndex=ReportData.TimeIndex
137
+ INNER JOIN ReportDataDictionary AS rddi ON rddi.ReportDataDictionaryIndex=ReportData.ReportDataDictionaryIndex
138
+ WHERE rddi.IndexGroup == 'Facility:Electricity'
139
+ AND rddi.ReportingFrequency == 'Zone Timestep'
140
+ AND Time.Year > 1900
141
+ ORDER BY ReportData.TimeIndex"
142
+
143
+ elec_query.each do |row| # Add up all the values for electricity usage across all Features at this timestep
144
+ # row[0] == TimeIndex, row[1] == Value
145
+
146
+ arr_match = values_arr.find { |v| v[:time_index] == row[0] }
147
+ if arr_match.nil?
148
+ # add new row to value_arr
149
+ 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 }
150
+ else
151
+ # running sum
152
+ arr_match[:elec_val] += Float(row[7])
153
+ end
154
+ end # End elec_query
155
+ elec_query.close
156
+
157
+ gas_query = feature_db.query "SELECT ReportData.TimeIndex, Time.Year, Time.Month, Time.Day, Time.Hour,
158
+ Time.Minute, Time.Dst, ReportData.Value
159
+ FROM ReportData
160
+ INNER JOIN Time ON Time.TimeIndex=ReportData.TimeIndex
161
+ INNER JOIN ReportDataDictionary AS rddi ON rddi.ReportDataDictionaryIndex=ReportData.ReportDataDictionaryIndex
162
+ WHERE rddi.IndexGroup == 'Facility:Gas'
163
+ AND rddi.ReportingFrequency == 'Zone Timestep'
164
+ AND Time.Year > 1900
165
+ ORDER BY ReportData.TimeIndex"
166
+
167
+ gas_query.each do |row|
168
+ # row[0] == TimeIndex, row[1] == Value
169
+ arr_match = values_arr.find { |v| v[:time_index] == row[0] }
170
+ if arr_match.nil?
171
+ # add new row to value_arr
172
+ 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 }
173
+ else
174
+ # running sum
175
+ arr_match[:gas_val] += Float(row[7])
176
+ end
177
+ end # End gas_query
178
+ gas_query.close
179
+ feature_db.close
180
+ end # End feature_list loop
181
+
182
+ elec_sql = []
183
+ gas_sql = []
184
+ values_arr.each do |i|
185
+ elec_sql << "(#{i[:time_index]}, #{i[:year]}, #{i[:month]}, #{i[:day]}, #{i[:hour]}, #{i[:minute]}, #{i[:dst]}, 'Electricity', #{i[:elec_val]}, 'J')"
186
+ gas_sql << "(#{i[:time_index]}, #{i[:year]}, #{i[:month]}, #{i[:day]}, #{i[:hour]}, #{i[:minute]}, #{i[:dst]}, 'Gas', #{i[:gas_val]}, 'J')"
187
+ end
188
+
189
+ # Put summed Values into the database
190
+ scenario_db.execute("INSERT INTO ReportData VALUES #{elec_sql.join(', ')}")
191
+ scenario_db.execute("INSERT INTO ReportData VALUES #{gas_sql.join(', ')}")
192
+ scenario_db.close
193
+ end
194
+
86
195
  ##
87
196
  # Save scenario result
88
197
  ##
89
198
  # [parameters:]
90
- # +file_name+ - _String_ - Assign a name to the saved scenario results file
91
- def save(file_name = 'default_scenario_report')
199
+ # * +file_name+ - _String_ - Assign a name to the saved scenario results file
200
+ def save(file_name = @default_save_name)
92
201
  @scenario_result.save
93
202
 
94
203
  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/scenario/default_reports'
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::Scenario::DefaultReports.logger
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::Scenario::DefaultReports::FeatureReport.new(id: k, name: k, directory_name: transformer_dir, feature_type: 'Transformer',
170
- timesteps_per_hour: @scenario_report.timesteps_per_hour,
171
- simulation_status: 'complete')
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.save_feature_report('default_feature_report_opendss')
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')