Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4007 - Model objects returned in inconsistent order #4010

Merged
merged 4 commits into from
Jul 10, 2020
Merged

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Jul 1, 2020

Pull request overview

Please read OpenStudio Pull Requests to better understand the OpenStudio Pull Request protocol.

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Checked behavior in OpenStudioApplication, adjusted policies as needed (src/openstudio_lib/library/OpenStudioPolicy.xml)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec added component - Model Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Jul 1, 2020
@jmarrec jmarrec requested a review from DavidGoldwasser July 1, 2020 14:14
@jmarrec jmarrec self-assigned this Jul 1, 2020
@@ -311,6 +311,9 @@ class MODEL_API Model : public openstudio::Workspace {
std::shared_ptr<typename T::ImplType> p = it->getImpl<typename T::ImplType>();
if (p) { result.push_back(T(p)); }
}
if (sorted) {
std::sort(result.begin(), result.end());
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an optional argument to sort stuff in getConcreteModelObjects, defaults to false like it was before.

@@ -72,7 +72,7 @@
%init %{
rb_eval_string("OpenStudio::IdfObject.class_eval { define_method(:to_" #_name ") { OpenStudio::Model::to" #_name "(self); } }");
rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name ") { |handle| OpenStudio::Model::get" #_name "(self, handle); } }");
rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "s) { OpenStudio::Model::get" #_name "s(self); } }");
rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "s) { | sorted = false | OpenStudio::Model::get" #_name "s(self, sorted); } }");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify the ruby wrapper to provide getXXXXs(sorted=false), so that if you call getXXXs it sill does what it used to (unsorted for ConcreteModelObjects and ModelObjects alike)

(These code changes are very simple to see, but it took me a surprising amount of effort to get right)

@jmarrec
Copy link
Collaborator Author

jmarrec commented Jul 1, 2020

example:

[1] OS-build-release(main)> m = OpenStudio::Model::exampleModel()

[2] OS-build-release(main)> m.getSurfaces(false).map{|s| s.name.to_s}
=> ["Surface 22",
 "Surface 21",
 "Surface 20",
 "Surface 19",
 "Surface 18",
 "Surface 17",
 "Surface 23",
 "Surface 16",
 "Surface 14",
 "Surface 24",
 "Surface 1",
 "Surface 2",
 "Surface 8",
 "Surface 4",
 "Surface 5",
 "Surface 6",
 "Surface 3",
 "Surface 7",
 "Surface 10",
 "Surface 15",
 "Surface 9",
 "Surface 13",
 "Surface 11",
 "Surface 12"]

[3] OS-build-release(main)> m.getSurfaces(true).map{|s| s.name.to_s}
=> ["Surface 1",
 "Surface 2",
 "Surface 3",
 "Surface 17",
 "Surface 18",
 "Surface 19",
 "Surface 4",
 "Surface 5",
 "Surface 6",
 "Surface 7",
 "Surface 9",
 "Surface 10",
 "Surface 11",
 "Surface 12",
 "Surface 13",
 "Surface 14",
 "Surface 15",
 "Surface 16",
 "Surface 20",
 "Surface 21",
 "Surface 22",
 "Surface 23",
 "Surface 24",
 "Surface 8"]

[4] OS-build-release(main)> m.getSurfaces(false).sort.map{|s| s.name.to_s}
=> ["Surface 1",
 "Surface 10",
 "Surface 11",
 "Surface 12",
 "Surface 13",
 "Surface 14",
 "Surface 15",
 "Surface 16",
 "Surface 17",
 "Surface 18",
 "Surface 19",
 "Surface 2",
 "Surface 20",
 "Surface 21",
 "Surface 22",
 "Surface 23",
 "Surface 24",
 "Surface 3",
 "Surface 4",
 "Surface 5",
 "Surface 6",
 "Surface 7",
 "Surface 8",
 "Surface 9"]

As you can see, the sort order within the bowels of Model/Workspace ([2]) is different than getting it unsorted, then calling sort on the ruby return value ([3]).

@tijcolem tijcolem linked an issue Jul 10, 2020 that may be closed by this pull request
@tijcolem tijcolem merged commit 0607f87 into develop Jul 10, 2020
@tijcolem tijcolem deleted the 4007_sorted branch July 10, 2020 16:14
@tijcolem tijcolem restored the 4007_sorted branch July 14, 2020 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component - Model Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Model objects returned in inconsistent order
2 participants