src/model/OutputTableSummaryReports.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include <vector> | ||
| 7 | #include <string> | ||
| 8 | #include "OutputTableSummaryReports.hpp" | ||
| 9 | #include "OutputTableSummaryReports_Impl.hpp" | ||
| 10 | |||
| 11 | #include "Model.hpp" | ||
| 12 | #include "Model_Impl.hpp" | ||
| 13 | |||
| 14 | #include "ModelExtensibleGroup.hpp" | ||
| 15 | |||
| 16 | #include <utilities/idd/IddFactory.hxx> | ||
| 17 | #include <utilities/idd/IddEnums.hxx> | ||
| 18 | #include <utilities/idd/OS_Output_Table_SummaryReports_FieldEnums.hxx> | ||
| 19 | |||
| 20 | #include "../utilities/core/Assert.hpp" | ||
| 21 | #include <algorithm> | ||
| 22 | |||
| 23 | namespace openstudio { | ||
| 24 | namespace model { | ||
| 25 | |||
| 26 | namespace detail { | ||
| 27 | |||
| 28 | 904 | OutputTableSummaryReports_Impl::OutputTableSummaryReports_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 29 | 904 | : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 30 |
4/6✓ Branch 1 taken 904 times.
✓ Branch 4 taken 904 times.
✓ Branch 7 taken 904 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 904 times.
✗ Branch 13 not taken.
|
904 | OS_ASSERT(idfObject.iddObject().type() == OutputTableSummaryReports::iddObjectType()); |
| 31 | 904 | } | |
| 32 | |||
| 33 | 5 | OutputTableSummaryReports_Impl::OutputTableSummaryReports_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, | |
| 34 | 5 | bool keepHandle) | |
| 35 | 5 | : ModelObject_Impl(other, model, keepHandle) { | |
| 36 |
4/6✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 5 times.
✗ Branch 13 not taken.
|
5 | OS_ASSERT(other.iddObject().type() == OutputTableSummaryReports::iddObjectType()); |
| 37 | 5 | } | |
| 38 | |||
| 39 | 8 | OutputTableSummaryReports_Impl::OutputTableSummaryReports_Impl(const OutputTableSummaryReports_Impl& other, Model_Impl* model, bool keepHandle) | |
| 40 | 8 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 41 | |||
| 42 | ✗ | const std::vector<std::string>& OutputTableSummaryReports_Impl::outputVariableNames() const { | |
| 43 | ✗ | static std::vector<std::string> result; | |
| 44 | ✗ | return result; | |
| 45 | } | ||
| 46 | |||
| 47 | 7 | IddObjectType OutputTableSummaryReports_Impl::iddObjectType() const { | |
| 48 | 7 | return OutputTableSummaryReports::iddObjectType(); | |
| 49 | } | ||
| 50 | |||
| 51 | 18 | unsigned int OutputTableSummaryReports_Impl::numberofSummaryReports() const { | |
| 52 | 18 | return numExtensibleGroups(); | |
| 53 | } | ||
| 54 | |||
| 55 | 931 | bool OutputTableSummaryReports_Impl::addSummaryReport(const std::string& summaryReport) { | |
| 56 | // Check if summaryReport already exists | ||
| 57 |
1/1✓ Branch 1 taken 931 times.
|
931 | boost::optional<unsigned> _existingIndex = summaryReportIndex(summaryReport); |
| 58 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 930 times.
|
931 | if (_existingIndex) { |
| 59 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | boost::optional<std::string> _summaryReport = getSummaryReport(_existingIndex.get()); |
| 60 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
|
1 | OS_ASSERT(_summaryReport); |
| 61 |
10/10✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 23 taken 1 time.
✓ Branch 26 taken 1 time.
✓ Branch 29 taken 1 time.
|
1 | LOG(Warn, "For " << briefDescription() << ", summary report '" << summaryReport << "' already exists."); |
| 62 | 1 | return false; | |
| 63 | 1 | } | |
| 64 | |||
| 65 | // Push an extensible group | ||
| 66 |
3/3✓ Branch 1 taken 930 times.
✓ Branch 4 taken 930 times.
✓ Branch 7 taken 930 times.
|
930 | auto eg = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>(); |
| 67 |
1/1✓ Branch 1 taken 930 times.
|
930 | bool result = eg.setString(OS_Output_Table_SummaryReportsExtensibleFields::ReportName, summaryReport); |
| 68 |
2/2✓ Branch 0 taken 929 times.
✓ Branch 1 taken 1 time.
|
930 | if (result) { |
| 69 | 929 | return true; | |
| 70 | } else { | ||
| 71 | // Something went wrong, probably the summary report name isn't in the list of possible choices | ||
| 72 | // So erase the new extensible group | ||
| 73 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex()); |
| 74 | 1 | return false; | |
| 75 | } | ||
| 76 | 930 | } | |
| 77 | |||
| 78 | 2 | bool OutputTableSummaryReports_Impl::removeSummaryReport(unsigned groupIndex) { | |
| 79 | bool result; | ||
| 80 | |||
| 81 | 2 | unsigned int num = numberofSummaryReports(); | |
| 82 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2 | if (groupIndex < num) { |
| 83 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | getObject<ModelObject>().eraseExtensibleGroup(groupIndex); |
| 84 | 1 | result = true; | |
| 85 | } else { | ||
| 86 | 1 | result = false; | |
| 87 | } | ||
| 88 | 2 | return result; | |
| 89 | } | ||
| 90 | |||
| 91 | 1 | bool OutputTableSummaryReports_Impl::enableAllSummaryReport() { | |
| 92 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | return addSummaryReport("AllSummary"); |
| 93 | } | ||
| 94 | |||
| 95 | 2 | void OutputTableSummaryReports_Impl::removeAllSummaryReports() { | |
| 96 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | getObject<ModelObject>().clearExtensibleGroups(); |
| 97 | 2 | } | |
| 98 | |||
| 99 | 903 | std::vector<std::string> OutputTableSummaryReports_Impl::summaryReports() const { | |
| 100 | 903 | std::vector<std::string> result; | |
| 101 | |||
| 102 |
1/1✓ Branch 1 taken 903 times.
|
903 | std::vector<IdfExtensibleGroup> groups = extensibleGroups(); |
| 103 | |||
| 104 |
2/2✓ Branch 5 taken 950 times.
✓ Branch 6 taken 903 times.
|
1853 | for (const auto& group : groups) { |
| 105 | boost::optional<std::string> summaryReport = | ||
| 106 |
2/2✓ Branch 1 taken 950 times.
✓ Branch 4 taken 950 times.
|
950 | group.cast<WorkspaceExtensibleGroup>().getString(OS_Output_Table_SummaryReportsExtensibleFields::ReportName); |
| 107 | |||
| 108 |
1/2✓ Branch 0 taken 950 times.
✗ Branch 1 not taken.
|
950 | if (summaryReport) { |
| 109 |
2/2✓ Branch 1 taken 950 times.
✓ Branch 4 taken 950 times.
|
950 | result.push_back(summaryReport.get()); |
| 110 | } | ||
| 111 | 950 | } | |
| 112 | |||
| 113 | 1806 | return result; | |
| 114 | 903 | } | |
| 115 | |||
| 116 | 1 | bool OutputTableSummaryReports_Impl::addSummaryReports(const std::vector<std::string>& summaryReports) { | |
| 117 | 1 | bool result = true; | |
| 118 |
2/2✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 time.
|
3 | for (const std::string& summaryReport : summaryReports) { |
| 119 |
1/1✓ Branch 1 taken 2 times.
|
2 | result &= addSummaryReport(summaryReport); |
| 120 | } | ||
| 121 | 1 | return result; | |
| 122 | } | ||
| 123 | |||
| 124 | 934 | boost::optional<unsigned> OutputTableSummaryReports_Impl::summaryReportIndex(const std::string& summaryReport) const { | |
| 125 | 934 | boost::optional<unsigned> result; | |
| 126 | |||
| 127 |
2/2✓ Branch 1 taken 934 times.
✓ Branch 4 taken 934 times.
|
934 | auto egs = castVector<WorkspaceExtensibleGroup>(extensibleGroups()); |
| 128 |
1/1✓ Branch 3 taken 934 times.
|
934 | auto it = std::find_if(egs.begin(), egs.end(), [&](const WorkspaceExtensibleGroup& eg) { |
| 129 |
3/3✓ Branch 1 taken 121 times.
✓ Branch 4 taken 121 times.
✓ Branch 7 taken 121 times.
|
121 | return openstudio::istringEqual(summaryReport, eg.getField(OS_Output_Table_SummaryReportsExtensibleFields::ReportName).get()); |
| 130 | }); | ||
| 131 | |||
| 132 | // If found, we compute the index by using std::distance between the start of vector and the iterator returned by std::find_if | ||
| 133 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 3 taken 931 times.
|
934 | if (it != egs.end()) { |
| 134 |
1/1✓ Branch 2 taken 3 times.
|
6 | result = std::distance(egs.begin(), it); |
| 135 | } | ||
| 136 | |||
| 137 | 934 | return result; | |
| 138 | 934 | } | |
| 139 | |||
| 140 | 4 | boost::optional<std::string> OutputTableSummaryReports_Impl::getSummaryReport(unsigned groupIndex) const { | |
| 141 | |||
| 142 | 4 | boost::optional<std::string> result; | |
| 143 | |||
| 144 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | auto group = getExtensibleGroup(groupIndex).cast<ModelExtensibleGroup>(); |
| 145 | |||
| 146 |
1/1✓ Branch 1 taken 4 times.
|
4 | boost::optional<std::string> _summaryReport = group.getString(OS_Output_Table_SummaryReportsExtensibleFields::ReportName); |
| 147 | |||
| 148 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
|
4 | if (!_summaryReport) { |
| 149 |
2/8✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | LOG(Error, "Could not retrieve ReportName for extensible group " << group.groupIndex() << "."); |
| 150 | } | ||
| 151 | |||
| 152 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
6 | return _summaryReport.get(); |
| 153 | 6 | } | |
| 154 | |||
| 155 | } // namespace detail | ||
| 156 | |||
| 157 | 11306 | IddObjectType OutputTableSummaryReports::iddObjectType() { | |
| 158 |
1/1✓ Branch 1 taken 11306 times.
|
11306 | return {IddObjectType::OS_Output_Table_SummaryReports}; |
| 159 | } | ||
| 160 | |||
| 161 | 2 | std::vector<std::string> OutputTableSummaryReports::summaryReportValues() { | |
| 162 |
5/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
|
2 | IddObject obj = IddFactory::instance().getObject(iddObjectType()).get(); |
| 163 | // Return IddKeyNames in extensible portion | ||
| 164 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
4 | return getIddKeyNames(obj, obj.numFields() + OS_Output_Table_SummaryReportsExtensibleFields::ReportName); |
| 165 | 2 | } | |
| 166 | |||
| 167 | 1 | std::vector<std::string> OutputTableSummaryReports::validSummaryReportValues() { | |
| 168 | 1 | return summaryReportValues(); | |
| 169 | } | ||
| 170 | |||
| 171 | 16 | unsigned int OutputTableSummaryReports::numberofSummaryReports() const { | |
| 172 |
1/1✓ Branch 3 taken 16 times.
|
16 | return getImpl<detail::OutputTableSummaryReports_Impl>()->numberofSummaryReports(); |
| 173 | } | ||
| 174 | |||
| 175 | 928 | bool OutputTableSummaryReports::addSummaryReport(const std::string& summaryReport) { | |
| 176 |
1/1✓ Branch 3 taken 928 times.
|
928 | return getImpl<detail::OutputTableSummaryReports_Impl>()->addSummaryReport(summaryReport); |
| 177 | } | ||
| 178 | |||
| 179 | 2 | bool OutputTableSummaryReports::removeSummaryReport(int groupIndex) { | |
| 180 |
1/1✓ Branch 3 taken 2 times.
|
2 | return getImpl<detail::OutputTableSummaryReports_Impl>()->removeSummaryReport(groupIndex); |
| 181 | } | ||
| 182 | |||
| 183 | 2 | void OutputTableSummaryReports::removeAllSummaryReports() { | |
| 184 |
1/1✓ Branch 3 taken 2 times.
|
2 | return getImpl<detail::OutputTableSummaryReports_Impl>()->removeAllSummaryReports(); |
| 185 | } | ||
| 186 | |||
| 187 | 903 | std::vector<std::string> OutputTableSummaryReports::summaryReports() const { | |
| 188 |
1/1✓ Branch 3 taken 903 times.
|
903 | return getImpl<detail::OutputTableSummaryReports_Impl>()->summaryReports(); |
| 189 | } | ||
| 190 | |||
| 191 | 1 | bool OutputTableSummaryReports::addSummaryReports(const std::vector<std::string>& summaryReports) { | |
| 192 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::OutputTableSummaryReports_Impl>()->addSummaryReports(summaryReports); |
| 193 | } | ||
| 194 | |||
| 195 | 3 | boost::optional<unsigned> OutputTableSummaryReports::summaryReportIndex(const std::string& summaryReport) const { | |
| 196 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::OutputTableSummaryReports_Impl>()->summaryReportIndex(summaryReport); |
| 197 | } | ||
| 198 | |||
| 199 | 3 | boost::optional<std::string> OutputTableSummaryReports::getSummaryReport(unsigned groupIndex) const { | |
| 200 |
1/1✓ Branch 3 taken 2 times.
|
3 | return getImpl<detail::OutputTableSummaryReports_Impl>()->getSummaryReport(groupIndex); |
| 201 | } | ||
| 202 | |||
| 203 | 1 | bool OutputTableSummaryReports::enableAllSummaryReport() { | |
| 204 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::OutputTableSummaryReports_Impl>()->enableAllSummaryReport(); |
| 205 | } | ||
| 206 | |||
| 207 | /// @cond | ||
| 208 |
1/1✓ Branch 3 taken 869 times.
|
869 | OutputTableSummaryReports::OutputTableSummaryReports(std::shared_ptr<detail::OutputTableSummaryReports_Impl> impl) : ModelObject(std::move(impl)) {} |
| 209 | |||
| 210 | 899 | OutputTableSummaryReports::OutputTableSummaryReports(Model& model) : ModelObject(OutputTableSummaryReports::iddObjectType(), model) {} | |
| 211 | |||
| 212 | /// @endcond | ||
| 213 | |||
| 214 | } // namespace model | ||
| 215 | } // namespace openstudio | ||
| 216 |