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

Issue #166 - Sort measures alphabetically in GUI #795

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

antonszilasi
Copy link

No description provided.

if (filterType == "components") {
responses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, pageIdx);
} else if (filterType == "measures") {
responses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, pageIdx);
Copy link
Author

Choose a reason for hiding this comment

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

It was too hard to refractor all the methods around this, instead I fetched all the responses from the BCL if it is the first page or the m_allRepsonses is empty (could just do the latter) then I sort them alphabetically

}

for (const auto& response : responses) {
// Paginate responses
int itemsPerPage = 10; // Assuming 10 items per page
Copy link
Author

Choose a reason for hiding this comment

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

I think this is a far assumption? items per page should be 10?

@@ -169,6 +168,34 @@ void BuildingComponentDialogCentralWidget::setTid() {
requestComponents(m_filterType, m_tid, m_pageIdx, m_searchString);
}

std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::fetchAndSortResponses(const std::string& filterType, int tid, const QString& searchString) {
Copy link
Author

Choose a reason for hiding this comment

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

will add tests for this shortly

@antonszilasi antonszilasi changed the title Checkpoint sort measures alphabetically Issue #166 - Sort measures alphabetically in GUI Mar 10, 2025
@antonszilasi
Copy link
Author

Animation

@@ -169,6 +168,34 @@ void BuildingComponentDialogCentralWidget::setTid() {
requestComponents(m_filterType, m_tid, m_pageIdx, m_searchString);
}

std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::fetchAndSortResponses(const std::string& filterType, int tid, const QString& searchString) {
m_allResponses.clear();
RemoteBCL remoteBCL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can set RemoteBCL::setResultsPerQuery to 100 which might make this go faster:

https://github.com/NREL/OpenStudio/blob/develop/src/utilities/bcl/RemoteBCL.cpp#L950

Comment on lines +188 to +189
currentPage++;
} while (currentPage < totalPages);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a C++ism

Suggested change
currentPage++;
} while (currentPage < totalPages);
} while (++currentPage < totalPages);

responses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, pageIdx);
} else if (filterType == "measures") {
responses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, pageIdx);
if (pageIdx == 0 || m_allResponses.empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be a bug if you changed tid or searchString but then called again with pageIdx=0. You need something like m_lastSearchString = filterType + tid + searchString, then clear m_allResponses when that last string cache key changes

Comment on lines +226 to +227
int startIdx = pageIdx * itemsPerPage;
int endIdx = std::min(startIdx + itemsPerPage, static_cast<int>(m_allResponses.size()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
int startIdx = pageIdx * itemsPerPage;
int endIdx = std::min(startIdx + itemsPerPage, static_cast<int>(m_allResponses.size()));
size_t startIdx = pageIdx * itemsPerPage;
size_t endIdx = std::min(startIdx + itemsPerPage, static_cast<int>(m_allResponses.size()));

Copy link
Collaborator

Choose a reason for hiding this comment

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

Use size_t instead of int when doing math with iterators

@@ -210,11 +238,11 @@ void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType,
m_collapsibleComponentList->setText(title);

// the total number of results
int lastTotalResults = remoteBCL.lastTotalResults();
int lastTotalResults = m_allResponses.size();
m_collapsibleComponentList->setNumResults(lastTotalResults);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do numResults and numPages do?

m_collapsibleComponentList->setNumResults(lastTotalResults);

// the number of pages of results
int numResultPages = remoteBCL.numResultPages();
int numResultPages = (lastTotalResults + itemsPerPage - 1) / itemsPerPage;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the same as (lastTotalResults / itemsPerPage) + 1?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also make a comment when using integer division

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants