GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 84.6% 33 / 0 / 39
Functions: 100.0% 1 / 0 / 1
Branches: 66.2% 47 / 0 / 71

src/energyplus/ReverseTranslator/ReverseTranslateEnergyManagementSystemSensor.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 "../ReverseTranslator.hpp"
7
8 #include "../../model/EnergyManagementSystemSensor.hpp"
9 #include "../../model/EnergyManagementSystemSensor_Impl.hpp"
10
11 #include <utilities/idd/EnergyManagementSystem_Sensor_FieldEnums.hxx>
12 #include "../../utilities/idd/IddEnums.hpp"
13 #include <utilities/idd/IddEnums.hxx>
14
15 using namespace openstudio::model;
16
17 namespace openstudio {
18
19 namespace energyplus {
20
21 9 OptionalModelObject ReverseTranslator::translateEnergyManagementSystemSensor(const WorkspaceObject& workspaceObject) {
22
4/5
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 9 times.
9 if (workspaceObject.iddObject().type() != IddObjectType::EnergyManagementSystem_Sensor) {
23 ✗ LOG(Error, "WorkspaceObject is not IddObjectType: EnergyManagementSystem_Sensor");
24 ✗ return boost::none;
25 }
26
27
1/1
✓ Branch 1 taken 9 times.
9 OptionalString s = workspaceObject.getString(EnergyManagementSystem_SensorFields::Name);
28
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 if (!s) {
29 ✗ LOG(Error, "WorkspaceObject EnergyManagementSystem_Sensor has no Name");
30 ✗ return boost::none;
31 }
32
33
1/1
✓ Branch 1 taken 9 times.
9 openstudio::model::EnergyManagementSystemSensor emsSensor(m_model);
34
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 emsSensor.setName(*s);
35
36
1/1
✓ Branch 1 taken 9 times.
9 Workspace workspace = workspaceObject.workspace();
37
38
1/1
✓ Branch 1 taken 9 times.
9 s = workspaceObject.getString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterIndexKeyName);
39
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (s) {
40
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 emsSensor.setKeyName(*s);
41 }
42
43
1/1
✓ Branch 1 taken 9 times.
9 s = workspaceObject.getString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterName);
44
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (s) {
45 //look for Output:Variables named *s
46
4/4
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 11 taken 8 times.
✓ Branch 12 taken 1 time.
9 for (const WorkspaceObject& wsObject : workspace.getObjectsByType(IddObjectType::Output_Variable)) {
47
1/1
✓ Branch 1 taken 8 times.
8 boost::optional<model::ModelObject> modelObject = translateAndMapWorkspaceObject(wsObject);
48
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (modelObject) {
49
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 boost::optional<OutputVariable> outvar = modelObject->optionalCast<OutputVariable>();
50
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (outvar) {
51
4/5
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
8 if (outvar.get().variableName() == s) {
52
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 emsSensor.setOutputVariable(outvar.get());
53
1/1
✓ Branch 1 taken 8 times.
8 return emsSensor;
54 }
55 }
56 8 }
57 17 }
58 //look for Output:Meters named *s
59
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 11 taken 1 time.
✗ Branch 12 not taken.
1 for (const WorkspaceObject& wsObject : workspace.getObjectsByType(IddObjectType::Output_Meter)) {
60
1/1
✓ Branch 1 taken 1 time.
1 boost::optional<model::ModelObject> modelObject = translateAndMapWorkspaceObject(wsObject);
61
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (modelObject) {
62
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 boost::optional<OutputMeter> outvar = modelObject->optionalCast<OutputMeter>();
63
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (outvar) {
64
4/5
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
1 if (outvar.get().name() == s) {
65
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 emsSensor.setOutputMeter(outvar.get());
66
1/1
✓ Branch 1 taken 1 time.
1 return emsSensor;
67 }
68 }
69 1 }
70 2 }
71 //set outputVariableOrMeterName to string value
72 ✗ emsSensor.setOutputVariableOrMeterName(s.get());
73 }
74
75 ✗ return emsSensor;
76 9 }
77
78 } // namespace energyplus
79
80 } // namespace openstudio
81