Skip to content

UI forms as JSON#1338

Merged
brtietz merged 31 commits into
patchfrom
SAM_504
Feb 3, 2023
Merged

UI forms as JSON#1338
brtietz merged 31 commits into
patchfrom
SAM_504

Conversation

@sjanzou

@sjanzou sjanzou commented Jan 30, 2023

Copy link
Copy Markdown
Collaborator

goes with associated pull requests in wex 155 and SAM-private

@sjanzou sjanzou self-assigned this Jan 30, 2023

@mjprilliman mjprilliman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like the json formatting of the UI files. How will we diff callback and equation changes in the future? Seems like it might be more difficult as a single string with \n values.

@brtietz

brtietz commented Jan 30, 2023

Copy link
Copy Markdown
Collaborator

I like the json formatting of the UI files. How will we diff callback and equation changes in the future? Seems like it might be more difficult as a single string with \n values.

That's a great point. The best recommendation for this seems to be using an array of strings, in which each element of the array is a line: https://stackoverflow.com/a/52557585

If we want to go that route I would recommend completing the review of this format and migrating to that format as a separate issue, so we're a little less locked down on forms changes for the patch.

@brtietz brtietz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is really exciting, but I think it needs a little more polish prior to merging. Edit: I was reviewing an older version of the branch - please ignore.

Comment thread src/variables.cpp
@@ -2348,7 +2347,8 @@ void VarInfo::Write(wxOutputStream &os)
wxDataOutputStream out(os);
out.Write8(0xe1);
// out.Write8(2);
out.Write8(3); // change to version 3 after wxString "UIObject" field added
// out.Write8(3); // change to version 3 after wxString "UIObject" field added
out.Write8(4); // change to version 3 after wxString "UIObject" field added

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment doesn't make sense here - what is version 4?

Comment thread src/variables.cpp
// Group
Write_JSON_value(doc, "Group", Group);
// IndexLabels
/* Handle multiline equations in IndexLabels

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice comment!

Comment thread src/ide.cpp
// sz_form_tools->Add(new wxButton(this, ID_FORM_LOAD_ALL, "Load all", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 0, wxALL | wxEXPAND, 2);
// sz_form_tools->Add(new wxButton(this, ID_FORM_SAVE_TEXT, "Save text", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 0, wxALL | wxEXPAND, 2);
// sz_form_tools->Add(new wxButton(this, ID_FORM_LOAD_TEXT, "Load text", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 0, wxALL | wxEXPAND, 2);
// sz_form_tools->Add(new wxButton(this, ID_FORM_SAVE_ALL_TEXT, "Save all text", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 0, wxALL | wxEXPAND, 2);
// sz_form_tools->Add(new wxButton(this, ID_FORM_LOAD_ALL_TEXT, "Load all text", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 0, wxALL | wxEXPAND, 2);
//sz_form_tools->Add(new wxButton(this, ID_FORM_LOAD_ALL_TEXT, "Load all text", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 0, wxALL | wxEXPAND, 2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe I'm missing something, but why add commented out lines? This is hard to follow with all the commented out code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Maybe I'm missing something, but why add commented out lines? This is hard to follow with all the commented out code.

The code is temporarily commented so that when merging into develop, the updated text forms can be loaded and then saved as JSON and then the text UI forms can be removed. The forms in develop have diverged from patch so that a separate pull request is necessary for the SAM repo.

@mjprilliman

Copy link
Copy Markdown
Collaborator

This is really exciting, but I think it needs a little more polish prior to merging. For example: why are there both "Save" and "Save as JSON" buttons in the IDE?

image

I feel like there should only be one save button at merge time. Or is there a reason we'll need both for a while?

Why am I not seeing these additional buttons when I build the branches?

@brtietz

brtietz commented Jan 30, 2023

Copy link
Copy Markdown
Collaborator

Why am I not seeing these additional buttons when I build the branches?

Oh, whoops. I had an older version of SAM 504 checked out.

@brtietz brtietz self-requested a review January 30, 2023 18:39
@mjprilliman

Copy link
Copy Markdown
Collaborator

Clicking out of a UI form in the IDE registers a diff in the json without hitting save or making any changes. Diff software cannot find any differences in the files but the file is shown to be modified.

image

@cpaulgilman

Copy link
Copy Markdown
Collaborator

This looks good from the UI.

I also tested loading all configs with this LK script:

techs = list_technologies();
for (t=0;t<#techs;t++)
{
	fins = list_financing(techs[t]);
	for (f=0;f<#fins;f++)
	{
		outln(techs[t] + ', ' + fins[f]);
		configuration(techs[t],fins[f]);
	}	
}

The script works in Windows, but on Linux (Mint 21.1), when I run the script, I get errors like:

  • Solar Resource Data: "could not find library:SolarResourceData" when loading the Solar Resource Data
  • Marine Wave Resource Time Series: "Error: 'PacWave East' is not available in the library. Choose a different item."
  • Wind Resource File: "Error: 'WY Cheyenne_2006' is not available in the library. Choose a different item."

But the forms load fine when opening a case by hand, so not sure it's worth pursuing at this stage.

@sjanzou

sjanzou commented Jan 31, 2023

Copy link
Copy Markdown
Collaborator Author

Clicking out of a UI form in the IDE registers a diff in the json without hitting save or making any changes. Diff software cannot find any differences in the files but the file is shown to be modified.

image

Clicking out of a UI form in the IDE registers a diff in the json without hitting save or making any changes. Diff software cannot find any differences in the files but the file is shown to be modified.

image

Maybe we can write a better code versioning system than github that sometimes defaults to date and time changes instead of actually comparing file contents...

@sjanzou sjanzou requested a review from mjprilliman January 31, 2023 10:42
@sjanzou

sjanzou commented Jan 31, 2023

Copy link
Copy Markdown
Collaborator Author

This looks good from the UI.

I also tested loading all configs with this LK script:

techs = list_technologies();
for (t=0;t<#techs;t++)
{
	fins = list_financing(techs[t]);
	for (f=0;f<#fins;f++)
	{
		outln(techs[t] + ', ' + fins[f]);
		configuration(techs[t],fins[f]);
	}	
}

The script works in Windows, but on Linux (Mint 21.1), when I run the script, I get errors like:

  • Solar Resource Data: "could not find library:SolarResourceData" when loading the Solar Resource Data
  • Marine Wave Resource Time Series: "Error: 'PacWave East' is not available in the library. Choose a different item."
  • Wind Resource File: "Error: 'WY Cheyenne_2006' is not available in the library. Choose a different item."

But the forms load fine when opening a case by hand, so not sure it's worth pursuing at this stage.

Where are you running SAM from to get this script error? Did you make from the SAM-private build_linux folder and run from the installation folder? I am not seeing this issue on MacOS or on CentOS7.

@brtietz brtietz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It looks like the updates to the CI script swapped the target branch from patch to develop, that need to be addressed prior to merge.

Also the comment on line 2351 of variables.cpp is referring to the wrong version number.

Other than that, the new code works well for me - thanks for updating the rapid json environment variable!

Comment thread .github/workflows/ci.yml Outdated
@sjanzou

sjanzou commented Feb 2, 2023

Copy link
Copy Markdown
Collaborator Author

@brtietz , @mjprilliman , @cpaulgilman the multiline string saving for equations and callbacks has been implemented in this pull request and in wex pull request 155.

An example of changing AA Widgets callback line 36 from x=0; to y=0;
image

and then using git diff:
image

Please recheck this pull request along with wex 155 and let me know if you run into any issues.

@brtietz

brtietz commented Feb 2, 2023

Copy link
Copy Markdown
Collaborator

The diff for changing lines looks great. The diff for adding a new line, however, is quite messy:

image

Adding one line (13) triggered a change to over 100 lines.

Is there a reason it has to be an object with line numbers as opposed to an array?

@sjanzou

sjanzou commented Feb 2, 2023 via email

Copy link
Copy Markdown
Collaborator Author

@sjanzou

sjanzou commented Feb 3, 2023

Copy link
Copy Markdown
Collaborator Author

After updating to RapidJSON array of strings, single line changes and new line added changes in AA Widgets results in desired diff viewing:
image

@sjanzou sjanzou requested a review from brtietz February 3, 2023 10:29

@brtietz brtietz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is great! One additional case not shown in Steve's tests, removal:

image

All of these diffs are perfectly readable, in my opinion.

@brtietz brtietz merged commit 99aa468 into patch Feb 3, 2023
@cpaulgilman cpaulgilman added the added to release notes PR and/or issue has been added to release notes for a public release label Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

added to release notes PR and/or issue has been added to release notes for a public release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiline JSON strings for callbacks and equations JSON for defaults and forms

4 participants