GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 87.4% 278 / 0 / 318
Functions: 84.1% 37 / 0 / 44
Branches: 70.1% 316 / 0 / 451

src/model/ScheduleDay.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 "ScheduleDay.hpp"
7 #include "ScheduleDay_Impl.hpp"
8
9 #include "Model.hpp"
10 #include "ScheduleTypeRegistry.hpp"
11 #include "ScheduleTypeLimits.hpp"
12 #include "ScheduleTypeLimits_Impl.hpp"
13 #include "Schedule.hpp"
14 #include "Schedule_Impl.hpp"
15 #include "ScheduleRuleset.hpp"
16 #include "ScheduleRuleset_Impl.hpp"
17 #include "ScheduleRule.hpp"
18 #include "ScheduleRule_Impl.hpp"
19 #include "Timestep.hpp"
20 #include "Timestep_Impl.hpp"
21
22 #include "../utilities/idf/IdfExtensibleGroup.hpp"
23 #include <utilities/idd/OS_Schedule_Day_FieldEnums.hxx>
24 #include <utilities/idd/OS_Schedule_Rule_FieldEnums.hxx>
25 #include <utilities/idd/IddEnums.hxx>
26
27 #include "../utilities/core/Assert.hpp"
28
29 #include "../utilities/time/Time.hpp"
30 #include "../utilities/data/TimeSeries.hpp"
31 #include "../utilities/data/Vector.hpp"
32
33 namespace openstudio {
34 namespace model {
35
36 namespace detail {
37
38 10369 ScheduleDay_Impl::ScheduleDay_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
39 10369 : ScheduleBase_Impl(idfObject, model, keepHandle) {
40
4/6
✓ Branch 1 taken 10369 times.
✓ Branch 4 taken 10369 times.
✓ Branch 7 taken 10369 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 10369 times.
✗ Branch 13 not taken.
10369 OS_ASSERT(idfObject.iddObject().type() == ScheduleDay::iddObjectType());
41
42 // connect signals
43
1/1
✓ Branch 1 taken 10369 times.
10369 this->ScheduleDay_Impl::onChange.connect<ScheduleDay_Impl, &ScheduleDay_Impl::clearCachedVariables>(this);
44 10369 }
45
46 3914 ScheduleDay_Impl::ScheduleDay_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
47 3914 : ScheduleBase_Impl(other, model, keepHandle) {
48
4/6
✓ Branch 1 taken 3914 times.
✓ Branch 4 taken 3914 times.
✓ Branch 7 taken 3914 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3914 times.
✗ Branch 13 not taken.
3914 OS_ASSERT(other.iddObject().type() == ScheduleDay::iddObjectType());
49
50 // connect signals
51
1/1
✓ Branch 1 taken 3914 times.
3914 this->ScheduleDay_Impl::onChange.connect<ScheduleDay_Impl, &ScheduleDay_Impl::clearCachedVariables>(this);
52 3914 }
53
54 13556 ScheduleDay_Impl::ScheduleDay_Impl(const ScheduleDay_Impl& other, Model_Impl* model, bool keepHandle)
55 13556 : ScheduleBase_Impl(other, model, keepHandle) {
56 // connect signals
57
1/1
✓ Branch 1 taken 13556 times.
13556 this->ScheduleDay_Impl::onChange.connect<ScheduleDay_Impl, &ScheduleDay_Impl::clearCachedVariables>(this);
58 13556 }
59
60 96 std::vector<IdfObject> ScheduleDay_Impl::remove() {
61
2/3
✓ Branch 1 taken 96 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96 times.
192 if (OptionalParentObject parent = this->parent()) {
62 ✗ LOG(Info, "Cannot remove " << briefDescription() << ", because that would invalidate " << parent->briefDescription() << ".");
63 ✗ return {};
64 96 }
65 96 return ParentObject_Impl::remove();
66 }
67
68 3663 boost::optional<ParentObject> ScheduleDay_Impl::parent() const {
69 3663 OptionalParentObject result;
70 // parented by ScheduleRuleset or ScheduleRule
71
2/2
✓ Branch 1 taken 3663 times.
✓ Branch 4 taken 3663 times.
3663 ModelObjectVector users = getObject<ScheduleDay>().getModelObjectSources<ModelObject>();
72
2/2
✓ Branch 1 taken 238 times.
✓ Branch 2 taken 3425 times.
3663 if (users.size() == 1u) {
73
3/3
✓ Branch 2 taken 238 times.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 157 times.
476 if (OptionalScheduleRuleset scheduleRuleset = users[0].optionalCast<ScheduleRuleset>()) {
74
2/2
✓ Branch 1 taken 81 times.
✓ Branch 4 taken 81 times.
81 result = *scheduleRuleset;
75 238 }
76
3/3
✓ Branch 2 taken 238 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 202 times.
476 if (OptionalScheduleRule scheduleRule = users[0].optionalCast<ScheduleRule>()) {
77
2/2
✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
36 result = *scheduleRule;
78 238 }
79 }
80 7326 return result;
81 3663 }
82
83 40 bool ScheduleDay_Impl::setParent(ParentObject& newParent) {
84
2/3
✓ Branch 1 taken 40 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
80 if (OptionalScheduleRule scheduleRule = newParent.optionalCast<ScheduleRule>()) {
85
3/4
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✓ Branch 9 taken 40 times.
✗ Branch 10 not taken.
40 if (getObject<ScheduleDay>().getModelObjectSources<ModelObject>().empty()) {
86
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 bool result = newParent.setPointer(OS_Schedule_RuleFields::DayScheduleName, handle());
87
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
✗ Branch 3 not taken.
40 OS_ASSERT(result);
88 40 return true;
89 }
90 40 }
91 ✗ return false;
92 }
93
94 51 const std::vector<std::string>& ScheduleDay_Impl::outputVariableNames() const {
95
3/4
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 50 times.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
51 static const std::vector<std::string> result;
96 51 return result;
97 }
98
99 38 IddObjectType ScheduleDay_Impl::iddObjectType() const {
100 38 return ScheduleDay::iddObjectType();
101 }
102
103 5130 boost::optional<ScheduleTypeLimits> ScheduleDay_Impl::scheduleTypeLimits() const {
104 OptionalScheduleTypeLimits result =
105
2/2
✓ Branch 1 taken 5130 times.
✓ Branch 4 taken 5130 times.
5130 getObject<ModelObject>().getModelObjectTarget<ScheduleTypeLimits>(OS_Schedule_DayFields::ScheduleTypeLimitsName);
106
2/2
✓ Branch 1 taken 2369 times.
✓ Branch 2 taken 2761 times.
5130 if (!result) {
107
4/4
✓ Branch 1 taken 2369 times.
✓ Branch 4 taken 2369 times.
✓ Branch 12 taken 21 times.
✓ Branch 13 taken 2364 times.
2385 for (const Schedule& schedule : getObject<ScheduleDay>().getModelObjectSources<Schedule>()) {
108
1/1
✓ Branch 1 taken 21 times.
21 result = schedule.scheduleTypeLimits();
109
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 16 times.
21 if (result) {
110 5 return result;
111 }
112 2369 }
113 }
114 5125 return result;
115 ✗ }
116
117 ✗ bool ScheduleDay_Impl::isScheduleTypeLimitsDefaulted() const {
118 ✗ return !getObject<ScheduleDay>().getModelObjectTarget<ScheduleTypeLimits>(OS_Schedule_DayFields::ScheduleTypeLimitsName);
119 }
120
121 2833 std::string ScheduleDay_Impl::interpolatetoTimestep() const {
122
1/1
✓ Branch 1 taken 2833 times.
2833 boost::optional<std::string> value = getString(OS_Schedule_DayFields::InterpolatetoTimestep, true);
123
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2833 times.
✗ Branch 4 not taken.
2833 OS_ASSERT(value);
124
2/2
✓ Branch 1 taken 2833 times.
✓ Branch 4 taken 2833 times.
5666 return value.get();
125 2833 }
126
127 3 bool ScheduleDay_Impl::isInterpolatetoTimestepDefaulted() const {
128 3 return isEmpty(OS_Schedule_DayFields::InterpolatetoTimestep);
129 }
130
131 42125 std::vector<openstudio::Time> ScheduleDay_Impl::times() const {
132
2/2
✓ Branch 1 taken 42029 times.
✓ Branch 2 taken 96 times.
42125 if (!m_cachedTimes) {
133
134 42029 std::vector<openstudio::Time> result;
135
136
3/3
✓ Branch 1 taken 42029 times.
✓ Branch 8 taken 188870 times.
✓ Branch 9 taken 42029 times.
230899 for (const IdfExtensibleGroup& group : extensibleGroups()) {
137
1/1
✓ Branch 1 taken 188870 times.
188870 OptionalInt hour = group.getInt(OS_Schedule_DayExtensibleFields::Hour, true);
138
1/1
✓ Branch 1 taken 188870 times.
188870 OptionalInt minute = group.getInt(OS_Schedule_DayExtensibleFields::Minute, true);
139
140
3/6
✓ Branch 0 taken 188870 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 188870 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 188870 times.
✗ Branch 5 not taken.
377740 if (hour && minute) {
141
3/3
✓ Branch 1 taken 188870 times.
✓ Branch 4 taken 188870 times.
✓ Branch 7 taken 188870 times.
188870 openstudio::Time time(0, *hour, *minute);
142
5/8
✓ Branch 1 taken 188870 times.
✓ Branch 3 taken 188870 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 188870 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 188870 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 188870 times.
188870 if (time.totalMinutes() <= 0.5 || time.totalDays() > 1.0) {
143 ✗ LOG(Error, "Time " << time << " in " << briefDescription() << " is out of range.");
144 } else {
145
1/1
✓ Branch 1 taken 188870 times.
188870 result.push_back(time);
146 }
147 } else {
148 ✗ LOG(Error, "Could not read time " << group.groupIndex() << " in " << briefDescription() << ".");
149 }
150 42029 }
151
152
1/1
✓ Branch 1 taken 42029 times.
42029 m_cachedTimes = result;
153 42029 }
154
155 42125 return m_cachedTimes.get();
156 }
157
158 2858 std::vector<double> ScheduleDay_Impl::values() const {
159
2/2
✓ Branch 1 taken 2769 times.
✓ Branch 2 taken 89 times.
2858 if (!m_cachedValues) {
160
161 2769 std::vector<double> result;
162
163
3/3
✓ Branch 1 taken 2769 times.
✓ Branch 8 taken 11585 times.
✓ Branch 9 taken 2769 times.
14354 for (const IdfExtensibleGroup& group : extensibleGroups()) {
164
1/1
✓ Branch 1 taken 11585 times.
11585 OptionalDouble value = group.getDouble(OS_Schedule_DayExtensibleFields::ValueUntilTime, true);
165
166
1/2
✓ Branch 0 taken 11585 times.
✗ Branch 1 not taken.
11585 if (value) {
167
2/2
✓ Branch 1 taken 11585 times.
✓ Branch 4 taken 11585 times.
11585 result.push_back(*value);
168 } else {
169 ✗ LOG(Error, "Could not read value " << group.groupIndex() << " in " << briefDescription() << ".");
170 }
171 2769 }
172
173
1/1
✓ Branch 1 taken 2769 times.
2769 m_cachedValues = result;
174 2769 }
175
176 2858 return m_cachedValues.get();
177 }
178
179 152 double ScheduleDay_Impl::getValue(const openstudio::Time& time) const {
180
8/8
✓ Branch 1 taken 152 times.
✓ Branch 3 taken 144 times.
✓ Branch 4 taken 8 times.
✓ Branch 6 taken 144 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 136 times.
✓ Branch 10 taken 16 times.
✓ Branch 11 taken 136 times.
152 if (time.totalMinutes() < 0.0 || time.totalDays() > 1.0) {
181 16 return 0.0;
182 }
183
184 // We'll calculate the entire day when we request a single value but that's on purpose:
185 // * We're talking about max 60 timesteps * 24 hours = 1440 points,
186 // but realistically more often than not you'll have a timestep of 6 (our default) or 4 so 96 to 144 points. So not a lot of points
187 // * We cache the timeSeries, and,
188 // * More often than not, the use case is to do it for the entire day anyways (eg: openstudio-standards to determine occupancy schedules)
189
1/1
✓ Branch 1 taken 136 times.
136 TimeSeries ts = this->timeSeries();
190
191
1/1
✓ Branch 1 taken 136 times.
136 DateTimeVector dateTimes = ts.dateTimes();
192
1/1
✓ Branch 1 taken 136 times.
136 Vector values = ts.values();
193
194 136 const unsigned N = dateTimes.size();
195
2/4
✓ Branch 1 taken 136 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 136 times.
✗ Branch 6 not taken.
136 OS_ASSERT(values.size() == N);
196
197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
136 if (N == 0) {
198 ✗ return 0.0;
199 }
200
201
1/1
✓ Branch 1 taken 136 times.
136 Vector x(N + 2);
202
1/1
✓ Branch 1 taken 136 times.
136 Vector y(N + 2);
203
204
1/1
✓ Branch 1 taken 136 times.
136 x[0] = 0.0;
205
1/1
✓ Branch 1 taken 136 times.
136 std::string interpolatetoTimestep = this->interpolatetoTimestep();
206
4/4
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
✓ Branch 7 taken 76 times.
✓ Branch 8 taken 60 times.
272 if (istringEqual("No", interpolatetoTimestep)) {
207
2/2
✓ Branch 1 taken 76 times.
✓ Branch 4 taken 76 times.
76 y[0] = values[0];
208
4/4
✓ Branch 1 taken 60 times.
✓ Branch 4 taken 60 times.
✓ Branch 7 taken 30 times.
✓ Branch 8 taken 30 times.
120 } else if (istringEqual("Average", interpolatetoTimestep)) {
209
2/2
✓ Branch 1 taken 30 times.
✓ Branch 4 taken 30 times.
30 y[0] = values[0];
210
3/4
✓ Branch 1 taken 30 times.
✓ Branch 4 taken 30 times.
✓ Branch 7 taken 30 times.
✗ Branch 8 not taken.
60 } else if (istringEqual("Linear", interpolatetoTimestep)) {
211
1/1
✓ Branch 1 taken 30 times.
30 y[0] = 0.0;
212 }
213
214
2/2
✓ Branch 0 taken 19152 times.
✓ Branch 1 taken 136 times.
19288 for (unsigned i = 0; i < N; ++i) {
215
1/1
✓ Branch 2 taken 19152 times.
19152 openstudio::Time t = dateTimes[i].time();
216
3/3
✓ Branch 1 taken 19152 times.
✓ Branch 3 taken 136 times.
✓ Branch 4 taken 19016 times.
19152 if (t.totalDays() == 0.0) { // this is 00:00:00 from the next day
217
2/2
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
136 t = openstudio::Time(0, 24, 0);
218 }
219
220
2/2
✓ Branch 1 taken 19152 times.
✓ Branch 4 taken 19152 times.
19152 x[i + 1] = t.totalDays();
221
2/2
✓ Branch 1 taken 19152 times.
✓ Branch 4 taken 19152 times.
19152 y[i + 1] = values[i];
222 }
223
224
1/1
✓ Branch 1 taken 136 times.
136 x[N + 1] = 1.0;
225
2/2
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
136 y[N + 1] = values[N - 1];
226
227
2/2
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
136 double result = interp(x, y, time.totalDays(), HoldNextInterp, NoneExtrap);
228
229 136 return result;
230 136 }
231
232 149 openstudio::TimeSeries ScheduleDay_Impl::timeSeries() const {
233
2/2
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 128 times.
149 if (!m_cachedTimeSeries) {
234
235 int numberOfTimestepsPerHour;
236
4/4
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 13 times.
✓ Branch 9 taken 8 times.
42 if (boost::optional<Timestep> timestep = this->model().getOptionalUniqueModelObject<Timestep>()) {
237
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 numberOfTimestepsPerHour = timestep->numberOfTimestepsPerHour();
238 } else {
239 8 numberOfTimestepsPerHour = 6;
240 21 }
241
242
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 Date startDate(Date(MonthOfYear(MonthOfYear::Jan), 1)); // this is arbitrary
243 21 int minutes = 60 / numberOfTimestepsPerHour;
244
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 DateTime startDateTime(startDate, Time(0, 0, 0));
245
246 21 DateTimeVector tsDateTimes;
247
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 21 times.
525 for (size_t hour = 0; hour < 24; ++hour) {
248
2/2
✓ Branch 0 taken 2952 times.
✓ Branch 1 taken 504 times.
3456 for (size_t minute = minutes; minute <= 60; minute += minutes) {
249
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 2448 times.
2952 if (minute == 60) {
250
1/1
✓ Branch 1 taken 504 times.
504 openstudio::Time t(0, hour + 1, 0);
251
2/2
✓ Branch 1 taken 504 times.
✓ Branch 4 taken 504 times.
504 tsDateTimes.push_back(startDateTime + t);
252 } else {
253
1/1
✓ Branch 1 taken 2448 times.
2448 openstudio::Time t(0, hour, minute);
254
2/2
✓ Branch 1 taken 2448 times.
✓ Branch 4 taken 2448 times.
2448 tsDateTimes.push_back(startDateTime + t);
255 }
256 }
257 }
258
259
1/1
✓ Branch 1 taken 21 times.
21 std::vector<double> values = this->values(); // these are already sorted
260
1/1
✓ Branch 1 taken 21 times.
21 std::vector<openstudio::Time> times = this->times(); // these are already sorted
261
262 21 const unsigned N = times.size();
263
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 4 not taken.
21 OS_ASSERT(values.size() == N);
264
265
1/1
✓ Branch 1 taken 21 times.
21 TimeSeries result;
266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (N == 0) {
267 ✗ return result;
268 }
269
270
1/1
✓ Branch 1 taken 21 times.
21 Vector x(N + 2);
271
1/1
✓ Branch 1 taken 21 times.
21 Vector y(N + 2);
272
273
1/1
✓ Branch 1 taken 21 times.
21 x[0] = -0.000001;
274
1/1
✓ Branch 1 taken 21 times.
21 y[0] = 0.0;
275
276
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 21 times.
78 for (unsigned i = 0; i < N; ++i) {
277
2/2
✓ Branch 2 taken 57 times.
✓ Branch 5 taken 57 times.
57 x[i + 1] = times[i].totalSeconds();
278
1/1
✓ Branch 2 taken 57 times.
57 y[i + 1] = values[i];
279 }
280
281
1/1
✓ Branch 1 taken 21 times.
21 x[N + 1] = 86400.000001;
282
1/1
✓ Branch 1 taken 21 times.
21 y[N + 1] = 0.0;
283
284
1/1
✓ Branch 1 taken 21 times.
21 std::string interpolatetoTimestep = this->interpolatetoTimestep();
285
1/1
✓ Branch 2 taken 21 times.
21 Vector tsValues(tsDateTimes.size());
286
2/2
✓ Branch 1 taken 2952 times.
✓ Branch 2 taken 21 times.
2973 for (unsigned j = 0; j < tsDateTimes.size(); ++j) {
287
1/1
✓ Branch 2 taken 2952 times.
2952 openstudio::Time t = tsDateTimes[j].time();
288
3/3
✓ Branch 1 taken 2952 times.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 2931 times.
2952 if (t.totalDays() == 0.0) { // this is 00:00:00 from the next day
289
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 t = openstudio::Time(0, 24, 0);
290 }
291
292
4/4
✓ Branch 1 taken 2952 times.
✓ Branch 4 taken 2952 times.
✓ Branch 7 taken 1656 times.
✓ Branch 8 taken 1296 times.
5904 if (istringEqual("No", interpolatetoTimestep)) {
293
3/3
✓ Branch 1 taken 1656 times.
✓ Branch 4 taken 1656 times.
✓ Branch 7 taken 1656 times.
1656 tsValues[j] = interp(x, y, t.totalSeconds(), HoldNextInterp, NoneExtrap);
294
4/4
✓ Branch 1 taken 1296 times.
✓ Branch 4 taken 1296 times.
✓ Branch 7 taken 648 times.
✓ Branch 8 taken 648 times.
2592 } else if (istringEqual("Average", interpolatetoTimestep)) {
295 648 double minutes = 60.0 / numberOfTimestepsPerHour;
296 648 double ti = minutes * 60.0; // total seconds of the timestep interval
297
3/3
✓ Branch 1 taken 648 times.
✓ Branch 4 taken 648 times.
✓ Branch 7 taken 648 times.
648 tsValues[j] = interp(x, y, t.totalSeconds(), AverageInterp, NoneExtrap, ti);
298
3/4
✓ Branch 1 taken 648 times.
✓ Branch 4 taken 648 times.
✓ Branch 7 taken 648 times.
✗ Branch 8 not taken.
1296 } else if (istringEqual("Linear", interpolatetoTimestep)) {
299
3/3
✓ Branch 1 taken 648 times.
✓ Branch 4 taken 648 times.
✓ Branch 7 taken 648 times.
648 tsValues[j] = interp(x, y, t.totalSeconds(), LinearInterp, NoneExtrap);
300 }
301 }
302
303
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 result = TimeSeries(tsDateTimes, tsValues, "");
304
1/1
✓ Branch 1 taken 21 times.
21 m_cachedTimeSeries = result;
305 21 }
306
307 149 return m_cachedTimeSeries.get();
308 }
309
310 7588 bool ScheduleDay_Impl::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) {
311
4/5
✓ Branch 1 taken 7588 times.
✓ Branch 4 taken 7588 times.
✓ Branch 7 taken 7588 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7588 times.
7588 if (scheduleTypeLimits.model() != model()) {
312 ✗ return false;
313 }
314
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7588 times.
7588 if (!candidateIsCompatibleWithCurrentUse(scheduleTypeLimits)) {
315 ✗ return false;
316 }
317
2/2
✓ Branch 1 taken 7588 times.
✓ Branch 4 taken 7588 times.
7588 return setPointer(OS_Schedule_DayFields::ScheduleTypeLimitsName, scheduleTypeLimits.handle());
318 }
319
320 ✗ bool ScheduleDay_Impl::resetScheduleTypeLimits() {
321 ✗ if (okToResetScheduleTypeLimits()) {
322 ✗ return setString(OS_Schedule_DayFields::ScheduleTypeLimitsName, "");
323 }
324 ✗ return false;
325 }
326
327 131 bool ScheduleDay_Impl::setInterpolatetoTimestep(const std::string& interpolatetoTimestep) {
328 131 return setString(OS_Schedule_DayFields::InterpolatetoTimestep, interpolatetoTimestep);
329 }
330
331 ✗ void ScheduleDay_Impl::resetInterpolatetoTimestep() {
332 ✗ bool result = setString(OS_Schedule_DayFields::InterpolatetoTimestep, "");
333 ✗ OS_ASSERT(result);
334 ✗ }
335
336 39303 bool ScheduleDay_Impl::addValue(const openstudio::Time& untilTime, double value) {
337
8/8
✓ Branch 1 taken 39303 times.
✓ Branch 3 taken 39299 times.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 39299 times.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 39298 times.
✓ Branch 10 taken 5 times.
✓ Branch 11 taken 39298 times.
39303 if (untilTime.totalMinutes() <= 0.5 || untilTime.totalDays() > 1.0) {
338 5 return false;
339 }
340
341 // Check validity, cannot be NaN, Inf, etc
342
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 39294 times.
39298 if (std::isinf(value)) {
343
7/7
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 14 taken 4 times.
✓ Branch 17 taken 4 times.
✓ Branch 20 taken 4 times.
4 LOG(Warn, "Cannot setDouble to Infinity for " << this->briefDescription());
344 4 return false;
345
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 39292 times.
39294 } else if (std::isnan(value)) {
346
7/7
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 14 taken 2 times.
✓ Branch 17 taken 2 times.
✓ Branch 20 taken 2 times.
2 LOG(Warn, "Cannot setDouble to a NaN for " << this->briefDescription());
347 2 return false;
348 }
349
350
2/2
✓ Branch 1 taken 39292 times.
✓ Branch 4 taken 39292 times.
39292 int untilHours = untilTime.hours() + 24 * untilTime.days();
351
2/2
✓ Branch 1 taken 39292 times.
✓ Branch 4 taken 39292 times.
39292 int untilMinutes = untilTime.minutes() + (int)std::floor((untilTime.seconds() / 60.0) + 0.5);
352
353
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 39056 times.
39292 if (untilMinutes >= 60) {
354 236 untilHours += 1;
355 236 untilMinutes += -60;
356 }
357
358 // use set to determine whether to overwrite or insert, and where
359 39292 std::set<openstudio::Time> times;
360 39292 std::pair<std::set<openstudio::Time>::const_iterator, bool> insertResult;
361
3/3
✓ Branch 1 taken 39292 times.
✓ Branch 8 taken 177389 times.
✓ Branch 9 taken 39292 times.
216681 for (const openstudio::Time& time : this->times()) {
362
1/1
✓ Branch 1 taken 177389 times.
177389 insertResult = times.insert(time);
363
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 177389 times.
✗ Branch 3 not taken.
177389 OS_ASSERT(insertResult.second);
364 39292 }
365
366
1/1
✓ Branch 1 taken 39292 times.
39292 insertResult = times.insert(untilTime);
367 39292 auto index = (unsigned)std::distance<std::set<openstudio::Time>::const_iterator>(times.begin(), insertResult.first);
368
2/4
✓ Branch 1 taken 39292 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39292 times.
✗ Branch 6 not taken.
39292 OS_ASSERT(index <= numExtensibleGroups());
369 39292 bool result(true);
370
2/2
✓ Branch 0 taken 34170 times.
✓ Branch 1 taken 5122 times.
39292 if (insertResult.second) {
371 // new time--insert an extensible group
372 34170 std::vector<std::string> groupValues;
373
2/2
✓ Branch 1 taken 34170 times.
✓ Branch 4 taken 34170 times.
34170 groupValues.push_back(boost::lexical_cast<std::string>(untilHours));
374
2/2
✓ Branch 1 taken 34170 times.
✓ Branch 4 taken 34170 times.
34170 groupValues.push_back(boost::lexical_cast<std::string>(untilMinutes));
375
2/2
✓ Branch 1 taken 34170 times.
✓ Branch 4 taken 34170 times.
34170 groupValues.push_back(toString(value));
376
377
1/1
✓ Branch 1 taken 34170 times.
34170 IdfExtensibleGroup group = insertExtensibleGroup(index, groupValues);
378
2/4
✓ Branch 1 taken 34170 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 34170 times.
✗ Branch 6 not taken.
34170 OS_ASSERT(!group.empty());
379 34170 } else {
380 // time already exists, overwrite value
381
1/1
✓ Branch 1 taken 5122 times.
5122 IdfExtensibleGroup group = getExtensibleGroup(index);
382
1/1
✓ Branch 1 taken 5122 times.
5122 result = group.setDouble(OS_Schedule_DayExtensibleFields::ValueUntilTime, value);
383 5122 }
384
385 39292 return result;
386 39292 }
387
388 54 boost::optional<double> ScheduleDay_Impl::removeValue(const openstudio::Time& time) {
389
390 54 boost::optional<unsigned> timeIndex;
391
392
1/1
✓ Branch 1 taken 54 times.
54 std::vector<openstudio::Time> times = this->times();
393
2/2
✓ Branch 1 taken 255 times.
✓ Branch 2 taken 2 times.
257 for (unsigned i = 0; i < times.size(); ++i) {
394
3/3
✓ Branch 2 taken 255 times.
✓ Branch 4 taken 52 times.
✓ Branch 5 taken 203 times.
255 if (times[i] == time) {
395
1/1
✓ Branch 1 taken 52 times.
52 timeIndex = i;
396 52 break;
397 }
398 }
399
400
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 52 times.
54 if (!timeIndex) {
401 2 return boost::none;
402 }
403
404 52 boost::optional<double> result;
405
406
1/1
✓ Branch 1 taken 52 times.
52 std::vector<double> values = this->values();
407
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 52 times.
✗ Branch 5 not taken.
52 OS_ASSERT(values.size() == times.size());
408
409
1/1
✓ Branch 1 taken 52 times.
52 clearValues();
410
2/2
✓ Branch 1 taken 1203 times.
✓ Branch 2 taken 52 times.
1255 for (unsigned i = 0; i < times.size(); ++i) {
411
3/3
✓ Branch 1 taken 1203 times.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 1151 times.
1203 if (i == *timeIndex) {
412
1/1
✓ Branch 2 taken 52 times.
52 result = values[i];
413 } else {
414
1/1
✓ Branch 3 taken 1151 times.
1151 addValue(times[i], values[i]);
415 }
416 }
417
418 52 return result;
419 54 }
420
421 4927 void ScheduleDay_Impl::clearValues() {
422
1/1
✓ Branch 1 taken 4927 times.
4927 this->clearExtensibleGroups();
423
424
2/2
✓ Branch 1 taken 4927 times.
✓ Branch 4 taken 4927 times.
4927 addValue(Time(1, 0), 0.0);
425 4927 }
426
427 ✗ void ScheduleDay_Impl::ensureNoLeapDays() {
428 // nothing to do
429 ✗ }
430
431 7588 bool ScheduleDay_Impl::candidateIsCompatibleWithCurrentUse(const ScheduleTypeLimits& candidate) const {
432 // currently only check ScheduleDay against Schedules
433
2/2
✓ Branch 1 taken 7588 times.
✓ Branch 4 taken 7588 times.
7588 ScheduleVector users = getObject<ScheduleDay>().getModelObjectSources<Schedule>();
434
2/2
✓ Branch 5 taken 4307 times.
✓ Branch 6 taken 7588 times.
11895 for (const Schedule& user : users) {
435
2/3
✓ Branch 1 taken 4307 times.
✓ Branch 3 taken 4307 times.
✗ Branch 4 not taken.
8614 if (OptionalScheduleTypeLimits userLimits = user.scheduleTypeLimits()) {
436
3/4
✓ Branch 1 taken 4307 times.
✓ Branch 4 taken 4307 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4307 times.
4307 if (!isCompatible(*userLimits, candidate)) {
437 ✗ return false;
438 }
439 4307 }
440 }
441 7588 return true;
442 7588 }
443
444 ✗ bool ScheduleDay_Impl::okToResetScheduleTypeLimits() const {
445 ✗ for (const ModelObject& user : getObject<ScheduleDay>().getModelObjectSources<ModelObject>()) {
446 // schedules using this ScheduleDay need to also have no limits
447 ✗ if (user.optionalCast<Schedule>() && user.cast<Schedule>().scheduleTypeLimits()) {
448 ✗ return false;
449 }
450 ✗ if (user.optionalCast<ScheduleRule>()) {
451 // test indirect use through ScheduleRule
452 ✗ if (user.cast<ScheduleRule>().scheduleRuleset().scheduleTypeLimits()) {
453 ✗ return false;
454 }
455 ✗ } else if (!user.optionalCast<ScheduleBase>()) {
456 // other non-schedule users impose limits
457 ✗ return false;
458 }
459 ✗ }
460 ✗ return true;
461 }
462
463 62287 void ScheduleDay_Impl::clearCachedVariables() {
464 62287 m_cachedTimes.reset();
465 62287 m_cachedValues.reset();
466 62287 m_cachedTimeSeries.reset();
467 62287 }
468
469 179 void ScheduleDay_Impl::clearCachedTimeSeries() {
470 179 m_cachedTimeSeries.reset();
471 179 }
472
473 } // namespace detail
474
475 6362 ScheduleDay::ScheduleDay(const Model& model) : ScheduleBase(ScheduleDay::iddObjectType(), model) {
476
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 6362 times.
✗ Branch 5 not taken.
6362 OS_ASSERT(getImpl<detail::ScheduleDay_Impl>());
477
478
2/2
✓ Branch 1 taken 6362 times.
✓ Branch 4 taken 6362 times.
6362 addValue(Time(1, 0), 0.0);
479 6362 }
480
481 34 ScheduleDay::ScheduleDay(const Model& model, double value) : ScheduleBase(ScheduleDay::iddObjectType(), model) {
482
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
✗ Branch 5 not taken.
34 OS_ASSERT(getImpl<detail::ScheduleDay_Impl>());
483
484
2/2
✓ Branch 1 taken 34 times.
✓ Branch 4 taken 34 times.
34 addValue(Time(1, 0), value);
485 34 }
486
487 28648 IddObjectType ScheduleDay::iddObjectType() {
488
1/1
✓ Branch 1 taken 28648 times.
28648 IddObjectType result(IddObjectType::OS_Schedule_Day);
489 28648 return result;
490 }
491
492 ✗ bool ScheduleDay::isScheduleTypeLimitsDefaulted() const {
493 ✗ return getImpl<detail::ScheduleDay_Impl>()->isScheduleTypeLimitsDefaulted();
494 }
495
496 2676 std::string ScheduleDay::interpolatetoTimestep() const {
497
1/1
✓ Branch 3 taken 2676 times.
2676 return getImpl<detail::ScheduleDay_Impl>()->interpolatetoTimestep();
498 }
499
500 3 bool ScheduleDay::isInterpolatetoTimestepDefaulted() const {
501
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::ScheduleDay_Impl>()->isInterpolatetoTimestepDefaulted();
502 }
503
504 2758 std::vector<openstudio::Time> ScheduleDay::times() const {
505
1/1
✓ Branch 3 taken 2758 times.
2758 return getImpl<detail::ScheduleDay_Impl>()->times();
506 }
507
508 2785 std::vector<double> ScheduleDay::values() const {
509
1/1
✓ Branch 3 taken 2785 times.
2785 return getImpl<detail::ScheduleDay_Impl>()->values();
510 }
511
512 152 double ScheduleDay::getValue(const openstudio::Time& time) const {
513
1/1
✓ Branch 3 taken 152 times.
152 return getImpl<detail::ScheduleDay_Impl>()->getValue(time);
514 }
515
516 13 openstudio::TimeSeries ScheduleDay::timeSeries() const {
517
1/1
✓ Branch 3 taken 13 times.
13 return getImpl<detail::ScheduleDay_Impl>()->timeSeries();
518 }
519
520 131 bool ScheduleDay::setInterpolatetoTimestep(const std::string& interpolatetoTimestep) {
521
1/1
✓ Branch 3 taken 131 times.
131 return getImpl<detail::ScheduleDay_Impl>()->setInterpolatetoTimestep(interpolatetoTimestep);
522 }
523
524 ✗ void ScheduleDay::resetInterpolatetoTimestep() {
525 ✗ getImpl<detail::ScheduleDay_Impl>()->resetInterpolatetoTimestep();
526 ✗ }
527
528 33225 bool ScheduleDay::addValue(const openstudio::Time& untilTime, double value) {
529
1/1
✓ Branch 3 taken 33225 times.
33225 return getImpl<detail::ScheduleDay_Impl>()->addValue(untilTime, value);
530 }
531
532 54 boost::optional<double> ScheduleDay::removeValue(const openstudio::Time& time) {
533
1/1
✓ Branch 3 taken 54 times.
54 return getImpl<detail::ScheduleDay_Impl>()->removeValue(time);
534 }
535
536 4875 void ScheduleDay::clearValues() {
537
1/1
✓ Branch 3 taken 4875 times.
4875 getImpl<detail::ScheduleDay_Impl>()->clearValues();
538 4875 }
539
540 /// @cond
541
1/1
✓ Branch 3 taken 56389 times.
56389 ScheduleDay::ScheduleDay(std::shared_ptr<detail::ScheduleDay_Impl> impl) : ScheduleBase(std::move(impl)) {}
542 /// @endcond
543
544 } // namespace model
545 } // namespace openstudio
546