honeybee-openstudio 2.15.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5a072c352d6cb78565cd3a69843d7e703121859a4684e56e193d8cc9a966e73
4
- data.tar.gz: f8d1f957f880db62bb76c2e04fb725473353db6a09702484741a1074c5b5ed46
3
+ metadata.gz: e2569dc4abe1834c7a927df0a13bec94de8ecc8584cf3b8edb8e2affd5d0a1de
4
+ data.tar.gz: 6684407214c56bcd19be74e7d93ed6aa4a9f2711a33b7dafdcce8341d63b75de
5
5
  SHA512:
6
- metadata.gz: 38a3302f5963735d28902658dd6d55ea282a23f5b3477c3674b780724f5c4a28227cd2726e65aaab8ecb04acbeb70e8604976a1ac0df8790c7cc3986deea626b
7
- data.tar.gz: fbdbd4fc1ced1eea8192b5e580d72b52fce7b8d96ae1136d3fbe77d3bddf5b2ea3986e263b8bb25c831b01b761e630a62d6a926b9a84acf209e6e245de2a33d4
6
+ metadata.gz: 2b81e0a2675b41298188da7b9d6e87ff2476304776358823796c36277887b21d1ffe7b9b5870ec19e9d80a5afe3fdd99a331cd4183ebac2654e7ec8c8c9d537b
7
+ data.tar.gz: c6c97f48723e86f865ba373471966306e8a5c7975a6a841087ad9014cf7d54c46394daba91c3fcb9c0fc1c6359943f44889364e00992ea3c43dcaaa90f4ba8e5
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'honeybee-openstudio'
7
- spec.version = '2.15.0'
7
+ spec.version = '2.16.0'
8
8
  spec.authors = ['Tanushree Charan', 'Dan Macumber', 'Chris Mackey', 'Mostapha Sadeghipour Roudsari']
9
9
  spec.email = ['tanushree.charan@nrel.gov', 'chris@ladybug.tools']
10
10
 
@@ -0,0 +1,23 @@
1
+ Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable Energy, LLC,
2
+ Ladybug Tools LLC and other contributors. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5
+ following conditions are met:
6
+
7
+ (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8
+ disclaimer.
9
+
10
+ (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11
+ disclaimer in the documentation and/or other materials provided with the distribution.
12
+
13
+ (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
14
+ derived from this software without specific prior written permission from the respective party.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
19
+ STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,32 @@
1
+
2
+
3
+ ###### (Automatically generated documentation)
4
+
5
+ # From gbXML Model
6
+
7
+ ## Description
8
+ Translate a gbXML model into a JSON file of a Honeybee Model.
9
+
10
+ ## Modeler Description
11
+ Translate a gbXML model into a JSON file of a Honeybee Model.
12
+
13
+ ## Measure Type
14
+ ModelMeasure
15
+
16
+ ## Taxonomy
17
+
18
+
19
+ ## Arguments
20
+
21
+
22
+ ### Path to the gbXML Model file
23
+
24
+ **Name:** gbxml_model,
25
+ **Type:** String,
26
+ **Units:** ,
27
+ **Required:** true,
28
+ **Model Dependent:** false
29
+
30
+
31
+
32
+
@@ -0,0 +1,114 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ # see the URL below for information on how to write OpenStudio measures
33
+ # http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
34
+
35
+ require 'from_openstudio'
36
+
37
+ # start the measure
38
+ class FromGbxmlModel < OpenStudio::Measure::ModelMeasure
39
+ # human readable name
40
+ def name
41
+ return "From Gbxml Model"
42
+ end
43
+
44
+ # human readable description
45
+ def description
46
+ return "Translate a gbXML into a JSON file of a Honeybee Model."
47
+ end
48
+
49
+ # human readable description of modeling approach
50
+ def modeler_description
51
+ return "Translate a gbXML into a JSON file of a Honeybee Model."
52
+ end
53
+
54
+ # define the arguments that the user will input
55
+ def arguments(model)
56
+ args = OpenStudio::Measure::OSArgumentVector.new
57
+
58
+ # Make an argument for the OpenStudio model
59
+ gbxml_model = OpenStudio::Measure::OSArgument.makeStringArgument('gbxml_model', true)
60
+ gbxml_model.setDisplayName('Path to the gbXML Model')
61
+ args << gbxml_model
62
+
63
+ # Make an argument for the output file path
64
+ output_file_path = OpenStudio::Measure::OSArgument.makeStringArgument('output_file_path', false)
65
+ output_file_path.setDisplayName('Output file path')
66
+ output_file_path.setDescription('If set, the output Honeybee JSON file will be exported to this path. Othervise The file will be exported to the same path as the gbXML model.')
67
+ output_file_path.setDefaultValue('')
68
+ args << output_file_path
69
+
70
+ return args
71
+ end
72
+
73
+ # define what happens when the measure is run
74
+ def run(model, runner, user_arguments)
75
+ super(model, runner, user_arguments)
76
+ STDOUT.flush
77
+ if !runner.validateUserArguments(arguments(model), user_arguments)
78
+ return false
79
+ end
80
+
81
+ gbxml_model = runner.getStringArgumentValue('gbxml_model', user_arguments)
82
+
83
+ gbxml_model_path, gbxml_model_name = File.split(gbxml_model)
84
+ honeybee_model_name = gbxml_model_name.split('.')[0] + '.hbjson'
85
+
86
+ if !File.exist?(gbxml_model)
87
+ runner.registerError("Cannot find file '#{gbxml_model}'")
88
+ return false
89
+ end
90
+
91
+ honeybee_model = Honeybee::Model.translate_from_gbxml_file(gbxml_model)
92
+ honeybee_hash = honeybee_model.hash
93
+
94
+ output_file_path = runner.getStringArgumentValue('output_file_path', user_arguments)
95
+
96
+ if output_file_path && !output_file_path.empty?
97
+ unless File.exist?(output_file_path)
98
+ output_folder = File.split(output_file_path)[0]
99
+ FileUtils.mkdir_p(output_folder)
100
+ end
101
+ else
102
+ output_file_path = File.join(gbxml_model_path, honeybee_model_name)
103
+ end
104
+
105
+ File.open(output_file_path, 'w') do |f|
106
+ f.puts JSON::pretty_generate(honeybee_hash)
107
+ end
108
+
109
+ return true
110
+ end
111
+ end
112
+
113
+ # register the measure to be used by the application
114
+ FromGbxmlModel.new.registerWithApplication
@@ -0,0 +1,131 @@
1
+ <?xml version="1.0"?>
2
+ <measure>
3
+ <schema_version>3.0</schema_version>
4
+ <name>from_gbxml_model</name>
5
+ <uid>e4b3a388-3468-4962-a12e-e2e02bacb0a2</uid>
6
+ <version_id>0261fa70-1322-43ce-ae24-e6e65eb98f03</version_id>
7
+ <version_modified>20210428T160059Z</version_modified>
8
+ <xml_checksum>6BA95EF6</xml_checksum>
9
+ <class_name>FromGbxmlModel</class_name>
10
+ <display_name>From Gbxml Model</display_name>
11
+ <description>Translate a gbXML into a JSON file of a Honeybee Model.</description>
12
+ <modeler_description>Translate a gbXML into a JSON file of a Honeybee Model.</modeler_description>
13
+ <arguments>
14
+ <argument>
15
+ <name>model_json</name>
16
+ <display_name>Path to the Honeybee Model JSON file</display_name>
17
+ <description></description>
18
+ <type>String</type>
19
+ <units></units>
20
+ <required>true</required>
21
+ <model_dependent>false</model_dependent>
22
+ <default_value></default_value>
23
+ <min_value></min_value>
24
+ <max_value></max_value>
25
+ </argument>
26
+ </arguments>
27
+ <outputs />
28
+ <provenances />
29
+ <tags>
30
+ <tag>Whole Building.Space Types</tag>
31
+ </tags>
32
+ <attributes>
33
+ <attribute>
34
+ <name>Intended Software Tool</name>
35
+ <value>Apply Measure Now</value>
36
+ <datatype>string</datatype>
37
+ </attribute>
38
+ <attribute>
39
+ <name>Intended Software Tool</name>
40
+ <value>OpenStudio Application</value>
41
+ <datatype>string</datatype>
42
+ </attribute>
43
+ <attribute>
44
+ <name>Intended Software Tool</name>
45
+ <value>Parametric Analysis Tool</value>
46
+ <datatype>string</datatype>
47
+ </attribute>
48
+ <attribute>
49
+ <name>Intended Software Tool</name>
50
+ <value>Apply Measure Now</value>
51
+ <datatype>string</datatype>
52
+ </attribute>
53
+ <attribute>
54
+ <name>Intended Software Tool</name>
55
+ <value>OpenStudio Application</value>
56
+ <datatype>string</datatype>
57
+ </attribute>
58
+ <attribute>
59
+ <name>Intended Software Tool</name>
60
+ <value>Parametric Analysis Tool</value>
61
+ <datatype>string</datatype>
62
+ </attribute>
63
+ <attribute>
64
+ <name>Intended Software Tool</name>
65
+ <value>Apply Measure Now</value>
66
+ <datatype>string</datatype>
67
+ </attribute>
68
+ <attribute>
69
+ <name>Intended Software Tool</name>
70
+ <value>OpenStudio Application</value>
71
+ <datatype>string</datatype>
72
+ </attribute>
73
+ <attribute>
74
+ <name>Intended Software Tool</name>
75
+ <value>Parametric Analysis Tool</value>
76
+ <datatype>string</datatype>
77
+ </attribute>
78
+ <attribute>
79
+ <name>Measure Type</name>
80
+ <value>ModelMeasure</value>
81
+ <datatype>string</datatype>
82
+ </attribute>
83
+ <attribute>
84
+ <name>Intended Software Tool</name>
85
+ <value>Apply Measure Now</value>
86
+ <datatype>string</datatype>
87
+ </attribute>
88
+ <attribute>
89
+ <name>Intended Software Tool</name>
90
+ <value>OpenStudio Application</value>
91
+ <datatype>string</datatype>
92
+ </attribute>
93
+ <attribute>
94
+ <name>Intended Software Tool</name>
95
+ <value>Parametric Analysis Tool</value>
96
+ <datatype>string</datatype>
97
+ </attribute>
98
+ </attributes>
99
+ <files>
100
+ <file>
101
+ <filename>LICENSE.md</filename>
102
+ <filetype>md</filetype>
103
+ <usage_type>license</usage_type>
104
+ <checksum>1E0EDDB0</checksum>
105
+ </file>
106
+ <file>
107
+ <filename>README.md</filename>
108
+ <filetype>md</filetype>
109
+ <usage_type>readme</usage_type>
110
+ <checksum>782C496D</checksum>
111
+ </file>
112
+ <file>
113
+ <version>
114
+ <software_program>OpenStudio</software_program>
115
+ <identifier>2.0.0</identifier>
116
+ <min_compatible>2.0.0</min_compatible>
117
+ </version>
118
+ <filename>measure.rb</filename>
119
+ <filetype>rb</filetype>
120
+ <usage_type>script</usage_type>
121
+ <checksum>D5D8CB66</checksum>
122
+ </file>
123
+ <file>
124
+ <filename>from_gbxml_model_test.rb</filename>
125
+ <filetype>rb</filetype>
126
+ <usage_type>test</usage_type>
127
+ <checksum>AE86B654</checksum>
128
+ </file>
129
+ </files>
130
+ </measure>
131
+ <error>cannot load such file -- from_openstudio</error>
@@ -0,0 +1,107 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ require 'openstudio'
33
+ require 'openstudio/ruleset/ShowRunnerOutput'
34
+ require 'minitest/autorun'
35
+ require_relative '../measure.rb'
36
+ require 'fileutils'
37
+
38
+ class FromGbxmlModel_Test < Minitest::Test
39
+ # method to apply arguments, run measure, and assert results (only populate args hash with non-default argument values)
40
+ def apply_measure_to_model(test_name, args, model_name = nil, result_value = 'Success', warnings_count = 0, info_count = nil)
41
+ # create an instance of the measure
42
+ measure = FromGbxmlModel.new
43
+
44
+ # create an instance of a runner
45
+ runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
46
+
47
+ if model_name.nil?
48
+ # make an empty model
49
+ model = OpenStudio::Model::Model.new
50
+ else
51
+ # load the test model
52
+ translator = OpenStudio::OSVersion::VersionTranslator.new
53
+ path = OpenStudio::Path.new(File.dirname(__FILE__) + '/' + model_name)
54
+ model = translator.loadModel(path)
55
+ assert(!model.empty?)
56
+ model = model.get
57
+ end
58
+
59
+ # get arguments
60
+ arguments = measure.arguments(model)
61
+ argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
62
+
63
+ # populate argument with specified hash value if specified
64
+ arguments.each do |arg|
65
+ temp_arg_var = arg.clone
66
+ if args.key?(arg.name)
67
+ assert(temp_arg_var.setValue(args[arg.name]), "could not set #{arg.name} to #{args[arg.name]}.")
68
+ end
69
+ argument_map[arg.name] = temp_arg_var
70
+ end
71
+
72
+ # run the measure
73
+ measure.run(model, runner, argument_map)
74
+ result = runner.result
75
+
76
+ puts "this is measure #{measure.run(model, runner, argument_map)}"
77
+ # show the output
78
+ puts "measure results for #{test_name}"
79
+ show_output(result)
80
+
81
+ # assert that it ran correctly
82
+ if result_value.nil? then result_value = 'Success' end
83
+ assert_equal(result_value, result.value.valueName)
84
+
85
+ # check count of warning and info messages
86
+ unless info_count.nil? then assert(result.info.size == info_count) end
87
+ unless warnings_count.nil? then assert(result.warnings.size == warnings_count, "warning count (#{result.warnings.size}) did not match expectation (#{warnings_count})") end
88
+
89
+ # if 'Fail' passed in make sure at least one error message (while not typical there may be more than one message)
90
+ if result_value == 'Fail' then assert(result.errors.size >= 1) end
91
+
92
+ end
93
+
94
+ def test_example_model_with_output_path
95
+ args = {}
96
+ args['gbxml_model'] = File.join(File.dirname(__FILE__) + '/../../../../spec/samples/gbxml/gbXML_TRK.xml')
97
+ args['output_file_path'] = File.join(File.dirname(__FILE__) + '/output/gbXML_TRK.hbjson')
98
+ apply_measure_to_model(__method__.to_s.gsub('test_',''),args, nil)
99
+ end
100
+
101
+ def test_example_model_without_output_path
102
+ args = {}
103
+ args['gbxml_model'] = File.join(File.dirname(__FILE__) + '/../../../../spec/samples/gbxml/gbXML_TRK.xml')
104
+ apply_measure_to_model(__method__.to_s.gsub('test_',''),args, nil)
105
+ end
106
+
107
+ end
@@ -0,0 +1,23 @@
1
+ Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable Energy, LLC,
2
+ Ladybug Tools LLC and other contributors. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5
+ following conditions are met:
6
+
7
+ (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8
+ disclaimer.
9
+
10
+ (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11
+ disclaimer in the documentation and/or other materials provided with the distribution.
12
+
13
+ (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
14
+ derived from this software without specific prior written permission from the respective party.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
19
+ STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,32 @@
1
+
2
+
3
+ ###### (Automatically generated documentation)
4
+
5
+ # From IDF Model
6
+
7
+ ## Description
8
+ Translate an IDF model into a JSON file of a Honeybee Model.
9
+
10
+ ## Modeler Description
11
+ Translate an IDF model into a JSON file of a Honeybee Model.
12
+
13
+ ## Measure Type
14
+ ModelMeasure
15
+
16
+ ## Taxonomy
17
+
18
+
19
+ ## Arguments
20
+
21
+
22
+ ### Path to the IDF Model file
23
+
24
+ **Name:** idf_model,
25
+ **Type:** String,
26
+ **Units:** ,
27
+ **Required:** true,
28
+ **Model Dependent:** false
29
+
30
+
31
+
32
+
@@ -0,0 +1,114 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ # see the URL below for information on how to write OpenStudio measures
33
+ # http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
34
+
35
+ require 'from_openstudio'
36
+
37
+ # start the measure
38
+ class FromIDFModel < OpenStudio::Measure::ModelMeasure
39
+ # human readable name
40
+ def name
41
+ return "From IDF Model"
42
+ end
43
+
44
+ # human readable description
45
+ def description
46
+ return "Translate an IDF into a JSON file of a Honeybee Model."
47
+ end
48
+
49
+ # human readable description of modeling approach
50
+ def modeler_description
51
+ return "Translate an IDF into a JSON file of a Honeybee Model."
52
+ end
53
+
54
+ # define the arguments that the user will input
55
+ def arguments(model)
56
+ args = OpenStudio::Measure::OSArgumentVector.new
57
+
58
+ # Make an argument for the OpenStudio model
59
+ idf_model = OpenStudio::Measure::OSArgument.makeStringArgument('idf_model', true)
60
+ idf_model.setDisplayName('Path to the IDF Model')
61
+ args << idf_model
62
+
63
+ # Make an argument for the output file path
64
+ output_file_path = OpenStudio::Measure::OSArgument.makeStringArgument('output_file_path', true)
65
+ output_file_path.setDisplayName('Output file path')
66
+ output_file_path.setDescription('If set, the output Honeybee JSON file will be exported to this path. Othervise The file will be exported to the same path as the IDF model.')
67
+ output_file_path.setDefaultValue('')
68
+ args << output_file_path
69
+
70
+ return args
71
+ end
72
+
73
+ # define what happens when the measure is run
74
+ def run(model, runner, user_arguments)
75
+ super(model, runner, user_arguments)
76
+ STDOUT.flush
77
+ if !runner.validateUserArguments(arguments(model), user_arguments)
78
+ return false
79
+ end
80
+
81
+ idf_model = runner.getStringArgumentValue('idf_model', user_arguments)
82
+
83
+ idf_model_path, idf_model_name = File.split(idf_model)
84
+ honeybee_model_name = idf_model_name.split('.')[0] + '.hbjson'
85
+
86
+ if !File.exist?(idf_model)
87
+ runner.registerError("Cannot find file '#{idf_model}'")
88
+ return false
89
+ end
90
+
91
+ honeybee_model = Honeybee::Model.translate_from_idf_file(idf_model)
92
+ honeybee_hash = honeybee_model.hash
93
+
94
+ output_file_path = runner.getStringArgumentValue('output_file_path', user_arguments)
95
+
96
+ if output_file_path && !output_file_path.empty?
97
+ unless File.exist?(output_file_path)
98
+ output_folder = File.split(output_file_path)[0]
99
+ FileUtils.mkdir_p(output_folder)
100
+ end
101
+ else
102
+ output_file_path = File.join(idf_model_path, honeybee_model_name)
103
+ end
104
+
105
+ File.open(output_file_path, 'w') do |f|
106
+ f.puts JSON::pretty_generate(honeybee_hash)
107
+ end
108
+
109
+ return true
110
+ end
111
+ end
112
+
113
+ # register the measure to be used by the application
114
+ FromIDFModel.new.registerWithApplication
@@ -0,0 +1,110 @@
1
+ <measure>
2
+ <schema_version>3.0</schema_version>
3
+ <error>cannot load such file -- from_openstudio</error>
4
+ <name>from_idf_model</name>
5
+ <uid>6289a4f0-a0b5-4c6e-901c-803bbfa86285</uid>
6
+ <version_id>83bb447b-e314-450e-ac1c-3907a7ac9857</version_id>
7
+ <version_modified>20210428T160244Z</version_modified>
8
+ <xml_checksum>9339BE01</xml_checksum>
9
+ <class_name>FromIDFModel</class_name>
10
+ <display_name>From IDF Model</display_name>
11
+ <description>Translate an IDF into a JSON file of a Honeybee Model.</description>
12
+ <modeler_description>Translate an IDF into a JSON file of a Honeybee Model.</modeler_description>
13
+ <arguments>
14
+ <argument>
15
+ <name>model_json</name>
16
+ <display_name>Path to the Honeybee Model JSON file</display_name>
17
+ <type>String</type>
18
+ <required>true</required>
19
+ <model_dependent>false</model_dependent>
20
+ </argument>
21
+ </arguments>
22
+ <outputs/>
23
+ <provenances/>
24
+ <tags>
25
+ <tag>Whole Building.Space Types</tag>
26
+ </tags>
27
+ <attributes>
28
+ <attribute>
29
+ <name>Intended Software Tool</name>
30
+ <value>Apply Measure Now</value>
31
+ <datatype>string</datatype>
32
+ </attribute>
33
+ <attribute>
34
+ <name>Intended Software Tool</name>
35
+ <value>OpenStudio Application</value>
36
+ <datatype>string</datatype>
37
+ </attribute>
38
+ <attribute>
39
+ <name>Intended Software Tool</name>
40
+ <value>Parametric Analysis Tool</value>
41
+ <datatype>string</datatype>
42
+ </attribute>
43
+ <attribute>
44
+ <name>Intended Software Tool</name>
45
+ <value>Apply Measure Now</value>
46
+ <datatype>string</datatype>
47
+ </attribute>
48
+ <attribute>
49
+ <name>Intended Software Tool</name>
50
+ <value>OpenStudio Application</value>
51
+ <datatype>string</datatype>
52
+ </attribute>
53
+ <attribute>
54
+ <name>Intended Software Tool</name>
55
+ <value>Parametric Analysis Tool</value>
56
+ <datatype>string</datatype>
57
+ </attribute>
58
+ <attribute>
59
+ <name>Measure Type</name>
60
+ <value>ModelMeasure</value>
61
+ <datatype>string</datatype>
62
+ </attribute>
63
+ <attribute>
64
+ <name>Intended Software Tool</name>
65
+ <value>Apply Measure Now</value>
66
+ <datatype>string</datatype>
67
+ </attribute>
68
+ <attribute>
69
+ <name>Intended Software Tool</name>
70
+ <value>OpenStudio Application</value>
71
+ <datatype>string</datatype>
72
+ </attribute>
73
+ <attribute>
74
+ <name>Intended Software Tool</name>
75
+ <value>Parametric Analysis Tool</value>
76
+ <datatype>string</datatype>
77
+ </attribute>
78
+ </attributes>
79
+ <files>
80
+ <file>
81
+ <filename>LICENSE.md</filename>
82
+ <filetype>md</filetype>
83
+ <usage_type>license</usage_type>
84
+ <checksum>1E0EDDB0</checksum>
85
+ </file>
86
+ <file>
87
+ <filename>README.md</filename>
88
+ <filetype>md</filetype>
89
+ <usage_type>readme</usage_type>
90
+ <checksum>782C496D</checksum>
91
+ </file>
92
+ <file>
93
+ <version>
94
+ <software_program>OpenStudio</software_program>
95
+ <identifier>2.0.0</identifier>
96
+ <min_compatible>2.0.0</min_compatible>
97
+ </version>
98
+ <filename>measure.rb</filename>
99
+ <filetype>rb</filetype>
100
+ <usage_type>script</usage_type>
101
+ <checksum>6ED73120</checksum>
102
+ </file>
103
+ <file>
104
+ <filename>from_idf_model_test.rb</filename>
105
+ <filetype>rb</filetype>
106
+ <usage_type>test</usage_type>
107
+ <checksum>8D19788D</checksum>
108
+ </file>
109
+ </files>
110
+ </measure>
@@ -0,0 +1,107 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ require 'openstudio'
33
+ require 'openstudio/ruleset/ShowRunnerOutput'
34
+ require 'minitest/autorun'
35
+ require_relative '../measure.rb'
36
+ require 'fileutils'
37
+
38
+ class FromIDFModel_Test < Minitest::Test
39
+ # method to apply arguments, run measure, and assert results (only populate args hash with non-default argument values)
40
+ def apply_measure_to_model(test_name, args, model_name = nil, result_value = 'Success', warnings_count = 0, info_count = nil)
41
+ # create an instance of the measure
42
+ measure = FromIDFModel.new
43
+
44
+ # create an instance of a runner
45
+ runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
46
+
47
+ if model_name.nil?
48
+ # make an empty model
49
+ model = OpenStudio::Model::Model.new
50
+ else
51
+ # load the test model
52
+ translator = OpenStudio::OSVersion::VersionTranslator.new
53
+ path = OpenStudio::Path.new(File.dirname(__FILE__) + '/' + model_name)
54
+ model = translator.loadModel(path)
55
+ assert(!model.empty?)
56
+ model = model.get
57
+ end
58
+
59
+ # get arguments
60
+ arguments = measure.arguments(model)
61
+ argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
62
+
63
+ # populate argument with specified hash value if specified
64
+ arguments.each do |arg|
65
+ temp_arg_var = arg.clone
66
+ if args.key?(arg.name)
67
+ assert(temp_arg_var.setValue(args[arg.name]), "could not set #{arg.name} to #{args[arg.name]}.")
68
+ end
69
+ argument_map[arg.name] = temp_arg_var
70
+ end
71
+
72
+ # run the measure
73
+ measure.run(model, runner, argument_map)
74
+ result = runner.result
75
+
76
+ puts "this is measure #{measure.run(model, runner, argument_map)}"
77
+ # show the output
78
+ puts "measure results for #{test_name}"
79
+ show_output(result)
80
+
81
+ # assert that it ran correctly
82
+ if result_value.nil? then result_value = 'Success' end
83
+ assert_equal(result_value, result.value.valueName)
84
+
85
+ # check count of warning and info messages
86
+ unless info_count.nil? then assert(result.info.size == info_count) end
87
+ unless warnings_count.nil? then assert(result.warnings.size == warnings_count, "warning count (#{result.warnings.size}) did not match expectation (#{warnings_count})") end
88
+
89
+ # if 'Fail' passed in make sure at least one error message (while not typical there may be more than one message)
90
+ if result_value == 'Fail' then assert(result.errors.size >= 1) end
91
+
92
+ end
93
+
94
+ def test_example_model_with_output_path
95
+ args = {}
96
+ args['idf_model'] = File.join(File.dirname(__FILE__) + '/../../../../spec/samples/idf/5ZoneAirCooled.idf')
97
+ args['output_file_path'] = File.join(File.dirname(__FILE__) + '/output/5ZoneAirCooled.hbjson')
98
+ apply_measure_to_model(__method__.to_s.gsub('test_',''),args, nil)
99
+ end
100
+
101
+ def test_example_model_without_output_path
102
+ args = {}
103
+ args['idf_model'] = File.join(File.dirname(__FILE__) + '/../../../../spec/samples/idf/5ZoneAirCooled.idf')
104
+ apply_measure_to_model(__method__.to_s.gsub('test_',''),args, nil)
105
+ end
106
+
107
+ end
@@ -0,0 +1,23 @@
1
+ Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable Energy, LLC,
2
+ Ladybug Tools LLC and other contributors. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5
+ following conditions are met:
6
+
7
+ (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8
+ disclaimer.
9
+
10
+ (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11
+ disclaimer in the documentation and/or other materials provided with the distribution.
12
+
13
+ (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
14
+ derived from this software without specific prior written permission from the respective party.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
19
+ STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,32 @@
1
+
2
+
3
+ ###### (Automatically generated documentation)
4
+
5
+ # From Openstudio Model
6
+
7
+ ## Description
8
+ Translate an OpenStudio model into a JSON file of a Honeybee Model.
9
+
10
+ ## Modeler Description
11
+ Translate an OpenStudio model into a JSON file of a Honeybee Model.
12
+
13
+ ## Measure Type
14
+ ModelMeasure
15
+
16
+ ## Taxonomy
17
+
18
+
19
+ ## Arguments
20
+
21
+
22
+ ### Path to the gbXML Model file
23
+
24
+ **Name:** openstudio_model,
25
+ **Type:** String,
26
+ **Units:** ,
27
+ **Required:** true,
28
+ **Model Dependent:** false
29
+
30
+
31
+
32
+
@@ -0,0 +1,114 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ # see the URL below for information on how to write OpenStudio measures
33
+ # http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
34
+
35
+ require 'from_openstudio'
36
+
37
+ # start the measure
38
+ class FromOpenstudioModel < OpenStudio::Measure::ModelMeasure
39
+ # human readable name
40
+ def name
41
+ return "From Openstudio Model"
42
+ end
43
+
44
+ # human readable description
45
+ def description
46
+ return "Translate an OpenStudio Model into a JSON file of a Honeybee Model."
47
+ end
48
+
49
+ # human readable description of modeling approach
50
+ def modeler_description
51
+ return "Translate an OpenStudio Model into a JSON file of a Honeybee Model."
52
+ end
53
+
54
+ # define the arguments that the user will input
55
+ def arguments(model)
56
+ args = OpenStudio::Measure::OSArgumentVector.new
57
+
58
+ # Make an argument for the OpenStudio model
59
+ openstudio_model = OpenStudio::Measure::OSArgument.makeStringArgument('openstudio_model', true)
60
+ openstudio_model.setDisplayName('Path to the OpenStudio Model')
61
+ args << openstudio_model
62
+
63
+ # Make an argument for the output file path
64
+ output_file_path = OpenStudio::Measure::OSArgument.makeStringArgument('output_file_path', true)
65
+ output_file_path.setDisplayName('Output file path')
66
+ output_file_path.setDescription('If set, the output Honeybee JSON file will be exported to this path. Othervise The file will be exported to the same path as the OpenStudio model.')
67
+ output_file_path.setDefaultValue('')
68
+ args << output_file_path
69
+
70
+ return args
71
+ end
72
+
73
+ # define what happens when the measure is run
74
+ def run(model, runner, user_arguments)
75
+ super(model, runner, user_arguments)
76
+ STDOUT.flush
77
+ if !runner.validateUserArguments(arguments(model), user_arguments)
78
+ return false
79
+ end
80
+
81
+ openstudio_model = runner.getStringArgumentValue('openstudio_model', user_arguments)
82
+
83
+ openstudio_model_path, openstudio_model_name = File.split(openstudio_model)
84
+ honeybee_model_name = openstudio_model_name.split('.')[0] + '.hbjson'
85
+
86
+ if !File.exist?(openstudio_model)
87
+ runner.registerError("Cannot find file '#{openstudio_model}'")
88
+ return false
89
+ end
90
+
91
+ honeybee_model = Honeybee::Model.translate_from_osm_file(openstudio_model)
92
+ honeybee_hash = honeybee_model.hash
93
+
94
+ output_file_path = runner.getStringArgumentValue('output_file_path', user_arguments)
95
+
96
+ if output_file_path && !output_file_path.empty?
97
+ unless File.exist?(output_file_path)
98
+ output_folder = File.split(output_file_path)[0]
99
+ FileUtils.mkdir_p(output_folder)
100
+ end
101
+ else
102
+ output_file_path = File.join(openstudio_model_path, honeybee_model_name)
103
+ end
104
+
105
+ File.open(output_file_path, 'w') do |f|
106
+ f.puts JSON::pretty_generate(honeybee_hash)
107
+ end
108
+
109
+ return true
110
+ end
111
+ end
112
+
113
+ # register the measure to be used by the application
114
+ FromOpenstudioModel.new.registerWithApplication
@@ -0,0 +1,95 @@
1
+ <measure>
2
+ <schema_version>3.0</schema_version>
3
+ <error>cannot load such file -- from_openstudio</error>
4
+ <name>to_honeybee_model</name>
5
+ <uid>16430548-e5e2-4f42-92bb-e9c56ece48a2</uid>
6
+ <version_id>111f10ae-7890-41b1-991e-8c80cc89a03e</version_id>
7
+ <version_modified>20210428T160245Z</version_modified>
8
+ <xml_checksum>48718AE9</xml_checksum>
9
+ <class_name>FromOpenstudioModel</class_name>
10
+ <display_name>From Openstudio Model</display_name>
11
+ <description>Translate an OpenStudio Model into a JSON file of a Honeybee Model.</description>
12
+ <modeler_description>Translate an OpenStudio Model into a JSON file of a Honeybee Model.</modeler_description>
13
+ <arguments>
14
+ <argument>
15
+ <name>model_json</name>
16
+ <display_name>Path to the Honeybee Model JSON file</display_name>
17
+ <type>String</type>
18
+ <required>true</required>
19
+ <model_dependent>false</model_dependent>
20
+ </argument>
21
+ </arguments>
22
+ <outputs/>
23
+ <provenances/>
24
+ <tags>
25
+ <tag>Whole Building.Space Types</tag>
26
+ </tags>
27
+ <attributes>
28
+ <attribute>
29
+ <name>Intended Software Tool</name>
30
+ <value>Apply Measure Now</value>
31
+ <datatype>string</datatype>
32
+ </attribute>
33
+ <attribute>
34
+ <name>Intended Software Tool</name>
35
+ <value>OpenStudio Application</value>
36
+ <datatype>string</datatype>
37
+ </attribute>
38
+ <attribute>
39
+ <name>Intended Software Tool</name>
40
+ <value>Parametric Analysis Tool</value>
41
+ <datatype>string</datatype>
42
+ </attribute>
43
+ <attribute>
44
+ <name>Measure Type</name>
45
+ <value>ModelMeasure</value>
46
+ <datatype>string</datatype>
47
+ </attribute>
48
+ <attribute>
49
+ <name>Intended Software Tool</name>
50
+ <value>Apply Measure Now</value>
51
+ <datatype>string</datatype>
52
+ </attribute>
53
+ <attribute>
54
+ <name>Intended Software Tool</name>
55
+ <value>OpenStudio Application</value>
56
+ <datatype>string</datatype>
57
+ </attribute>
58
+ <attribute>
59
+ <name>Intended Software Tool</name>
60
+ <value>Parametric Analysis Tool</value>
61
+ <datatype>string</datatype>
62
+ </attribute>
63
+ </attributes>
64
+ <files>
65
+ <file>
66
+ <filename>LICENSE.md</filename>
67
+ <filetype>md</filetype>
68
+ <usage_type>license</usage_type>
69
+ <checksum>1E0EDDB0</checksum>
70
+ </file>
71
+ <file>
72
+ <filename>README.md</filename>
73
+ <filetype>md</filetype>
74
+ <usage_type>readme</usage_type>
75
+ <checksum>782C496D</checksum>
76
+ </file>
77
+ <file>
78
+ <version>
79
+ <software_program>OpenStudio</software_program>
80
+ <identifier>2.0.0</identifier>
81
+ <min_compatible>2.0.0</min_compatible>
82
+ </version>
83
+ <filename>measure.rb</filename>
84
+ <filetype>rb</filetype>
85
+ <usage_type>script</usage_type>
86
+ <checksum>F2CBBDA4</checksum>
87
+ </file>
88
+ <file>
89
+ <filename>from_openstudio_model_test.rb</filename>
90
+ <filetype>rb</filetype>
91
+ <usage_type>test</usage_type>
92
+ <checksum>4E11086F</checksum>
93
+ </file>
94
+ </files>
95
+ </measure>
@@ -0,0 +1,107 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ require 'openstudio'
33
+ require 'openstudio/ruleset/ShowRunnerOutput'
34
+ require 'minitest/autorun'
35
+ require_relative '../measure.rb'
36
+ require 'fileutils'
37
+
38
+ class FromOpenstudioModel_Test < Minitest::Test
39
+ # method to apply arguments, run measure, and assert results (only populate args hash with non-default argument values)
40
+ def apply_measure_to_model(test_name, args, model_name = nil, result_value = 'Success', warnings_count = 0, info_count = nil)
41
+ # create an instance of the measure
42
+ measure = FromOpenstudioModel.new
43
+
44
+ # create an instance of a runner
45
+ runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
46
+
47
+ if model_name.nil?
48
+ # make an empty model
49
+ model = OpenStudio::Model::Model.new
50
+ else
51
+ # load the test model
52
+ translator = OpenStudio::OSVersion::VersionTranslator.new
53
+ path = OpenStudio::Path.new(File.dirname(__FILE__) + '/' + model_name)
54
+ model = translator.loadModel(path)
55
+ assert(!model.empty?)
56
+ model = model.get
57
+ end
58
+
59
+ # get arguments
60
+ arguments = measure.arguments(model)
61
+ argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
62
+
63
+ # populate argument with specified hash value if specified
64
+ arguments.each do |arg|
65
+ temp_arg_var = arg.clone
66
+ if args.key?(arg.name)
67
+ assert(temp_arg_var.setValue(args[arg.name]), "could not set #{arg.name} to #{args[arg.name]}.")
68
+ end
69
+ argument_map[arg.name] = temp_arg_var
70
+ end
71
+
72
+ # run the measure
73
+ measure.run(model, runner, argument_map)
74
+ result = runner.result
75
+
76
+ puts "this is measure #{measure.run(model, runner, argument_map)}"
77
+ # show the output
78
+ puts "measure results for #{test_name}"
79
+ show_output(result)
80
+
81
+ # assert that it ran correctly
82
+ if result_value.nil? then result_value = 'Success' end
83
+ assert_equal(result_value, result.value.valueName)
84
+
85
+ # check count of warning and info messages
86
+ unless info_count.nil? then assert(result.info.size == info_count) end
87
+ unless warnings_count.nil? then assert(result.warnings.size == warnings_count, "warning count (#{result.warnings.size}) did not match expectation (#{warnings_count})") end
88
+
89
+ # if 'Fail' passed in make sure at least one error message (while not typical there may be more than one message)
90
+ if result_value == 'Fail' then assert(result.errors.size >= 1) end
91
+
92
+ end
93
+
94
+ def test_example_model_with_output_path
95
+ args = {}
96
+ args['openstudio_model'] = File.join(File.dirname(__FILE__) + '/../../../../spec/samples/osm/exampleModel.osm')
97
+ args['output_file_path'] = File.join(File.dirname(__FILE__) + '/output/exampleModel.hbjson')
98
+ apply_measure_to_model(__method__.to_s.gsub('test_',''),args, nil)
99
+ end
100
+
101
+ def test_example_model_without_output_path
102
+ args = {}
103
+ args['openstudio_model'] = File.join(File.dirname(__FILE__) + '/../../../../spec/samples/osm/exampleModel.osm')
104
+ apply_measure_to_model(__method__.to_s.gsub('test_',''),args, nil)
105
+ end
106
+
107
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honeybee-openstudio
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 2.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanushree Charan
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-04-27 00:00:00.000000000 Z
14
+ date: 2021-04-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json_pure
@@ -152,6 +152,11 @@ files:
152
152
  - lib/honeybee/ventcool/opening.rb
153
153
  - lib/honeybee/ventcool/simulation.rb
154
154
  - lib/measures/.gitkeep
155
+ - lib/measures/from_gbxml_model/LICENSE.md
156
+ - lib/measures/from_gbxml_model/README.md
157
+ - lib/measures/from_gbxml_model/measure.rb
158
+ - lib/measures/from_gbxml_model/measure.xml
159
+ - lib/measures/from_gbxml_model/tests/from_gbxml_model_test.rb
155
160
  - lib/measures/from_honeybee_model/LICENSE.md
156
161
  - lib/measures/from_honeybee_model/README.md
157
162
  - lib/measures/from_honeybee_model/measure.rb
@@ -162,6 +167,16 @@ files:
162
167
  - lib/measures/from_honeybee_simulation_parameter/measure.rb
163
168
  - lib/measures/from_honeybee_simulation_parameter/measure.xml
164
169
  - lib/measures/from_honeybee_simulation_parameter/tests/from_honeybee_simulation_parameter_test.rb
170
+ - lib/measures/from_idf_model/LICENSE.md
171
+ - lib/measures/from_idf_model/README.md
172
+ - lib/measures/from_idf_model/measure.rb
173
+ - lib/measures/from_idf_model/measure.xml
174
+ - lib/measures/from_idf_model/tests/from_idf_model_test.rb
175
+ - lib/measures/from_openstudio_model/LICENSE.md
176
+ - lib/measures/from_openstudio_model/README.md
177
+ - lib/measures/from_openstudio_model/measure.rb
178
+ - lib/measures/from_openstudio_model/measure.xml
179
+ - lib/measures/from_openstudio_model/tests/from_openstudio_model_test.rb
165
180
  - lib/to_openstudio.rb
166
181
  - lib/to_openstudio/construction/air.rb
167
182
  - lib/to_openstudio/construction/opaque.rb