| 274 | } |
| 275 | |
| 276 | void MeasureUpdateOptions::execute(MeasureUpdateOptions const& opt, ScriptEngineInstance& rubyEngine, ScriptEngineInstance& pythonEngine) { |
| 277 | // opt.debug_print(); |
| 278 | |
| 279 | if (opt.server_port > 0) { |
| 280 | MeasureManagerServer server(opt.server_port, rubyEngine, pythonEngine); |
| 281 | server.open(); // This starts the cpprestsdk http listener, which processes tasks in subthreads |
| 282 | server.do_tasks_forever(); // This starts the event loop on the **main** thread to process the requests there and NOT in a subthread |
| 283 | |
| 284 | return; |
| 285 | } else if (opt.update) { |
| 286 | MeasureManager measureManager(rubyEngine, pythonEngine); |
| 287 | if (auto measure_ = measureManager.getMeasure(opt.directoryPath, true)) { |
| 288 | // TODO: maybe I should write an OSMeasureInfo::toJSON() method, but that'd be duplicating the code in BCLMeasure (BCLXML to be exact). |
| 289 | // So since the only thing that's different is the OSArgument (OSMeasureInfo) versus BCLMeasureArgument (BCLMeasure), we just override |
| 290 | auto result = measure_->toJSON(); |
| 291 | |
| 292 | fmt::print("{}\n", result.toStyledString()); |
| 293 | } else { |
| 294 | fmt::print(stderr, "Cannot load measure from {}\n", opt.directoryPath.generic_string()); |
| 295 | } |
| 296 | return; |
| 297 | } else if (opt.update_all) { |
| 298 | MeasureManager measureManager(rubyEngine, pythonEngine); |
| 299 | std::vector<openstudio::path> subDirPaths; |
| 300 | for (auto const& dir_entry : boost::filesystem::directory_iterator{opt.directoryPath}) { |
| 301 | const auto& subDirPath = dir_entry.path(); |
| 302 | |
| 303 | if (openstudio::filesystem::is_directory(subDirPath) && openstudio::filesystem::is_regular_file(subDirPath / "measure.xml")) { |
| 304 | subDirPaths.emplace_back(subDirPath); |
| 305 | } |
| 306 | } |
| 307 | fmt::print("Found {} measure directories to update\n", subDirPaths.size()); |
| 308 | for (const auto& subDirPath : subDirPaths) { |
| 309 | measureManager.getMeasure(subDirPath, true); |
| 310 | } |
| 311 | } else if (!opt.compute_arguments_model.empty()) { |
| 312 | // NOTE: cannot move into MeasureManager to avoid repeating the code shared with MeasureManagerServer. This expects an OSM **or an IDF** in the |
| 313 | // case of an EnergyPlus Measure, whereas the server /compute_arguments endpoint always expects an OSM |
| 314 | MeasureManager measureManager(rubyEngine, pythonEngine); |
| 315 | auto measure_ = measureManager.getMeasure(opt.directoryPath, true); |
| 316 | if (!measure_) { |
| 317 | auto msg = fmt::format("Cannot load measure at '{}'", opt.directoryPath.generic_string()); |
| 318 | fmt::print(stderr, "{}\n", msg); |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | openstudio::measure::OSMeasureInfo info = measureManager.getMeasureInfo(opt.directoryPath, *measure_, opt.compute_arguments_model); |
| 323 | if (auto errorString_ = info.error()) { |
| 324 | fmt::print(stderr, "{}\n", *errorString_); |
| 325 | return; |
| 326 | } |
| 327 | // TODO: maybe I should write an OSMeasureInfo::toJSON() method, but that'd be duplicating the code in BCLMeasure (BCLXML to be exact). |
| 328 | // So since the only thing that's different is the OSArgument (OSMeasureInfo) versus BCLMeasureArgument (BCLMeasure), we just override |
| 329 | auto result = measure_->toJSON(); |
| 330 | auto& arguments = result["arguments"]; |
| 331 | arguments.clear(); |
| 332 | for (const measure::OSArgument& argument : info.arguments()) { |
| 333 | arguments.append(argument.toJSON()); |
nothing calls this directly
no test coverage detected