NatLabRockies / NatLabRockies/OpenStudio

ResourceObject.directUseCount() does not look inside EMS objects

Open
#3,185 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

component - Model severity - Minor Bug
Dominant language
C++
Stars
646
Forks
237
Avg merge
3d 11h
Merged PRs (30d)
10

Description

The method ResourceObject.directUseCount() does not check to see if objects are referenced inside of EMS objects. I hit this when trying to remove all unused ResourceObjects from a model before runtime to make it cleaner. The simple ruby test below reproduces the issue I had.

require 'openstudio'

model = OpenStudio::Model::Model.new

sch = OpenStudio::Model::ScheduleConstant.new(model)
sch_handle = sch.handle

sensor = OpenStudio::Model::EnergyManagementSystemSensor.new(model, 'Schedule Value')

sensor.setKeyName(sch_handle.to_s)

puts sensor

# Delete unused resource objects
model.getResourceObjects.sort.each do |obj|
  puts "checking #{obj.name}"
  if obj.directUseCount.zero?
    puts "#{obj.name} is unused; it will be removed."
    model.removeObject(obj.handle)
  end
end

if model.getModelObject(sch_handle).is_initialized
  puts "Success"
else
  puts "Fail"
end

I expect that this issue would affect all EMS object types where handles can be used in the string fields, but are then replaced by Names at forward translation time. This may be a situation where the only solution is to hard-code some special checks of those EMS objects into the ResourceObject.directUseCount() method, but not sure.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ResourceObject.directUseCount() and reproduce the issue using the Ruby example in the report, especially the ScheduleConstant referenced by an EnergyManagementSystemSensor. Check how EMS string fields reference resource handles and consider all EMS object types mentioned; done means unused-resource cleanup preserves resources referenced inside EMS objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.