| 590 | } |
| 591 | |
| 592 | void OSWorkflow::runExtractInputsAndOutputs() const { |
| 593 | const Json::Value results = outputAttributesToJSON(output_attributes, true); |
| 594 | Json::StreamWriterBuilder wbuilder; |
| 595 | wbuilder["indentation"] = " "; |
| 596 | |
| 597 | { |
| 598 | const std::string result = Json::writeString(wbuilder, results); |
| 599 | |
| 600 | auto jsonPath = workflowJSON.absoluteRunDir() / "results.json"; |
| 601 | openstudio::filesystem::ofstream file(jsonPath); |
| 602 | OS_ASSERT(file.is_open()); |
| 603 | file << result; |
| 604 | file.close(); |
| 605 | } |
| 606 | |
| 607 | const auto osa_abs_path = workflowJSON.absoluteRootDir().parent_path() / "analysis.json"; |
| 608 | if (!openstudio::filesystem::is_regular_file(osa_abs_path)) { |
| 609 | return; |
| 610 | } |
| 611 | |
| 612 | std::ifstream ifs(openstudio::toSystemFilename(osa_abs_path)); |
| 613 | |
| 614 | Json::CharReaderBuilder rbuilder; |
| 615 | std::string formattedErrors; |
| 616 | |
| 617 | Json::Value analysis_json; |
| 618 | const bool parsingSuccessful = Json::parseFromStream(rbuilder, ifs, &analysis_json, &formattedErrors); |
| 619 | if (!parsingSuccessful) { |
| 620 | LOG_AND_THROW("OSA Analysis JSON '" << toString(osa_abs_path) << "' cannot be processed, " << formattedErrors); |
| 621 | } |
| 622 | |
| 623 | if (!openstudio::checkKeyAndType(analysis_json, "analysis", Json::objectValue)) { |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | if (!openstudio::checkKeyAndType(analysis_json["analysis"], "output_variables", Json::arrayValue)) { |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | Json::Value objectiveFunctions(Json::objectValue); |
| 632 | |
| 633 | auto& outputVars = analysis_json["analysis"]["output_variables"]; |
| 634 | for (const auto& variable : outputVars) { |
| 635 | if (openstudio::checkKeyAndType(variable, "objective_function", Json::booleanValue) && variable["objective_function"].asBool()) { |
| 636 | assertKeyAndType(variable, "name", Json::stringValue); |
| 637 | assertKeyAndType(variable, "objective_function_index", Json::intValue); |
| 638 | const std::string name = variable["name"].asString(); |
| 639 | const int idx = variable["objective_function_index"].asInt() + 1; |
| 640 | |
| 641 | LOG(Info, "Looking for objective function " << name); |
| 642 | |
| 643 | // Splitting on a `.` feels very unrealiable |
| 644 | const size_t pos = name.find('.'); |
| 645 | if (pos == std::string::npos) { |
| 646 | LOG(Warn, "Objective function name='" << name << "' does not contain a dot (`.`)"); |
| 647 | continue; |
| 648 | } |
| 649 | const std::string measureName = name.substr(0, pos); |
nothing calls this directly
no test coverage detected