urbanopt-scenario 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.rdoc_options +36 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +10 -0
  6. data/.travis.yml +23 -0
  7. data/CHANGELOG.md +5 -0
  8. data/Gemfile +42 -0
  9. data/Jenkinsfile +10 -0
  10. data/LICENSE.md +27 -0
  11. data/RDOC_MAIN.md +39 -0
  12. data/README.md +39 -0
  13. data/Rakefile +51 -0
  14. data/deploy_docs.sh +5 -0
  15. data/doc_templates/LICENSE.md +27 -0
  16. data/doc_templates/README.md.erb +42 -0
  17. data/doc_templates/copyright_erb.txt +31 -0
  18. data/doc_templates/copyright_js.txt +4 -0
  19. data/doc_templates/copyright_ruby.txt +29 -0
  20. data/docs/.gitignore +3 -0
  21. data/docs/.vuepress/components/InnerJsonSchema.vue +84 -0
  22. data/docs/.vuepress/components/JsonSchema.vue +12 -0
  23. data/docs/.vuepress/components/ScenarioSchema.vue +12 -0
  24. data/docs/.vuepress/components/StaticLink.vue +8 -0
  25. data/docs/.vuepress/config.js +15 -0
  26. data/docs/.vuepress/highlight.js +8 -0
  27. data/docs/.vuepress/public/custom_rdoc_styles.css +74 -0
  28. data/docs/.vuepress/utils.js +17 -0
  29. data/docs/README.md +39 -0
  30. data/docs/package-lock.json +11791 -0
  31. data/docs/package.json +22 -0
  32. data/docs/schemas/scenario-schema.md +3 -0
  33. data/lib/measures/.rubocop.yml +5 -0
  34. data/lib/measures/default_feature_reports/LICENSE.md +27 -0
  35. data/lib/measures/default_feature_reports/README.md +56 -0
  36. data/lib/measures/default_feature_reports/README.md.erb +42 -0
  37. data/lib/measures/default_feature_reports/measure.rb +731 -0
  38. data/lib/measures/default_feature_reports/measure.xml +139 -0
  39. data/lib/measures/default_feature_reports/tests/USA_CO_Golden-NREL.724666_TMY3.epw +8768 -0
  40. data/lib/measures/default_feature_reports/tests/default_feature_reports_test.rb +238 -0
  41. data/lib/measures/default_feature_reports/tests/example_model.osm +4378 -0
  42. data/lib/urbanopt-scenario.rb +31 -0
  43. data/lib/urbanopt/scenario.rb +45 -0
  44. data/lib/urbanopt/scenario/default_reports.rb +40 -0
  45. data/lib/urbanopt/scenario/default_reports/construction_cost.rb +169 -0
  46. data/lib/urbanopt/scenario/default_reports/date.rb +97 -0
  47. data/lib/urbanopt/scenario/default_reports/end_use.rb +159 -0
  48. data/lib/urbanopt/scenario/default_reports/end_uses.rb +140 -0
  49. data/lib/urbanopt/scenario/default_reports/feature_report.rb +207 -0
  50. data/lib/urbanopt/scenario/default_reports/location.rb +99 -0
  51. data/lib/urbanopt/scenario/default_reports/logger.rb +44 -0
  52. data/lib/urbanopt/scenario/default_reports/program.rb +261 -0
  53. data/lib/urbanopt/scenario/default_reports/reporting_period.rb +298 -0
  54. data/lib/urbanopt/scenario/default_reports/scenario_report.rb +276 -0
  55. data/lib/urbanopt/scenario/default_reports/schema/README.md +33 -0
  56. data/lib/urbanopt/scenario/default_reports/schema/scenario_csv_columns.txt +13 -0
  57. data/lib/urbanopt/scenario/default_reports/schema/scenario_schema.json +742 -0
  58. data/lib/urbanopt/scenario/default_reports/timeseries_csv.rb +231 -0
  59. data/lib/urbanopt/scenario/default_reports/validator.rb +97 -0
  60. data/lib/urbanopt/scenario/extension.rb +63 -0
  61. data/lib/urbanopt/scenario/logger.rb +42 -0
  62. data/lib/urbanopt/scenario/scenario_base.rb +79 -0
  63. data/lib/urbanopt/scenario/scenario_csv.rb +122 -0
  64. data/lib/urbanopt/scenario/scenario_datapoint_base.rb +162 -0
  65. data/lib/urbanopt/scenario/scenario_post_processor_base.rb +69 -0
  66. data/lib/urbanopt/scenario/scenario_post_processor_default.rb +97 -0
  67. data/lib/urbanopt/scenario/scenario_runner_base.rb +63 -0
  68. data/lib/urbanopt/scenario/scenario_runner_osw.rb +158 -0
  69. data/lib/urbanopt/scenario/simulation_dir_base.rb +90 -0
  70. data/lib/urbanopt/scenario/simulation_dir_osw.rb +261 -0
  71. data/lib/urbanopt/scenario/simulation_mapper_base.rb +47 -0
  72. data/lib/urbanopt/scenario/version.rb +35 -0
  73. data/urbanopt-scenario-gem.gemspec +36 -0
  74. metadata +227 -0
@@ -0,0 +1,31 @@
1
+ # *********************************************************************************
2
+ # URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
3
+ # contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list
9
+ # of conditions and the following disclaimer.
10
+ #
11
+ # Redistributions in binary form must reproduce the above copyright notice, this
12
+ # list of conditions and the following disclaimer in the documentation and/or other
13
+ # materials provided with the distribution.
14
+ #
15
+ # Neither the name of the copyright holder nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without specific
17
+ # prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+ # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ # *********************************************************************************
30
+
31
+ require_relative 'urbanopt/scenario'
@@ -0,0 +1,45 @@
1
+ # *********************************************************************************
2
+ # URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
3
+ # contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list
9
+ # of conditions and the following disclaimer.
10
+ #
11
+ # Redistributions in binary form must reproduce the above copyright notice, this
12
+ # list of conditions and the following disclaimer in the documentation and/or other
13
+ # materials provided with the distribution.
14
+ #
15
+ # Neither the name of the copyright holder nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without specific
17
+ # prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+ # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ # *********************************************************************************
30
+
31
+ require 'urbanopt/scenario/version'
32
+ require 'urbanopt/scenario/logger'
33
+ require 'urbanopt/scenario/extension'
34
+
35
+ require 'urbanopt/scenario/scenario_base'
36
+ require 'urbanopt/scenario/scenario_csv'
37
+ require 'urbanopt/scenario/scenario_post_processor_base'
38
+ require 'urbanopt/scenario/scenario_post_processor_default'
39
+ require 'urbanopt/scenario/scenario_runner_base'
40
+ require 'urbanopt/scenario/scenario_runner_osw'
41
+ require 'urbanopt/scenario/simulation_dir_base'
42
+ require 'urbanopt/scenario/simulation_dir_osw'
43
+ require 'urbanopt/scenario/simulation_mapper_base'
44
+
45
+ require 'urbanopt/scenario/default_reports'
@@ -0,0 +1,40 @@
1
+ # *********************************************************************************
2
+ # URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
3
+ # contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list
9
+ # of conditions and the following disclaimer.
10
+ #
11
+ # Redistributions in binary form must reproduce the above copyright notice, this
12
+ # list of conditions and the following disclaimer in the documentation and/or other
13
+ # materials provided with the distribution.
14
+ #
15
+ # Neither the name of the copyright holder nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without specific
17
+ # prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+ # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ # *********************************************************************************
30
+
31
+ ##
32
+ # Retrieve all default_reports classes.
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'
@@ -0,0 +1,169 @@
1
+ # *********************************************************************************
2
+ # URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
3
+ # contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list
9
+ # of conditions and the following disclaimer.
10
+ #
11
+ # Redistributions in binary form must reproduce the above copyright notice, this
12
+ # list of conditions and the following disclaimer in the documentation and/or other
13
+ # materials provided with the distribution.
14
+ #
15
+ # Neither the name of the copyright holder nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without specific
17
+ # prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+ # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ # *********************************************************************************
30
+
31
+ require 'json'
32
+ require 'urbanopt/scenario/default_reports/validator'
33
+ require 'json-schema'
34
+
35
+ module URBANopt
36
+ module Scenario
37
+ module DefaultReports
38
+ ##
39
+ # ConstructionCost include construction cost information.
40
+ ##
41
+ class ConstructionCost
42
+ attr_accessor :category, :item_name, :unit_cost, :cost_units, :item_quantity, :total_cost # :nodoc:
43
+ ##
44
+ # ConstructionCost class intialize all construction_cost attributes:
45
+ # +:category+ , +:item_name+ , +:unit_cost+ , +:cost_units+ , +:item_quantity+ , +:total_cost+
46
+ ##
47
+ # [parameters:]
48
+ # +hash+ - _Hash_ - A hash which may contain a deserialized construction_cost.
49
+ ##
50
+ def initialize(hash = {})
51
+ hash.delete_if { |k, v| v.nil? }
52
+ hash = defaults.merge(hash)
53
+
54
+ @category = hash[:category]
55
+ @item_name = hash[:item_name]
56
+ @unit_cost = hash[:unit_cost]
57
+ @cost_units = hash[:cost_units]
58
+ @item_quantity = hash[:item_quantity]
59
+ @total_cost = hash[:total_cost]
60
+
61
+ # initialize class variables @@validator and @@schema
62
+ @@validator ||= Validator.new
63
+ @@schema ||= @@validator.schema
64
+ end
65
+
66
+ ##
67
+ # Assigns default values if attribute values do not exist.
68
+ ##
69
+ def defaults
70
+ hash = {}
71
+ hash[:category] = nil
72
+ hash[:item_name] = nil
73
+ hash[:unit_cost] = nil
74
+ hash[:cost_units] = nil
75
+ hash[:item_quantity] = nil
76
+ hash[:total_cost] = nil
77
+
78
+ return hash
79
+ end
80
+
81
+ ##
82
+ # Converts to a Hash equivalent for JSON serialization.
83
+ ##
84
+ # - Exclude attributes with nil values.
85
+ # - Validate construct_cost hash properties against schema.
86
+ ##
87
+ def to_hash
88
+ result = {}
89
+ result[:category] = @category if @category
90
+ result[:item_name] = @item_name if @item_name
91
+ result[:unit_cost] = @unit_cost if @unit_cost
92
+ result[:cost_units] = @cost_units if @cost_units
93
+ result[:item_quantity] = @item_quantity if @item_quantity
94
+ result[:total_cost] = @total_cost if @total_cost
95
+
96
+ # validate construct_cost properties against schema
97
+ if @@validator.validate(@@schema[:definitions][:ConstructionCost][:properties], result).any?
98
+ raise "construction_cost properties does not match schema: #{@@validator.validate(@@schema[:definitions][:ConstructionCost][:properties], result)}"
99
+ end
100
+
101
+ return result
102
+ end
103
+
104
+ ##
105
+ # Merges an +existing_cost+ with a +new_cost+:
106
+ # - modify the existing_cost by summing the +:total_cost+ and +:item_quantity+ of new_cost and existing_cost.
107
+ # - raise an error if +:category+ , +:cost_units+ and +:unit_cost+ are not identical
108
+ ##
109
+ # [Parameters:]
110
+ # +existing_cost+ - _ConstructionCost_ - An object of ConstructionCost class.
111
+ ##
112
+ # +new_cost+ - _ConstructionCost_ - An object of ConstructionCost class.
113
+ ##
114
+ def self.merge_construction_cost(existing_cost, new_cost)
115
+ # modify the existing_cost by adding the :total_cost and :item_quantity
116
+ existing_cost.total_cost += new_cost.total_cost
117
+ existing_cost.item_quantity += new_cost.item_quantity
118
+
119
+ if existing_cost.category != new_cost.category
120
+ raise "Cannot merge existing cost of category \"#{existing_cost.category}\" with new cost of category \"#{new_cost.category}\"."
121
+ end
122
+
123
+ if existing_cost.cost_units != new_cost.cost_units
124
+ raise "Cannot merge existing cost with cost units \"#{existing_cost.cost_units}\" with new cost with cost units \"#{new_cost.cost_units}\". "
125
+ end
126
+
127
+ if existing_cost.unit_cost != new_cost.unit_cost
128
+ raise "Cannot merge existing cost with unit cost \"#{existing_cost.unit_cost}\" with new cost with unit cost \"#{new_cost.unit_cost}\"; identical items should have identical unit cost."
129
+ end
130
+
131
+ return existing_cost
132
+ end
133
+
134
+ ##
135
+ # Merges muliple construction costs together.
136
+ # - loops over the new_costs and find the index of the cost with identical +:item_name+.
137
+ # - if +item_name+ is identical then modify the existing_cost array by summing the :total_cost and :item_quantity. Else add the new_cost to existing_costs array.
138
+ ##
139
+ # [Parameters:]
140
+ # +existing_costs+ - _Array_ - An array of ConstructionCost objects.
141
+ ##
142
+ # +new_costs+ - _Array_ - An array of ConstructionCost objects.
143
+ def self.merge_construction_costs(existing_costs, new_costs)
144
+ item_name_list = []
145
+ item_name_list = existing_costs.collect(&:item_name)
146
+
147
+ new_costs.each do |x_new|
148
+ if item_name_list.include?(x_new.item_name)
149
+
150
+ # when looping over the new_cost item_names find the index of the item_name_list with the same item name
151
+ id = item_name_list.find_index(x_new.item_name) # the order of the item_name_list is the same as the order of the existing_cost hash-array
152
+
153
+ # modify the existing_cost array by adding the :total_cost and :item_quantity when looping over costs
154
+ existing_costs[id] = merge_construction_cost(existing_costs[id], x_new)
155
+
156
+ else
157
+
158
+ # insert the new hash in to the array
159
+ existing_costs << x_new
160
+
161
+ end
162
+ end
163
+
164
+ return existing_costs
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,97 @@
1
+ # *********************************************************************************
2
+ # URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
3
+ # contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list
9
+ # of conditions and the following disclaimer.
10
+ #
11
+ # Redistributions in binary form must reproduce the above copyright notice, this
12
+ # list of conditions and the following disclaimer in the documentation and/or other
13
+ # materials provided with the distribution.
14
+ #
15
+ # Neither the name of the copyright holder nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without specific
17
+ # prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+ # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ # *********************************************************************************
30
+
31
+ require 'urbanopt/scenario/default_reports/validator'
32
+ require 'json-schema'
33
+ require 'json'
34
+
35
+ module URBANopt
36
+ module Scenario
37
+ module DefaultReports
38
+ ##
39
+ # Date class include information of simulation run date.
40
+ ##
41
+ class Date
42
+ attr_accessor :month, :day_of_month, :year #:nodoc:
43
+ ##
44
+ # Date class intialize all date attributes:
45
+ # +:month+ , +:day_of_month+ , +:year+
46
+ ##
47
+ # [parameters:]
48
+ # +hash+ - _Hash_ - A hash which may contain a deserialized date.
49
+ ##
50
+ def initialize(hash = {})
51
+ hash.delete_if { |k, v| v.nil? }
52
+ hash = defaults.merge(hash)
53
+
54
+ @month = hash[:month].to_i
55
+ @day_of_month = hash[:day_of_month].to_i
56
+ @year = hash[:year].to_i
57
+
58
+ # initialize class variables @@validator and @@schema
59
+ @@validator ||= Validator.new
60
+ @@schema ||= @@validator.schema
61
+ end
62
+
63
+ ##
64
+ # Converts to a hash equivalent for JSON serialization.
65
+ ##
66
+ # - Exclude attributes with nil values.
67
+ # - Validate date properties against schema.
68
+ ##
69
+ def to_hash
70
+ result = {}
71
+ result[:month] = @month if @month
72
+ result[:day_of_month] = @day_of_month if @day_of_month
73
+ result[:year] = @year if @year
74
+
75
+ # validate date hash properties against schema
76
+ if @@validator.validate(@@schema[:definitions][:Date][:properties], result).any?
77
+ raise "end_uses properties does not match schema: #{@@validator.validate(@@schema[:definitions][:Date][:properties], result)}"
78
+ end
79
+
80
+ return result
81
+ end
82
+
83
+ ##
84
+ # Assigns default values if values do not exist.
85
+ ##
86
+ def defaults
87
+ hash = {}
88
+ hash[:month] = nil
89
+ hash[:day_of_month] = nil
90
+ hash[:year] = nil
91
+
92
+ return hash
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,159 @@
1
+ # *********************************************************************************
2
+ # URBANopt, Copyright (c) 2019, Alliance for Sustainable Energy, LLC, and other
3
+ # contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list
9
+ # of conditions and the following disclaimer.
10
+ #
11
+ # Redistributions in binary form must reproduce the above copyright notice, this
12
+ # list of conditions and the following disclaimer in the documentation and/or other
13
+ # materials provided with the distribution.
14
+ #
15
+ # Neither the name of the copyright holder nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without specific
17
+ # prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
+ # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
+ # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
+ # OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ # *********************************************************************************
30
+
31
+ require 'urbanopt/scenario/default_reports/validator'
32
+ require 'json-schema'
33
+
34
+ module URBANopt
35
+ module Scenario
36
+ module DefaultReports
37
+ ##
38
+ # Enduse class all enduse energy consumption results.
39
+ ##
40
+ class EndUse
41
+ attr_accessor :heating, :cooling, :interior_lighting, :exterior_lighting, :interior_equipment, :exterior_equipment,
42
+ :fans, :pumps, :heat_rejection, :humidification, :heat_recovery, :water_systems, :refrigeration, :generators # :nodoc:
43
+
44
+ ##
45
+ # EndUse class intialize all enduse atributes: +:heating+ , +:cooling+ , +:interior_lighting+ ,
46
+ # +:exterior_lighting+ , +:interior_equipment+ , +:exterior_equipment+ ,
47
+ # +:fans+ , +:pumps+ , +:heat_rejection+ , +:humidification+ , +:heat_recovery+ , +:water_systems+ , +:refrigeration+ , +:generators+
48
+ ##
49
+ # [parameters:]
50
+ # +hash+ - _Hash_ - A hash which may contain a deserialized end_use.
51
+ ##
52
+ def initialize(hash = {})
53
+ hash.delete_if { |k, v| v.nil? }
54
+ hash = defaults.merge(hash)
55
+
56
+ @heating = hash[:heating]
57
+ @cooling = hash[:cooling]
58
+ @interior_lighting = hash[:interior_lighting]
59
+ @exterior_lighting = hash[:exterior_lighting]
60
+ @interior_equipment = hash[:interior_equipment]
61
+ @exterior_equipment = hash[:exterior_equipment]
62
+ @fans = hash[:fans]
63
+ @pumps = hash[:pumps]
64
+ @heat_rejection = hash[:heat_rejection]
65
+ @humidification = hash[:humidification]
66
+ @heat_recovery = hash[:heat_recovery]
67
+ @water_systems = hash[:water_systems]
68
+ @refrigeration = hash[:refrigeration]
69
+ @generators = hash[:generators]
70
+
71
+ # initialize class variables @@validator and @@schema
72
+ @@validator ||= Validator.new
73
+ @@schema ||= @@validator.schema
74
+ end
75
+
76
+ ##
77
+ # Assign default values if values does not exist
78
+ ##
79
+ def defaults
80
+ hash = {}
81
+
82
+ hash[:heating] = nil
83
+ hash[:cooling] = nil
84
+ hash[:interior_lighting] = nil
85
+ hash[:exterior_lighting] = nil
86
+ hash[:interior_equipment] = nil
87
+ hash[:exterior_equipment] = nil
88
+ hash[:fans] = nil
89
+ hash[:pumps] = nil
90
+ hash[:heat_rejection] = nil
91
+ hash[:humidification] = nil
92
+ hash[:heat_recovery] = nil
93
+ hash[:water_systems] = nil
94
+ hash[:refrigeration] = nil
95
+ hash[:generators] = nil
96
+
97
+ return hash
98
+ end
99
+
100
+ ##
101
+ # Convert to a Hash equivalent for JSON serialization.
102
+ ##
103
+ # - Exclude attributes with nil values.
104
+ # - Validate end_use hash properties against schema.
105
+ ##
106
+ def to_hash
107
+ result = {}
108
+
109
+ result[:heating] = @heating
110
+ result[:cooling] = @cooling
111
+ result[:interior_lighting] = @interior_lighting
112
+ result[:exterior_lighting] = @exterior_lighting
113
+ result[:interior_equipment] = @interior_equipment
114
+ result[:exterior_equipment] = @exterior_equipment
115
+ result[:fans] = @fans
116
+ result[:pumps] = @pumps
117
+ result[:heat_rejection] = @heat_rejection
118
+ result[:humidification] = @humidification
119
+ result[:heat_recovery] = @heat_recovery
120
+ result[:water_systems] = @water_systems
121
+ result[:refrigeration] = @refrigeration
122
+ result[:generators] = @generators
123
+
124
+ # validate end_use properties against schema
125
+ if @@validator.validate(@@schema[:definitions][:EndUse][:properties], result).any?
126
+ raise "end_use properties does not match schema: #{@@validator.validate(@@schema[:definitions][:EndUse][:properties], result)}"
127
+ end
128
+
129
+ return result
130
+ end
131
+
132
+ ##
133
+ # Aggregate values of each EndUse attribute.
134
+ ##
135
+ # [Parameters:]
136
+ # +new_end_use+ - _EndUse_ - An object of EndUse class.
137
+ ##
138
+ def merge_end_use!(new_end_use)
139
+ @heating += new_end_use.heating if new_end_use.heating
140
+ @cooling += new_end_use.cooling if new_end_use.cooling
141
+ @interior_lighting += new_end_use.interior_lighting if new_end_use.interior_lighting
142
+ @exterior_lighting += new_end_use.exterior_lighting if new_end_use.exterior_lighting
143
+ @interior_equipment += new_end_use.interior_equipment if new_end_use.interior_equipment
144
+ @exterior_equipment += new_end_use.exterior_equipment if new_end_use.exterior_equipment
145
+ @fans += new_end_use.fans if new_end_use.fans
146
+ @pumps += new_end_use.pumps if new_end_use.pumps
147
+ @heat_rejection += new_end_use.heat_rejection if new_end_use.heat_rejection
148
+ @humidification += new_end_use.humidification if new_end_use.humidification
149
+ @heat_recovery += new_end_use.heat_recovery if new_end_use.heat_recovery
150
+ @water_systems += new_end_use.water_systems if new_end_use.water_systems
151
+ @refrigeration += new_end_use.refrigeration if new_end_use.refrigeration
152
+ @generators += new_end_use.generators if new_end_use.generators
153
+
154
+ return self
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end