GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 46 / 0 / 46
Functions: 100.0% 1 / 0 / 1
Branches: 90.3% 65 / 0 / 72

src/energyplus/ForwardTranslator/ForwardTranslateEnergyManagementSystemOutputVariable.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/EnergyManagementSystemOutputVariable.hpp"
16 #include "../../model/EnergyManagementSystemOutputVariable_Impl.hpp"
17
18 #include <utilities/idd/EnergyManagementSystem_OutputVariable_FieldEnums.hxx>
19 #include "../../utilities/idd/IddEnums.hpp"
20 #include <utilities/idd/IddEnums.hxx>
21
22 using namespace openstudio::model;
23
24 using namespace std;
25
26 namespace openstudio {
27
28 namespace energyplus {
29
30 8 boost::optional<IdfObject> ForwardTranslator::translateEnergyManagementSystemOutputVariable(EnergyManagementSystemOutputVariable& modelObject) {
31 8 boost::optional<std::string> m;
32 8 boost::optional<std::string> s;
33
34
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 IdfObject idfObject(openstudio::IddObjectType::EnergyManagementSystem_OutputVariable);
35
36 //Name
37
1/1
✓ Branch 1 taken 8 times.
8 s = modelObject.name();
38
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (s) {
39
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 idfObject.setName(*s);
40 }
41
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 s = modelObject.emsVariableName();
42
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (s) {
43
44 //find uids
45 8 const int subs[] = {1};
46
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 std::string newline = s.get();
47 8 std::string possible_uid;
48 size_t pos;
49 8 bool is_uuid = false;
50
1/1
✓ Branch 1 taken 8 times.
8 const Model m = modelObject.model();
51 8 boost::optional<ModelObject> mObject;
52
53
4/4
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 9 taken 8 times.
✓ Branch 14 taken 8 times.
8 boost::sregex_token_iterator j(s.get().begin(), s.get().end(), uuidInString(), subs);
54
55
3/3
✓ Branch 2 taken 11 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 7 times.
11 while (j != boost::sregex_token_iterator()) {
56
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
4 possible_uid = *j++;
57 //look to see if uid is in the model and return the object
58
1/1
✓ Branch 1 taken 4 times.
4 UUID uid = toUUID(possible_uid);
59
1/1
✓ Branch 1 taken 4 times.
4 mObject = m.getModelObject<model::ModelObject>(uid);
60
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
4 if (mObject) {
61 3 is_uuid = true;
62 //replace uid with namestring
63 3 pos = newline.find(possible_uid);
64
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (pos + 38 <= newline.length()) {
65
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
3 newline.replace(pos, 38, mObject.get().nameString());
66
1/1
✓ Branch 1 taken 3 times.
3 idfObject.setString(EnergyManagementSystem_OutputVariableFields::EMSVariableName, newline);
67 }
68 } else {
69 //did not find an object with the UID so do not FT
70
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 EMS:OutputVariable '" << modelObject.nameString() << "' is UID but does not exist, it will not be translated.");
71 1 return boost::none;
72 }
73 }
74 //string is not a uuid so just translate its value for the EMSVariableName
75
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
7 if (!is_uuid) {
76
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 idfObject.setString(EnergyManagementSystem_OutputVariableFields::EMSVariableName, s.get());
77 }
78 12 }
79
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 s = modelObject.typeOfDataInVariable();
80
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 if (s.is_initialized()) {
81
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 idfObject.setString(EnergyManagementSystem_OutputVariableFields::TypeofDatainVariable, s.get());
82 }
83
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 s = modelObject.updateFrequency();
84
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 if (s.is_initialized()) {
85
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 idfObject.setString(EnergyManagementSystem_OutputVariableFields::UpdateFrequency, s.get());
86 }
87
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 m = modelObject.emsProgramOrSubroutineName();
88
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 if (m.is_initialized()) {
89
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 idfObject.setString(EnergyManagementSystem_OutputVariableFields::EMSProgramorSubroutineName, m.get());
90 }
91
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 m = modelObject.units();
92
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 if (m.is_initialized()) {
93
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 idfObject.setString(EnergyManagementSystem_OutputVariableFields::Units, m.get());
94 }
95
1/1
✓ Branch 1 taken 7 times.
7 m_idfObjects.push_back(idfObject);
96
1/1
✓ Branch 1 taken 7 times.
7 return idfObject;
97 8 }
98
99 } // namespace energyplus
100
101 } // namespace openstudio
102