Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

Running Measure Test via OpenStudio CLI Returns Error

I was modifying a copy of a reporting measure. To save test time, I am using OpenStudio CLI. My modified OS measure was from the OpenStudio Result IP measure and I was testing how to create my own sections using the example template within the same measure. I did this by modifying a copy of os_lib_reporting.rb. See my modified file below:

# Custom OS reporting

require 'json'

module OsLib_Reporting_Custom

#setup - get model, sql, and setup web assets path
def self.setup(runner)
    results = {}

    #get the last model
    model = runner.lastOpenStudioModel

    if model.empty?
        runner.registerError('Cannot find last model.')
        return false
    end
    model = model.get

    #get the last idf
    workspace = runner.lastEnergyPlusWorkspace
    if workspace.empty?
        runner.registerError('Cannot find last idf file.')
        return false
    end
    workspace = workspace.get

    #get the last sql file
    sqlFile = runner.lastEnergyPlusSqlFile
    if sqlFile.empty?
        runner.registerError('Cannot find last sql file.')
        return false
    end
    sqlFile = sqlFile.get
    model.setSqlFile(sqlFile)

    #populate hash to pass to measure
    results[:model] = model
    #results[:workspace] = workspace
    results[:sqlFile] = sqlFile
    results[:web_asset_path] = OpenStudio.getSharedResourcesPath / OpenStudio::Path.new('web_assets')

    return results
end

#create template section
def self.template_section(model, sqlFile, runner, name_only = false)
    #array to hold tables
    template_tables = []

    #gather data for section
    @template_section = {}
    @template_section[:title] = 'Template Section'
    @template_section[:tables] = template_tables

    #stop here if only name is requested - this is used to populate display name for arguments
    if name_only == true
        return @template_section
    end

    #create table
    template_table_01 = {}
    template_table_01[:title] = 'Sample Table 1'
    template_table_01[:header] = ['Bldg', 'Energy']
    template_table_01[:units] = ['', 'kWh']
    template_table_01[:data] = []

    #add rows to table
    template_table_01[:data] << ['Bldg 1', 1000]
    template_table_01[:data] << ['Bldg 2', 9870]
    template_table_01[:data] << ['Bldg 3', 431]

    #create chart
    template_table_01[:chart_type] = 'simple_pie' #search for value options
    template_table_01[:chart] = []
    template_table_01[:data].each do |row|
        template_table_01[:chart] << JSON.generate(label: row[0], value: row[1])
    end

    #add table to array of tables
    template_tables << template_table_01

    #use helper method that generates additional table for section
    #template_tables << OsLib_Reporting_Custom.template_table(model, sqlFile, runner)


    return @template_section
end
end

I added this file into my measure.rb as shown below:

require 'erb'
require 'json'

require "#{File.dirname(__FILE__)}/resources/os_lib_reporting"
require "#{File.dirname(__FILE__)}/resources/os_lib_reporting_custom"
require "#{File.dirname(__FILE__)}/resources/os_lib_schedules"
require "#{File.dirname(__FILE__)}/resources/os_lib_helper_methods"
require_relative 'resources/Siz.Model'

# start the measure
class ReportFormatV1 < OpenStudio::Measure::ReportingMeasure
  # human readable name
  def name
    # Measure name should be the title case of the class name.
    return "Report Format v1"
  end

Besides renaming all instances of OsLib_Reporting to OsLib_Reporting_Custom, I haven't edited measure.rb yet as I was excited to see my simple section template.

So what I did next was to proceed to my test file. Once again, I modified a copy of the existing test file (now named report_format_v_1_test.rb). Within it, I simply updated the expected number of arguments; e.g.,

def test_number_of_arguments_and_argument_names
# create an instance of the measure
measure = ReportFormatV1.new

# get arguments and test that they are what we are expecting
arguments = measure.arguments()
assert_equal(1, arguments.size) #originally this was 0
end

Finally, I got this error:

ERROR MESSAGES: Cannot find last idf file
[...]

1) Failure:
ReportFormatV1Test#test_good_argument_values [C:/..../Measures/report_format_v_1/tests/report_format_v_1_test.rb:148]:
Expected: "Success"
Actual: "Fail"

2 runs, 12 assertions, 1 failures, 0 errors, 0 skips

Any help is very much appreciated. Thanks!

Running Measure Test via OpenStudio CLI Returns Error

I was modifying a copy of a reporting measure. To save test time, I am using OpenStudio CLI. My modified OS measure was from the OpenStudio Result IP measure and I was testing how to create my own sections using the example template within the same measure. I did this by modifying a copy of os_lib_reporting.rb. See my modified file below:

# Custom OS reporting

require 'json'

module OsLib_Reporting_Custom

#setup - get model, sql, and setup web assets path
def self.setup(runner)
    results = {}

    #get the last model
    model = runner.lastOpenStudioModel

    if model.empty?
        runner.registerError('Cannot find last model.')
        return false
    end
    model = model.get

    #get the last idf
    workspace = runner.lastEnergyPlusWorkspace
    if workspace.empty?
        runner.registerError('Cannot find last idf file.')
        return false
    end
    workspace = workspace.get

    #get the last sql file
    sqlFile = runner.lastEnergyPlusSqlFile
    if sqlFile.empty?
        runner.registerError('Cannot find last sql file.')
        return false
    end
    sqlFile = sqlFile.get
    model.setSqlFile(sqlFile)

    #populate hash to pass to measure
    results[:model] = model
    #results[:workspace] = workspace
    results[:sqlFile] = sqlFile
    results[:web_asset_path] = OpenStudio.getSharedResourcesPath / OpenStudio::Path.new('web_assets')

    return results
end

#create template section
def self.template_section(model, sqlFile, runner, name_only = false)
    #array to hold tables
    template_tables = []

    #gather data for section
    @template_section = {}
    @template_section[:title] = 'Template Section'
    @template_section[:tables] = template_tables

    #stop here if only name is requested - this is used to populate display name for arguments
    if name_only == true
        return @template_section
    end

    #create table
    template_table_01 = {}
    template_table_01[:title] = 'Sample Table 1'
    template_table_01[:header] = ['Bldg', 'Energy']
    template_table_01[:units] = ['', 'kWh']
    template_table_01[:data] = []

    #add rows to table
    template_table_01[:data] << ['Bldg 1', 1000]
    template_table_01[:data] << ['Bldg 2', 9870]
    template_table_01[:data] << ['Bldg 3', 431]

    #create chart
    template_table_01[:chart_type] = 'simple_pie' #search for value options
    template_table_01[:chart] = []
    template_table_01[:data].each do |row|
        template_table_01[:chart] << JSON.generate(label: row[0], value: row[1])
    end

    #add table to array of tables
    template_tables << template_table_01

    #use helper method that generates additional table for section
    #template_tables << OsLib_Reporting_Custom.template_table(model, sqlFile, runner)


    return @template_section
end
end

I added this file into my measure.rb as shown below:

require 'erb'
require 'json'

require "#{File.dirname(__FILE__)}/resources/os_lib_reporting"
require "#{File.dirname(__FILE__)}/resources/os_lib_reporting_custom"
require "#{File.dirname(__FILE__)}/resources/os_lib_schedules"
require "#{File.dirname(__FILE__)}/resources/os_lib_helper_methods"
require_relative 'resources/Siz.Model'

# start the measure
class ReportFormatV1 < OpenStudio::Measure::ReportingMeasure
  # human readable name
  def name
    # Measure name should be the title case of the class name.
    return "Report Format v1"
  end

Besides renaming all instances of OsLib_Reporting to OsLib_Reporting_Custom, I haven't edited measure.rb yet as I was excited to see my simple section template.

So what I did next was to proceed to my test file. Once again, I modified a copy of the existing test file (now named report_format_v_1_test.rb). Within it, I simply updated the expected number of arguments; e.g.,

def test_number_of_arguments_and_argument_names
# create an instance of the measure
measure = ReportFormatV1.new

# get arguments and test that they are what we are expecting
arguments = measure.arguments()
assert_equal(1, arguments.size) #originally this was 0
end

Finally, I got this error:

ERROR MESSAGES: Cannot find last idf file
[...]

1) Failure:
ReportFormatV1Test#test_good_argument_values [C:/..../Measures/report_format_v_1/tests/report_format_v_1_test.rb:148]:
Expected: "Success"
Actual: "Fail"

2 runs, 12 assertions, 1 failures, 0 errors, 0 skips

Any help is very much appreciated. Thanks!

Running Measure Test via OpenStudio CLI Returns Error

I was modifying a copy of a reporting measure. To save test time, I am using OpenStudio CLI. My modified OS measure was from the OpenStudio Result IP measure and I was testing how to create my own sections using the example template within the same measure. I did this by modifying a copy of os_lib_reporting.rb. See my modified file below:

# Custom OS reporting

require 'json'

module OsLib_Reporting_Custom

#setup - get model, sql, and setup web assets path
def self.setup(runner)
    results = {}

    #get the last model
    model = runner.lastOpenStudioModel

    if model.empty?
        runner.registerError('Cannot find last model.')
        return false
    end
    model = model.get

    #get the last idf
    workspace = runner.lastEnergyPlusWorkspace
    if workspace.empty?
        runner.registerError('Cannot find last idf file.')
        return false
    end
    workspace = workspace.get

    #get the last sql file
    sqlFile = runner.lastEnergyPlusSqlFile
    if sqlFile.empty?
        runner.registerError('Cannot find last sql file.')
        return false
    end
    sqlFile = sqlFile.get
    model.setSqlFile(sqlFile)

    #populate hash to pass to measure
    results[:model] = model
    #results[:workspace] = workspace
    results[:sqlFile] = sqlFile
    results[:web_asset_path] = OpenStudio.getSharedResourcesPath / OpenStudio::Path.new('web_assets')

    return results
end

#create template section
def self.template_section(model, sqlFile, runner, name_only = false)
    #array to hold tables
    template_tables = []

    #gather data for section
    @template_section = {}
    @template_section[:title] = 'Template Section'
    @template_section[:tables] = template_tables

    #stop here if only name is requested - this is used to populate display name for arguments
    if name_only == true
        return @template_section
    end

    #create table
    template_table_01 = {}
    template_table_01[:title] = 'Sample Table 1'
    template_table_01[:header] = ['Bldg', 'Energy']
    template_table_01[:units] = ['', 'kWh']
    template_table_01[:data] = []

    #add rows to table
    template_table_01[:data] << ['Bldg 1', 1000]
    template_table_01[:data] << ['Bldg 2', 9870]
    template_table_01[:data] << ['Bldg 3', 431]

    #create chart
    template_table_01[:chart_type] = 'simple_pie' #search for value options
    template_table_01[:chart] = []
    template_table_01[:data].each do |row|
        template_table_01[:chart] << JSON.generate(label: row[0], value: row[1])
    end

    #add table to array of tables
    template_tables << template_table_01

    #use helper method that generates additional table for section
    #template_tables << OsLib_Reporting_Custom.template_table(model, sqlFile, runner)


    return @template_section
end
end

I added this file into my measure.rb as shown below:

require 'erb'
require 'json'

require "#{File.dirname(__FILE__)}/resources/os_lib_reporting"
require "#{File.dirname(__FILE__)}/resources/os_lib_reporting_custom"
require "#{File.dirname(__FILE__)}/resources/os_lib_schedules"
require "#{File.dirname(__FILE__)}/resources/os_lib_helper_methods"
require_relative 'resources/Siz.Model'

# start the measure
class ReportFormatV1 < OpenStudio::Measure::ReportingMeasure
  # human readable name
  def name
    # Measure name should be the title case of the class name.
    return "Report Format v1"
  end

Besides renaming all instances of OsLib_Reporting to OsLib_Reporting_Custom, I haven't edited measure.rb yet as I was excited to see my simple section template.

So what I did next was to proceed to my test file. Once again, I modified a copy of the existing test file (now named report_format_v_1_test.rb). Within it, I simply updated the expected number of arguments; e.g.,

def test_number_of_arguments_and_argument_names
# create an instance of the measure
measure = ReportFormatV1.new

# get arguments and test that they are what we are expecting
arguments = measure.arguments()
assert_equal(1, arguments.size) #originally this was 0
end

Finally, I got this error:

ERROR MESSAGES: Cannot find last idf file
[...]

1) Failure:
ReportFormatV1Test#test_good_argument_values [C:/..../Measures/report_format_v_1/tests/report_format_v_1_test.rb:148]:
Expected: "Success"
Actual: "Fail"

2 runs, 12 assertions, 1 failures, 0 errors, 0 skips

Any help is very much appreciated. Thanks!