GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 80.6% 308 / 0 / 382
Functions: 100.0% 45 / 0 / 45
Branches: 59.8% 520 / 0 / 869

src/utilities/data/CalibrationResult.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 "CalibrationResult.hpp"
7 #include "../core/Assert.hpp"
8 #include "../time/Date.hpp"
9
10 namespace openstudio {
11
12 16 std::string CalibrationBillingPeriod::attributeName() {
13
1/1
✓ Branch 1 taken 16 times.
32 return "CalibrationBillingPeriod";
14 }
15
16 12 boost::optional<CalibrationBillingPeriod> CalibrationBillingPeriod::fromAttribute(const Attribute& attribute) {
17
3/4
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 12 times.
12 if (attribute.name() != CalibrationBillingPeriod::attributeName()) {
18 ✗ LOG(Warn, "Cannot create CalibrationBillingPeriod from Attribute because attribute name is '" << attribute.name() << "'.");
19 ✗ return boost::none;
20 }
21
22
3/4
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12 times.
12 if (attribute.valueType() != AttributeValueType::AttributeVector) {
23 ✗ LOG(Warn, "Cannot create CalibrationBillingPeriod from Attribute because attribute is a " << attribute.valueType().valueDescription()
24 << ", not an AttributeVector.");
25 ✗ return boost::none;
26 }
27
28
2/3
✓ Branch 1 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
24 if (attribute.units()) {
29 ✗ LOG(Warn, "Cannot create CalibrationBillingPeriod from Attribute because attribute has units '" << attribute.units().get() << "'.");
30 ✗ return boost::none;
31 }
32
33 // at minimum need startDate, numberOfDays, consumptionUnit
34
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 boost::optional<Attribute> test = attribute.findChildByName("startDate");
35
6/9
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 12 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 12 times.
12 if (!test || !(test->valueType() == AttributeValueType::String)) {
36 ✗ LOG(Warn, "Cannot create CalibrationBillingPeriod from Attribute without 'startDate'.");
37 ✗ return boost::none;
38 }
39 try {
40 // cppcheck-suppress unusedScopedObject
41
3/3
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
12 Date(test->valueAsString());
42 ✗ } catch (const std::exception&) {
43 ✗ LOG(Warn, "Cannot create CalibrationBillingPeriod from Attribute with improper 'startDate'.");
44 ✗ return boost::none;
45 ✗ }
46
47
3/3
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
12 test = attribute.findChildByName("numberOfDays");
48
6/9
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 12 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 12 times.
12 if (!test || !(test->valueType() == AttributeValueType::Unsigned)) {
49 ✗ LOG(Warn, "Cannot create CalibrationBillingPeriod from Attribute without 'numberOfDays'.");
50 ✗ return boost::none;
51 }
52
53
3/3
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
12 test = attribute.findChildByName("consumptionUnit");
54
6/9
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 12 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 12 times.
12 if (!test || !(test->valueType() == AttributeValueType::String)) {
55 ✗ LOG(Warn, "Cannot create CalibrationBillingPeriod from Attribute without 'consumptionUnit'.");
56 ✗ return boost::none;
57 }
58
59
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 return CalibrationBillingPeriod(attribute);
60 12 }
61
62 4 CalibrationBillingPeriod::CalibrationBillingPeriod(const Date& startDate, unsigned numberOfDays, const std::string& consumptionUnit,
63 boost::optional<std::string> peakDemandUnit, boost::optional<double> consumption,
64 boost::optional<double> peakDemand, boost::optional<double> totalCost,
65 boost::optional<double> modelConsumption, boost::optional<double> modelPeakDemand,
66 4 boost::optional<double> modelTotalCost)
67
2/2
✓ Branch 3 taken 4 times.
✓ Branch 6 taken 4 times.
4 : m_attribute(CalibrationBillingPeriod::attributeName(), std::vector<openstudio::Attribute>(), boost::none) {
68 4 std::vector<Attribute> values;
69
70
1/1
✓ Branch 1 taken 4 times.
4 std::stringstream ss;
71
1/1
✓ Branch 1 taken 4 times.
4 ss << startDate;
72
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
12 values.push_back(Attribute("startDate", ss.str()));
73
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
8 values.push_back(Attribute("numberOfDays", numberOfDays));
74
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
8 values.push_back(Attribute("consumptionUnit", consumptionUnit));
75
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (peakDemandUnit) {
76
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 values.push_back(Attribute("peakDemandUnit", *peakDemandUnit));
77 }
78
79
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (consumption) {
80
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
12 values.push_back(Attribute("consumption", *consumption, consumptionUnit));
81 }
82
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (peakDemand) {
83
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (peakDemandUnit) {
84
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.
6 values.push_back(Attribute("peakDemand", *peakDemand, *peakDemandUnit));
85 }
86 }
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (totalCost) {
88 ✗ values.push_back(Attribute("totalCost", *totalCost));
89 }
90
91
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (modelConsumption) {
92
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
12 values.push_back(Attribute("modelConsumption", *modelConsumption, consumptionUnit));
93 }
94
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (modelPeakDemand) {
95
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (peakDemandUnit) {
96
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.
6 values.push_back(Attribute("modelPeakDemand", *modelPeakDemand, *peakDemandUnit));
97 }
98 }
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (modelTotalCost) {
100 ✗ values.push_back(Attribute("modelTotalCost", *modelTotalCost));
101 }
102
103
1/1
✓ Branch 1 taken 4 times.
4 m_attribute.setValue(values);
104 4 }
105
106 12 CalibrationBillingPeriod::CalibrationBillingPeriod(const Attribute& attribute) : m_attribute(attribute) {}
107
108 4 Attribute CalibrationBillingPeriod::attribute() const {
109 4 return m_attribute;
110 }
111
112 2 Date CalibrationBillingPeriod::startDate() const {
113
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
4 boost::optional<Attribute> attribute = m_attribute.findChildByName("startDate");
114
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(attribute);
115
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::String);
116
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 return Date(attribute->valueAsString());
117 2 }
118
119 1 Date CalibrationBillingPeriod::endDate() const {
120
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 Date result = this->startDate() + Time(this->numberOfDays() - 1);
121 1 return result;
122 }
123
124 2 unsigned CalibrationBillingPeriod::numberOfDays() const {
125
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
4 boost::optional<Attribute> attribute = m_attribute.findChildByName("numberOfDays");
126
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(attribute);
127
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Unsigned);
128
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
4 return attribute->valueAsUnsigned();
129 2 }
130
131 7 std::string CalibrationBillingPeriod::consumptionUnit() const {
132
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
14 boost::optional<Attribute> attribute = m_attribute.findChildByName("consumptionUnit");
133
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 4 not taken.
7 OS_ASSERT(attribute);
134
4/6
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 7 times.
✗ Branch 13 not taken.
7 OS_ASSERT(attribute->valueType() == AttributeValueType::String);
135
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
14 return attribute->valueAsString();
136 7 }
137
138 6 boost::optional<std::string> CalibrationBillingPeriod::peakDemandUnit() const {
139
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
18 boost::optional<Attribute> attribute = m_attribute.findChildByName("peakDemandUnit");
140
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if (attribute) {
141
4/6
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 13 not taken.
4 OS_ASSERT(attribute->valueType() == AttributeValueType::String);
142
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
4 return attribute->valueAsString();
143 }
144 2 return boost::none;
145 6 }
146
147 2 boost::optional<double> CalibrationBillingPeriod::consumption() const {
148
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("consumption");
149
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
150
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
151
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsDouble();
152 }
153 ✗ return boost::none;
154 2 }
155
156 2 boost::optional<double> CalibrationBillingPeriod::peakDemand() const {
157
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("peakDemand");
158
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
159
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
160
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsDouble();
161 }
162 ✗ return boost::none;
163 2 }
164
165 1 boost::optional<double> CalibrationBillingPeriod::totalCost() const {
166
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
3 boost::optional<Attribute> attribute = m_attribute.findChildByName("totalCost");
167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (attribute) {
168 ✗ OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
169 ✗ return attribute->valueAsDouble();
170 }
171 1 return boost::none;
172 1 }
173
174 2 boost::optional<double> CalibrationBillingPeriod::modelConsumption() const {
175
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("modelConsumption");
176
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
177
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
178
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsDouble();
179 }
180 ✗ return boost::none;
181 2 }
182
183 2 boost::optional<double> CalibrationBillingPeriod::modelPeakDemand() const {
184
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("modelPeakDemand");
185
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
186
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
187
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsDouble();
188 }
189 ✗ return boost::none;
190 2 }
191
192 1 boost::optional<double> CalibrationBillingPeriod::modelTotalCost() const {
193
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
3 boost::optional<Attribute> attribute = m_attribute.findChildByName("modelTotalCost");
194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (attribute) {
195 ✗ OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
196 ✗ return attribute->valueAsDouble();
197 }
198 1 return boost::none;
199 1 }
200
201 8 std::string CalibrationUtilityBill::attributeName() {
202
1/1
✓ Branch 1 taken 8 times.
16 return "CalibrationUtilityBill";
203 }
204
205 6 boost::optional<CalibrationUtilityBill> CalibrationUtilityBill::fromAttribute(const Attribute& attribute) {
206
3/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
6 if (attribute.name() != CalibrationUtilityBill::attributeName()) {
207 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute because attribute name is '" << attribute.name() << "'.");
208 ✗ return boost::none;
209 }
210
211
3/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
6 if (attribute.valueType() != AttributeValueType::AttributeVector) {
212 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute because attribute is a " << attribute.valueType().valueDescription()
213 << ", not an AttributeVector.");
214 ✗ return boost::none;
215 }
216
217
2/3
✓ Branch 1 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
12 if (attribute.units()) {
218 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute because attribute has units '" << attribute.units().get() << "'.");
219 ✗ return boost::none;
220 }
221
222 // minimum required attributes are name, fuelType, meterInstallLocation, consumptionUnit, consumptionUnitConversionFactor
223
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 boost::optional<Attribute> test = attribute.findChildByName("name");
224
6/9
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
6 if (!test || !(test->valueType() == AttributeValueType::String)) {
225 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute without 'name'.");
226 ✗ return boost::none;
227 }
228
229
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 test = attribute.findChildByName("fuelType");
230
6/9
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
6 if (!test || !(test->valueType() == AttributeValueType::String)) {
231 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute without 'fuelType'.");
232 ✗ return boost::none;
233 }
234 try {
235 // cppcheck-suppress unusedScopedObject
236
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 FuelType(test->valueAsString());
237 ✗ } catch (const std::exception&) {
238 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute with improper 'fuelType'.");
239 ✗ return boost::none;
240 ✗ }
241
242
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 test = attribute.findChildByName("meterInstallLocation");
243
6/9
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
6 if (!test || !(test->valueType() == AttributeValueType::String)) {
244 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute without 'meterInstallLocation'.");
245 ✗ return boost::none;
246 }
247 try {
248 // cppcheck-suppress unusedScopedObject
249
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 InstallLocationType(test->valueAsString());
250 ✗ } catch (const std::exception&) {
251 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute with improper 'meterInstallLocation'.");
252 ✗ return boost::none;
253 ✗ }
254
255
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 test = attribute.findChildByName("consumptionUnit");
256
6/9
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
6 if (!test || !(test->valueType() == AttributeValueType::String)) {
257 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute without 'consumptionUnit'.");
258 ✗ return boost::none;
259 }
260
261
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 test = attribute.findChildByName("consumptionUnitConversionFactor");
262
6/9
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
6 if (!test || !(test->valueType() == AttributeValueType::Double)) {
263 ✗ LOG(Warn, "Cannot create CalibrationUtilityBill from Attribute without 'consumptionUnitConversionFactor'.");
264 ✗ return boost::none;
265 }
266
267
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 return CalibrationUtilityBill(attribute);
268 6 }
269
270 2 CalibrationUtilityBill::CalibrationUtilityBill(
271 const std::string& name, const FuelType& fuelType, const InstallLocationType& meterInstallLocation,
272 boost::optional<std::string> meterSpecificInstallLocation, boost::optional<EndUseCategoryType> meterEndUseCategory,
273 boost::optional<std::string> meterSpecificEndUse, const std::string& consumptionUnit, double consumptionUnitConversionFactor,
274 boost::optional<std::string> peakDemandUnit, boost::optional<double> peakDemandUnitConversionFactor,
275 boost::optional<unsigned> timestepsInPeakDemandWindow, boost::optional<double> minutesInPeakDemandWindow,
276 2 boost::optional<unsigned> numberBillingPeriodsInCalculations, boost::optional<double> CVRMSE, boost::optional<double> NMBE)
277
2/2
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 2 times.
2 : m_attribute(CalibrationUtilityBill::attributeName(), std::vector<openstudio::Attribute>(), boost::none) {
278 2 std::vector<Attribute> values;
279
280
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 values.push_back(Attribute("name", name));
281
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 values.push_back(Attribute("fuelType", fuelType.valueName()));
282
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 values.push_back(Attribute("meterInstallLocation", meterInstallLocation.valueName()));
283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (meterSpecificInstallLocation) {
284 ✗ values.push_back(Attribute("meterSpecificInstallLocation", *meterSpecificInstallLocation));
285 }
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (meterEndUseCategory) {
287 ✗ values.push_back(Attribute("meterEndUseCategory", meterEndUseCategory->valueName()));
288 }
289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (meterSpecificEndUse) {
290 ✗ values.push_back(Attribute("meterSpecificEndUse", *meterSpecificEndUse));
291 }
292
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 values.push_back(Attribute("consumptionUnit", consumptionUnit));
293
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 values.push_back(Attribute("consumptionUnitConversionFactor", consumptionUnitConversionFactor));
294
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (peakDemandUnit) {
295
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
3 values.push_back(Attribute("peakDemandUnit", *peakDemandUnit));
296 }
297
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (peakDemandUnitConversionFactor) {
298
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
3 values.push_back(Attribute("peakDemandUnitConversionFactor", *peakDemandUnitConversionFactor));
299 }
300
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (timestepsInPeakDemandWindow) {
301
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
3 values.push_back(Attribute("timestepsInPeakDemandWindow", *timestepsInPeakDemandWindow));
302 }
303
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (minutesInPeakDemandWindow) {
304
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
3 values.push_back(Attribute("minutesInPeakDemandWindow", *minutesInPeakDemandWindow));
305 }
306
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (numberBillingPeriodsInCalculations) {
307
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 values.push_back(Attribute("numberBillingPeriodsInCalculations", *numberBillingPeriodsInCalculations));
308 }
309
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (CVRMSE) {
310
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 values.push_back(Attribute("cvrmse", *CVRMSE));
311 }
312
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (NMBE) {
313
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 values.push_back(Attribute("nmbe", *NMBE));
314 }
315
316
3/3
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
6 values.push_back(Attribute("billingPeriods", std::vector<Attribute>()));
317
318
1/1
✓ Branch 1 taken 2 times.
2 m_attribute.setValue(values);
319 2 }
320
321 6 CalibrationUtilityBill::CalibrationUtilityBill(const Attribute& attribute) : m_attribute(attribute) {}
322
323 2 Attribute CalibrationUtilityBill::attribute() const {
324 2 return m_attribute;
325 }
326
327 3 std::string CalibrationUtilityBill::name() const {
328
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("name");
329
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 4 not taken.
3 OS_ASSERT(attribute);
330
4/6
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 13 not taken.
3 OS_ASSERT(attribute->valueType() == AttributeValueType::String);
331
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
6 return attribute->valueAsString();
332 3 }
333
334 1 FuelType CalibrationUtilityBill::fuelType() const {
335
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 boost::optional<Attribute> attribute = m_attribute.findChildByName("fuelType");
336
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(attribute);
337
4/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 13 not taken.
1 OS_ASSERT(attribute->valueType() == AttributeValueType::String);
338
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
2 return FuelType(attribute->valueAsString());
339 1 }
340
341 1 InstallLocationType CalibrationUtilityBill::meterInstallLocation() const {
342
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 boost::optional<Attribute> attribute = m_attribute.findChildByName("meterInstallLocation");
343
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(attribute);
344
4/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 13 not taken.
1 OS_ASSERT(attribute->valueType() == AttributeValueType::String);
345
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
2 return InstallLocationType(attribute->valueAsString());
346 1 }
347
348 1 boost::optional<std::string> CalibrationUtilityBill::meterSpecificInstallLocation() const {
349
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
3 boost::optional<Attribute> attribute = m_attribute.findChildByName("meterSpecificInstallLocation");
350
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (attribute) {
351 ✗ OS_ASSERT(attribute->valueType() == AttributeValueType::String);
352 ✗ return attribute->valueAsString();
353 }
354 1 return boost::none;
355 1 }
356
357 1 boost::optional<EndUseCategoryType> CalibrationUtilityBill::meterEndUseCategory() const {
358
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
3 boost::optional<Attribute> attribute = m_attribute.findChildByName("meterEndUseCategory");
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (attribute) {
360 ✗ OS_ASSERT(attribute->valueType() == AttributeValueType::String);
361 ✗ return EndUseCategoryType(attribute->valueAsString());
362 }
363 1 return boost::none;
364 1 }
365
366 1 boost::optional<std::string> CalibrationUtilityBill::meterSpecificEndUse() const {
367
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
3 boost::optional<Attribute> attribute = m_attribute.findChildByName("meterSpecificEndUse");
368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 if (attribute) {
369 ✗ OS_ASSERT(attribute->valueType() == AttributeValueType::String);
370 ✗ return attribute->valueAsString();
371 }
372 1 return boost::none;
373 1 }
374
375 7 std::string CalibrationUtilityBill::consumptionUnit() const {
376
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
14 boost::optional<Attribute> attribute = m_attribute.findChildByName("consumptionUnit");
377
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 4 not taken.
7 OS_ASSERT(attribute);
378
4/6
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 7 times.
✗ Branch 13 not taken.
7 OS_ASSERT(attribute->valueType() == AttributeValueType::String);
379
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
14 return attribute->valueAsString();
380 7 }
381
382 1 double CalibrationUtilityBill::consumptionUnitConversionFactor() const {
383
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 boost::optional<Attribute> attribute = m_attribute.findChildByName("consumptionUnitConversionFactor");
384
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(attribute);
385
4/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 13 not taken.
1 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
386
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 return attribute->valueAsDouble();
387 1 }
388
389 6 boost::optional<std::string> CalibrationUtilityBill::peakDemandUnit() const {
390
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
18 boost::optional<Attribute> attribute = m_attribute.findChildByName("peakDemandUnit");
391
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if (attribute) {
392
4/6
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 13 not taken.
4 OS_ASSERT(attribute->valueType() == AttributeValueType::String);
393
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
4 return attribute->valueAsString();
394 }
395 2 return boost::none;
396 6 }
397
398 2 boost::optional<double> CalibrationUtilityBill::peakDemandUnitConversionFactor() const {
399
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("peakDemandUnitConversionFactor");
400
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
401
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
402
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsDouble();
403 }
404 ✗ return boost::none;
405 2 }
406
407 2 boost::optional<unsigned> CalibrationUtilityBill::timestepsInPeakDemandWindow() const {
408
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("timestepsInPeakDemandWindow");
409
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
410
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Unsigned);
411
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsUnsigned();
412 }
413 ✗ return boost::none;
414 2 }
415
416 2 boost::optional<double> CalibrationUtilityBill::minutesInPeakDemandWindow() const {
417
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("minutesInPeakDemandWindow");
418
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
419
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
420
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsDouble();
421 }
422 ✗ return boost::none;
423 2 }
424
425 2 boost::optional<unsigned> CalibrationUtilityBill::numberBillingPeriodsInCalculations() const {
426
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("numberBillingPeriodsInCalculations");
427
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
428
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Unsigned);
429
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsUnsigned();
430 }
431 ✗ return boost::none;
432 2 }
433
434 2 boost::optional<double> CalibrationUtilityBill::CVRMSE() const {
435
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("cvrmse");
436
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
437
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
438
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsDouble();
439 }
440 ✗ return boost::none;
441 2 }
442
443 2 boost::optional<double> CalibrationUtilityBill::NMBE() const {
444
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("nmbe");
445
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (attribute) {
446
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::Double);
447
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return attribute->valueAsDouble();
448 }
449 ✗ return boost::none;
450 2 }
451
452 6 std::vector<CalibrationBillingPeriod> CalibrationUtilityBill::billingPeriods() const {
453 6 std::vector<CalibrationBillingPeriod> result;
454
455
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
12 boost::optional<Attribute> attribute = m_attribute.findChildByName("billingPeriods");
456
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 4 not taken.
6 OS_ASSERT(attribute);
457
4/6
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 13 not taken.
6 OS_ASSERT(attribute->valueType() == AttributeValueType::AttributeVector);
458
4/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 11 taken 12 times.
✓ Branch 12 taken 6 times.
18 for (const Attribute& value : attribute->valueAsAttributeVector()) {
459
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<CalibrationBillingPeriod> tmp = CalibrationBillingPeriod::fromAttribute(value);
460
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (tmp) {
461
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 result.push_back(*tmp);
462 }
463 18 }
464
465 12 return result;
466 6 }
467
468 6 bool CalibrationUtilityBill::addBillingPeriod(const CalibrationBillingPeriod& billingPeriod) {
469
4/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 4 times.
6 if (billingPeriod.consumptionUnit() != this->consumptionUnit()) {
470 2 return false;
471 }
472
4/5
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
4 if (billingPeriod.peakDemandUnit() != this->peakDemandUnit()) {
473 ✗ return false;
474 }
475
476
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
8 boost::optional<Attribute> attribute = m_attribute.findChildByName("billingPeriods");
477
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 4 not taken.
4 OS_ASSERT(attribute);
478
4/6
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 13 not taken.
4 OS_ASSERT(attribute->valueType() == AttributeValueType::AttributeVector);
479
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 std::vector<Attribute> values = attribute->valueAsAttributeVector();
480
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 values.push_back(billingPeriod.attribute());
481
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 attribute->setValue(values);
482
483 4 return true;
484 4 }
485
486 2 std::string CalibrationResult::attributeName() {
487
1/1
✓ Branch 1 taken 2 times.
4 return "CalibrationResult";
488 }
489
490 1 boost::optional<CalibrationResult> CalibrationResult::fromAttribute(const Attribute& attribute) {
491
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
1 if (attribute.name() != CalibrationResult::attributeName()) {
492 ✗ LOG(Warn, "Cannot create CalibrationResult from Attribute because attribute name is '" << attribute.name() << "'.");
493 ✗ return boost::none;
494 }
495
496
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
1 if (attribute.valueType() != AttributeValueType::AttributeVector) {
497 ✗ LOG(Warn, "Cannot create CalibrationResult from Attribute because attribute is a " << attribute.valueType().valueDescription()
498 << ", not an AttributeVector.");
499 ✗ return boost::none;
500 }
501
502
2/3
✓ Branch 1 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
2 if (attribute.units()) {
503 ✗ LOG(Warn, "Cannot create CalibrationResult from Attribute because attribute has units '" << attribute.units().get() << "'.");
504 ✗ return boost::none;
505 }
506
507 // minimum required attributes are utilityBills
508
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 boost::optional<Attribute> test = attribute.findChildByName("utilityBills");
509
6/9
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 time.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 time.
1 if (!test || !(test->valueType() == AttributeValueType::AttributeVector)) {
510 ✗ LOG(Warn, "Cannot create CalibrationResult from Attribute without 'utilityBills'.");
511 ✗ return boost::none;
512 }
513
514
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 return CalibrationResult(attribute);
515 1 }
516
517
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
1 CalibrationResult::CalibrationResult() : m_attribute(CalibrationResult::attributeName(), std::vector<Attribute>(), boost::none) {
518 1 std::vector<Attribute> values;
519
520
3/3
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
3 values.push_back(Attribute("utilityBills", std::vector<Attribute>()));
521
522
1/1
✓ Branch 1 taken 1 time.
1 m_attribute.setValue(values);
523 1 }
524
525 1 CalibrationResult::CalibrationResult(const Attribute& attribute) : m_attribute(attribute) {}
526
527 1 Attribute CalibrationResult::attribute() const {
528 1 return m_attribute;
529 }
530
531 3 std::vector<CalibrationUtilityBill> CalibrationResult::utilityBills() const {
532 3 std::vector<CalibrationUtilityBill> result;
533
534
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
6 boost::optional<Attribute> attribute = m_attribute.findChildByName("utilityBills");
535
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 4 not taken.
3 OS_ASSERT(attribute);
536
4/6
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 13 not taken.
3 OS_ASSERT(attribute->valueType() == AttributeValueType::AttributeVector);
537
4/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 11 taken 6 times.
✓ Branch 12 taken 3 times.
9 for (const Attribute& value : attribute->valueAsAttributeVector()) {
538
1/1
✓ Branch 1 taken 6 times.
6 boost::optional<CalibrationUtilityBill> tmp = CalibrationUtilityBill::fromAttribute(value);
539
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (tmp) {
540
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 result.push_back(*tmp);
541 }
542 9 }
543
544 6 return result;
545 3 }
546
547 2 bool CalibrationResult::addUtilityBill(const CalibrationUtilityBill& utilityBill) {
548
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
4 boost::optional<Attribute> attribute = m_attribute.findChildByName("utilityBills");
549
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(attribute);
550
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 13 not taken.
2 OS_ASSERT(attribute->valueType() == AttributeValueType::AttributeVector);
551
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 std::vector<Attribute> values = attribute->valueAsAttributeVector();
552
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 values.push_back(utilityBill.attribute());
553
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 attribute->setValue(values);
554
555 2 return true;
556 2 }
557
558 } // namespace openstudio
559