Class: UserDataCSV

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/ashrae_90_1_prm.UserData.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, save_dir) ⇒ UserDataCSV

Abstract class for writing user data template from user model.

Parameters:

  • model (OpenStudio::Model::Model)
  • save_dir (String)

    directory to save user data files



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/ashrae_90_1_prm.UserData.rb', line 6

def initialize(model, save_dir)
  @model = model
  @component_name = nil
  unless Dir.exist?(save_dir)
    raise ArgumentError "Saving directory #{save_dir} does not exist!"
  end

  @save_dir = save_dir
  @components = nil
  @headers = nil
  @file_name = nil
end

Instance Attribute Details

#file_nameObject (readonly)

getter function to get file name



20
21
22
# File 'lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/ashrae_90_1_prm.UserData.rb', line 20

def file_name
  @file_name
end

Instance Method Details

#write_csvBoolean

method to write csv files this method controls the workflow for generating a user data file.

Returns:

  • (Boolean)

    True for success, false otherwise



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/ashrae_90_1_prm.UserData.rb', line 25

def write_csv
  @components = load_component
  @headers = load_header
  unless @components
    OpenStudio.logFree(OpenStudio::Warn, 'prm.log', "No relevant component #{@component_name} found in model. Skip the process")
    return false
  end

  CSV.open("#{@save_dir}/#{@file_name}.csv", 'w') do |csv|
    csv << @headers
    @components.each do |component|
      csv << ([prm_get_component_name(component)] + write_default_rows(component))
    end
  end
  return true
end