GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.7% 44 / 0 / 46
Functions: 100.0% 1 / 0 / 1
Branches: 91.2% 62 / 0 / 68

src/energyplus/ForwardTranslator/ForwardTranslateEnergyManagementSystemSensor.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 "../ForwardTranslator.hpp"
7
8 #include "../../model/Model.hpp"
9 #include "../../model/OutputVariable.hpp"
10 #include "../../model/OutputVariable_Impl.hpp"
11 #include "../../model/OutputMeter.hpp"
12 #include "../../model/OutputMeter_Impl.hpp"
13 #include "../../model/Schedule.hpp"
14 #include "../../model/Schedule_Impl.hpp"
15 #include "../../model/EnergyManagementSystemSensor.hpp"
16 #include "../../model/EnergyManagementSystemSensor_Impl.hpp"
17
18 #include "../../utilities/core/UUID.hpp"
19 #include "../../utilities/core/StringHelpers.hpp"
20
21 #include <utilities/idd/EnergyManagementSystem_Sensor_FieldEnums.hxx>
22 #include "../../utilities/idd/IddEnums.hpp"
23 #include <utilities/idd/IddEnums.hxx>
24
25 using namespace openstudio::model;
26
27 using namespace std;
28
29 namespace openstudio {
30
31 namespace energyplus {
32
33 18 boost::optional<IdfObject> ForwardTranslator::translateEnergyManagementSystemSensor(EnergyManagementSystemSensor& modelObject) {
34 18 boost::optional<OutputVariable> d;
35 18 boost::optional<OutputMeter> m;
36 18 boost::optional<std::string> s;
37
38
2/2
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
18 IdfObject idfObject(openstudio::IddObjectType::EnergyManagementSystem_Sensor);
39 //Name
40
1/1
✓ Branch 1 taken 18 times.
18 s = modelObject.name();
41
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (s) {
42
2/2
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
18 idfObject.setName(*s);
43 }
44
2/2
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
18 s = modelObject.keyName();
45
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (s) {
46 //find uids
47 18 const int subs[] = {1};
48
2/2
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
18 std::string newline = s.get();
49 18 std::string possible_uid;
50 size_t pos;
51
1/1
✓ Branch 1 taken 18 times.
18 const Model m = modelObject.model();
52 18 boost::optional<ModelObject> mObject;
53
54
4/4
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✓ Branch 9 taken 18 times.
✓ Branch 14 taken 18 times.
18 boost::sregex_token_iterator j(s.get().begin(), s.get().end(), uuidInString(), subs);
55
56
3/3
✓ Branch 2 taken 20 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 17 times.
20 while (j != boost::sregex_token_iterator()) {
57
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
3 possible_uid = *j++;
58 //look to see if uid is in the model and return the object
59
1/1
✓ Branch 1 taken 3 times.
3 UUID uid = toUUID(possible_uid);
60
1/1
✓ Branch 1 taken 3 times.
3 mObject = m.getModelObject<model::ModelObject>(uid);
61
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
3 if (mObject) {
62 //replace uid with namestring
63 2 pos = newline.find(possible_uid);
64
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (pos + 38 <= newline.length()) {
65
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 newline.replace(pos, 38, mObject.get().nameString());
66 }
67 } else {
68 //did not find an object with the UID so do not FT
69
8/8
✓ 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 17 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 23 taken 1 time.
1 LOG(Error, "Key Name for Sensor '" << modelObject.nameString() << "' is UID but does not exist, it will not be translated.");
70 1 return boost::none;
71 }
72 }
73
1/1
✓ Branch 1 taken 17 times.
17 idfObject.setString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterIndexKeyName, newline);
74 22 }
75
1/1
✓ Branch 1 taken 17 times.
17 d = modelObject.outputVariable();
76
2/2
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 4 times.
17 if (d.is_initialized()) {
77
3/3
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 13 times.
13 idfObject.setString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterName, d.get().variableName());
78
1/1
✓ Branch 1 taken 13 times.
13 m_idfObjects.push_back(idfObject);
79
1/1
✓ Branch 1 taken 13 times.
13 return idfObject;
80 }
81
1/1
✓ Branch 1 taken 4 times.
4 m = modelObject.outputMeter();
82
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
4 if (m.is_initialized()) {
83
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 idfObject.setString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterName, m.get().name());
84
1/1
✓ Branch 1 taken 2 times.
2 m_idfObjects.push_back(idfObject);
85
1/1
✓ Branch 1 taken 2 times.
2 return idfObject;
86 }
87
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 s = modelObject.outputVariableOrMeterName();
88
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (s.is_initialized()) {
89
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 idfObject.setString(EnergyManagementSystem_SensorFields::Output_VariableorOutput_MeterName, s.get());
90
1/1
✓ Branch 1 taken 2 times.
2 m_idfObjects.push_back(idfObject);
91
1/1
✓ Branch 1 taken 2 times.
2 return idfObject;
92 }
93 ✗ m_idfObjects.push_back(idfObject);
94 ✗ return idfObject;
95 18 }
96
97 } // namespace energyplus
98
99 } // namespace openstudio
100