-
Notifications
You must be signed in to change notification settings - Fork 26
Issue #166 - Sort measures alphabetically in GUI #795
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
Changes from all commits
934e973
4a50fb7
77398d3
1a508b6
1a36e84
1005c12
7b1f59d
29ebd36
4b383bc
0d0a373
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |
|
|
||
| #include <cstddef> | ||
| #include <openstudio/measure/OSArgument.hpp> | ||
|
|
||
| #include <openstudio/utilities/bcl/BCL.hpp> | ||
| #include <openstudio/utilities/bcl/LocalBCL.hpp> | ||
| #include <openstudio/utilities/bcl/RemoteBCL.hpp> | ||
|
|
@@ -169,53 +168,90 @@ 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; | ||
macumber marked this conversation as resolved.
Show resolved
Hide resolved
macumber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| remoteBCL.setTimeOutSeconds(m_timeoutSeconds); | ||
|
|
||
| std::vector<BCLSearchResult> responses; | ||
| int totalPages = 1; | ||
| int currentPage = 0; | ||
|
|
||
| // Collect all responses from all pages | ||
| do { | ||
| std::vector<BCLSearchResult> pageResponses; | ||
| if (filterType == "components") { | ||
| pageResponses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, currentPage); | ||
| } else if (filterType == "measures") { | ||
| pageResponses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, currentPage); | ||
| } | ||
| responses.insert(responses.end(), pageResponses.begin(), pageResponses.end()); | ||
| totalPages = remoteBCL.numResultPages(); | ||
| } while (++currentPage < totalPages); | ||
|
|
||
| if (!responses.empty()) { | ||
| std::sort(responses.begin(), responses.end(), [](const BCLSearchResult& a, const BCLSearchResult& b) { | ||
| return a.name() < b.name(); | ||
| }); | ||
| } | ||
|
Comment on lines
+193
to
+197
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm following correctly, you just factored a bit of code into a function, and added this bit that sorts the results. Side note: the (Running it a bunch of times locally produces results where one is sometimes faster than the other, so they're the same). |
||
|
|
||
| return responses; | ||
| } | ||
|
|
||
| // Note: don't call this directly if the "wait" screen is desired | ||
| void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType, int tid, int pageIdx, const QString& title, | ||
| const QString& searchString) { | ||
|
|
||
| if (m_tid != tid || m_searchString != searchString) { | ||
| m_collapsibleComponentList->firstPage(); | ||
| } | ||
| std::string newKey = std::to_string(tid) + filterType + searchString.toStdString(); | ||
| std::string currentKey = std::to_string(m_tid) + m_filterType + m_searchString.toStdString(); | ||
|
|
||
| m_searchString = searchString; | ||
| m_filterType = filterType; | ||
|
|
||
| m_tid = tid; | ||
|
|
||
| m_searchString = searchString; | ||
| if (newKey != currentKey) { | ||
| m_allResponses = fetchAndSortResponses(filterType, tid, searchString); | ||
| m_collapsibleComponentList->firstPage(); | ||
| pageIdx = 0; | ||
| } | ||
|
|
||
| //std::vector<Component *> components = m_collapsibleComponentList->components(); | ||
| // Clear existing components | ||
| std::vector<Component*> components = m_componentList->components(); // TODO replace with code above | ||
|
|
||
| for (auto& comp : components) { | ||
| delete comp; | ||
| } | ||
|
|
||
| RemoteBCL remoteBCL; | ||
| remoteBCL.setTimeOutSeconds(m_timeoutSeconds); | ||
| std::vector<BCLSearchResult> responses; | ||
| if (filterType == "components") { | ||
| responses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, pageIdx); | ||
| } else if (filterType == "measures") { | ||
| responses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, pageIdx); | ||
macumber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| for (const auto& response : responses) { | ||
| auto* component = new Component(response); | ||
|
|
||
| // TODO replace with a componentList owned by m_collapsibleComponentList | ||
| m_componentList->addComponent(component); | ||
| // Paginate responses | ||
| int itemsPerPage = 10; // Assuming 10 items per page | ||
macumber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!m_allResponses.empty()) { | ||
| size_t startIdx = pageIdx * itemsPerPage; | ||
| size_t endIdx = std::min(startIdx + itemsPerPage, m_allResponses.size()); | ||
| std::vector<BCLSearchResult> paginatedResponses(m_allResponses.begin() + startIdx, m_allResponses.begin() + endIdx); | ||
|
|
||
| for (const auto& response : paginatedResponses) { | ||
| auto* component = new Component(response); | ||
|
|
||
| // TODO replace with a componentList owned by m_collapsibleComponentList | ||
macumber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| m_componentList->addComponent(component); | ||
| } | ||
| } | ||
|
|
||
| // the parent taxonomy | ||
| m_collapsibleComponentList->setText(title); | ||
|
|
||
| // the total number of results | ||
| int lastTotalResults = remoteBCL.lastTotalResults(); | ||
| int lastTotalResults = m_allResponses.size(); | ||
| m_collapsibleComponentList->setNumResults(lastTotalResults); | ||
antonszilasi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // the number of pages of results | ||
| int numResultPages = remoteBCL.numResultPages(); | ||
| m_collapsibleComponentList->setNumPages(numResultPages); | ||
| if (lastTotalResults == 0) { | ||
| m_collapsibleComponentList->setNumPages(0); | ||
| } else { | ||
| int numResultPages = (lastTotalResults % itemsPerPage == 0) ? (lastTotalResults / itemsPerPage) : (lastTotalResults / itemsPerPage) + 1; | ||
| m_collapsibleComponentList->setNumPages(numResultPages); | ||
| } | ||
|
|
||
| // make sure the header is expanded | ||
| if (m_collapsibleComponentList->checkedCollapsibleComponent()) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.