Skip to content

Commit 65d6505

Browse files
committed
Move standardReportMeasure to MeasureManager, test updates to measures by version id and timestamp
1 parent 6ae468f commit 65d6505

File tree

6 files changed

+45
-80
lines changed

6 files changed

+45
-80
lines changed

src/openstudio_app/OpenStudioApp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ OpenStudioApp::OpenStudioApp(int& argc, char** argv)
221221
waitDialog->show();
222222
emit resetWaitDialog();
223223

224+
measureManager().setResourcesPath(resourcesPath());
225+
224226
// Non blocking
225227
startMeasureManagerProcess();
226228

src/openstudio_lib/OSDocument.cpp

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ void OSDocument::addStandardMeasures() {
13151315

13161316
// standard report measure
13171317
bool srmAdded = false;
1318-
boost::optional<BCLMeasure> srm = standardReportMeasure();
1318+
boost::optional<BCLMeasure> srm = OSAppBase::instance()->measureManager().standardReportMeasure();
13191319
if (srm) {
13201320
try {
13211321
std::pair<bool, std::string> result = OSAppBase::instance()->measureManager().updateMeasure(*srm);
@@ -1480,32 +1480,6 @@ std::vector<BCLComponent> OSDocument::componentAttributeSearch(const std::vector
14801480
return result;
14811481
}
14821482

1483-
boost::optional<BCLMeasure> OSDocument::standardReportMeasure() {
1484-
// DLM: Breaking changes in openstudio_results measures prevent us from being able to ensure
1485-
// that measure in users local BCL or remote BCL will work, just use measure in installer
1486-
return BCLMeasure::load(m_resourcesPath / toPath("openstudio_results"));
1487-
1488-
/*
1489-
const std::string uid("a25386cd-60e4-46bc-8b11-c755f379d916");
1490-
boost::optional<BCLMeasure> result = getLocalMeasure(uid);
1491-
1492-
if (!result) {
1493-
// if we don't have a result measure in local bcl, use the one in the installer
1494-
result = BCLMeasure::load(m_resourcesPath / toPath("openstudio_results"));
1495-
}
1496-
1497-
if (m_haveLocalBCL && RemoteBCL::isOnline()) {
1498-
RemoteBCL remoteBCL;
1499-
boost::optional<BCLMeasure> onlineResult = remoteBCL.getMeasure(uid);
1500-
if (onlineResult) {
1501-
result = onlineResult;
1502-
}
1503-
}
1504-
1505-
return result;
1506-
*/
1507-
}
1508-
15091483
bool OSDocument::save() {
15101484
LOG(Debug, "OSDocument::save");
15111485
bool fileSaved = false;

src/openstudio_lib/OSDocument.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ class OPENSTUDIO_API OSDocument : public OSQObjectController
137137

138138
std::vector<BCLComponent> componentAttributeSearch(const std::vector<std::pair<std::string, std::string>>& pairs) const;
139139

140-
boost::optional<BCLMeasure> standardReportMeasure();
141-
142140
// Returns IddObjectType from either model, componentLibrary, or BCL
143141
boost::optional<IddObjectType> getIddObjectType(const OSItemId& itemId) const;
144142

src/shared_gui_components/MeasureManager.cpp

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ void MeasureManager::setUrl(const QUrl& url) {
9696
m_url = url;
9797
}
9898

99+
void MeasureManager::setResourcesPath(const openstudio::path& resourcesPath) {
100+
m_resourcesPath = resourcesPath;
101+
}
102+
99103
bool MeasureManager::waitForStarted(int msec) {
100104
if (m_started) {
101105
return true;
@@ -199,6 +203,13 @@ void MeasureManager::saveTempModel(const path& tempDir) {
199203
m_measureArguments.clear();
200204
}
201205

206+
207+
boost::optional<BCLMeasure> MeasureManager::standardReportMeasure() const {
208+
// DLM: Breaking changes in openstudio_results measures prevent us from being able to ensure
209+
// that measure in users local BCL or remote BCL will work, just use measure in installer
210+
return BCLMeasure::load(m_resourcesPath / toPath("openstudio_results"));
211+
}
212+
202213
std::vector<BCLMeasure> MeasureManager::bclMeasures() const {
203214
std::vector<BCLMeasure> result;
204215
result.reserve(m_bclMeasures.size());
@@ -224,6 +235,7 @@ std::vector<BCLMeasure> MeasureManager::combinedMeasures() const {
224235
result.reserve(m_myMeasures.size() + m_bclMeasures.size());
225236

226237
std::set<UUID> resultUUIDs;
238+
227239
// insert my measures
228240
for (auto it = m_myMeasures.begin(), itend = m_myMeasures.end(); it != itend; ++it) {
229241
if (resultUUIDs.find(it->first) == resultUUIDs.end()) {
@@ -958,11 +970,25 @@ bool MeasureManager::checkForUpdates(const openstudio::path& measureDir, bool fo
958970

959971
void MeasureManager::checkForRemoteBCLUpdates() {
960972
RemoteBCL remoteBCL;
961-
int numUpdates = remoteBCL.checkForMeasureUpdates();
973+
remoteBCL.checkForMeasureUpdates();
974+
std::vector<BCLSearchResult> updates = remoteBCL.measuresWithUpdates();
975+
976+
// remove false updates (e.g. measure was updated after downloading from bcl due to incorrect sha)
977+
updates.erase(std::remove_if(updates.begin(), updates.end(), [this](const BCLSearchResult& update) {
978+
auto current = m_bclMeasures.find(toUUID(update.uid()));
979+
if (current != m_bclMeasures.end()) {
980+
if (update.versionModified() && current->second.versionModified()) {
981+
return update.versionModified().get() < current->second.versionModified().get();
982+
}
983+
}
984+
return false;
985+
}), updates.end());
986+
987+
int numUpdates = updates.size();
988+
962989
if (numUpdates == 0) {
963990
QMessageBox::information(m_app->mainWidget(), tr("Measures Updated"), tr("All measures are up-to-date."));
964-
} else {
965-
std::vector<BCLSearchResult> updates = remoteBCL.measuresWithUpdates();
991+
} else {
966992

967993
QString text(QString::number(numUpdates) + tr(" measures have been updated on BCL compared to your local BCL directory.\n")
968994
+ tr("Would you like update them?"));
@@ -997,50 +1023,6 @@ void MeasureManager::checkForRemoteBCLUpdates() {
9971023
}
9981024
}
9991025

1000-
void MeasureManager::downloadBCLMeasures() {
1001-
RemoteBCL remoteBCL;
1002-
int numUpdates = remoteBCL.checkForMeasureUpdates();
1003-
if (numUpdates == 0) {
1004-
QMessageBox::information(m_app->mainWidget(), "Measures Updated", "All measures are up-to-date.");
1005-
} else {
1006-
std::vector<BCLSearchResult> updates = remoteBCL.measuresWithUpdates();
1007-
1008-
QString detailedText;
1009-
for (const BCLSearchResult& update : updates) {
1010-
detailedText += toQString("* name: " + update.name() + "\n");
1011-
detailedText += toQString(" - uid: " + update.uid() + "\n");
1012-
auto current = m_bclMeasures.find(toUUID(update.uid()));
1013-
if (current != m_bclMeasures.end()) {
1014-
detailedText += toQString(" - old versionId: " + current->second.versionId() + "\n");
1015-
}
1016-
detailedText += toQString(" - new versionId: " + update.versionId() + "\n\n");
1017-
}
1018-
1019-
remoteBCL.updateMeasures();
1020-
1021-
// remoteBCL.updateMeasures should remove outdated measures, but won't work correctly until https://github.com/NREL/OpenStudio/pull/5129
1022-
// if we have the new measure, delete outdated ones
1023-
for (const BCLSearchResult& update : updates) {
1024-
if (OSAppBase::instance()->currentDocument()->getLocalMeasure(update.uid(), update.versionId())) {
1025-
OSAppBase::instance()->currentDocument()->removeOutdatedLocalMeasures(update.uid(), update.versionId());
1026-
}
1027-
}
1028-
1029-
updateMeasuresLists(false);
1030-
1031-
QMessageBox msg(m_app->mainWidget());
1032-
msg.setIcon(QMessageBox::Information);
1033-
msg.setWindowTitle("Measures Updated");
1034-
if (numUpdates == 1) {
1035-
msg.setText("1 measure has been updated.");
1036-
} else {
1037-
msg.setText(QString::number(numUpdates) + " measures have been updated.");
1038-
}
1039-
msg.setDetailedText(detailedText);
1040-
msg.exec();
1041-
}
1042-
}
1043-
10441026
void MeasureManager::addMeasure() {
10451027
// open modal dialog
10461028
//QSharedPointer<BCLMeasureDialog> dialog(new BCLMeasureDialog(this->mainWindow));

src/shared_gui_components/MeasureManager.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class MeasureManager : public QObject
104104

105105
void setUrl(const QUrl& url);
106106

107+
void setResourcesPath(const openstudio::path& resourcesPath);
108+
107109
bool waitForStarted(int msec = 10000);
108110

109111
void setLibraryController(const QSharedPointer<LocalLibraryController>& t_libraryController);
@@ -114,6 +116,9 @@ class MeasureManager : public QObject
114116
//// Saves the current model to a temp location, used when computing arguments
115117
void saveTempModel(const path& tempDir);
116118

119+
/// The standard report measure that comes with the application
120+
boost::optional<BCLMeasure> standardReportMeasure() const;
121+
117122
//// Measures downloaded from the BCL.
118123
std::vector<BCLMeasure> bclMeasures() const;
119124

@@ -178,9 +183,6 @@ class MeasureManager : public QObject
178183
// Checks for updated versions
179184
void checkForRemoteBCLUpdates();
180185

181-
/// Downloads updated versions of all BCL measures
182-
void downloadBCLMeasures();
183-
184186
void addMeasure();
185187

186188
void duplicateSelectedMeasure();
@@ -210,6 +212,7 @@ class MeasureManager : public QObject
210212
std::map<UUID, BCLMeasure> m_bclMeasures;
211213
std::map<openstudio::path, std::vector<measure::OSArgument>> m_measureArguments;
212214
QUrl m_url;
215+
openstudio::path m_resourcesPath;
213216
QSharedPointer<LocalLibraryController> m_libraryController;
214217
bool m_started;
215218
QMutex m_mutex;

src/shared_gui_components/SyncMeasuresDialog.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ void SyncMeasuresDialog::findUpdates() {
124124
boost::optional<BCLMeasure> workflowMeasure = m_workflow.getBCLMeasureByUUID(measure.uuid());
125125
if (workflowMeasure) {
126126
if (workflowMeasure->versionUUID() != measure.versionUUID()) {
127-
m_measuresNeedingUpdates.push_back(measure);
127+
if (workflowMeasure->versionModified() && measure.versionModified()) {
128+
if (workflowMeasure->versionModified().get() < measure.versionModified().get()) {
129+
m_measuresNeedingUpdates.push_back(measure);
130+
}
131+
} else {
132+
m_measuresNeedingUpdates.push_back(measure);
133+
}
128134
}
129135
}
130136

0 commit comments

Comments
 (0)