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

Function gatherReports

src/workflow/Util.cpp:68–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66};
67
68void gatherReports(const openstudio::filesystem::path& runDirPath, const openstudio::filesystem::path& rootDirPath) {
69 namespace fs = openstudio::filesystem;
70
71 LOG_FREE(Info, "openstudio.workflow.Util", "Run directory: " << runDirPath);
72
73 // It's been wiped out during runInitialization
74 auto reportsDirPath = rootDirPath / "reports";
75 fs::create_directories(reportsDirPath);
76
77 LOG_FREE(Info, "openstudio.workflow.Util", "Reports directory" << rootDirPath);
78
79 // Try to find E+ result file
80 auto epHTMPath = runDirPath / "eplustbl.htm";
81 if (fs::is_regular_file(epHTMPath)) {
82 // TODO: try to force UTF-8? html = File.read(eplus_html); html = html.force_encoding('ISO-8859-1').encode('utf-8', replace: nil)
83 LOG_FREE(Info, "openstudio.workflow.Util", "Saving EnergyPlus HTML report to " << reportsDirPath << "/eplustbl.html");
84
85 fs::copy_file(epHTMPath, reportsDirPath / "eplustbl.html", fs::copy_options::overwrite_existing);
86 }
87
88 // Find any `/report.*\..*/` files
89 static const boost::regex runDirNumbers(R"(^[0-9]+[0-9]+[0-9]+_(.*)$)");
90 for (auto& fPath : fs::recursive_directory_files(runDirPath)) {
91 auto fnamePath = fPath.filename();
92 std::string fnamePathStr = fnamePath.string();
93 if (fnamePathStr.substr(0, 6) == "report" && fnamePath.has_extension()) {
94 // TODO: lots of workarounds happening in https://github.com/NREL/OpenStudio-workflow-gem/blob/cf99e6096f33b717df79a71c245a4d7aa4ccb7a6/lib/openstudio/workflow/util/post_process.rb#L188-L216
95 // TODO: I don't like it one bit. Instead we should store a stepRunDir on the workflowJSON Steps and iterate on that or something
96 boost::smatch matches;
97 const std::string dirNameStr = fPath.parent_path().filename().string();
98 if (boost::regex_search(dirNameStr, matches, runDirNumbers)) {
99 const std::string measure_dir_name(matches[1].first, matches[1].second);
100 const fs::path measureXmlPath = rootDirPath / "measures" / measure_dir_name / "measure.xml";
101 std::string measure_class_name;
102 if (fs::is_regular_file(measureXmlPath)) {
103 measure_class_name = BCLXML(measureXmlPath).className();
104 } else {
105 measure_class_name = measure_dir_name;
106 }
107 measure_class_name = openstudio::toUnderscoreCase(measure_class_name);
108 const fs::path outPath = reportsDirPath / fmt::format("{}_{}", measure_class_name, fnamePathStr);
109
110 const fs::path oriPath = runDirPath / fPath;
111 LOG_FREE(Info, "openstudio.workflow.Util", "Saving report " << oriPath << " to " << outPath);
112 fs::copy_file(oriPath, outPath, fs::copy_options::overwrite_existing);
113 }
114 }
115 }
116
117 // Remove empty directories
118 for (const auto& dirEnt : fs::directory_iterator{runDirPath}) {
119 const auto& dirEntryPath = dirEnt.path();
120 if (fs::is_directory(dirEntryPath) && fs::is_empty(dirEntryPath)) {
121 LOG_FREE(Info, "openstudio.workflow.Util", "Removing empty directory " << dirEntryPath);
122 fs::remove(dirEntryPath);
123 }
124 }
125}

Callers 1

runPostProcessMethod · 0.85

Calls 6

toUnderscoreCaseFunction · 0.85
filenameMethod · 0.80
stringMethod · 0.45
classNameMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected