GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 70.4% 107 / 0 / 152
Functions: 72.0% 18 / 0 / 25
Branches: 49.8% 120 / 0 / 241

src/model/ScheduleYear.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 "ScheduleYear.hpp"
7 #include "ScheduleYear_Impl.hpp"
8 #include "ScheduleWeek.hpp"
9 #include "ScheduleWeek_Impl.hpp"
10 #include "ScheduleTypeLimits.hpp"
11 #include "ScheduleTypeLimits_Impl.hpp"
12 #include "YearDescription.hpp"
13 #include "YearDescription_Impl.hpp"
14 #include "Model.hpp"
15 #include "Model_Impl.hpp"
16 #include "ModelExtensibleGroup.hpp"
17
18 #include <utilities/idd/OS_Schedule_Year_FieldEnums.hxx>
19 #include <utilities/idd/IddEnums.hxx>
20
21 #include "../utilities/core/Assert.hpp"
22 #include "../utilities/time/Date.hpp"
23
24 namespace openstudio {
25 namespace model {
26
27 namespace detail {
28
29 396 ScheduleYear_Impl::ScheduleYear_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
30 396 : Schedule_Impl(idfObject, model, keepHandle) {
31
4/6
✓ Branch 1 taken 396 times.
✓ Branch 4 taken 396 times.
✓ Branch 7 taken 396 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 396 times.
✗ Branch 13 not taken.
396 OS_ASSERT(idfObject.iddObject().type() == ScheduleYear::iddObjectType());
32 396 }
33
34 330 ScheduleYear_Impl::ScheduleYear_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
35 330 : Schedule_Impl(other, model, keepHandle) {
36
4/6
✓ Branch 1 taken 330 times.
✓ Branch 4 taken 330 times.
✓ Branch 7 taken 330 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 330 times.
✗ Branch 13 not taken.
330 OS_ASSERT(other.iddObject().type() == ScheduleYear::iddObjectType());
37 330 }
38
39 20 ScheduleYear_Impl::ScheduleYear_Impl(const ScheduleYear_Impl& other, Model_Impl* model, bool keepHandle)
40 20 : Schedule_Impl(other, model, keepHandle) {}
41
42 ✗ const std::vector<std::string>& ScheduleYear_Impl::outputVariableNames() const {
43 ✗ static const std::vector<std::string> result;
44 ✗ return result;
45 }
46
47 ✗ IddObjectType ScheduleYear_Impl::iddObjectType() const {
48 ✗ return ScheduleYear::iddObjectType();
49 }
50
51 174 boost::optional<ScheduleTypeLimits> ScheduleYear_Impl::scheduleTypeLimits() const {
52
2/2
✓ Branch 1 taken 174 times.
✓ Branch 4 taken 174 times.
174 return getObject<ModelObject>().getModelObjectTarget<ScheduleTypeLimits>(OS_Schedule_YearFields::ScheduleTypeLimitsName);
53 }
54
55 ✗ std::vector<double> ScheduleYear_Impl::values() const {
56 ✗ return {};
57 }
58
59 62 bool ScheduleYear_Impl::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) {
60
4/5
✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
✓ Branch 7 taken 62 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 62 times.
62 if (scheduleTypeLimits.model() != model()) {
61 ✗ return false;
62 }
63
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
62 if (!candidateIsCompatibleWithCurrentUse(scheduleTypeLimits)) {
64 ✗ return false;
65 }
66
2/2
✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
62 return setPointer(OS_Schedule_YearFields::ScheduleTypeLimitsName, scheduleTypeLimits.handle());
67 }
68
69 ✗ bool ScheduleYear_Impl::resetScheduleTypeLimits() {
70 ✗ if (okToResetScheduleTypeLimits()) {
71 ✗ return setString(OS_Schedule_YearFields::ScheduleTypeLimitsName, "");
72 }
73 ✗ return false;
74 }
75
76 179 std::vector<openstudio::Date> ScheduleYear_Impl::dates() const {
77 179 std::vector<openstudio::Date> result;
78
79
2/2
✓ Branch 1 taken 179 times.
✓ Branch 4 taken 179 times.
179 YearDescription yd = this->model().getUniqueModelObject<YearDescription>();
80
81
3/3
✓ Branch 1 taken 179 times.
✓ Branch 8 taken 227 times.
✓ Branch 9 taken 179 times.
406 for (const auto& group : this->extensibleGroups()) {
82
1/1
✓ Branch 1 taken 227 times.
227 OptionalUnsigned month = group.getUnsigned(0, true);
83
1/1
✓ Branch 1 taken 227 times.
227 OptionalUnsigned day = group.getUnsigned(1, true);
84
85
3/6
✓ Branch 0 taken 227 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 227 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 227 times.
✗ Branch 5 not taken.
454 if (month && day) {
86
4/4
✓ Branch 1 taken 227 times.
✓ Branch 4 taken 227 times.
✓ Branch 7 taken 227 times.
✓ Branch 10 taken 227 times.
227 result.push_back(yd.makeDate(*month, *day));
87 } else {
88 ✗ LOG(Error, "Could not read date " << group.groupIndex() << " in " << briefDescription() << ".");
89 }
90 179 }
91
92 358 return result;
93 179 }
94
95 184 std::vector<ScheduleWeek> ScheduleYear_Impl::scheduleWeeks() const {
96 184 std::vector<ScheduleWeek> result;
97
98
4/4
✓ Branch 1 taken 184 times.
✓ Branch 4 taken 184 times.
✓ Branch 12 taken 232 times.
✓ Branch 13 taken 184 times.
416 for (const ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(this->extensibleGroups())) {
99
1/1
✓ Branch 1 taken 232 times.
232 OptionalWorkspaceObject object = group.getTarget(2);
100
1/2
✓ Branch 0 taken 232 times.
✗ Branch 1 not taken.
232 if (object) {
101
2/2
✓ Branch 1 taken 232 times.
✓ Branch 4 taken 232 times.
232 boost::optional<ScheduleWeek> schedule = object->optionalCast<ScheduleWeek>();
102
103
1/2
✓ Branch 0 taken 232 times.
✗ Branch 1 not taken.
232 if (schedule) {
104
2/2
✓ Branch 1 taken 232 times.
✓ Branch 4 taken 232 times.
232 result.push_back(*schedule);
105 } else {
106 ✗ LOG(Error, "Could not read schedule " << group.groupIndex() << " in " << briefDescription() << ".");
107 }
108 232 }
109 416 }
110
111 184 return result;
112 ✗ }
113
114 39 boost::optional<ScheduleWeek> ScheduleYear_Impl::getScheduleWeek(const openstudio::Date& date) const {
115
2/2
✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
39 YearDescription yd = this->model().getUniqueModelObject<YearDescription>();
116
117
3/4
✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 39 times.
39 if (yd.assumedYear() != date.assumedBaseYear()) {
118 ✗ LOG(Error,
119 "Assumed base year " << date.assumedBaseYear() << " of date does not match this model's assumed base year of " << yd.assumedYear());
120 ✗ return boost::none;
121 }
122
123
1/1
✓ Branch 1 taken 39 times.
39 std::vector<ScheduleWeek> scheduleWeeks = this->scheduleWeeks(); // these are already sorted
124
1/1
✓ Branch 1 taken 39 times.
39 std::vector<openstudio::Date> dates = this->dates(); // these are already sorted
125
126 39 unsigned N = dates.size();
127
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 4 not taken.
39 OS_ASSERT(scheduleWeeks.size() == N);
128
129
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 33 times.
39 if (N == 0) {
130 6 return boost::none;
131 }
132
133 33 boost::optional<ScheduleWeek> result;
134
135
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 3 times.
53 for (unsigned i = 0; i < N; ++i) {
136
137 // want first date which is greater than or equal to the target date
138
3/3
✓ Branch 2 taken 50 times.
✓ Branch 4 taken 30 times.
✓ Branch 5 taken 20 times.
50 if (dates[i] >= date) {
139
1/1
✓ Branch 2 taken 30 times.
30 result = scheduleWeeks[i];
140 30 break;
141 }
142 }
143
144 33 return result;
145 39 }
146
147 100 bool ScheduleYear_Impl::addScheduleWeek(const openstudio::Date& untilDate, const ScheduleWeek& scheduleWeek) {
148
2/2
✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
100 YearDescription yd = this->model().getUniqueModelObject<YearDescription>();
149
150
3/4
✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 100 times.
100 if (yd.assumedYear() != untilDate.assumedBaseYear()) {
151 ✗ LOG(Error, "Assumed base year " << untilDate.assumedBaseYear() << " of untilDate does not match this model's assumed base year of "
152 << yd.assumedYear());
153 ✗ return false;
154 }
155
156
1/1
✓ Branch 1 taken 100 times.
100 std::vector<ScheduleWeek> scheduleWeeks = this->scheduleWeeks(); // these are already sorted
157
1/1
✓ Branch 1 taken 100 times.
100 std::vector<openstudio::Date> dates = this->dates(); // these are already sorted
158 100 bool inserted = false;
159
160 100 unsigned N = dates.size();
161
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
✗ Branch 4 not taken.
100 OS_ASSERT(scheduleWeeks.size() == N);
162
163
1/1
✓ Branch 1 taken 100 times.
100 this->clearExtensibleGroups();
164
165
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 100 times.
190 for (unsigned i = 0; i < N; ++i) {
166
167
2/3
✓ Branch 2 taken 90 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 90 times.
90 if (dates[i] == untilDate) {
168
169 ✗ bool doEmit = (i == (N - 1));
170
171 // push back just this schedule/date pair
172 ✗ std::vector<std::string> groupValues{boost::lexical_cast<std::string>(untilDate.monthOfYear().value()),
173 ✗ boost::lexical_cast<std::string>(untilDate.dayOfMonth()), scheduleWeek.name().get()};
174
175 ✗ auto group = pushExtensibleGroup(groupValues, doEmit);
176 ✗ OS_ASSERT(!group.empty());
177
178 ✗ inserted = true;
179
180 ✗ } else {
181
182 // if we need to insert new schedule/date pair here
183
7/7
✓ Branch 2 taken 90 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 87 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 88 times.
90 if ((untilDate < dates[i]) && !inserted) {
184
185 // push back this schedule/date pair
186
1/1
✓ Branch 1 taken 2 times.
2 std::vector<std::string> groupValues{boost::lexical_cast<std::string>(untilDate.monthOfYear().value()),
187
4/6
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
12 boost::lexical_cast<std::string>(untilDate.dayOfMonth()), scheduleWeek.name().get()};
188
189
1/1
✓ Branch 1 taken 2 times.
2 auto group = pushExtensibleGroup(groupValues, false);
190
2/4
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 6 not taken.
2 OS_ASSERT(!group.empty());
191
192 2 inserted = true;
193 2 }
194
195
4/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 26 times.
90 bool doEmit = (i == (N - 1)) && inserted;
196
197 // insert existing schedule/date pair
198
2/2
✓ Branch 1 taken 90 times.
✓ Branch 4 taken 90 times.
90 std::vector<std::string> groupValues{boost::lexical_cast<std::string>(dates[i].monthOfYear().value()),
199
6/8
✓ Branch 1 taken 90 times.
✓ Branch 4 taken 90 times.
✓ Branch 7 taken 90 times.
✓ Branch 10 taken 90 times.
✓ Branch 12 taken 270 times.
✓ Branch 13 taken 90 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
630 boost::lexical_cast<std::string>(dates[i].dayOfMonth()), scheduleWeeks[i].name().get()};
200
201
1/1
✓ Branch 1 taken 90 times.
90 auto group = pushExtensibleGroup(groupValues, doEmit);
202
2/4
✓ Branch 1 taken 90 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 90 times.
✗ Branch 6 not taken.
90 OS_ASSERT(!group.empty());
203 90 }
204 }
205
206
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 2 times.
100 if (!inserted) {
207 // push back this schedule/date pair
208
1/1
✓ Branch 1 taken 98 times.
98 std::vector<std::string> groupValues{boost::lexical_cast<std::string>(untilDate.monthOfYear().value()),
209
4/6
✓ Branch 1 taken 98 times.
✓ Branch 4 taken 98 times.
✓ Branch 6 taken 294 times.
✓ Branch 7 taken 98 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
588 boost::lexical_cast<std::string>(untilDate.dayOfMonth()), scheduleWeek.name().get()};
210
211
1/1
✓ Branch 1 taken 98 times.
98 auto group = pushExtensibleGroup(groupValues, true);
212
2/4
✓ Branch 1 taken 98 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 98 times.
✗ Branch 6 not taken.
98 OS_ASSERT(!group.empty());
213 98 }
214
215 100 return true;
216 760 }
217
218 6 void ScheduleYear_Impl::clearScheduleWeeks() {
219
1/1
✓ Branch 1 taken 6 times.
6 this->clearExtensibleGroups();
220 6 }
221
222 ✗ void ScheduleYear_Impl::ensureNoLeapDays() {
223 ✗ for (const IdfExtensibleGroup& group : this->extensibleGroups()) {
224 ✗ boost::optional<int> month;
225 ✗ boost::optional<int> day;
226
227 ✗ month = group.getInt(OS_Schedule_YearExtensibleFields::Month);
228 ✗ if (month && (month.get() == 2)) {
229 ✗ day = group.getInt(OS_Schedule_YearExtensibleFields::Day);
230 ✗ if (day && (day.get() == 29)) {
231 ✗ this->setInt(OS_Schedule_YearExtensibleFields::Day, 28);
232 }
233 }
234 ✗ }
235 ✗ }
236
237 ✗ std::vector<EMSActuatorNames> ScheduleYear_Impl::emsActuatorNames() const {
238 ✗ std::vector<EMSActuatorNames> actuators{{"Schedule:Year", "Schedule Value"}};
239 ✗ return actuators;
240 ✗ }
241
242 ✗ std::vector<std::string> ScheduleYear_Impl::emsInternalVariableNames() const {
243 ✗ std::vector<std::string> types;
244 ✗ return types;
245 }
246 } // namespace detail
247
248 66 ScheduleYear::ScheduleYear(const Model& model) : Schedule(ScheduleYear::iddObjectType(), model) {
249
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 66 times.
✗ Branch 5 not taken.
66 OS_ASSERT(getImpl<detail::ScheduleYear_Impl>());
250 66 }
251
252 8529 IddObjectType ScheduleYear::iddObjectType() {
253
1/1
✓ Branch 1 taken 8529 times.
8529 IddObjectType result(IddObjectType::OS_Schedule_Year);
254 8529 return result;
255 }
256
257 /// @cond
258
1/1
✓ Branch 3 taken 27 times.
27 ScheduleYear::ScheduleYear(std::shared_ptr<detail::ScheduleYear_Impl> impl) : Schedule(std::move(impl)) {}
259 /// @endcond
260
261 40 std::vector<openstudio::Date> ScheduleYear::dates() const {
262
1/1
✓ Branch 3 taken 40 times.
40 return getImpl<detail::ScheduleYear_Impl>()->dates();
263 }
264
265 45 std::vector<ScheduleWeek> ScheduleYear::scheduleWeeks() const {
266
1/1
✓ Branch 3 taken 45 times.
45 return getImpl<detail::ScheduleYear_Impl>()->scheduleWeeks();
267 }
268
269 39 boost::optional<ScheduleWeek> ScheduleYear::getScheduleWeek(const openstudio::Date& date) const {
270
1/1
✓ Branch 3 taken 39 times.
39 return getImpl<detail::ScheduleYear_Impl>()->getScheduleWeek(date);
271 }
272
273 100 bool ScheduleYear::addScheduleWeek(const openstudio::Date& untilDate, const ScheduleWeek& scheduleWeek) {
274
1/1
✓ Branch 3 taken 100 times.
100 return getImpl<detail::ScheduleYear_Impl>()->addScheduleWeek(untilDate, scheduleWeek);
275 }
276
277 6 void ScheduleYear::clearScheduleWeeks() {
278
1/1
✓ Branch 3 taken 6 times.
6 getImpl<detail::ScheduleYear_Impl>()->clearScheduleWeeks();
279 6 }
280
281 } // namespace model
282 } // namespace openstudio
283