Skip to content

Commit

Permalink
Add data_point_out.json as requested
Browse files Browse the repository at this point in the history
I talked to some folks who suggested just adding it, and I filed #5029 for investigating at a later date if we can just use a single file.
  • Loading branch information
jmarrec committed Nov 13, 2023
1 parent 659cd67 commit 5193679
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
17 changes: 7 additions & 10 deletions src/cli/test/test_with_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def test_run_with_analysis(osclipath, is_labs: bool):
"scaling_factor_3": None,
}

data_point_out_path = runDir / "data_point_out.json"
assert data_point_out_path.is_file()
data_point_out = json.loads(data_point_out_path.read_text())
assert data_point_out == {
"FakeReport": {"applicable": True, "net_site_energy": 167.1, "something_with_invalid_chars": 1}
}

expected_files_in_run_dir = {
"data_point.zip",
"finished.job",
Expand All @@ -71,17 +78,7 @@ def test_run_with_analysis(osclipath, is_labs: bool):
"results.json",
"run.log",
"started.job",
# TODO: see below
"data_point_out.json",
}
# TODO: I'm letting this test fail so it's obvious this needs to be addressed
if True: # not is_labs:
# We get the SAME exact info in measure_attributes.json, results.json and data_point_out.json...
# measure_attributes.json is flushed after each apply measure Step (ModelMeasures, EnergyPlusMeasures,
# ReportingMeasures), then at the end of ReportingMeasures it's done once again and results.json is spat out too
# Do we really need the data_point_out.json in addition to this?
# Seems like we could just run the output of results.json/data_point_out.json at the end of the workflow run
# instead
expected_files_in_run_dir.add("data_point_out.json")

assert set([x.name for x in runDir.glob("*")]) == expected_files_in_run_dir
34 changes: 27 additions & 7 deletions src/workflow/OSWorkflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,7 @@ bool OSWorkflow::run() {
}

if (!workflowJSON.runOptions()->fast()) {
if (m_add_timings) {
m_timers->newTimer("Zip datapoint");
}
openstudio::workflow::util::zipResults(runDirPath);
if (m_add_timings) {
m_timers->tockCurrentTimer();
}
communicateResults();
}

if (state == State::Errored) {
Expand Down Expand Up @@ -491,6 +485,7 @@ void OSWorkflow::communicateMeasureAttributes() const {
Json::StreamWriterBuilder wbuilder;
// mimic the old StyledWriter behavior:
wbuilder["indentation"] = " ";

const std::string result = Json::writeString(wbuilder, root);

auto jsonPath = workflowJSON.absoluteRunDir() / "measure_attributes.json";
Expand Down Expand Up @@ -598,4 +593,29 @@ void OSWorkflow::runExtractInputsAndOutputs() const {
}
}

void OSWorkflow::communicateResults() const {
if (!workflowJSON.runOptions()->skipZipResults()) {
if (m_add_timings) {
m_timers->newTimer("Zip datapoint");
}
openstudio::workflow::util::zipResults(workflowJSON.absoluteRunDir());
if (m_add_timings) {
m_timers->tockCurrentTimer();
}
}

const Json::Value root = outputAttributesToJSON(output_attributes, true);
Json::StreamWriterBuilder wbuilder;
// mimic the old StyledWriter behavior:
wbuilder["indentation"] = " ";

const std::string result = Json::writeString(wbuilder, root);

auto jsonPath = workflowJSON.absoluteRunDir() / "data_point_out.json";
openstudio::filesystem::ofstream file(jsonPath);
OS_ASSERT(file.is_open());
file << result;
file.close();
}

} // namespace openstudio
3 changes: 3 additions & 0 deletions src/workflow/OSWorkflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class OSWorkflow
/** Write results.json (same as the final measure_attributes.json but with sanitized keys)
* and if `absoluteRootDir (oswDir) / .. / analysis.json` is found, write the objectives.json */
void runExtractInputsAndOutputs() const;

// Zip and write data_point_out.osw
void communicateResults() const;
};

} // namespace openstudio
Expand Down

0 comments on commit 5193679

Please sign in to comment.