Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Output:JSON tabular data output incorrectly dependent on OutputControl:Files input #10155

Merged
merged 3 commits into from Jan 5, 2024

Conversation

shorowit
Copy link
Contributor

@shorowit shorowit commented Aug 19, 2023

Pull request overview

NOTE: ENHANCEMENTS MUST FOLLOW A SUBMISSION PROCESS INCLUDING A FEATURE PROPOSAL AND DESIGN DOCUMENT PRIOR TO SUBMITTING CODE

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies

Reviewer

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@shorowit shorowit added the Defect Includes code to repair a defect in EnergyPlus label Aug 19, 2023
@shorowit shorowit added this to the EnergyPlus 23.2 milestone Aug 19, 2023
@shorowit shorowit self-assigned this Aug 19, 2023
@shorowit
Copy link
Contributor Author

To test, add an Output:JSON object to any test file, like so:

Output:JSON,
  TimeSeriesAndTabular,                   !- Option Type
  Yes;                                    !- Output JSON

Note that you now get the same eplusout.json output whether you have:

OutputControl:Files,
  ,                                    !- Output CSV
  ,                                    !- Output MTR
  ,                                    !- Output ESO
  ,                                    !- Output EIO
  Yes;                                 !- Output Tabular

or

OutputControl:Files,
  ,                                    !- Output CSV
  ,                                    !- Output MTR
  ,                                    !- Output ESO
  ,                                    !- Output EIO
  No;                                  !- Output Tabular

@JasonGlazer JasonGlazer self-requested a review August 30, 2023 19:12
@JasonGlazer
Copy link
Contributor

@shorowit I think the lines:

if (!(state.files.outputControl.tabular || state.files.outputControl.sqlite || state.files.outputControl.json)) 

should probably be something like

if (!(state.files.outputControl.tabular || state.files.outputControl.sqlite || (state.files.outputControl.json & state.dataResultsFramework->resultsFramework->timeSeriesAndTabularEnabled()) )) 

Honestly, the portion that says just says "state.files.outputControl.sqlite" doesn't seem quite correct to me for the same reason but I haven't tried testing that.

@Myoldmopar
Copy link
Member

And if we go that way, I would prefer a valid version of something like this:

bool const htmlTabular = state.files.outputControl.tabular;
bool const jsonTabular = state.files.outputControl.json && state.dataResultsFramework->resultsFramework->timeSeriesAndTabularEnabled();
bool const sqliteTabular = state.files.outputControl.sqlite; // && @JasonGlazer thinks something else maybe?
if (!(htmlTabular || jsonTabular || sqliteTabular)) 

@shorowit
Copy link
Contributor Author

shorowit commented Sep 1, 2023

@Myoldmopar @JasonGlazer Is this what you had in mind? It seems weird to me that the code in four different places is setting state.dataOutRptTab->WriteTabularFiles = false;, but maybe that's fine. I'm not that familiar with what is going on.

@JasonGlazer
Copy link
Contributor

@shorowit that seems like a nice approach keeping the logic in the function. I didn't mean to imply that I know that my suggestion will fix the problem that @Myoldmopar brought up but I think it will. I would recommend either running some test files to make sure it works as expected and then adding some unit tests. Some digging might be needed if the SQL is not working right.

@shorowit
Copy link
Contributor Author

I don't have an immediate need for this improvement, and I'm not going to have a chance to further test this and bring it to completion in the near future. So I'm going to change the milestone to the next release. (If someone else wants to bring it to completion sooner, feel free to have at it.)

@nrel-bot-3
Copy link

@shorowit @Myoldmopar it has been 28 days since this pull request was last updated.

@Myoldmopar Myoldmopar assigned Myoldmopar and unassigned shorowit Oct 25, 2023
@@ -2711,7 +2711,7 @@ void ComputeTariff(EnergyPlusData &state)

Real64 annualAggregate;

if (!(state.files.outputControl.tabular || state.files.outputControl.sqlite)) {
if (!state.files.outputControl.writeTabular(state)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb question here...why is the state.dataOutRptTab->WriteTabularFiles being set here in a function called ComputeTariff inside EconomicTariff.cc anyway?? That alone seems super weird.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good question. And I don't remember, I suppose this might be the first place that a call to something dependent on actually writing tabular reports occurs, although that does not seem likely.

@@ -323,7 +323,7 @@ void GetInputTabularMonthly(EnergyPlusData &state)
// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
auto &ort = state.dataOutRptTab;

if (!(state.files.outputControl.tabular || state.files.outputControl.sqlite)) {
if (!state.files.outputControl.writeTabular(state)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd like to take a crack at this where state.dataOutRptTab->WriteTabularFiles is set once very early in the simulation and we don't need to keep calling this function. As soon as we have read inputs, we should be able to assign that flag.

I like that the function collects all the flags in one place -- that's always welcomed. The flag checks themselves may need a little extra work as described above, but regardless it's a good step.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Contributor

@JasonGlazer JasonGlazer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested it to make sure the files are produced as expected but the logic looks good to me. Thanks @shorowit and @Myoldmopar

@@ -2711,7 +2711,7 @@ void ComputeTariff(EnergyPlusData &state)

Real64 annualAggregate;

if (!(state.files.outputControl.tabular || state.files.outputControl.sqlite)) {
if (!state.files.outputControl.writeTabular(state)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good question. And I don't remember, I suppose this might be the first place that a call to something dependent on actually writing tabular reports occurs, although that does not seem likely.

bool const sqliteTabular = state.files.outputControl.sqlite; // && @JasonGlazer thinks something else maybe?
return (htmlTabular || jsonTabular || sqliteTabular);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I was concerned is the Output:SQLite field "Option Type" has two options Simple, SimpleAndTabular and they don't seem to impact this.

@@ -323,7 +323,7 @@ void GetInputTabularMonthly(EnergyPlusData &state)
// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
auto &ort = state.dataOutRptTab;

if (!(state.files.outputControl.tabular || state.files.outputControl.sqlite)) {
if (!state.files.outputControl.writeTabular(state)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@nrel-bot-2
Copy link

@Myoldmopar @shorowit @Myoldmopar it has been 28 days since this pull request was last updated.

@Myoldmopar
Copy link
Member

OK, this has lingered long enough. It seems good. I'm going to just pull and test and get this in. If some further improvements are needed, they can come later.

@Myoldmopar
Copy link
Member

Everything is running fine, merging this. Thanks @shorowit and @JasonGlazer.

@Myoldmopar Myoldmopar merged commit bc827aa into develop Jan 5, 2024
10 of 15 checks passed
@Myoldmopar Myoldmopar deleted the output-json-tabular-data branch January 5, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Includes code to repair a defect in EnergyPlus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Output:JSON tabular data output incorrectly dependent on OutputControl:Files input
6 participants