openstudio-analysis 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7721505c4383067dbed378a9de67e7ca4d86277d0000fc47c764b7b16e79a191
4
- data.tar.gz: 68d711d6ac89e4c879c1fda531e267479afce94b9b10c87b1ef30193e16f96fb
3
+ metadata.gz: 76642f1d452e8e46218af9c36e388da0033e43469ec2063d6c61f4e4cd9b99fd
4
+ data.tar.gz: 40b243f4b0375a79e726bf4105913f75fc3ce65d09134aa27e5a927c36984b57
5
5
  SHA512:
6
- metadata.gz: dc866e59c1c8c5a80c21ddb3614069c7a94b48b422390a7a0f35b1781db71d10830afc7663c187082df7962a69f1d9cf5bbb5cfb9f44d1aabd53f592b6d185a0
7
- data.tar.gz: 4e01767d2ea6431b0673b861552dbed0c971c7c58f7e8618814d7cfcb8c9e31774bb5b2c70ecf8f10e9c2f4b6cc264f4e96f434dabe5223a2298e1b2f2ceece9
6
+ metadata.gz: 5a9bbb7d5567cf1a7ecb6b243490e4eb3c50b0dd28cdad09fec821eaece6803fb45a3cb554ad975cca257e84644b8fe28630a5243ec4c62c4fc371583c01f638
7
+ data.tar.gz: 5a245e5b8c151fe7f079cc26af188115da571e420fc7a8df0b02a2c859bbd72ca2b91bff0aacac675677e86c7cf0d553463980ecf75ddc78e926221471f3b418
@@ -1,9 +1,16 @@
1
1
  OpenStudio Analysis Gem Change Log
2
2
  ==================================
3
3
 
4
+ Version 1.0.5
5
+ -------------
6
+ * Upgrade to latest BCL (0.6.1)
7
+ * Remove the need for the measure.json (which has been deprecated in BCL gem). Now parses the measure.xml.
8
+ * Upgrade Faraday (1.0.1)
9
+ * Remove dependency on Nokogiri.
10
+
4
11
  Version 1.0.4
5
12
  -------------
6
- * Update dependency nokogiri
13
+ * Update dependency Nokogiri
7
14
 
8
15
  Version 1.0.3
9
16
  -------------
@@ -70,6 +70,7 @@ require 'openstudio/analysis/translator/workflow'
70
70
  # helpers / core_ext
71
71
  require 'openstudio/helpers/string'
72
72
  require 'openstudio/helpers/hash'
73
+ require 'openstudio/helpers/utils'
73
74
 
74
75
  # weather file parsing
75
76
  require 'openstudio/weather/epw'
@@ -58,7 +58,7 @@ module OpenStudio
58
58
  attr_accessor :name
59
59
  attr_reader :analysis_name
60
60
 
61
- require 'nokogiri'
61
+ require 'rexml/document'
62
62
 
63
63
  # Pass in the filename to read
64
64
  def initialize(csv_filename)
@@ -368,16 +368,16 @@ module OpenStudio
368
368
  data = []
369
369
  measures.each_with_index do |measure, measure_index|
370
370
  data[measure_index] = {}
371
- measure_xml, measure_type = find_measure(measure.to_s)
371
+ measure_parsed = find_measure(measure.to_s)
372
372
 
373
- raise "Could not find measure #{measure} xml in measure_paths: '#{@measure_paths.join("\n")}'" unless measure_xml
373
+ raise "Could not find measure #{measure} xml in measure_paths: '#{@measure_paths.join("\n")}'" unless measure_parsed
374
374
  measure_data = {}
375
- measure_data[:classname] = measure_xml.xpath('/measure/class_name').text
376
- measure_data[:name] = measure_xml.xpath('/measure/name').text
377
- measure_data[:display_name] = measure_xml.xpath('/measure/display_name').text
378
- measure_data[:measure_type] = measure_type
379
- measure_data[:uid] = measure_xml.xpath('/measure/uid').text
380
- measure_data[:version_id] = measure_xml.xpath('/measure/version_id').text
375
+ measure_data[:classname] = measure_parsed[:classname]
376
+ measure_data[:name] = measure_parsed[:name]
377
+ measure_data[:display_name] = measure_parsed[:display_name]
378
+ measure_data[:measure_type] = measure_parsed[:measure_type]
379
+ measure_data[:uid] = measure_parsed[:uid]
380
+ measure_data[:version_id] = measure_parsed[:version_id]
381
381
  data[measure_index][:measure_data] = measure_data
382
382
  data[measure_index][:vars] = []
383
383
  vars = measure_map[measure]
@@ -389,8 +389,8 @@ module OpenStudio
389
389
  next if var.to_s == 'None'
390
390
  var_hash = {}
391
391
  found_arg = nil
392
- measure_xml.xpath('/measure/arguments/argument').each do |arg|
393
- if var.to_s == '__SKIP__' || arg.xpath('name').text == var.to_s
392
+ measure_parsed[:arguments].each do |arg|
393
+ if var.to_s == '__SKIP__' || arg[:name] == var.to_s
394
394
  found_arg = arg
395
395
  break
396
396
  end
@@ -404,8 +404,8 @@ module OpenStudio
404
404
  var_type = 'boolean'
405
405
  var_units = ''
406
406
  else
407
- var_type = found_arg.xpath('type').text.downcase
408
- var_units = found_arg.xpath('units')
407
+ var_type = found_arg[:variable_type].downcase
408
+ var_units = found_arg[:units]
409
409
  end
410
410
 
411
411
  var_hash[:name] = var.to_s
@@ -437,7 +437,8 @@ module OpenStudio
437
437
  var_hash[:distribution][:type] = 'discrete'
438
438
  var_hash[:distribution][:units] = var_hash[:units]
439
439
  if var_hash[:type] == 'choice'
440
- var_hash[:distribution][:enumerations] = found_arg.xpath('choices/choice').map { |s| s.xpath('value').text }
440
+ # var_hash[:distribution][:enumerations] = found_arg.xpath('choices/choice').map { |s| s.xpath('value').text }
441
+ # This would need to be updated if we want to do this again... sorry.
441
442
  elsif var_hash[:type] == 'bool'
442
443
  var_hash[:distribution][:enumerations] = []
443
444
  var_hash[:distribution][:enumerations] << true
@@ -447,13 +448,13 @@ module OpenStudio
447
448
  end
448
449
  data[measure_index][:args] = []
449
450
 
450
- measure_xml.xpath('/measure/arguments/argument').each do |arg_xml|
451
+ measure_parsed[:arguments].each do |arg_xml|
451
452
  arg = {}
452
- arg[:value_type] = arg_xml.xpath('type').text.downcase
453
- arg[:name] = arg_xml.xpath('name').text.downcase
454
- arg[:display_name] = arg_xml.xpath('display_name').text.downcase
453
+ arg[:value_type] = arg_xml[:variable_type]
454
+ arg[:name] = arg_xml[:name]
455
+ arg[:display_name] = arg_xml[:display_name].downcase
455
456
  arg[:display_name_short] = arg[:display_name]
456
- arg[:default_value] = arg_xml.xpath('default_value').text.downcase
457
+ arg[:default_value] = arg_xml[:default_value].downcase
457
458
  arg[:value] = arg[:default_value]
458
459
  data[measure_index][:args] << arg
459
460
  end
@@ -470,27 +471,12 @@ module OpenStudio
470
471
  measure_xml = File.join(mp, measure_name, 'measure.xml')
471
472
  measure_rb = File.join(mp, measure_name, 'measure.rb')
472
473
  if File.exist?(measure_xml) && File.exist?(measure_rb)
473
- return Nokogiri::XML File.read(measure_xml), parse_measure_type(measure_rb)
474
+ measure_parsed = parse_measure_xml(measure_xml)
475
+ return measure_parsed
474
476
  end
475
477
  end
476
478
 
477
- return nil, nil
478
- end
479
-
480
- def parse_measure_type(measure_filename)
481
- measure_string = File.read(measure_filename)
482
-
483
- if measure_string =~ /OpenStudio::Ruleset::WorkspaceUserScript/
484
- return 'EnergyPlusMeasure'
485
- elsif measure_string =~ /OpenStudio::Ruleset::ModelUserScript/
486
- return 'RubyMeasure'
487
- elsif measure_string =~ /OpenStudio::Ruleset::ReportingUserScript/
488
- return 'ReportingMeasure'
489
- elsif measure_string =~ /OpenStudio::Ruleset::UtilityUserScript/
490
- return 'UtilityUserScript'
491
- else
492
- raise "measure type is unknown with an inherited class in #{measure_filename}"
493
- end
479
+ return nil
494
480
  end
495
481
  end
496
482
  end
@@ -96,7 +96,7 @@ module OpenStudio
96
96
  step_hash[:modeler_description] = step[:modeler_description] if step[:modeler_description]
97
97
  step_hash[:taxonomy] = step[:taxonomy] if step[:taxonomy]
98
98
  step_hash[:measure_type] = step[:measure_type]
99
- step_hash[:measure_type] = 'ModelMeasure' if step_hash[:measure_type] == 'RubyMeasure'
99
+ step_hash[:measure_type] = 'ModelMeasure'
100
100
  @steps << step_hash
101
101
  end
102
102
  end
@@ -35,6 +35,6 @@
35
35
 
36
36
  module OpenStudio
37
37
  module Analysis
38
- VERSION = '1.0.4'.freeze
38
+ VERSION = '1.0.5'.freeze
39
39
  end
40
40
  end
@@ -53,8 +53,7 @@ module OpenStudio
53
53
  @items.clear
54
54
  end
55
55
 
56
- # Add a measure to the workflow from a path. Inside the path it is expecting to have a measure.json file
57
- # if not, the BCL gem is used to create the measure.json file.
56
+ # Add a measure to the workflow from a path. This will parse the measure.xml which must exist.
58
57
  #
59
58
  # @params instance_name [String] The name of the instance. This allows for multiple measures to be added to the workflow with uni que names
60
59
  # @params instance_display_name [String] The display name of the instance. This allows for multiple measures to be added to the workflow with unique names
@@ -69,19 +68,11 @@ module OpenStudio
69
68
  end
70
69
 
71
70
  if Dir.exist?(local_path_to_measure) && File.directory?(local_path_to_measure)
72
- # Watch out for namespace conflicts (use ::BCL)
73
- b = ::BCL::ComponentMethods.new
74
71
  measure_hash = nil
75
- unless File.exist?(File.join(local_path_to_measure, 'measure.json'))
76
- measure_hash = b.parse_measure_file(nil, File.join(local_path_to_measure, measure_filename))
77
- File.open(File.join(local_path_to_measure, 'measure.json'), 'w') { |f| f << JSON.pretty_generate(measure_hash) }
78
- warn("measure.json not found in #{local_path_to_measure}, will parse measure file using BCL gem")
79
- end
80
-
81
- if measure_hash.nil? && File.exist?(File.join(local_path_to_measure, 'measure.json'))
82
- measure_hash = JSON.parse(File.read(File.join(local_path_to_measure, 'measure.json')), symbolize_names: true)
83
- elsif measure_hash.nil?
84
- raise 'measure.json was not found and was not automatically created'
72
+ if File.exist?(File.join(local_path_to_measure, 'measure.xml'))
73
+ measure_hash = parse_measure_xml(File.join(local_path_to_measure, 'measure.xml'))
74
+ else
75
+ raise "Could not find measure.xml"
85
76
  end
86
77
 
87
78
  add_measure(instance_name, instance_display_name, local_path_to_measure, measure_hash)
@@ -92,12 +83,12 @@ module OpenStudio
92
83
  @items.last
93
84
  end
94
85
 
95
- # Add a measure from the custom hash format without reading the measure.rb or measure.json file
86
+ # Add a measure from the custom hash format without reading the measure.rb or measure.xml file
96
87
  #
97
88
  # @params instance_name [String] The name of the instance. This allows for multiple measures to be added to the workflow with unique names
98
89
  # @params instance_display_name [String] The display name of the instance. This allows for multiple measures to be added to the workflow with unique names
99
90
  # @param local_path_to_measure [String] This is the local path to the measure directory, relative or absolute. It is used when zipping up all the measures.
100
- # @param measure_metadata [Hash] Format of the measure.json
91
+ # @param measure_metadata [Hash] Format of the measure.xml in JSON format
101
92
  # @return [Object] Returns the measure that was added as an OpenStudio::AnalysisWorkflowStep object
102
93
  def add_measure(instance_name, instance_display_name, local_path_to_measure, measure_metadata)
103
94
  @items << OpenStudio::Analysis::WorkflowStep.from_measure_hash(instance_name, instance_display_name, local_path_to_measure, measure_metadata)
@@ -110,7 +101,7 @@ module OpenStudio
110
101
  # @params instance_name [String] The name of the instance. This allows for multiple measures to be added to the workflow with unique names
111
102
  # @params instance_display_name [String] The display name of the instance. This allows for multiple measures to be added to the workflow with unique names
112
103
  # @param local_path_to_measure [String] This is the local path to the measure directory, relative or absolute. It is used when zipping up all the measures.
113
- # @param measure_metadata [Hash] Format of the measure.json
104
+ # @param measure_metadata [Hash] Format of the measure.xml in JSON format
114
105
  # @return [Object] Returns the measure that was added as an OpenStudio::AnalysisWorkflowStep object
115
106
  def add_measure_from_analysis_hash(instance_name, instance_display_name, local_path_to_measure, measure_metadata)
116
107
  @items << OpenStudio::Analysis::WorkflowStep.from_analysis_hash(instance_name, instance_display_name, local_path_to_measure, measure_metadata)
@@ -60,7 +60,7 @@ module OpenStudio
60
60
  @name = ''
61
61
  @display_name = ''
62
62
 
63
- # The type of item being added (RubyMeasure, EnergyPlusMeasure, ...)
63
+ # The type of item being added (ModelMeasure, EnergyPlusMeasure, ...)
64
64
  @type = nil
65
65
 
66
66
  @measure_definition_class_name = nil
@@ -267,15 +267,12 @@ module OpenStudio
267
267
  #
268
268
  # @param instance_name [String] Machine name of the instance
269
269
  # @param instance_display_name [String] Display name of the instance
270
- # @param path_to_measure [String] This is the local path to the measure directroy, relative or absolute. It is used when zipping up all the measures.
271
- # @param hash [Hash] Measure hash in the format of the measure.json (from the Analysis Spreadsheet project)
270
+ # @param path_to_measure [String] This is the local path to the measure directory, relative or absolute. It is used when zipping up all the measures.
271
+ # @param hash [Hash] Measure hash in the format of a converted measure.xml hash (from the Analysis Spreadsheet project)
272
272
  # @param options [Hash] Optional arguments
273
273
  # @option options [Boolean] :ignore_not_found Do not raise an exception if the measure could not be found on the machine
274
274
  # @return [Object] Returns the OpenStudio::Analysis::WorkflowStep
275
275
  def self.from_measure_hash(instance_name, instance_display_name, path_to_measure, hash, options = {})
276
- # TODO: Validate the hash
277
- # TODO: validate that the measure exists?
278
-
279
276
  if File.directory? path_to_measure
280
277
  path_to_measure = File.join(path_to_measure, 'measure.rb')
281
278
  end
@@ -352,7 +349,7 @@ module OpenStudio
352
349
  # @param instance_name [String] Machine name of the instance
353
350
  # @param instance_display_name [String] Display name of the instance
354
351
  # @param path_to_measure [String] This is the local path to the measure directroy, relative or absolute. It is used when zipping up all the measures.
355
- # @param hash [Hash] Measure hash in the format of the measure.json (from the Analysis Spreadsheet project)
352
+ # @param hash [Hash] Measure hash in the format of the measure.xml converted to JSON (from the Analysis Spreadsheet project)
356
353
  # @param options [Hash] Optional arguments
357
354
  # @option options [Boolean] :ignore_not_found Do not raise an exception if the measure could not be found on the machine
358
355
  # @return [Object] Returns the OpenStudio::Analysis::WorkflowStep
@@ -0,0 +1,67 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
36
+ require 'rexml/document'
37
+
38
+ def parse_measure_xml(measure_xml_filename)
39
+ measure_hash = {}
40
+ xml_to_parse = File.open(measure_xml_filename)
41
+ xml_root = REXML::Document.new(xml_to_parse).root
42
+
43
+ # pull out some information
44
+ measure_hash[:classname] = xml_root.elements['//measure/class_name'].text
45
+ measure_hash[:name] = xml_root.elements['//measure/name'].text
46
+ measure_hash[:display_name] = xml_root.elements['//measure/display_name'].text
47
+ measure_hash[:display_name_titleized] = measure_hash[:name].titleize
48
+ measure_hash[:measure_type] = xml_root.elements['//measure/attributes/attribute[name="Measure Type"]/value'].text
49
+ measure_hash[:description] = xml_root.elements['//measure/description'].text
50
+ measure_hash[:modeler_description] = xml_root.elements['//measure/modeler_description'].text
51
+ measure_hash[:uid] = xml_root.elements['//measure/uid'].text
52
+ measure_hash[:version_id] = xml_root.elements['//measure/version_id'].text
53
+ measure_hash[:arguments] = []
54
+
55
+ REXML::XPath.each(xml_root, '//measure/arguments/argument' ) do |arg|
56
+
57
+ measure_hash[:arguments] << {
58
+ name: arg.elements['name'].text,
59
+ display_name: arg.elements['display_name'].text,
60
+ variable_type: arg.elements['type'].text.downcase,
61
+ default_value: arg.elements['default_value'].text,
62
+ units: arg.elements['units'] ? arg.elements['units'].text : ''
63
+ }
64
+ end
65
+
66
+ measure_hash
67
+ end
@@ -23,10 +23,9 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.required_ruby_version = '~> 2.5.0'
25
25
 
26
- s.add_dependency 'bcl', '= 0.5.8'
26
+ s.add_dependency 'bcl', '~> 0.6.1'
27
27
  s.add_dependency 'dencity', '~> 0.1.0'
28
- s.add_dependency 'faraday', '~> 0.14'
29
- s.add_dependency 'nokogiri', '~> 1.10.8'
28
+ s.add_dependency 'faraday', '~> 1.0.1'
30
29
  s.add_dependency 'roo', '~> 2.8.3'
31
30
  s.add_dependency 'rubyzip', '~> 2.3.0'
32
31
  s.add_dependency 'semantic', '~> 1.4'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstudio-analysis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Long
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcl
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.8
19
+ version: 0.6.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.8
26
+ version: 0.6.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dencity
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.14'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.14'
55
- - !ruby/object:Gem::Dependency
56
- name: nokogiri
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 1.10.8
47
+ version: 1.0.1
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 1.10.8
54
+ version: 1.0.1
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: roo
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +180,7 @@ files:
194
180
  - lib/openstudio/analysis/workflow_step.rb
195
181
  - lib/openstudio/helpers/hash.rb
196
182
  - lib/openstudio/helpers/string.rb
183
+ - lib/openstudio/helpers/utils.rb
197
184
  - lib/openstudio/weather/epw.rb
198
185
  - openstudio-analysis.gemspec
199
186
  - update_license.rb