NatLabRockies / NatLabRockies/OpenStudio
ResourceObject.directUseCount() does not look inside EMS objects
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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