class UserDataCSV

Attributes

file_name[R]

getter function to get file name

Public Class Methods

new(model, save_dir) click to toggle source

Abstract class for writing user data template from user model.

@param model [OpenStudio::Model::Model] @param save_dir [String] directory to save user data files

# 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

Public Instance Methods

write_csv() click to toggle source

method to write csv files this method controls the workflow for generating a user data file. @return [Boolean] True for success, false otherwise

# 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

Private Instance Methods

load_component() click to toggle source

Method to load OpenStudio component list from the model and save to @Component subclass shall determine what data group to extract from a modle. @return [Array] array of OpenStudio components.

# File lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/ashrae_90_1_prm.UserData.rb, line 72
def load_component
  return @model.public_send("get#{@component_name}")
end
load_header() click to toggle source

Load header from pre-defined user data files. This method loads the user data file from the list.

@return [Boolean] returns true if successful, false if not

# File lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/ashrae_90_1_prm.UserData.rb, line 56
def load_header
  userdata_dir = __dir__
  src_csv_dir = "#{userdata_dir}/*.csv"
  headers = nil
  Dir.glob(src_csv_dir).each do |csv_full_name|
    csv_file_name = File.basename(csv_full_name, File.extname(csv_full_name))
    if csv_file_name == @file_name
      headers = CSV.read(csv_full_name, headers: true).headers
    end
  end
  return headers
end
write_default_rows(component) click to toggle source

method to write the parameters in the csv file. This method provides a template to write in default values to the user data file @param component [OpenStudio::Model::Component] Openstudio component return [Array] array of strings that contains the data in the userdata file

# File lib/openstudio-standards/standards/ashrae_90_1_prm/userdata_csv/ashrae_90_1_prm.UserData.rb, line 48
def write_default_rows(component)
  raise NotImplementedError, 'Method write rows should be implemented in class'
end