-
Notifications
You must be signed in to change notification settings - Fork 475
Introduce optional sort option field for output control #11523
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
base: develop
Are you sure you want to change the base?
Changes from all commits
5e5a8d4
27d1c41
22e105e
075dcb6
87b882b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1280,6 +1280,8 @@ void GetInputTabularStyle(EnergyPlusData &state) | |
| AlphArray(2) = "None"; | ||
| ort->unitsStyle_Tabular = UnitsStyle::None; | ||
| ort->formatReals_Tabular = true; | ||
| AlphArray(4) = "UNSORTED"; | ||
| ort->sortOption = SortOption::Unsorted; | ||
| } else if (NumTabularStyle == 1) { | ||
| state.dataInputProcessing->inputProcessor->getObjectItem(state, | ||
| CurrentModuleObject, | ||
|
|
@@ -1363,8 +1365,8 @@ void GetInputTabularStyle(EnergyPlusData &state) | |
| ort->del(1) = DataStringGlobals::CharComma; // comma | ||
| AlphArray(1) = "COMMA"; | ||
| } | ||
| // MonthlyUnitConversion | ||
| if (NumAlphas >= 2) { | ||
| // UnitConversion | ||
| ort->unitsStyle_Tabular = SetUnitsStyleFromString(AlphArray(2)); | ||
| if (ort->unitsStyle_Tabular == UnitsStyle::NotFound) { | ||
| ShowWarningError(state, | ||
|
|
@@ -1373,9 +1375,19 @@ void GetInputTabularStyle(EnergyPlusData &state) | |
| state.dataIPShortCut->cAlphaFieldNames(2), | ||
| AlphArray(2))); | ||
| } | ||
| ort->sortOption = SetSortOptionFromString(AlphArray(4)); | ||
| if (ort->sortOption == SortOption::NotFound) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sortOption is a key choice, and has a default. It is not possible for sortOption to be NotFound. If the field is missing or blank then the InputProcessor will fill that field with Unsorted. This check can be deleted, same for the new function SetSortOptionalFromString, just read the input here as done in SetSortOptionalFromString. |
||
| ShowWarningError(state, | ||
| EnergyPlus::format("{}: Invalid {}=\"{}\". No sorting will be performed.", | ||
| CurrentModuleObject, | ||
| state.dataIPShortCut->cAlphaFieldNames(4), | ||
| AlphArray(4))); | ||
| } | ||
| } else { | ||
| ort->unitsStyle_Tabular = UnitsStyle::None; | ||
| AlphArray(2) = "None"; | ||
| AlphArray(4) = "UNSORTED"; | ||
| ort->sortOption = SortOption::Unsorted; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't even matter |
||
| } | ||
| } else if (NumTabularStyle > 1) { | ||
| ShowWarningError(state, EnergyPlus::format("{}: Only one instance of this object is allowed. Commas will be used.", CurrentModuleObject)); | ||
|
|
@@ -1385,10 +1397,12 @@ void GetInputTabularStyle(EnergyPlusData &state) | |
| ort->unitsStyle_Tabular = UnitsStyle::None; | ||
| AlphArray(2) = "None"; | ||
| ort->formatReals_Tabular = getYesNoValue(AlphArray(3)) == BooleanSwitch::Yes; | ||
| AlphArray(4) = "UNSORTED"; | ||
| ort->sortOption = SortOption::Unsorted; | ||
| } | ||
|
|
||
| print(state.files.eio, "! <Tabular Report>,Style,Unit Conversion, Format Reals\n"); | ||
| print(state.files.eio, "Tabular Report,{},{},{}\n", AlphArray(1), AlphArray(2), ort->formatReals_Tabular ? "Yes" : "No"); | ||
| print(state.files.eio, "! <Tabular Report>,Style,Unit Conversion,Format Reals,Sort Option\n"); | ||
| print(state.files.eio, "Tabular Report,{},{},{},{}\n", AlphArray(1), AlphArray(2), ort->formatReals_Tabular ? "Yes" : "No", AlphArray(4)); | ||
| } | ||
|
|
||
| UnitsStyle SetUnitsStyleFromString(std::string const &unitStringIn) | ||
|
|
@@ -1401,6 +1415,52 @@ UnitsStyle SetUnitsStyleFromString(std::string const &unitStringIn) | |
| return unitsStyleReturn; | ||
| } | ||
|
|
||
| SortOption SetSortOptionFromString(std::string const &sortStringIn) | ||
| { | ||
| SortOption sortOptionReturn = static_cast<SortOption>(getEnumValue(SortOptionNamesUC, Util::makeUPPER(sortStringIn))); | ||
| if (sortOptionReturn == SortOption::Invalid) { | ||
| sortOptionReturn = SortOption::NotFound; | ||
| } | ||
|
|
||
| return sortOptionReturn; | ||
| } | ||
|
|
||
| Array2D_string SortTableByName(EnergyPlusData &state, Array2D_string body, const Array1D_string &cLabels, int rowsBody, int colsBody) | ||
| { | ||
| // starting from the left most column, find the first one that contains the Name substring | ||
| std::string sCol = "Name"; | ||
| auto it = std::find_if(cLabels.begin(), cLabels.end(), [&sCol](const std::string& s) { return s.find(sCol) != std::string::npos; }); | ||
| if (it != cLabels.end()) { | ||
| sCol = *it; | ||
| } | ||
|
|
||
| int index = 0; | ||
| it = std::find(cLabels.begin(), cLabels.end(), sCol); | ||
| if (it != cLabels.end()) { | ||
| index = std::distance(cLabels.begin(), it) + 1; | ||
| } | ||
|
|
||
| // if no column with Name found, just return the original unsorted table | ||
| if (index > 0) { | ||
| Array1D_int rowHeadSorted; | ||
| rowHeadSorted.allocate(rowsBody); | ||
| for (int jRow = 1; jRow <= rowsBody; ++jRow) { | ||
| rowHeadSorted(jRow) = jRow; | ||
| } | ||
| std::sort(rowHeadSorted.begin(), rowHeadSorted.end(), [&](int a, int b) { return body(index, a) < body(index, b); }); | ||
|
|
||
| Array2D_string bodySorted; | ||
| bodySorted.allocate(colsBody, rowsBody); | ||
| for (int jRow = 1; jRow <= rowsBody; ++jRow) { | ||
| for (int iCol = 1; iCol <= colsBody; ++iCol) { | ||
| bodySorted(iCol, jRow) = body(iCol, rowHeadSorted(jRow)); | ||
| } | ||
| } | ||
| body = bodySorted; | ||
| } | ||
| return body; | ||
| } | ||
|
|
||
| void GetInputOutputTableSummaryReports(EnergyPlusData &state) | ||
| { | ||
| // SUBROUTINE INFORMATION: | ||
|
|
@@ -14731,6 +14791,9 @@ void WriteEioTables(EnergyPlusData &state) | |
| } | ||
|
|
||
| if (currentStyle.produceTabular) { | ||
| if (ort->sortOption == SortOption::Name) { // optionally sort | ||
| tableBody = SortTableByName(state, tableBody, columnHead, numRows, numCols); | ||
| } | ||
| WriteSubtitle(state, tableName); | ||
| std::string footnote; | ||
| WriteTable(state, tableBody, rowHead, columnHead, columnWidth, false, footnote); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2357,7 +2357,10 @@ | |
| !- =========== ALL OBJECTS IN CLASS: OUTPUTCONTROL:TABLE:STYLE =========== | ||
|
|
||
| OutputControl:Table:Style, | ||
| HTML; !- Column Separator | ||
| HTML, !- Column Separator | ||
| , !- Unit Conversion | ||
| , !- Format Numeric Values | ||
| Name; !- Sort Option | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could introduce similar field for Output:JSON and Output:SQLite? I'm not totally sure how these three objects are all related.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Output:JSON it would be good to have something similar. I'm not so sure if SQLite. |
||
|
|
||
| !- =========== ALL OBJECTS IN CLASS: OUTPUT:VARIABLE =========== | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field name and keys borrowed from Output:VariableDictionary.