-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: develop
Are you sure you want to change the base?
Conversation
if (filterType == "components") { | ||
responses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, pageIdx); | ||
} else if (filterType == "measures") { | ||
responses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, pageIdx); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
@@ -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; |
There was a problem hiding this comment.
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
currentPage++; | ||
} while (currentPage < totalPages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a C++
ism
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()) { |
There was a problem hiding this comment.
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
int startIdx = pageIdx * itemsPerPage; | ||
int endIdx = std::min(startIdx + itemsPerPage, static_cast<int>(m_allResponses.size())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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())); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
No description provided.