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

Relax Alfalfa Point ID Requirements #5296

Merged
merged 6 commits into from
Nov 8, 2024
Merged

Relax Alfalfa Point ID Requirements #5296

merged 6 commits into from
Nov 8, 2024

Conversation

TShapinsky
Copy link
Member

Pull request overview

After testing the new interface in the real world I found the requirements on id characters to be too onerous. This PR removes all requirements outside of non emptiness.

Pull Request Author

  • 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)
  • 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

@TShapinsky TShapinsky changed the title Relax Point ID Requirements Relax Alfalfa Point ID Requirements Nov 7, 2024
@TShapinsky TShapinsky added the Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. label Nov 7, 2024
@TShapinsky TShapinsky force-pushed the alfalfa_id_validation branch from 93af06f to 912124c Compare November 7, 2024 22:28
@TShapinsky TShapinsky requested review from jmarrec and kbenne November 7, 2024 23:42
Comment on lines -128 to -130
bool AlfalfaPoint_Impl::isValidId(const std::string& id) {
return !id.empty() && boost::regex_match(id, boost::regex(R"(^[A-Za-z0-9_\-\[\]:()]*$)"));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@TShapinsky can you clarify what you meant by "onerous"?

Was it just annoying / too restrictive?
Or was is slow?

Boost (and std) regexes are awful in terms of performance, but using a static regex makes it better (we use Meyers singletons in IddRegex.hpp for eg)

Copy link
Member Author

Choose a reason for hiding this comment

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

It was mostly annoying / too restrictive. For some background, the point ids become path parameters when interacting with the Alfalfa/BOPTest REST API. Originally I thought it would be neat to restrict the character set to avoid needing a lot of percent encoded characters. However, it's pretty common for names in open studio to include various different characters and since the requirement isn't hard I decided to get rid of it in the interest of making the alfalfa interface more user friendly.

src/alfalfa/AlfalfaJSON.cpp Outdated Show resolved Hide resolved
bool AlfalfaPoint_Impl::isValidId(const std::string& id) {
return !id.empty() && boost::regex_match(id, boost::regex(R"(^[A-Za-z0-9_\-\[\]:()]*$)"));
}

std::string AlfalfaPoint_Impl::toIdString(const std::string& str) {
return boost::regex_replace(str, boost::regex(" "), "_");
Copy link
Collaborator

@jmarrec jmarrec Nov 8, 2024

Choose a reason for hiding this comment

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

just a side note, but this is probably much faster, not that it matters much probably

#include <algorithm>
std::replace( str.begin(), str.end(), ' ', '_')

Edit: It is in fact, 150 times faster: https://quick-bench.com/q/LBF5Z_hhF14xxmjJ8IGs7UhGAUY

src/alfalfa/test/AlfalfaJSON_GTest.cpp Outdated Show resolved Hide resolved
TShapinsky and others added 4 commits November 8, 2024 09:05
Co-authored-by: Julien Marrec <julien.marrec@gmail.com>
Co-authored-by: Julien Marrec <julien.marrec@gmail.com>
@TShapinsky
Copy link
Member Author

@kbenne can you merge it? I don't have permission to do so.

@jmarrec jmarrec merged commit ae56871 into develop Nov 8, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants