Module: OpenStudio::Analysis

Defined in:
lib/openstudio/analysis.rb,
lib/openstudio/analysis/version.rb,
lib/openstudio/analysis/workflow.rb,
lib/openstudio/analysis/server_api.rb,
lib/openstudio/analysis/formulation.rb,
lib/openstudio/analysis/support_files.rb,
lib/openstudio/analysis/workflow_step.rb,
lib/openstudio/analysis/server_scripts.rb,
lib/openstudio/analysis/translator/excel.rb,
lib/openstudio/analysis/translator/workflow.rb,
lib/openstudio/analysis/algorithm_attributes.rb,
lib/openstudio/analysis/translator/datapoints.rb

Defined Under Namespace

Modules: Translator Classes: AlgorithmAttributes, Formulation, SeedModel, ServerApi, ServerScripts, SupportFiles, WeatherFile, Workflow, WorkflowStep

Constant Summary collapse

VERSION =

format should be ^.*-1[0-9] for example: -rc1, -beta6, -customusecase0

'1.3.4'.freeze
@@measure_paths =
['./measures']

Class Method Summary collapse

Class Method Details

.aws_instance_options(filename) ⇒ Object

Retrieve aws instance options from a project. This will return a hash



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/openstudio/analysis.rb', line 44

def self.aws_instance_options(filename)
  if File.extname(filename) == '.xlsx'
    excel = OpenStudio::Analysis::Translator::Excel.new(filename)
    excel.process
    options = {
      os_server_version: excel.settings['openstudio_server_version'],
      server_instance_type: excel.settings['server_instance_type'],
      worker_instance_type: excel.settings['worker_instance_type'],
      worker_node_number: excel.settings['worker_nodes'].to_i,
      user_id: excel.settings['user_id'],
      aws_tags: excel.aws_tags,
      analysis_type: excel.analyses.first.analysis_type,
      cluster_name: excel.cluster_name
    }
  elsif File.extname(filename) == '.csv'
    csv = OpenStudio::Analysis::Translator::Datapoints.new(filename)
    csv.process
    options = csv.settings
  else
    raise 'Invalid file extension'
  end

  return options
end

.create(display_name) ⇒ Object

Create a new analysis



10
11
12
# File 'lib/openstudio/analysis.rb', line 10

def self.create(display_name)
  OpenStudio::Analysis::Formulation.new(display_name)
end

.from_csv(filename) ⇒ Object

Load an set of batch datapoints from a csv. This will create a analysis of type ‘batch_datapoints’ which requires ‘batch_run’



31
32
33
34
35
# File 'lib/openstudio/analysis.rb', line 31

def self.from_csv(filename)
  csv = OpenStudio::Analysis::Translator::Datapoints.new(filename)
  csv.process
  csv.analysis
end

.from_excel(filename) ⇒ Object

Load an analysis from excel. This will create an array of analyses because excel can create more than one analyses



23
24
25
26
27
# File 'lib/openstudio/analysis.rb', line 23

def self.from_excel(filename)
  excel = OpenStudio::Analysis::Translator::Excel.new(filename)
  excel.process
  excel.analyses
end

.load(h) ⇒ Object

Load the analysis json or from a file. If this is a json then it must have symbolized keys



16
17
18
19
# File 'lib/openstudio/analysis.rb', line 16

def self.load(h)
  h = MultiJson.load(h, symbolize_keys: true) unless h.is_a? Hash
  OpenStudio::Analysis::Formulation.from_hash h
end

.make_osws(osa_filename, osd_array) ⇒ Object

Process an OSA with a set of OSDs into OSWs



38
39
40
41
# File 'lib/openstudio/analysis.rb', line 38

def self.make_osws(osa_filename, osd_array)
  translator = OpenStudio::Analysis::Translator::Workflow.new(osa_filename)
  osd_array.each { |osd| translator.process_datapoints osd }
end

.measure_pathsObject

List of paths to look for measures when adding them. This currently only is used when loading an analysis hash file. It looks in the order of the measure_paths. As soon as it finds one, it stops.



15
16
17
# File 'lib/openstudio/analysis/formulation.rb', line 15

def self.measure_paths
  @@measure_paths
end

.measure_paths=(new_array) ⇒ Object



19
20
21
# File 'lib/openstudio/analysis/formulation.rb', line 19

def self.measure_paths=(new_array)
  @@measure_paths = new_array
end

.to_dencity_analysis(analysis_hash, analysis_uuid) ⇒ Object

Generate a DEnCity complient hash for uploading from the analysis hash TODO make this work off of the analysis object, not the hash.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/openstudio/analysis.rb', line 71

def self.to_dencity_analysis(analysis_hash, analysis_uuid)
  dencity_hash = {}
  a = analysis_hash[:analysis]
  provenance = {}
  provenance[:user_defined_id] = analysis_uuid
  provenance[:user_created_date] = ::Time.now
  provenance[:analysis_types] = [a[:problem][:analysis_type]]
  provenance[:name] = a[:name]
  provenance[:display_name] = a[:display_name]
  provenance[:description] = 'Auto-generated DEnCity analysis hash using the OpenStudio Analysis Gem'
   = []
  if a[:problem]
    if a[:problem][:algorithm]
      provenance[:analysis_information] = a[:problem][:algorithm]
    else
      raise 'No algorithm found in the analysis.json.'
    end

    if a[:problem][:workflow]
      a[:problem][:workflow].each do |wf|
        new_wfi = {}
        new_wfi[:id] = wf[:measure_definition_uuid]
        new_wfi[:version_id] = wf[:measure_definition_version_uuid]

        # Eventually all of this could be pulled directly from BCL
        new_wfi[:name] = wf[:measure_definition_class_name] if wf[:measure_definition_class_name]
        new_wfi[:display_name] = wf[:measure_definition_display_name] if wf[:measure_definition_display_name]
        new_wfi[:type] = wf[:measure_type] if wf[:measure_type]
        new_wfi[:modeler_description] = wf[:modeler_description] if wf[:modeler_description]
        new_wfi[:description] = wf[:description] if wf[:description]
        new_wfi[:arguments] = []

        wf[:arguments]&.each do |arg|
          wfi_arg = {}
          wfi_arg[:display_name] = arg[:display_name] if arg[:display_name]
          wfi_arg[:display_name_short] = arg[:display_name_short] if arg[:display_name_short]
          wfi_arg[:name] = arg[:name] if arg[:name]
          wfi_arg[:data_type] = arg[:value_type] if arg[:value_type]
          wfi_arg[:default_value] = nil
          wfi_arg[:description] = ''
          wfi_arg[:display_units] = '' # should be haystack compatible unit strings
          wfi_arg[:units] = '' # should be haystack compatible unit strings

          new_wfi[:arguments] << wfi_arg
        end

        wf[:variables]&.each do |arg|
          wfi_var = {}
          wfi_var[:display_name] = arg[:argument][:display_name] if arg[:argument][:display_name]
          wfi_var[:display_name_short] = arg[:argument][:display_name_short] if arg[:argument][:display_name_short]
          wfi_var[:name] = arg[:argument][:name] if arg[:argument][:name]
          wfi_var[:default_value] = nil
          wfi_var[:data_type] = arg[:argument][:value_type] if arg[:argument][:value_type]
          wfi_var[:description] = ''
          wfi_var[:display_units] = arg[:units] if arg[:units]
          wfi_var[:units] = '' # should be haystack compatible unit strings
          new_wfi[:arguments] << wfi_var
        end

         << new_wfi
      end
    else
      raise 'No workflow found in the analysis.json'
    end

    dencity_hash[:analysis] = provenance
    dencity_hash[:measure_definitions] = 
  else
    raise 'No problem found in the analysis.json'
  end
  return dencity_hash
end