src/model/OutputVariable.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 "OutputVariable.hpp" | ||
| 7 | #include "OutputVariable_Impl.hpp" | ||
| 8 | #include "Schedule.hpp" | ||
| 9 | #include "Schedule_Impl.hpp" | ||
| 10 | #include "EnergyManagementSystemSensor.hpp" | ||
| 11 | #include "EnergyManagementSystemSensor_Impl.hpp" | ||
| 12 | |||
| 13 | #include "Model.hpp" | ||
| 14 | |||
| 15 | #include <utilities/idd/IddFactory.hxx> | ||
| 16 | |||
| 17 | #include <utilities/idd/OS_Output_Variable_FieldEnums.hxx> | ||
| 18 | #include <utilities/idd/IddEnums.hxx> | ||
| 19 | |||
| 20 | #include "../utilities/sql/SqlFileEnums.hpp" | ||
| 21 | #include "../utilities/sql/SqlFile.hpp" | ||
| 22 | |||
| 23 | #include "../utilities/core/Assert.hpp" | ||
| 24 | |||
| 25 | using openstudio::Handle; | ||
| 26 | using openstudio::OptionalHandle; | ||
| 27 | using openstudio::HandleVector; | ||
| 28 | using openstudio::IdfObject; | ||
| 29 | using openstudio::WorkspaceObject; | ||
| 30 | using openstudio::OptionalWorkspaceObject; | ||
| 31 | using openstudio::WorkspaceObjectVector; | ||
| 32 | using openstudio::Workspace; | ||
| 33 | |||
| 34 | using std::string; | ||
| 35 | |||
| 36 | namespace openstudio { | ||
| 37 | namespace model { | ||
| 38 | |||
| 39 | namespace detail { | ||
| 40 | |||
| 41 | 1277 | OutputVariable_Impl::OutputVariable_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 42 | 1277 | : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 43 |
4/6✓ Branch 1 taken 1277 times.
✓ Branch 4 taken 1277 times.
✓ Branch 7 taken 1277 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1277 times.
✗ Branch 13 not taken.
|
1277 | OS_ASSERT(idfObject.iddObject().type() == OutputVariable::iddObjectType()); |
| 44 | 1277 | } | |
| 45 | |||
| 46 | 196 | OutputVariable_Impl::OutputVariable_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 47 | 196 | : ModelObject_Impl(other, model, keepHandle) { | |
| 48 |
4/6✓ Branch 1 taken 196 times.
✓ Branch 4 taken 196 times.
✓ Branch 7 taken 196 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 196 times.
✗ Branch 13 not taken.
|
196 | OS_ASSERT(other.iddObject().type() == OutputVariable::iddObjectType()); |
| 49 | 196 | } | |
| 50 | |||
| 51 | 278 | OutputVariable_Impl::OutputVariable_Impl(const OutputVariable_Impl& other, Model_Impl* model, bool keepHandle) | |
| 52 | 278 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 53 | |||
| 54 | 2 | const std::vector<std::string>& OutputVariable_Impl::outputVariableNames() const { | |
| 55 |
3/4✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
2 | static const std::vector<std::string> result; |
| 56 | 2 | return result; | |
| 57 | } | ||
| 58 | |||
| 59 | 9 | IddObjectType OutputVariable_Impl::iddObjectType() const { | |
| 60 | 9 | return OutputVariable::iddObjectType(); | |
| 61 | } | ||
| 62 | |||
| 63 | 2 | std::vector<openstudio::IdfObject> OutputVariable_Impl::remove() { | |
| 64 | //Note: Cant do /object-list implementation for EMS Sensor since Auto Naming of Objects causes issues. | ||
| 65 | // Instead, doing an /alpha getString implementation so we need to manually remove any referring Sensors | ||
| 66 |
1/1✓ Branch 1 taken 2 times.
|
2 | const Model m = this->model(); |
| 67 | |||
| 68 |
1/1✓ Branch 1 taken 2 times.
|
2 | std::vector<EnergyManagementSystemSensor> objects = m.getConcreteModelObjects<EnergyManagementSystemSensor>(); |
| 69 |
2/2✓ Branch 5 taken 6 times.
✓ Branch 6 taken 2 times.
|
8 | for (auto& sensor : objects) { |
| 70 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 1 time.
|
12 | if (sensor.outputVariable()) { |
| 71 | //if (sensor.outputVariable().get().variableName() == this->variableName()) { | ||
| 72 | // sensor.remove(); | ||
| 73 | //} | ||
| 74 | // check handle instead of name | ||
| 75 |
7/7✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 3 times.
|
5 | if (sensor.outputVariable().get().handle() == this->handle()) { |
| 76 |
1/1✓ Branch 1 taken 2 times.
|
2 | sensor.remove(); |
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 |
1/1✓ Branch 1 taken 2 times.
|
4 | return ModelObject_Impl::remove(); |
| 82 | 2 | } | |
| 83 | |||
| 84 | ✗ | std::vector<ScheduleTypeKey> OutputVariable_Impl::getScheduleTypeKeys(const Schedule& schedule) const { | |
| 85 | ✗ | std::vector<ScheduleTypeKey> result; | |
| 86 | ✗ | UnsignedVector fieldIndices = getSourceIndices(schedule.handle()); | |
| 87 | ✗ | UnsignedVector::const_iterator b(fieldIndices.begin()); | |
| 88 | ✗ | UnsignedVector::const_iterator e(fieldIndices.end()); | |
| 89 | ✗ | if (std::find(b, e, OS_Output_VariableFields::ScheduleName) != e) { | |
| 90 | ✗ | result.push_back(ScheduleTypeKey("OutputVariable", "Active Hours")); | |
| 91 | } | ||
| 92 | ✗ | return result; | |
| 93 | ✗ | } | |
| 94 | |||
| 95 | 82 | std::string OutputVariable_Impl::keyValue() const { | |
| 96 |
1/1✓ Branch 1 taken 82 times.
|
82 | OptionalString result = getString(OS_Output_VariableFields::KeyValue, true); |
| 97 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 82 times.
✗ Branch 4 not taken.
|
82 | OS_ASSERT(result); |
| 98 |
2/2✓ Branch 1 taken 82 times.
✓ Branch 4 taken 82 times.
|
164 | return result.get(); |
| 99 | 82 | } | |
| 100 | |||
| 101 | 174 | bool OutputVariable_Impl::isKeyValueDefaulted() const { | |
| 102 | 174 | return isEmpty(OS_Output_VariableFields::KeyValue); | |
| 103 | } | ||
| 104 | |||
| 105 | 206 | std::string OutputVariable_Impl::variableName() const { | |
| 106 |
1/1✓ Branch 1 taken 206 times.
|
206 | OptionalString result = getString(OS_Output_VariableFields::VariableName, true); |
| 107 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
✗ Branch 4 not taken.
|
206 | OS_ASSERT(result); |
| 108 |
2/2✓ Branch 1 taken 206 times.
✓ Branch 4 taken 206 times.
|
412 | return result.get(); |
| 109 | 206 | } | |
| 110 | |||
| 111 | 63 | std::string OutputVariable_Impl::reportingFrequency() const { | |
| 112 |
1/1✓ Branch 1 taken 63 times.
|
63 | OptionalString result = getString(OS_Output_VariableFields::ReportingFrequency, true); |
| 113 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
✗ Branch 4 not taken.
|
63 | OS_ASSERT(result); |
| 114 |
2/2✓ Branch 1 taken 63 times.
✓ Branch 4 taken 63 times.
|
126 | return result.get(); |
| 115 | 63 | } | |
| 116 | |||
| 117 | 148 | bool OutputVariable_Impl::isReportingFrequencyDefaulted() const { | |
| 118 | 148 | return isEmpty(OS_Output_VariableFields::ReportingFrequency); | |
| 119 | } | ||
| 120 | |||
| 121 | 116 | bool OutputVariable_Impl::setKeyValue(const std::string& keyValue) { | |
| 122 | 116 | return setString(OS_Output_VariableFields::KeyValue, keyValue); | |
| 123 | } | ||
| 124 | |||
| 125 | ✗ | void OutputVariable_Impl::resetKeyValue() { | |
| 126 | ✗ | bool test = setString(OS_Output_VariableFields::KeyValue, ""); | |
| 127 | ✗ | OS_ASSERT(test); | |
| 128 | ✗ | } | |
| 129 | |||
| 130 | 1180 | bool OutputVariable_Impl::setVariableName(const std::string& variableName) { | |
| 131 | 1180 | return setString(OS_Output_VariableFields::VariableName, variableName); | |
| 132 | } | ||
| 133 | |||
| 134 | 696 | bool OutputVariable_Impl::setReportingFrequency(const std::string& reportingFrequency) { | |
| 135 | 696 | return setString(OS_Output_VariableFields::ReportingFrequency, reportingFrequency); | |
| 136 | } | ||
| 137 | |||
| 138 | ✗ | void OutputVariable_Impl::resetReportingFrequency() { | |
| 139 | ✗ | bool test = setString(OS_Output_VariableFields::ReportingFrequency, ""); | |
| 140 | ✗ | OS_ASSERT(test); | |
| 141 | ✗ | } | |
| 142 | |||
| 143 | 148 | boost::optional<Schedule> OutputVariable_Impl::schedule() const { | |
| 144 |
2/2✓ Branch 1 taken 148 times.
✓ Branch 4 taken 148 times.
|
148 | return getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_Output_VariableFields::ScheduleName); |
| 145 | } | ||
| 146 | |||
| 147 | ✗ | bool OutputVariable_Impl::setSchedule(Schedule& schedule) { | |
| 148 | ✗ | bool result = ModelObject_Impl::setSchedule(OS_Output_VariableFields::ScheduleName, "OutputVariable", "Active Hours", schedule); | |
| 149 | ✗ | return result; | |
| 150 | } | ||
| 151 | |||
| 152 | ✗ | void OutputVariable_Impl::resetSchedule() { | |
| 153 | ✗ | this->setString(OS_Output_VariableFields::ScheduleName, ""); | |
| 154 | ✗ | } | |
| 155 | |||
| 156 | ✗ | boost::optional<ModelObject> OutputVariable_Impl::scheduleAsModelObject() const { | |
| 157 | ✗ | OptionalModelObject result; | |
| 158 | ✗ | OptionalSchedule intermediate = schedule(); | |
| 159 | ✗ | if (intermediate) { | |
| 160 | ✗ | result = *intermediate; | |
| 161 | } | ||
| 162 | ✗ | return result; | |
| 163 | ✗ | } | |
| 164 | |||
| 165 | ✗ | bool OutputVariable_Impl::setScheduleAsModelObject(const boost::optional<ModelObject>& modelObject) { | |
| 166 | ✗ | if (modelObject) { | |
| 167 | ✗ | OptionalSchedule intermediate = modelObject->optionalCast<Schedule>(); | |
| 168 | ✗ | if (intermediate) { | |
| 169 | ✗ | Schedule schedule(*intermediate); | |
| 170 | ✗ | return setSchedule(schedule); | |
| 171 | ✗ | } else { | |
| 172 | ✗ | return false; | |
| 173 | } | ||
| 174 | ✗ | } else { | |
| 175 | ✗ | resetSchedule(); | |
| 176 | } | ||
| 177 | ✗ | return true; | |
| 178 | } | ||
| 179 | |||
| 180 | ✗ | std::vector<std::string> OutputVariable_Impl::reportingFrequencyValues() const { | |
| 181 | ✗ | return OutputVariable::reportingFrequencyValues(); | |
| 182 | } | ||
| 183 | |||
| 184 | 3 | bool OutputVariable_Impl::exportToBCVTB() const { | |
| 185 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::optional<std::string> value = getString(OS_Output_VariableFields::ExportToBCVTB, true); |
| 186 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 4 not taken.
|
3 | OS_ASSERT(value); |
| 187 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
6 | return openstudio::istringEqual(value.get(), "True"); |
| 188 | 3 | } | |
| 189 | |||
| 190 | 1 | bool OutputVariable_Impl::isExportToBCVTBDefaulted() const { | |
| 191 | 1 | return isEmpty(OS_Output_VariableFields::ExportToBCVTB); | |
| 192 | } | ||
| 193 | |||
| 194 | 1 | bool OutputVariable_Impl::setExportToBCVTB(bool exportToBCVTB) { | |
| 195 | 1 | bool result = false; | |
| 196 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (exportToBCVTB) { |
| 197 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
3 | result = setString(OS_Output_VariableFields::ExportToBCVTB, "True"); |
| 198 | } else { | ||
| 199 | ✗ | result = setString(OS_Output_VariableFields::ExportToBCVTB, "False"); | |
| 200 | } | ||
| 201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | OS_ASSERT(result); |
| 202 | 1 | return result; | |
| 203 | } | ||
| 204 | |||
| 205 | 1 | void OutputVariable_Impl::resetExportToBCVTB() { | |
| 206 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | bool result = setString(OS_Output_VariableFields::ExportToBCVTB, ""); |
| 207 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | OS_ASSERT(result); |
| 208 | 1 | } | |
| 209 | |||
| 210 | } // namespace detail | ||
| 211 | |||
| 212 | 1075 | OutputVariable::OutputVariable(const std::string& variableName, const Model& model) : ModelObject(OutputVariable::iddObjectType(), model) { | |
| 213 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1075 times.
✗ Branch 5 not taken.
|
1075 | OS_ASSERT(getImpl<detail::OutputVariable_Impl>()); |
| 214 |
1/1✓ Branch 3 taken 1075 times.
|
1075 | bool test = getImpl<detail::OutputVariable_Impl>()->setVariableName(variableName); |
| 215 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 1075 times.
✗ Branch 3 not taken.
|
1075 | OS_ASSERT(test); |
| 216 | 1075 | } | |
| 217 | |||
| 218 |
1/1✓ Branch 3 taken 236 times.
|
236 | OutputVariable::OutputVariable(std::shared_ptr<detail::OutputVariable_Impl> impl) : ModelObject(std::move(impl)) {} |
| 219 | |||
| 220 | 10301 | IddObjectType OutputVariable::iddObjectType() { | |
| 221 |
1/1✓ Branch 1 taken 10301 times.
|
10301 | IddObjectType result(IddObjectType::OS_Output_Variable); |
| 222 | 10301 | return result; | |
| 223 | } | ||
| 224 | |||
| 225 | ✗ | std::vector<std::string> OutputVariable::reportingFrequencyValues() { | |
| 226 | ✗ | std::vector<std::string> retvals; | |
| 227 | |||
| 228 | ✗ | std::map<int, std::string> names = openstudio::ReportingFrequency::getNames(); | |
| 229 | |||
| 230 | ✗ | for (auto itr = names.begin(); itr != names.end(); ++itr) { | |
| 231 | ✗ | retvals.push_back(itr->second); | |
| 232 | } | ||
| 233 | |||
| 234 | ✗ | return retvals; | |
| 235 | ✗ | } | |
| 236 | |||
| 237 | 82 | std::string OutputVariable::keyValue() const { | |
| 238 |
1/1✓ Branch 3 taken 82 times.
|
82 | return getImpl<detail::OutputVariable_Impl>()->keyValue(); |
| 239 | } | ||
| 240 | |||
| 241 | 174 | bool OutputVariable::isKeyValueDefaulted() const { | |
| 242 |
1/1✓ Branch 3 taken 174 times.
|
174 | return getImpl<detail::OutputVariable_Impl>()->isKeyValueDefaulted(); |
| 243 | } | ||
| 244 | |||
| 245 | 206 | std::string OutputVariable::variableName() const { | |
| 246 |
1/1✓ Branch 3 taken 206 times.
|
206 | return getImpl<detail::OutputVariable_Impl>()->variableName(); |
| 247 | } | ||
| 248 | |||
| 249 | 63 | std::string OutputVariable::reportingFrequency() const { | |
| 250 |
1/1✓ Branch 3 taken 63 times.
|
63 | return getImpl<detail::OutputVariable_Impl>()->reportingFrequency(); |
| 251 | } | ||
| 252 | |||
| 253 | 148 | bool OutputVariable::isReportingFrequencyDefaulted() const { | |
| 254 |
1/1✓ Branch 3 taken 148 times.
|
148 | return getImpl<detail::OutputVariable_Impl>()->isReportingFrequencyDefaulted(); |
| 255 | } | ||
| 256 | |||
| 257 | 116 | bool OutputVariable::setKeyValue(const std::string& keyValue) { | |
| 258 |
1/1✓ Branch 3 taken 116 times.
|
116 | return getImpl<detail::OutputVariable_Impl>()->setKeyValue(keyValue); |
| 259 | } | ||
| 260 | |||
| 261 | ✗ | void OutputVariable::resetKeyValue() { | |
| 262 | ✗ | getImpl<detail::OutputVariable_Impl>()->resetKeyValue(); | |
| 263 | ✗ | } | |
| 264 | |||
| 265 | 105 | bool OutputVariable::setVariableName(const std::string& variableName) { | |
| 266 |
1/1✓ Branch 3 taken 105 times.
|
105 | return getImpl<detail::OutputVariable_Impl>()->setVariableName(variableName); |
| 267 | } | ||
| 268 | |||
| 269 | 696 | bool OutputVariable::setReportingFrequency(const std::string& reportingFrequency) { | |
| 270 |
1/1✓ Branch 3 taken 696 times.
|
696 | return getImpl<detail::OutputVariable_Impl>()->setReportingFrequency(reportingFrequency); |
| 271 | } | ||
| 272 | |||
| 273 | ✗ | void OutputVariable::resetReportingFrequency() { | |
| 274 | ✗ | getImpl<detail::OutputVariable_Impl>()->resetReportingFrequency(); | |
| 275 | ✗ | } | |
| 276 | |||
| 277 | 148 | boost::optional<Schedule> OutputVariable::schedule() const { | |
| 278 |
1/1✓ Branch 3 taken 148 times.
|
148 | return getImpl<detail::OutputVariable_Impl>()->schedule(); |
| 279 | } | ||
| 280 | |||
| 281 | ✗ | bool OutputVariable::setSchedule(Schedule& schedule) { | |
| 282 | ✗ | return getImpl<detail::OutputVariable_Impl>()->setSchedule(schedule); | |
| 283 | } | ||
| 284 | |||
| 285 | ✗ | void OutputVariable::resetSchedule() { | |
| 286 | ✗ | getImpl<detail::OutputVariable_Impl>()->resetSchedule(); | |
| 287 | ✗ | } | |
| 288 | |||
| 289 | 2 | std::vector<IdfObject> OutputVariable::remove() { | |
| 290 |
1/1✓ Branch 3 taken 2 times.
|
2 | return getImpl<detail::OutputVariable_Impl>()->remove(); |
| 291 | } | ||
| 292 | |||
| 293 | 3 | bool OutputVariable::exportToBCVTB() const { | |
| 294 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::OutputVariable_Impl>()->exportToBCVTB(); |
| 295 | } | ||
| 296 | |||
| 297 | 1 | bool OutputVariable::isExportToBCVTBDefaulted() const { | |
| 298 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::OutputVariable_Impl>()->isExportToBCVTBDefaulted(); |
| 299 | } | ||
| 300 | |||
| 301 | 1 | bool OutputVariable::setExportToBCVTB(bool exportToBCVTB) { | |
| 302 |
1/1✓ Branch 3 taken 1 time.
|
1 | return getImpl<detail::OutputVariable_Impl>()->setExportToBCVTB(exportToBCVTB); |
| 303 | } | ||
| 304 | |||
| 305 | 1 | void OutputVariable::resetExportToBCVTB() { | |
| 306 |
1/1✓ Branch 3 taken 1 time.
|
1 | getImpl<detail::OutputVariable_Impl>()->resetExportToBCVTB(); |
| 307 | 1 | } | |
| 308 | |||
| 309 | } // namespace model | ||
| 310 | } // namespace openstudio | ||
| 311 |