MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / getMeasure

Method getMeasure

src/cli/MeasureManager.cpp:288–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

286}
287
288boost::optional<BCLMeasure> MeasureManager::getMeasure(const openstudio::path& measureDirPath, bool force_reload) {
289
290 const auto& measureDirPathStr = measureDirPath.string();
291
292 // check if measure exists on disk
293 if (!openstudio::filesystem::is_directory(measureDirPath)) {
294 fmt::print("Measure '{}' does not exist.\n", measureDirPathStr);
295 m_measures.erase(measureDirPath);
296 return boost::none;
297 }
298 if (!openstudio::filesystem::is_regular_file(measureDirPath / "measure.xml")) {
299 fmt::print("Measure directory '{}' exists but does not have a measure.xml.\n", measureDirPathStr);
300 m_measures.erase(measureDirPath);
301 return boost::none;
302 }
303
304 BCLMeasureInfo* measureInfo_ = nullptr;
305 if (!force_reload) {
306 auto it = m_measures.find(measureDirPath);
307 if (it != m_measures.end()) {
308 measureInfo_ = &(it->second);
309 fmt::print("Using cached measure {}\n", measureDirPath.generic_string());
310 }
311 }
312
313 if (!measureInfo_) {
314 m_measures.erase(measureDirPath);
315
316 // load from disk
317 fmt::print("Attempting to load measure '{}'\n", measureDirPathStr);
318
319 boost::optional<BCLMeasure> measure_ = openstudio::BCLMeasure::load(measureDirPath);
320
321 if (!measure_) {
322 fmt::print("Failed to load measure '{}'\n", measureDirPathStr);
323 return boost::none;
324 }
325 fmt::print("Successfully loaded measure '{}'\n", measureDirPathStr);
326 auto [it, ok] = m_measures.insert({measureDirPath, BCLMeasureInfo{std::move(*measure_)}});
327 measureInfo_ = &(it->second);
328 }
329
330 auto& measure = measureInfo_->measure;
331
332 // see if there are updates, want to make sure to perform both checks so do outside of conditional
333 bool file_updates = measure.checkForUpdatesFiles(); // checks if any files have been updated
334 bool xml_updates = measure.checkForUpdatesXML(); // only checks if xml as loaded has been changed since last save
335
336 auto readmeInPath = measureDirPath / "README.md.erb";
337 auto readmeOutPath = measureDirPath / "README.md";
338
339 const bool hasReadmeIn = openstudio::filesystem::is_regular_file(readmeInPath);
340 const bool hasReadmeOut = openstudio::filesystem::is_regular_file(readmeOutPath);
341 const bool readme_out_of_date = hasReadmeIn && !hasReadmeOut;
342
343 // TODO: try catch like in measure_manager.rb?
344 bool missing_fields = measure.missingRequiredFields();
345

Callers 8

do_POSTMethod · 0.45
download_bcl_measureMethod · 0.45
bcl_measuresMethod · 0.45
update_measuresMethod · 0.45
compute_argumentsMethod · 0.45
create_measureMethod · 0.45
duplicate_measureMethod · 0.45
executeMethod · 0.45

Calls 14

checkForUpdatesFilesMethod · 0.80
missingRequiredFieldsMethod · 0.80
renderFileMethod · 0.80
stringMethod · 0.45
eraseMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
checkForUpdatesXMLMethod · 0.45
clearMethod · 0.45
updateMethod · 0.45
evalMethod · 0.45

Tested by

no test coverage detected