GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 80.4% 414 / 0 / 515
Functions: 85.9% 61 / 0 / 71
Branches: 63.5% 467 / 0 / 736

src/model/ScheduleRuleset.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 "ScheduleRuleset.hpp"
7 #include "ScheduleRuleset_Impl.hpp"
8 #include "ScheduleRule.hpp"
9 #include "ScheduleRule_Impl.hpp"
10 #include "ScheduleDay.hpp"
11 #include "ScheduleDay_Impl.hpp"
12 #include "ScheduleTypeLimits.hpp"
13 #include "ScheduleTypeLimits_Impl.hpp"
14 #include "ScheduleTypeRegistry.hpp"
15 #include "YearDescription.hpp"
16 #include "YearDescription_Impl.hpp"
17 #include "Model.hpp"
18 #include "Model_Impl.hpp"
19 #include "ModelExtensibleGroup.hpp"
20
21 #include <utilities/idd/OS_Schedule_Ruleset_FieldEnums.hxx>
22 #include <utilities/idd/IddEnums.hxx>
23
24 #include "../utilities/core/Assert.hpp"
25 #include "../utilities/time/Date.hpp"
26
27 namespace openstudio {
28 namespace model {
29
30 namespace detail {
31
32 2638 ScheduleRuleset_Impl::ScheduleRuleset_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
33 2638 : Schedule_Impl(idfObject, model, keepHandle) {
34
4/6
✓ Branch 1 taken 2638 times.
✓ Branch 4 taken 2638 times.
✓ Branch 7 taken 2638 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2638 times.
✗ Branch 13 not taken.
2638 OS_ASSERT(idfObject.iddObject().type() == ScheduleRuleset::iddObjectType());
35 2638 }
36
37 669 ScheduleRuleset_Impl::ScheduleRuleset_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
38 669 : Schedule_Impl(other, model, keepHandle) {
39
4/6
✓ Branch 1 taken 669 times.
✓ Branch 4 taken 669 times.
✓ Branch 7 taken 669 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 669 times.
✗ Branch 13 not taken.
669 OS_ASSERT(other.iddObject().type() == ScheduleRuleset::iddObjectType());
40 669 }
41
42 1524 ScheduleRuleset_Impl::ScheduleRuleset_Impl(const ScheduleRuleset_Impl& other, Model_Impl* model, bool keepHandle)
43 1524 : Schedule_Impl(other, model, keepHandle) {}
44
45 24 ModelObject ScheduleRuleset_Impl::clone(Model model) const {
46
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 ModelObject newScheduleRulesetAsModelObject = ModelObject_Impl::clone(model);
47
1/1
✓ Branch 1 taken 24 times.
24 auto newScheduleRuleset = newScheduleRulesetAsModelObject.cast<ScheduleRuleset>();
48
49
3/3
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
✓ Branch 7 taken 24 times.
24 ModelObject newDefaultDaySchedule = defaultDaySchedule().clone(model);
50
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 bool test = newScheduleRuleset.setPointer(OS_Schedule_RulesetFields::DefaultDayScheduleName, newDefaultDaySchedule.handle());
51
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 3 not taken.
24 OS_ASSERT(test);
52
53
3/3
✓ Branch 1 taken 24 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 8 times.
24 if (!isSummerDesignDayScheduleDefaulted()) {
54
3/3
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
16 ModelObject newSummerDesignDaySchedule = summerDesignDaySchedule().clone(model);
55
2/2
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
16 test = newScheduleRuleset.setPointer(OS_Schedule_RulesetFields::SummerDesignDayScheduleName, newSummerDesignDaySchedule.handle());
56
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
✗ Branch 3 not taken.
16 OS_ASSERT(test);
57 16 }
58
59
3/3
✓ Branch 1 taken 24 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 9 times.
24 if (!isWinterDesignDayScheduleDefaulted()) {
60
3/3
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
15 ModelObject newWinterDesignDaySchedule = winterDesignDaySchedule().clone(model);
61
2/2
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
15 test = newScheduleRuleset.setPointer(OS_Schedule_RulesetFields::WinterDesignDayScheduleName, newWinterDesignDaySchedule.handle());
62
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
✗ Branch 3 not taken.
15 OS_ASSERT(test);
63 15 }
64
65
2/3
✓ Branch 1 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
24 if (!isHolidayScheduleDefaulted()) {
66 ✗ ModelObject newHolidaySchedule = holidaySchedule().clone(model);
67 ✗ test = newScheduleRuleset.setPointer(OS_Schedule_RulesetFields::HolidayScheduleName, newHolidaySchedule.handle());
68 ✗ OS_ASSERT(test);
69 ✗ }
70
71
2/3
✓ Branch 1 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
24 if (!isCustomDay1ScheduleDefaulted()) {
72 ✗ ModelObject newCustomDay1Schedule = customDay1Schedule().clone(model);
73 ✗ test = newScheduleRuleset.setPointer(OS_Schedule_RulesetFields::CustomDay1ScheduleName, newCustomDay1Schedule.handle());
74 ✗ OS_ASSERT(test);
75 ✗ }
76
77
2/3
✓ Branch 1 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
24 if (!isCustomDay2ScheduleDefaulted()) {
78 ✗ ModelObject newCustomDay2Schedule = customDay2Schedule().clone(model);
79 ✗ test = newScheduleRuleset.setPointer(OS_Schedule_RulesetFields::CustomDay2ScheduleName, newCustomDay2Schedule.handle());
80 ✗ OS_ASSERT(test);
81 ✗ }
82
83
3/3
✓ Branch 1 taken 24 times.
✓ Branch 8 taken 40 times.
✓ Branch 9 taken 24 times.
64 for (const ScheduleRule& scheduleRule : scheduleRules()) {
84
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 ModelObject newScheduleRule = scheduleRule.clone(model);
85
1/1
✓ Branch 1 taken 40 times.
40 test = newScheduleRule.setParent(newScheduleRuleset);
86
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
✗ Branch 3 not taken.
40 OS_ASSERT(test);
87 64 }
88
89 48 return newScheduleRulesetAsModelObject;
90 24 }
91
92 37 std::vector<ResourceObject> ScheduleRuleset_Impl::resources() const {
93 // remove daySchedule as a resource so it can be a child
94
1/1
✓ Branch 1 taken 37 times.
37 ResourceObjectVector result = ModelObject_Impl::resources();
95
2/2
✓ Branch 1 taken 37 times.
✓ Branch 4 taken 37 times.
37 ScheduleDayVector daySchedules(1u, defaultDaySchedule());
96
3/3
✓ Branch 1 taken 37 times.
✓ Branch 3 taken 23 times.
✓ Branch 4 taken 14 times.
37 if (!isSummerDesignDayScheduleDefaulted()) {
97
2/2
✓ Branch 1 taken 23 times.
✓ Branch 4 taken 23 times.
23 daySchedules.push_back(summerDesignDaySchedule());
98 }
99
3/3
✓ Branch 1 taken 37 times.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 16 times.
37 if (!isWinterDesignDayScheduleDefaulted()) {
100
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 daySchedules.push_back(winterDesignDaySchedule());
101 }
102
2/3
✓ Branch 1 taken 37 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
37 if (!isHolidayScheduleDefaulted()) {
103 ✗ daySchedules.push_back(holidaySchedule());
104 }
105
2/3
✓ Branch 1 taken 37 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
37 if (!isCustomDay1ScheduleDefaulted()) {
106 ✗ daySchedules.push_back(customDay1Schedule());
107 }
108
2/3
✓ Branch 1 taken 37 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
37 if (!isCustomDay2ScheduleDefaulted()) {
109 ✗ daySchedules.push_back(customDay2Schedule());
110 }
111 37 auto it = result.begin();
112
2/2
✓ Branch 2 taken 107 times.
✓ Branch 3 taken 37 times.
144 while (it != result.end()) {
113
1/1
✓ Branch 4 taken 107 times.
107 auto jit = std::find(daySchedules.begin(), daySchedules.end(), *it);
114
2/2
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 26 times.
107 if (jit != daySchedules.end()) {
115
1/1
✓ Branch 2 taken 81 times.
81 it = result.erase(it);
116
1/1
✓ Branch 2 taken 81 times.
81 daySchedules.erase(jit);
117 } else {
118 26 ++it;
119 }
120 }
121 74 return result;
122 37 }
123
124 1066 std::vector<ModelObject> ScheduleRuleset_Impl::children() const {
125 1066 std::vector<ModelObject> result;
126
127 // can add the ScheduleDays as children because removed from resource list
128
2/3
✓ Branch 1 taken 1066 times.
✓ Branch 3 taken 1066 times.
✗ Branch 4 not taken.
2132 if (OptionalScheduleDay schedule = optionalDefaultDaySchedule()) {
129
2/2
✓ Branch 1 taken 1066 times.
✓ Branch 4 taken 1066 times.
1066 result.push_back(*schedule);
130 1066 }
131
132
3/3
✓ Branch 1 taken 1066 times.
✓ Branch 3 taken 693 times.
✓ Branch 4 taken 373 times.
1066 if (!this->isSummerDesignDayScheduleDefaulted()) {
133
2/2
✓ Branch 1 taken 693 times.
✓ Branch 4 taken 693 times.
693 result.push_back(this->summerDesignDaySchedule());
134 }
135
136
3/3
✓ Branch 1 taken 1066 times.
✓ Branch 3 taken 606 times.
✓ Branch 4 taken 460 times.
1066 if (!this->isWinterDesignDayScheduleDefaulted()) {
137
2/2
✓ Branch 1 taken 606 times.
✓ Branch 4 taken 606 times.
606 result.push_back(this->winterDesignDaySchedule());
138 }
139
140
3/3
✓ Branch 1 taken 1066 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 1056 times.
1066 if (!this->isHolidayScheduleDefaulted()) {
141
2/2
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
10 result.push_back(this->holidaySchedule());
142 }
143
144
3/3
✓ Branch 1 taken 1066 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 1056 times.
1066 if (!this->isCustomDay1ScheduleDefaulted()) {
145
2/2
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
10 result.push_back(this->customDay1Schedule());
146 }
147
148
3/3
✓ Branch 1 taken 1066 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 1056 times.
1066 if (!this->isCustomDay2ScheduleDefaulted()) {
149
2/2
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
10 result.push_back(this->customDay2Schedule());
150 }
151
152
1/1
✓ Branch 1 taken 1066 times.
1066 auto schRules = this->scheduleRules();
153
1/1
✓ Branch 5 taken 1066 times.
1066 result.insert(result.end(), schRules.begin(), schRules.end());
154
155 2132 return result;
156 1066 }
157
158 9 const std::vector<std::string>& ScheduleRuleset_Impl::outputVariableNames() const {
159
6/11
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 1 time.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
12 static const std::vector<std::string> result{"Schedule Value"};
160 9 return result;
161 3 }
162
163 9 IddObjectType ScheduleRuleset_Impl::iddObjectType() const {
164 9 return ScheduleRuleset::iddObjectType();
165 }
166
167 12719 boost::optional<ScheduleTypeLimits> ScheduleRuleset_Impl::scheduleTypeLimits() const {
168
2/2
✓ Branch 1 taken 12719 times.
✓ Branch 4 taken 12719 times.
12719 return getObject<ModelObject>().getModelObjectTarget<ScheduleTypeLimits>(OS_Schedule_RulesetFields::ScheduleTypeLimitsName);
169 }
170
171 ✗ std::vector<double> ScheduleRuleset_Impl::values() const {
172 ✗ return {};
173 }
174
175 1871 bool ScheduleRuleset_Impl::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) {
176
4/5
✓ Branch 1 taken 1871 times.
✓ Branch 4 taken 1871 times.
✓ Branch 7 taken 1871 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1871 times.
1871 if (scheduleTypeLimits.model() != model()) {
177 ✗ return false;
178 }
179
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1871 times.
1871 if (!candidateIsCompatibleWithCurrentUse(scheduleTypeLimits)) {
180 ✗ return false;
181 }
182
2/2
✓ Branch 1 taken 1871 times.
✓ Branch 4 taken 1871 times.
1871 bool result = setPointer(OS_Schedule_RulesetFields::ScheduleTypeLimitsName, scheduleTypeLimits.handle());
183
1/2
✓ Branch 0 taken 1871 times.
✗ Branch 1 not taken.
1871 if (result) {
184
2/2
✓ Branch 1 taken 1871 times.
✓ Branch 4 taken 1871 times.
1871 result = defaultDaySchedule().setScheduleTypeLimits(scheduleTypeLimits);
185
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1871 times.
✗ Branch 3 not taken.
1871 OS_ASSERT(result);
186
3/3
✓ Branch 1 taken 1871 times.
✓ Branch 3 taken 1022 times.
✓ Branch 4 taken 849 times.
1871 if (!isSummerDesignDayScheduleDefaulted()) {
187
2/2
✓ Branch 1 taken 1022 times.
✓ Branch 4 taken 1022 times.
1022 result = summerDesignDaySchedule().setScheduleTypeLimits(scheduleTypeLimits);
188
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1022 times.
✗ Branch 3 not taken.
1022 OS_ASSERT(result);
189 }
190
3/3
✓ Branch 1 taken 1871 times.
✓ Branch 3 taken 854 times.
✓ Branch 4 taken 1017 times.
1871 if (!isWinterDesignDayScheduleDefaulted()) {
191
2/2
✓ Branch 1 taken 854 times.
✓ Branch 4 taken 854 times.
854 result = winterDesignDaySchedule().setScheduleTypeLimits(scheduleTypeLimits);
192
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 854 times.
✗ Branch 3 not taken.
854 OS_ASSERT(result);
193 }
194
3/3
✓ Branch 1 taken 1871 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1868 times.
1871 if (!isHolidayScheduleDefaulted()) {
195
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 result = holidaySchedule().setScheduleTypeLimits(scheduleTypeLimits);
196
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
3 OS_ASSERT(result);
197 }
198
3/3
✓ Branch 1 taken 1871 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1868 times.
1871 if (!isCustomDay1ScheduleDefaulted()) {
199
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 result = customDay1Schedule().setScheduleTypeLimits(scheduleTypeLimits);
200
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
3 OS_ASSERT(result);
201 }
202
3/3
✓ Branch 1 taken 1871 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1868 times.
1871 if (!isCustomDay2ScheduleDefaulted()) {
203
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 result = customDay2Schedule().setScheduleTypeLimits(scheduleTypeLimits);
204
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
3 OS_ASSERT(result);
205 }
206
1/1
✓ Branch 1 taken 1871 times.
1871 ScheduleRuleVector rules = scheduleRules();
207
2/2
✓ Branch 5 taken 2019 times.
✓ Branch 6 taken 1871 times.
3890 for (const ScheduleRule& rule : rules) {
208
2/2
✓ Branch 1 taken 2019 times.
✓ Branch 4 taken 2019 times.
2019 result = rule.daySchedule().setScheduleTypeLimits(scheduleTypeLimits);
209
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 2019 times.
✗ Branch 3 not taken.
2019 OS_ASSERT(result);
210 }
211 1871 }
212 1871 return result;
213 }
214
215 ✗ bool ScheduleRuleset_Impl::resetScheduleTypeLimits() {
216 ✗ bool result(false);
217 ✗ if (okToResetScheduleTypeLimits()) {
218 ✗ result = setString(OS_Schedule_RulesetFields::ScheduleTypeLimitsName, "");
219 ✗ OS_ASSERT(result);
220 ✗ result = defaultDaySchedule().resetScheduleTypeLimits();
221 ✗ OS_ASSERT(result);
222 ✗ if (!isSummerDesignDayScheduleDefaulted()) {
223 ✗ result = summerDesignDaySchedule().resetScheduleTypeLimits();
224 ✗ OS_ASSERT(result);
225 }
226 ✗ if (!isWinterDesignDayScheduleDefaulted()) {
227 ✗ result = winterDesignDaySchedule().resetScheduleTypeLimits();
228 ✗ OS_ASSERT(result);
229 }
230 ✗ if (!isHolidayScheduleDefaulted()) {
231 ✗ result = holidaySchedule().resetScheduleTypeLimits();
232 ✗ OS_ASSERT(result);
233 }
234 ✗ if (!isCustomDay1ScheduleDefaulted()) {
235 ✗ result = customDay1Schedule().resetScheduleTypeLimits();
236 ✗ OS_ASSERT(result);
237 }
238 ✗ if (!isCustomDay2ScheduleDefaulted()) {
239 ✗ result = customDay2Schedule().resetScheduleTypeLimits();
240 ✗ OS_ASSERT(result);
241 }
242 ✗ ScheduleRuleVector rules = scheduleRules();
243 ✗ for (ScheduleRule& rule : rules) {
244 ✗ result = rule.daySchedule().resetScheduleTypeLimits();
245 ✗ OS_ASSERT(result);
246 }
247 ✗ }
248 ✗ return result;
249 }
250
251 11345 ScheduleDay ScheduleRuleset_Impl::defaultDaySchedule() const {
252
1/1
✓ Branch 1 taken 11345 times.
11345 OptionalScheduleDay result = optionalDefaultDaySchedule();
253
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11345 times.
11345 if (!result) {
254 ✗ LOG_AND_THROW(briefDescription() << " has been corrupted. It no longer points to a default " << "OS:Schedule:Day object.");
255 }
256
2/2
✓ Branch 1 taken 11345 times.
✓ Branch 4 taken 11345 times.
22690 return *result;
257 11345 }
258
259 2637 ScheduleDay ScheduleRuleset_Impl::summerDesignDaySchedule() const {
260 OptionalScheduleDay result =
261
2/2
✓ Branch 1 taken 2637 times.
✓ Branch 4 taken 2637 times.
2637 getObject<ScheduleRuleset>().getModelObjectTarget<ScheduleDay>(OS_Schedule_RulesetFields::SummerDesignDayScheduleName);
262
2/2
✓ Branch 0 taken 2333 times.
✓ Branch 1 taken 304 times.
2637 if (result) {
263
2/2
✓ Branch 1 taken 2333 times.
✓ Branch 4 taken 2333 times.
2333 return *result;
264 }
265
1/1
✓ Branch 1 taken 304 times.
304 return this->defaultDaySchedule();
266 2637 }
267
268 4236 bool ScheduleRuleset_Impl::isSummerDesignDayScheduleDefaulted() const {
269 4236 return this->isEmpty(OS_Schedule_RulesetFields::SummerDesignDayScheduleName);
270 }
271
272 2378 ScheduleDay ScheduleRuleset_Impl::winterDesignDaySchedule() const {
273 OptionalScheduleDay result =
274
2/2
✓ Branch 1 taken 2378 times.
✓ Branch 4 taken 2378 times.
2378 getObject<ScheduleRuleset>().getModelObjectTarget<ScheduleDay>(OS_Schedule_RulesetFields::WinterDesignDayScheduleName);
275
2/2
✓ Branch 0 taken 2029 times.
✓ Branch 1 taken 349 times.
2378 if (result) {
276
2/2
✓ Branch 1 taken 2029 times.
✓ Branch 4 taken 2029 times.
2029 return *result;
277 }
278
1/1
✓ Branch 1 taken 349 times.
349 return this->defaultDaySchedule();
279 2378 }
280
281 4067 bool ScheduleRuleset_Impl::isWinterDesignDayScheduleDefaulted() const {
282 4067 return this->isEmpty(OS_Schedule_RulesetFields::WinterDesignDayScheduleName);
283 }
284
285 690 ScheduleDay ScheduleRuleset_Impl::holidaySchedule() const {
286
2/2
✓ Branch 1 taken 690 times.
✓ Branch 4 taken 690 times.
690 OptionalScheduleDay result = getObject<ScheduleRuleset>().getModelObjectTarget<ScheduleDay>(OS_Schedule_RulesetFields::HolidayScheduleName);
287
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 615 times.
690 if (result) {
288
2/2
✓ Branch 1 taken 75 times.
✓ Branch 4 taken 75 times.
75 return *result;
289 }
290
1/1
✓ Branch 1 taken 615 times.
615 return this->defaultDaySchedule();
291 690 }
292
293 3046 bool ScheduleRuleset_Impl::isHolidayScheduleDefaulted() const {
294 3046 return this->isEmpty(OS_Schedule_RulesetFields::HolidayScheduleName);
295 }
296
297 689 ScheduleDay ScheduleRuleset_Impl::customDay1Schedule() const {
298
2/2
✓ Branch 1 taken 689 times.
✓ Branch 4 taken 689 times.
689 OptionalScheduleDay result = getObject<ScheduleRuleset>().getModelObjectTarget<ScheduleDay>(OS_Schedule_RulesetFields::CustomDay1ScheduleName);
299
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 614 times.
689 if (result) {
300
2/2
✓ Branch 1 taken 75 times.
✓ Branch 4 taken 75 times.
75 return *result;
301 }
302
1/1
✓ Branch 1 taken 614 times.
614 return this->defaultDaySchedule();
303 689 }
304
305 3046 bool ScheduleRuleset_Impl::isCustomDay1ScheduleDefaulted() const {
306 3046 return this->isEmpty(OS_Schedule_RulesetFields::CustomDay1ScheduleName);
307 }
308
309 689 ScheduleDay ScheduleRuleset_Impl::customDay2Schedule() const {
310
2/2
✓ Branch 1 taken 689 times.
✓ Branch 4 taken 689 times.
689 OptionalScheduleDay result = getObject<ScheduleRuleset>().getModelObjectTarget<ScheduleDay>(OS_Schedule_RulesetFields::CustomDay2ScheduleName);
311
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 613 times.
689 if (result) {
312
2/2
✓ Branch 1 taken 76 times.
✓ Branch 4 taken 76 times.
76 return *result;
313 }
314
1/1
✓ Branch 1 taken 613 times.
613 return this->defaultDaySchedule();
315 689 }
316
317 3046 bool ScheduleRuleset_Impl::isCustomDay2ScheduleDefaulted() const {
318 3046 return this->isEmpty(OS_Schedule_RulesetFields::CustomDay2ScheduleName);
319 }
320
321 1237 bool ScheduleRuleset_Impl::setSummerDesignDaySchedule(const ScheduleDay& schedule) {
322
3/3
✓ Branch 1 taken 1237 times.
✓ Branch 3 taken 209 times.
✓ Branch 4 taken 1028 times.
2474 if (OptionalScheduleTypeLimits candidateLimits = schedule.scheduleTypeLimits()) {
323
2/3
✓ Branch 1 taken 209 times.
✓ Branch 3 taken 209 times.
✗ Branch 4 not taken.
418 if (OptionalScheduleTypeLimits parentLimits = scheduleTypeLimits()) {
324
4/5
✓ Branch 1 taken 209 times.
✓ Branch 4 taken 209 times.
✓ Branch 7 taken 209 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 209 times.
209 if (!isCompatible(*parentLimits, *candidateLimits)) {
325 ✗ return false;
326 }
327 } else {
328 ✗ return false;
329 209 }
330 1237 }
331
332 1237 boost::optional<ScheduleDay> existingSummerDDSchedule;
333
2/3
✓ Branch 1 taken 1237 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1237 times.
1237 if (!this->isSummerDesignDayScheduleDefaulted()) {
334 ✗ existingSummerDDSchedule = this->summerDesignDaySchedule();
335 }
336
1/1
✓ Branch 1 taken 1237 times.
1237 ModelObject clone = schedule.clone();
337
2/2
✓ Branch 1 taken 1237 times.
✓ Branch 4 taken 1237 times.
1237 bool result = setPointer(OS_Schedule_RulesetFields::SummerDesignDayScheduleName, clone.handle());
338
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1237 times.
✗ Branch 3 not taken.
1237 OS_ASSERT(result);
339
3/3
✓ Branch 1 taken 1237 times.
✓ Branch 3 taken 211 times.
✓ Branch 4 taken 1026 times.
2474 if (OptionalScheduleTypeLimits limits = scheduleTypeLimits()) {
340
3/3
✓ Branch 1 taken 211 times.
✓ Branch 4 taken 211 times.
✓ Branch 7 taken 211 times.
211 result = summerDesignDaySchedule().setScheduleTypeLimits(*limits);
341
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 211 times.
✗ Branch 3 not taken.
211 OS_ASSERT(result);
342 1237 }
343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1237 times.
1237 if (existingSummerDDSchedule) {
344 ✗ existingSummerDDSchedule->remove();
345 }
346 1237 return result;
347 1237 }
348
349 1 void ScheduleRuleset_Impl::resetSummerDesignDaySchedule() {
350 1 boost::optional<ScheduleDay> existingSummerDDSchedule;
351
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!this->isSummerDesignDayScheduleDefaulted()) {
352
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingSummerDDSchedule = this->summerDesignDaySchedule();
353 }
354
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool test = this->setString(OS_Schedule_RulesetFields::SummerDesignDayScheduleName, "");
355
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(test);
356
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (existingSummerDDSchedule) {
357
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingSummerDDSchedule->remove();
358 }
359 1 }
360
361 1068 bool ScheduleRuleset_Impl::setWinterDesignDaySchedule(const ScheduleDay& schedule) {
362
3/3
✓ Branch 1 taken 1068 times.
✓ Branch 3 taken 209 times.
✓ Branch 4 taken 859 times.
2136 if (OptionalScheduleTypeLimits candidateLimits = schedule.scheduleTypeLimits()) {
363
2/3
✓ Branch 1 taken 209 times.
✓ Branch 3 taken 209 times.
✗ Branch 4 not taken.
418 if (OptionalScheduleTypeLimits parentLimits = scheduleTypeLimits()) {
364
4/5
✓ Branch 1 taken 209 times.
✓ Branch 4 taken 209 times.
✓ Branch 7 taken 209 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 209 times.
209 if (!isCompatible(*parentLimits, *candidateLimits)) {
365 ✗ return false;
366 }
367 } else {
368 ✗ return false;
369 209 }
370 1068 }
371
372 1068 boost::optional<ScheduleDay> existingWinterDDSchedule;
373
2/3
✓ Branch 1 taken 1068 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1068 times.
1068 if (!this->isWinterDesignDayScheduleDefaulted()) {
374 ✗ existingWinterDDSchedule = this->winterDesignDaySchedule();
375 }
376
1/1
✓ Branch 1 taken 1068 times.
1068 ModelObject clone = schedule.clone();
377
2/2
✓ Branch 1 taken 1068 times.
✓ Branch 4 taken 1068 times.
1068 bool result = setPointer(OS_Schedule_RulesetFields::WinterDesignDayScheduleName, clone.handle());
378
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1068 times.
✗ Branch 3 not taken.
1068 OS_ASSERT(result);
379
3/3
✓ Branch 1 taken 1068 times.
✓ Branch 3 taken 211 times.
✓ Branch 4 taken 857 times.
2136 if (OptionalScheduleTypeLimits limits = scheduleTypeLimits()) {
380
3/3
✓ Branch 1 taken 211 times.
✓ Branch 4 taken 211 times.
✓ Branch 7 taken 211 times.
211 result = winterDesignDaySchedule().setScheduleTypeLimits(*limits);
381
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 211 times.
✗ Branch 3 not taken.
211 OS_ASSERT(result);
382 1068 }
383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1068 times.
1068 if (existingWinterDDSchedule) {
384 ✗ existingWinterDDSchedule->remove();
385 }
386 1068 return result;
387 1068 }
388
389 1 void ScheduleRuleset_Impl::resetWinterDesignDaySchedule() {
390 1 boost::optional<ScheduleDay> existingWinterDDSchedule;
391
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!this->isWinterDesignDayScheduleDefaulted()) {
392
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingWinterDDSchedule = this->winterDesignDaySchedule();
393 }
394
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool test = this->setString(OS_Schedule_RulesetFields::WinterDesignDayScheduleName, "");
395
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(test);
396
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (existingWinterDDSchedule) {
397
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingWinterDDSchedule->remove();
398 }
399 1 }
400
401 47 bool ScheduleRuleset_Impl::setHolidaySchedule(const ScheduleDay& schedule) {
402
3/3
✓ Branch 1 taken 47 times.
✓ Branch 3 taken 41 times.
✓ Branch 4 taken 6 times.
94 if (OptionalScheduleTypeLimits candidateLimits = schedule.scheduleTypeLimits()) {
403
2/3
✓ Branch 1 taken 41 times.
✓ Branch 3 taken 41 times.
✗ Branch 4 not taken.
82 if (OptionalScheduleTypeLimits parentLimits = scheduleTypeLimits()) {
404
4/5
✓ Branch 1 taken 41 times.
✓ Branch 4 taken 41 times.
✓ Branch 7 taken 41 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 41 times.
41 if (!isCompatible(*parentLimits, *candidateLimits)) {
405 ✗ return false;
406 }
407 } else {
408 ✗ return false;
409 41 }
410 47 }
411
412 47 boost::optional<ScheduleDay> existingHolidaySchedule;
413
2/3
✓ Branch 1 taken 47 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47 times.
47 if (!this->isHolidayScheduleDefaulted()) {
414 ✗ existingHolidaySchedule = this->holidaySchedule();
415 }
416
1/1
✓ Branch 1 taken 47 times.
47 ModelObject clone = schedule.clone();
417
2/2
✓ Branch 1 taken 47 times.
✓ Branch 4 taken 47 times.
47 bool result = setPointer(OS_Schedule_RulesetFields::HolidayScheduleName, clone.handle());
418
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
✗ Branch 3 not taken.
47 OS_ASSERT(result);
419
3/3
✓ Branch 1 taken 47 times.
✓ Branch 3 taken 43 times.
✓ Branch 4 taken 4 times.
94 if (OptionalScheduleTypeLimits limits = scheduleTypeLimits()) {
420
3/3
✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
43 result = holidaySchedule().setScheduleTypeLimits(*limits);
421
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✗ Branch 3 not taken.
43 OS_ASSERT(result);
422 47 }
423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if (existingHolidaySchedule) {
424 ✗ existingHolidaySchedule->remove();
425 }
426 47 return result;
427 47 }
428
429 1 void ScheduleRuleset_Impl::resetHolidaySchedule() {
430 1 boost::optional<ScheduleDay> existingHolidaySchedule;
431
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!this->isHolidayScheduleDefaulted()) {
432
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingHolidaySchedule = this->holidaySchedule();
433 }
434
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool test = this->setString(OS_Schedule_RulesetFields::HolidayScheduleName, "");
435
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(test);
436
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (existingHolidaySchedule) {
437
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingHolidaySchedule->remove();
438 }
439 1 }
440
441 47 bool ScheduleRuleset_Impl::setCustomDay1Schedule(const ScheduleDay& schedule) {
442
3/3
✓ Branch 1 taken 47 times.
✓ Branch 3 taken 41 times.
✓ Branch 4 taken 6 times.
94 if (OptionalScheduleTypeLimits candidateLimits = schedule.scheduleTypeLimits()) {
443
2/3
✓ Branch 1 taken 41 times.
✓ Branch 3 taken 41 times.
✗ Branch 4 not taken.
82 if (OptionalScheduleTypeLimits parentLimits = scheduleTypeLimits()) {
444
4/5
✓ Branch 1 taken 41 times.
✓ Branch 4 taken 41 times.
✓ Branch 7 taken 41 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 41 times.
41 if (!isCompatible(*parentLimits, *candidateLimits)) {
445 ✗ return false;
446 }
447 } else {
448 ✗ return false;
449 41 }
450 47 }
451
452 47 boost::optional<ScheduleDay> existingCustomD1Schedule;
453
2/3
✓ Branch 1 taken 47 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47 times.
47 if (!this->isCustomDay1ScheduleDefaulted()) {
454 ✗ existingCustomD1Schedule = this->customDay1Schedule();
455 }
456
1/1
✓ Branch 1 taken 47 times.
47 ModelObject clone = schedule.clone();
457
2/2
✓ Branch 1 taken 47 times.
✓ Branch 4 taken 47 times.
47 bool result = setPointer(OS_Schedule_RulesetFields::CustomDay1ScheduleName, clone.handle());
458
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
✗ Branch 3 not taken.
47 OS_ASSERT(result);
459
3/3
✓ Branch 1 taken 47 times.
✓ Branch 3 taken 43 times.
✓ Branch 4 taken 4 times.
94 if (OptionalScheduleTypeLimits limits = scheduleTypeLimits()) {
460
3/3
✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
43 result = customDay1Schedule().setScheduleTypeLimits(*limits);
461
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✗ Branch 3 not taken.
43 OS_ASSERT(result);
462 47 }
463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if (existingCustomD1Schedule) {
464 ✗ existingCustomD1Schedule->remove();
465 }
466 47 return result;
467 47 }
468
469 1 void ScheduleRuleset_Impl::resetCustomDay1Schedule() {
470 1 boost::optional<ScheduleDay> existingCustomD1Schedule;
471
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!this->isCustomDay1ScheduleDefaulted()) {
472
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingCustomD1Schedule = this->customDay1Schedule();
473 }
474
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool test = this->setString(OS_Schedule_RulesetFields::CustomDay1ScheduleName, "");
475
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(test);
476
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (existingCustomD1Schedule) {
477
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingCustomD1Schedule->remove();
478 }
479 1 }
480
481 47 bool ScheduleRuleset_Impl::setCustomDay2Schedule(const ScheduleDay& schedule) {
482
3/3
✓ Branch 1 taken 47 times.
✓ Branch 3 taken 41 times.
✓ Branch 4 taken 6 times.
94 if (OptionalScheduleTypeLimits candidateLimits = schedule.scheduleTypeLimits()) {
483
2/3
✓ Branch 1 taken 41 times.
✓ Branch 3 taken 41 times.
✗ Branch 4 not taken.
82 if (OptionalScheduleTypeLimits parentLimits = scheduleTypeLimits()) {
484
4/5
✓ Branch 1 taken 41 times.
✓ Branch 4 taken 41 times.
✓ Branch 7 taken 41 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 41 times.
41 if (!isCompatible(*parentLimits, *candidateLimits)) {
485 ✗ return false;
486 }
487 } else {
488 ✗ return false;
489 41 }
490 47 }
491
492 47 boost::optional<ScheduleDay> existingCustomD2Schedule;
493
2/3
✓ Branch 1 taken 47 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47 times.
47 if (!this->isCustomDay2ScheduleDefaulted()) {
494 ✗ ScheduleDay existingCustomD2Schedule = this->customDay2Schedule();
495 ✗ }
496
1/1
✓ Branch 1 taken 47 times.
47 ModelObject clone = schedule.clone();
497
2/2
✓ Branch 1 taken 47 times.
✓ Branch 4 taken 47 times.
47 bool result = setPointer(OS_Schedule_RulesetFields::CustomDay2ScheduleName, clone.handle());
498
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
✗ Branch 3 not taken.
47 OS_ASSERT(result);
499
3/3
✓ Branch 1 taken 47 times.
✓ Branch 3 taken 43 times.
✓ Branch 4 taken 4 times.
94 if (OptionalScheduleTypeLimits limits = scheduleTypeLimits()) {
500
3/3
✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
43 result = customDay2Schedule().setScheduleTypeLimits(*limits);
501
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✗ Branch 3 not taken.
43 OS_ASSERT(result);
502 47 }
503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if (existingCustomD2Schedule) {
504 ✗ existingCustomD2Schedule->remove();
505 }
506 47 return result;
507 47 }
508
509 1 void ScheduleRuleset_Impl::resetCustomDay2Schedule() {
510 1 boost::optional<ScheduleDay> existingCustomD2Schedule;
511
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!this->isCustomDay2ScheduleDefaulted()) {
512
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingCustomD2Schedule = this->customDay2Schedule();
513 }
514
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool test = this->setString(OS_Schedule_RulesetFields::CustomDay2ScheduleName, "");
515
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
1 OS_ASSERT(test);
516
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (existingCustomD2Schedule) {
517
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 existingCustomD2Schedule->remove();
518 }
519 1 }
520
521 struct ScheduleRuleIndexCompare
522 {
523 6185 bool operator()(const ScheduleRule& left, const ScheduleRule& right) const {
524 6185 return (left.ruleIndex() < right.ruleIndex());
525 }
526 };
527
528 6491 std::vector<ScheduleRule> ScheduleRuleset_Impl::scheduleRules() const {
529
3/3
✓ Branch 1 taken 6491 times.
✓ Branch 4 taken 6491 times.
✓ Branch 7 taken 6491 times.
6491 std::vector<ScheduleRule> result = this->getObject<ModelObject>().getModelObjectSources<ScheduleRule>(ScheduleRule::iddObjectType());
530
1/1
✓ Branch 3 taken 6491 times.
6491 std::sort(result.begin(), result.end(), ScheduleRuleIndexCompare());
531 6491 return result;
532 ✗ }
533
534 2840 bool ScheduleRuleset_Impl::setScheduleRuleIndex(ScheduleRule& scheduleRule, unsigned index) {
535
1/1
✓ Branch 1 taken 2840 times.
2840 std::vector<ScheduleRule> scheduleRules = this->scheduleRules();
536 2840 unsigned N = scheduleRules.size();
537
538 2840 boost::optional<unsigned> indexFound;
539
1/2
✓ Branch 0 taken 4360 times.
✗ Branch 1 not taken.
4360 for (unsigned i = 0; i < N; ++i) {
540
5/5
✓ Branch 2 taken 4360 times.
✓ Branch 5 taken 4360 times.
✓ Branch 8 taken 4360 times.
✓ Branch 10 taken 2840 times.
✓ Branch 11 taken 1520 times.
4360 if (scheduleRule.handle() == scheduleRules[i].handle()) {
541
1/1
✓ Branch 1 taken 2840 times.
2840 indexFound = i;
542
543
3/3
✓ Branch 1 taken 2840 times.
✓ Branch 3 taken 1412 times.
✓ Branch 4 taken 1428 times.
2840 if (indexFound == index) {
544
3/3
✓ Branch 1 taken 1412 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1411 times.
1412 if (scheduleRule.ruleIndex() == (int)index) {
545 1 return true;
546 }
547 }
548 // set index for target rule, when called in constructor this rule has no index
549
1/1
✓ Branch 1 taken 2839 times.
2839 scheduleRule.setRuleIndex(index);
550 2839 break;
551 }
552 }
553
554
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2839 times.
2839 if (!indexFound) {
555 ✗ return false;
556 }
557
558 2839 int increment = 0;
559
2/2
✓ Branch 0 taken 4367 times.
✓ Branch 1 taken 2839 times.
7206 for (unsigned i = 0; i < N; ++i) {
560
561 // have to move remaining rules up to fill hole
562
3/3
✓ Branch 1 taken 4367 times.
✓ Branch 3 taken 2839 times.
✓ Branch 4 taken 1528 times.
4367 if (i == indexFound) {
563 2839 increment--;
564 2839 continue;
565 }
566
567 // have to move this and remaining cells down
568
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 100 times.
1528 if (i == index) {
569
3/3
✓ Branch 1 taken 1428 times.
✓ Branch 3 taken 1426 times.
✓ Branch 4 taken 2 times.
1428 if (index < indexFound) {
570 1426 increment++;
571 }
572 }
573
574
2/2
✓ Branch 0 taken 1518 times.
✓ Branch 1 taken 10 times.
1528 if (increment != 0) {
575 OS_ASSERT(i + increment >= 0);
576 1518 unsigned newIndex = i + increment;
577
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1518 times.
✗ Branch 3 not taken.
1518 OS_ASSERT(newIndex < N);
578
1/1
✓ Branch 2 taken 1518 times.
1518 scheduleRules[i].setRuleIndex(newIndex);
579 }
580
581 // have to move this and remaining cells down
582
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 100 times.
1528 if (i == index) {
583
3/3
✓ Branch 1 taken 1428 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1426 times.
1428 if (index > indexFound) {
584 2 increment++;
585 }
586 }
587 }
588
589 2839 return true;
590 2840 }
591
592 6 std::vector<int> ScheduleRuleset_Impl::getActiveRuleIndices(const openstudio::Date& startDate, const openstudio::Date& endDate) const {
593
594 // need to check or adjust assumed base year on input date?
595
596 // populate dates to check
597 6 std::vector<openstudio::Date> dates;
598
2/3
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
6 if (startDate <= endDate) {
599
1/1
✓ Branch 1 taken 6 times.
6 openstudio::Date date = startDate;
600
3/3
✓ Branch 1 taken 2196 times.
✓ Branch 3 taken 2190 times.
✓ Branch 4 taken 6 times.
2196 while (date <= endDate) {
601
1/1
✓ Branch 1 taken 2190 times.
2190 dates.push_back(date);
602
2/2
✓ Branch 1 taken 2190 times.
✓ Branch 4 taken 2190 times.
2190 date += Time(1);
603 }
604 } else {
605 ✗ openstudio::Date date = startDate;
606 ✗ openstudio::Date endOfYear(MonthOfYear::Dec, 31);
607 ✗ while (date <= endOfYear) {
608 ✗ dates.push_back(date);
609 ✗ date += Time(1);
610 }
611 ✗ date = openstudio::Date(MonthOfYear::Jan, 1);
612 ✗ while (date <= endDate) {
613 ✗ dates.push_back(date);
614 ✗ date += Time(1);
615 }
616 }
617
618 6 unsigned numDates = dates.size();
619
620 // check if each rule contains each date
621
1/1
✓ Branch 1 taken 6 times.
6 std::vector<ScheduleRule> scheduleRules = this->scheduleRules();
622 6 unsigned numRules = scheduleRules.size();
623 6 std::vector<std::vector<bool>> test;
624
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (unsigned i = 0; i < numRules; ++i) {
625
2/2
✓ Branch 2 taken 6 times.
✓ Branch 5 taken 6 times.
6 test.push_back(scheduleRules[i].containsDates(dates));
626 }
627
628 // now create result
629
1/1
✓ Branch 1 taken 6 times.
6 std::vector<int> result(numDates, -1);
630
2/2
✓ Branch 0 taken 2190 times.
✓ Branch 1 taken 6 times.
2196 for (unsigned j = 0; j < numDates; ++j) {
631
2/2
✓ Branch 0 taken 1982 times.
✓ Branch 1 taken 730 times.
2712 for (unsigned i = 0; i < numRules; ++i) {
632
3/3
✓ Branch 2 taken 1982 times.
✓ Branch 5 taken 1460 times.
✓ Branch 6 taken 522 times.
1982 if (test[i][j]) {
633 1460 result[j] = i;
634 1460 break;
635 }
636 }
637 }
638
639 12 return result;
640 6 }
641
642 3 std::vector<ScheduleDay> ScheduleRuleset_Impl::getDaySchedules(const openstudio::Date& startDate, const openstudio::Date& endDate) const {
643 3 std::vector<ScheduleDay> result;
644
1/1
✓ Branch 1 taken 3 times.
3 ScheduleDay defaultDaySchedule = this->defaultDaySchedule();
645
1/1
✓ Branch 1 taken 3 times.
3 std::vector<ScheduleRule> scheduleRules = this->scheduleRules();
646
1/1
✓ Branch 1 taken 3 times.
3 std::vector<int> activeRuleIndices = this->getActiveRuleIndices(startDate, endDate);
647
2/2
✓ Branch 5 taken 1095 times.
✓ Branch 6 taken 3 times.
1098 for (int i : activeRuleIndices) {
648
2/2
✓ Branch 0 taken 365 times.
✓ Branch 1 taken 730 times.
1095 if (i == -1) {
649
1/1
✓ Branch 1 taken 365 times.
365 result.push_back(defaultDaySchedule);
650 } else {
651
2/2
✓ Branch 2 taken 730 times.
✓ Branch 5 taken 730 times.
730 result.push_back(scheduleRules[i].daySchedule());
652 }
653 }
654
655 6 return result;
656 3 }
657
658 ✗ bool ScheduleRuleset_Impl::moveToEnd(ScheduleRule& scheduleRule) {
659 ✗ std::vector<ScheduleRule> scheduleRules = this->scheduleRules();
660 ✗ return setScheduleRuleIndex(scheduleRule, scheduleRules.size() - 1);
661 ✗ }
662
663 ✗ void ScheduleRuleset_Impl::ensureNoLeapDays() {
664 ✗ for (ScheduleRule& scheduleRule : this->scheduleRules()) {
665 ✗ scheduleRule.ensureNoLeapDays();
666 ✗ }
667 ✗ }
668
669 12411 boost::optional<ScheduleDay> ScheduleRuleset_Impl::optionalDefaultDaySchedule() const {
670
2/2
✓ Branch 1 taken 12411 times.
✓ Branch 4 taken 12411 times.
12411 return getObject<ScheduleRuleset>().getModelObjectTarget<ScheduleDay>(OS_Schedule_RulesetFields::DefaultDayScheduleName);
671 }
672
673 } // namespace detail
674
675 1922 ScheduleRuleset::ScheduleRuleset(const Model& model) : Schedule(ScheduleRuleset::iddObjectType(), model) {
676
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 1922 times.
✗ Branch 5 not taken.
1922 OS_ASSERT(getImpl<detail::ScheduleRuleset_Impl>());
677
1/1
✓ Branch 1 taken 1922 times.
1922 ScheduleDay defaultDaySchedule(model);
678
2/2
✓ Branch 3 taken 1922 times.
✓ Branch 6 taken 1922 times.
1922 getImpl<detail::ScheduleRuleset_Impl>()->setPointer(OS_Schedule_RulesetFields::DefaultDayScheduleName, defaultDaySchedule.handle());
679 1922 }
680
681 34 ScheduleRuleset::ScheduleRuleset(const Model& model, double value) : Schedule(ScheduleRuleset::iddObjectType(), model) {
682
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
✗ Branch 5 not taken.
34 OS_ASSERT(getImpl<detail::ScheduleRuleset_Impl>());
683
1/1
✓ Branch 1 taken 34 times.
34 ScheduleDay defaultDaySchedule(model, value);
684
2/2
✓ Branch 3 taken 34 times.
✓ Branch 6 taken 34 times.
34 getImpl<detail::ScheduleRuleset_Impl>()->setPointer(OS_Schedule_RulesetFields::DefaultDayScheduleName, defaultDaySchedule.handle());
685 34 }
686
687 13010 IddObjectType ScheduleRuleset::iddObjectType() {
688
1/1
✓ Branch 1 taken 13010 times.
13010 IddObjectType result(IddObjectType::OS_Schedule_Ruleset);
689 13010 return result;
690 }
691
692 /// @cond
693
1/1
✓ Branch 3 taken 20376 times.
20376 ScheduleRuleset::ScheduleRuleset(std::shared_ptr<detail::ScheduleRuleset_Impl> impl) : Schedule(std::move(impl)) {}
694 /// @endcond
695
696 6915 ScheduleDay ScheduleRuleset::defaultDaySchedule() const {
697
1/1
✓ Branch 3 taken 6915 times.
6915 return getImpl<detail::ScheduleRuleset_Impl>()->defaultDaySchedule();
698 }
699
700 671 ScheduleDay ScheduleRuleset::summerDesignDaySchedule() const {
701
1/1
✓ Branch 3 taken 671 times.
671 return getImpl<detail::ScheduleRuleset_Impl>()->summerDesignDaySchedule();
702 }
703
704 ✗ bool ScheduleRuleset::isSummerDesignDayScheduleDefaulted() const {
705 ✗ return getImpl<detail::ScheduleRuleset_Impl>()->isSummerDesignDayScheduleDefaulted();
706 }
707
708 670 ScheduleDay ScheduleRuleset::winterDesignDaySchedule() const {
709
1/1
✓ Branch 3 taken 670 times.
670 return getImpl<detail::ScheduleRuleset_Impl>()->winterDesignDaySchedule();
710 }
711
712 ✗ bool ScheduleRuleset::isWinterDesignDayScheduleDefaulted() const {
713 ✗ return getImpl<detail::ScheduleRuleset_Impl>()->isWinterDesignDayScheduleDefaulted();
714 }
715
716 633 ScheduleDay ScheduleRuleset::holidaySchedule() const {
717
1/1
✓ Branch 3 taken 633 times.
633 return getImpl<detail::ScheduleRuleset_Impl>()->holidaySchedule();
718 }
719
720 ✗ bool ScheduleRuleset::isHolidayScheduleDefaulted() const {
721 ✗ return getImpl<detail::ScheduleRuleset_Impl>()->isHolidayScheduleDefaulted();
722 }
723
724 632 ScheduleDay ScheduleRuleset::customDay1Schedule() const {
725
1/1
✓ Branch 3 taken 632 times.
632 return getImpl<detail::ScheduleRuleset_Impl>()->customDay1Schedule();
726 }
727
728 ✗ bool ScheduleRuleset::isCustomDay1ScheduleDefaulted() const {
729 ✗ return getImpl<detail::ScheduleRuleset_Impl>()->isCustomDay1ScheduleDefaulted();
730 }
731
732 632 ScheduleDay ScheduleRuleset::customDay2Schedule() const {
733
1/1
✓ Branch 3 taken 632 times.
632 return getImpl<detail::ScheduleRuleset_Impl>()->customDay2Schedule();
734 }
735
736 ✗ bool ScheduleRuleset::isCustomDay2ScheduleDefaulted() const {
737 ✗ return getImpl<detail::ScheduleRuleset_Impl>()->isCustomDay2ScheduleDefaulted();
738 }
739
740 1237 bool ScheduleRuleset::setSummerDesignDaySchedule(const ScheduleDay& schedule) {
741
1/1
✓ Branch 3 taken 1237 times.
1237 return getImpl<detail::ScheduleRuleset_Impl>()->setSummerDesignDaySchedule(schedule);
742 }
743
744 1 void ScheduleRuleset::resetSummerDesignDaySchedule() {
745
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::ScheduleRuleset_Impl>()->resetSummerDesignDaySchedule();
746 }
747
748 1068 bool ScheduleRuleset::setWinterDesignDaySchedule(const ScheduleDay& schedule) {
749
1/1
✓ Branch 3 taken 1068 times.
1068 return getImpl<detail::ScheduleRuleset_Impl>()->setWinterDesignDaySchedule(schedule);
750 }
751
752 1 void ScheduleRuleset::resetWinterDesignDaySchedule() {
753
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::ScheduleRuleset_Impl>()->resetWinterDesignDaySchedule();
754 }
755
756 47 bool ScheduleRuleset::setHolidaySchedule(const ScheduleDay& schedule) {
757
1/1
✓ Branch 3 taken 47 times.
47 return getImpl<detail::ScheduleRuleset_Impl>()->setHolidaySchedule(schedule);
758 }
759
760 1 void ScheduleRuleset::resetHolidaySchedule() {
761
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::ScheduleRuleset_Impl>()->resetHolidaySchedule();
762 }
763
764 47 bool ScheduleRuleset::setCustomDay1Schedule(const ScheduleDay& schedule) {
765
1/1
✓ Branch 3 taken 47 times.
47 return getImpl<detail::ScheduleRuleset_Impl>()->setCustomDay1Schedule(schedule);
766 }
767
768 1 void ScheduleRuleset::resetCustomDay1Schedule() {
769
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::ScheduleRuleset_Impl>()->resetCustomDay1Schedule();
770 }
771
772 47 bool ScheduleRuleset::setCustomDay2Schedule(const ScheduleDay& schedule) {
773
1/1
✓ Branch 3 taken 47 times.
47 return getImpl<detail::ScheduleRuleset_Impl>()->setCustomDay2Schedule(schedule);
774 }
775
776 1 void ScheduleRuleset::resetCustomDay2Schedule() {
777
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::ScheduleRuleset_Impl>()->resetCustomDay2Schedule();
778 }
779
780 681 std::vector<ScheduleRule> ScheduleRuleset::scheduleRules() const {
781
1/1
✓ Branch 3 taken 681 times.
681 return getImpl<detail::ScheduleRuleset_Impl>()->scheduleRules();
782 }
783
784 2840 bool ScheduleRuleset::setScheduleRuleIndex(ScheduleRule& scheduleRule, unsigned index) {
785
1/1
✓ Branch 3 taken 2840 times.
2840 return getImpl<detail::ScheduleRuleset_Impl>()->setScheduleRuleIndex(scheduleRule, index);
786 }
787
788 3 std::vector<int> ScheduleRuleset::getActiveRuleIndices(const openstudio::Date& startDate, const openstudio::Date& endDate) const {
789
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ScheduleRuleset_Impl>()->getActiveRuleIndices(startDate, endDate);
790 }
791
792 3 std::vector<ScheduleDay> ScheduleRuleset::getDaySchedules(const openstudio::Date& startDate, const openstudio::Date& endDate) const {
793
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ScheduleRuleset_Impl>()->getDaySchedules(startDate, endDate);
794 }
795
796 ✗ bool ScheduleRuleset::moveToEnd(ScheduleRule& scheduleRule) {
797 ✗ return getImpl<detail::ScheduleRuleset_Impl>()->moveToEnd(scheduleRule);
798 }
799
800 } // namespace model
801 } // namespace openstudio
802