GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 56.6% 107 / 0 / 189
Functions: 40.5% 15 / 0 / 37
Branches: 48.3% 128 / 0 / 265

src/model/ScheduleVariableInterval.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 "ScheduleVariableInterval.hpp"
7 #include "ScheduleVariableInterval_Impl.hpp"
8 #include "Model.hpp"
9 #include "ModelExtensibleGroup.hpp"
10
11 #include "ScheduleTypeLimits.hpp"
12 #include "ScheduleTypeLimits_Impl.hpp"
13
14 #include <utilities/idd/OS_Schedule_VariableInterval_FieldEnums.hxx>
15 #include <utilities/idd/IddEnums.hxx>
16
17 #include "../utilities/time/DateTime.hpp"
18 #include "../utilities/data/TimeSeries.hpp"
19 #include "../utilities/core/Assert.hpp"
20
21 namespace openstudio {
22 namespace model {
23
24 namespace detail {
25
26 8 ScheduleVariableInterval_Impl::ScheduleVariableInterval_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
27 8 : ScheduleInterval_Impl(idfObject, model, keepHandle) {
28
4/6
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 8 times.
✗ Branch 13 not taken.
8 OS_ASSERT(idfObject.iddObject().type() == ScheduleVariableInterval::iddObjectType());
29 8 }
30
31 ✗ ScheduleVariableInterval_Impl::ScheduleVariableInterval_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model,
32 ✗ bool keepHandle)
33 ✗ : ScheduleInterval_Impl(other, model, keepHandle) {
34 ✗ OS_ASSERT(other.iddObject().type() == ScheduleVariableInterval::iddObjectType());
35 ✗ }
36
37 2 ScheduleVariableInterval_Impl::ScheduleVariableInterval_Impl(const ScheduleVariableInterval_Impl& other, Model_Impl* model, bool keepHandle)
38 2 : ScheduleInterval_Impl(other, model, keepHandle) {}
39
40 ✗ IddObjectType ScheduleVariableInterval_Impl::iddObjectType() const {
41 ✗ return ScheduleVariableInterval::iddObjectType();
42 }
43
44 2 boost::optional<ScheduleTypeLimits> ScheduleVariableInterval_Impl::scheduleTypeLimits() const {
45
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 return getObject<ModelObject>().getModelObjectTarget<ScheduleTypeLimits>(OS_Schedule_VariableIntervalFields::ScheduleTypeLimitsName);
46 }
47
48 ✗ bool ScheduleVariableInterval_Impl::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) {
49 ✗ if (scheduleTypeLimits.model() != model()) {
50 ✗ return false;
51 }
52 ✗ return setPointer(OS_Schedule_VariableIntervalFields::ScheduleTypeLimitsName, scheduleTypeLimits.handle());
53 }
54
55 ✗ bool ScheduleVariableInterval_Impl::resetScheduleTypeLimits() {
56 // can only reset if not used
57 ✗ if (okToResetScheduleTypeLimits()) {
58 ✗ return setString(OS_Schedule_VariableIntervalFields::ScheduleTypeLimitsName, "");
59 }
60 ✗ return false;
61 }
62
63 2 bool ScheduleVariableInterval_Impl::interpolatetoTimestep() const {
64
1/1
✓ Branch 1 taken 2 times.
2 boost::optional<std::string> value = getString(OS_Schedule_VariableIntervalFields::InterpolatetoTimestep, true);
65
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(value);
66
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 return openstudio::istringEqual(value.get(), "Yes");
67 2 }
68
69 ✗ bool ScheduleVariableInterval_Impl::isInterpolatetoTimestepDefaulted() const {
70 ✗ return isEmpty(OS_Schedule_VariableIntervalFields::InterpolatetoTimestep);
71 }
72
73 10 int ScheduleVariableInterval_Impl::startMonth() const {
74
1/1
✓ Branch 1 taken 10 times.
10 boost::optional<int> value = getInt(OS_Schedule_VariableIntervalFields::StartMonth, true);
75
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 4 not taken.
10 OS_ASSERT(value);
76
1/1
✓ Branch 1 taken 10 times.
20 return value.get();
77 }
78
79 ✗ int ScheduleVariableInterval_Impl::startDay() const {
80 ✗ boost::optional<int> value = getInt(OS_Schedule_VariableIntervalFields::StartDay, true);
81 ✗ OS_ASSERT(value);
82 ✗ return value.get();
83 }
84
85 5 double ScheduleVariableInterval_Impl::outOfRangeValue() const {
86
1/1
✓ Branch 1 taken 5 times.
5 boost::optional<double> value = getDouble(OS_Schedule_VariableIntervalFields::OutOfRangeValue, true);
87
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 4 not taken.
5 OS_ASSERT(value);
88
1/1
✓ Branch 1 taken 5 times.
10 return value.get();
89 }
90
91 ✗ bool ScheduleVariableInterval_Impl::isOutOfRangeValueDefaulted() const {
92 ✗ return isEmpty(OS_Schedule_VariableIntervalFields::OutOfRangeValue);
93 }
94
95 ✗ bool ScheduleVariableInterval_Impl::setInterpolatetoTimestep(bool interpolatetoTimestep, bool driverMethod) {
96 ✗ bool result = false;
97 ✗ if (interpolatetoTimestep) {
98 ✗ result = setString(OS_Schedule_VariableIntervalFields::InterpolatetoTimestep, "Yes", driverMethod);
99 } else {
100 ✗ result = setString(OS_Schedule_VariableIntervalFields::InterpolatetoTimestep, "No", driverMethod);
101 }
102 ✗ OS_ASSERT(result);
103 ✗ return result;
104 }
105
106 ✗ void ScheduleVariableInterval_Impl::resetInterpolatetoTimestep(bool driverMethod) {
107 ✗ bool result = setString(OS_Schedule_VariableIntervalFields::InterpolatetoTimestep, "", driverMethod);
108 ✗ OS_ASSERT(result);
109 ✗ }
110
111 8 bool ScheduleVariableInterval_Impl::setStartMonth(int startMonth, bool driverMethod) {
112 8 bool result = setInt(OS_Schedule_VariableIntervalFields::StartMonth, startMonth, driverMethod);
113 8 return result;
114 }
115
116 8 bool ScheduleVariableInterval_Impl::setStartDay(int startDay, bool driverMethod) {
117 8 bool result = setInt(OS_Schedule_VariableIntervalFields::StartDay, startDay, driverMethod);
118 8 return result;
119 }
120
121 8 bool ScheduleVariableInterval_Impl::setOutOfRangeValue(double outOfRangeValue, bool driverMethod) {
122 8 bool result = setDouble(OS_Schedule_VariableIntervalFields::OutOfRangeValue, outOfRangeValue, driverMethod);
123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 OS_ASSERT(result);
124 8 return result;
125 }
126
127 ✗ void ScheduleVariableInterval_Impl::resetOutOfRangeValue(bool driverMethod) {
128 ✗ bool result = setString(OS_Schedule_VariableIntervalFields::OutOfRangeValue, "", driverMethod);
129 ✗ OS_ASSERT(result);
130 ✗ }
131
132 ✗ void ScheduleVariableInterval_Impl::ensureNoLeapDays() {
133 ✗ boost::optional<int> month;
134 ✗ boost::optional<int> day;
135
136 ✗ month = getInt(OS_Schedule_VariableIntervalFields::StartMonth);
137 ✗ if (month && (month.get() == 2)) {
138 ✗ day = this->getInt(OS_Schedule_VariableIntervalFields::StartDay);
139 ✗ if (day && (day.get() == 29)) {
140 ✗ this->setInt(OS_Schedule_VariableIntervalFields::StartDay, 28);
141 }
142 }
143
144 ✗ for (const IdfExtensibleGroup& group : this->extensibleGroups()) {
145 ✗ month = group.getInt(OS_Schedule_VariableIntervalExtensibleFields::Month);
146 ✗ if (month && (month.get() == 2)) {
147 ✗ day = group.getInt(OS_Schedule_VariableIntervalExtensibleFields::Day);
148 ✗ if (day && (day.get() == 29)) {
149 ✗ this->setInt(OS_Schedule_VariableIntervalExtensibleFields::Day, 28);
150 }
151 }
152 ✗ }
153 ✗ }
154
155 6 openstudio::TimeSeries ScheduleVariableInterval_Impl::timeSeries() const {
156
1/1
✓ Branch 1 taken 6 times.
6 unsigned numExtensibleGroups = this->numExtensibleGroups();
157
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 5 times.
6 if (numExtensibleGroups == 0) {
158
6/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
2 return TimeSeries(Date(MonthOfYear::Jan, 1), 0, Vector(), "");
159 }
160
161
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 OptionalInt startMonth = this->startMonth();
162
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 OptionalInt startDay = this->startMonth();
163 // Grotesquely assume that the schedule starts at the start of the first day
164
1/1
✓ Branch 1 taken 5 times.
5 OptionalInt startHour = 0;
165
1/1
✓ Branch 1 taken 5 times.
5 OptionalInt startMinute = 0;
166
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 4 not taken.
5 OS_ASSERT(startMonth);
167
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 4 not taken.
5 OS_ASSERT(startDay);
168
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 4 not taken.
5 OS_ASSERT(startHour);
169
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 4 not taken.
5 OS_ASSERT(startMinute);
170
171 5 DateTimeVector dateTimes;
172
9/9
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 5 times.
✓ Branch 19 taken 5 times.
✓ Branch 22 taken 5 times.
✓ Branch 25 taken 5 times.
5 dateTimes.push_back(DateTime(Date(MonthOfYear(*startMonth), *startDay), Time(0, *startHour, *startMinute)));
173
1/1
✓ Branch 1 taken 5 times.
5 Vector values(numExtensibleGroups);
174 5 unsigned i = 0;
175
4/4
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 11 taken 26780 times.
✓ Branch 12 taken 5 times.
26785 for (const ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(extensibleGroups())) {
176
1/1
✓ Branch 1 taken 26780 times.
26780 OptionalInt month = group.getInt(0);
177
1/1
✓ Branch 1 taken 26780 times.
26780 OptionalInt day = group.getInt(1);
178
1/1
✓ Branch 1 taken 26780 times.
26780 OptionalInt hour = group.getInt(2);
179
1/1
✓ Branch 1 taken 26780 times.
26780 OptionalInt minute = group.getInt(3);
180
1/1
✓ Branch 1 taken 26780 times.
26780 OptionalDouble x = group.getDouble(4);
181
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 26780 times.
✗ Branch 4 not taken.
26780 OS_ASSERT(month);
182
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 26780 times.
✗ Branch 4 not taken.
26780 OS_ASSERT(day);
183
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 26780 times.
✗ Branch 4 not taken.
26780 OS_ASSERT(hour);
184
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 26780 times.
✗ Branch 4 not taken.
26780 OS_ASSERT(minute);
185
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 26780 times.
✗ Branch 4 not taken.
26780 OS_ASSERT(x);
186
9/9
✓ Branch 1 taken 26780 times.
✓ Branch 4 taken 26780 times.
✓ Branch 7 taken 26780 times.
✓ Branch 10 taken 26780 times.
✓ Branch 13 taken 26780 times.
✓ Branch 16 taken 26780 times.
✓ Branch 19 taken 26780 times.
✓ Branch 22 taken 26780 times.
✓ Branch 25 taken 26780 times.
26780 dateTimes.push_back(DateTime(Date(MonthOfYear(*month), *day), Time(0, *hour, *minute)));
187
2/2
✓ Branch 1 taken 26780 times.
✓ Branch 4 taken 26780 times.
26780 values[i] = *x;
188 26780 ++i;
189 5 }
190
191
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 TimeSeries result(dateTimes, values, "");
192
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 result.setOutOfRangeValue(this->outOfRangeValue());
193
194 5 return result;
195 5 }
196
197 8 bool ScheduleVariableInterval_Impl::setTimeSeries(const openstudio::TimeSeries& timeSeries) {
198 // check the values
199
1/1
✓ Branch 1 taken 8 times.
8 openstudio::Vector values = timeSeries.values();
200
5/5
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 9 taken 44308 times.
✓ Branch 11 taken 44300 times.
✓ Branch 12 taken 8 times.
44308 for (const auto& value : values) {
201 // Get the position
202
1/1
✓ Branch 1 taken 44300 times.
44300 int pos = (int)(&value - &values[0]);
203 // Check validity, cannot be NaN, Inf, etc
204
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 44300 times.
44300 if (std::isinf(value)) {
205 ✗ LOG(Warn, "There is Infinity on position " << pos << " in the timeSeries provided for " << this->briefDescription());
206 ✗ return false;
207
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 44300 times.
44300 } else if (std::isnan(value)) {
208 ✗ LOG(Warn, "There is a NaN on position " << pos << " in the timeSeries provided for " << this->briefDescription());
209 ✗ return false;
210 }
211 8 }
212
213
1/1
✓ Branch 1 taken 8 times.
8 clearExtensibleGroups(false);
214
215
1/1
✓ Branch 1 taken 8 times.
8 DateTime firstReportDateTime = timeSeries.firstReportDateTime();
216
1/1
✓ Branch 1 taken 8 times.
8 Date startDate = firstReportDateTime.date();
217
218 // set the start date
219
3/3
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
8 this->setStartMonth(startDate.monthOfYear().value(), false);
220
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 this->setStartDay(startDate.dayOfMonth(), false);
221
222 // set the out of range value
223
1/1
✓ Branch 1 taken 8 times.
8 double outOfRangeValue = timeSeries.outOfRangeValue();
224
1/1
✓ Branch 1 taken 8 times.
8 this->setOutOfRangeValue(outOfRangeValue);
225
226 // set the values
227
1/1
✓ Branch 1 taken 8 times.
8 std::vector<long> secondsFromFirstReport = timeSeries.secondsFromFirstReport();
228
3/3
✓ Branch 1 taken 44308 times.
✓ Branch 3 taken 44300 times.
✓ Branch 4 taken 8 times.
44308 for (unsigned i = 0; i < values.size(); ++i) {
229
2/2
✓ Branch 2 taken 44300 times.
✓ Branch 5 taken 44300 times.
44300 DateTime dateTime = firstReportDateTime + Time(0, 0, 0, secondsFromFirstReport[i]);
230
1/1
✓ Branch 1 taken 44300 times.
44300 Date date = dateTime.date();
231
1/1
✓ Branch 1 taken 44300 times.
44300 Time time = dateTime.time();
232
233 44300 std::vector<std::string> temp;
234
4/4
✓ Branch 1 taken 44300 times.
✓ Branch 4 taken 44300 times.
✓ Branch 7 taken 44300 times.
✓ Branch 10 taken 44300 times.
44300 temp.push_back(boost::lexical_cast<std::string>(date.monthOfYear().value()));
235
3/3
✓ Branch 1 taken 44300 times.
✓ Branch 4 taken 44300 times.
✓ Branch 7 taken 44300 times.
44300 temp.push_back(boost::lexical_cast<std::string>(date.dayOfMonth()));
236
3/3
✓ Branch 1 taken 44300 times.
✓ Branch 4 taken 44300 times.
✓ Branch 7 taken 44300 times.
44300 temp.push_back(boost::lexical_cast<std::string>(time.hours()));
237
3/3
✓ Branch 1 taken 44300 times.
✓ Branch 4 taken 44300 times.
✓ Branch 7 taken 44300 times.
44300 temp.push_back(boost::lexical_cast<std::string>(time.minutes()));
238
3/3
✓ Branch 1 taken 44300 times.
✓ Branch 4 taken 44300 times.
✓ Branch 7 taken 44300 times.
44300 temp.push_back(toString(values[i]));
239
240
2/2
✓ Branch 1 taken 44300 times.
✓ Branch 4 taken 44300 times.
44300 auto group = pushExtensibleGroup(temp, false).cast<ModelExtensibleGroup>();
241
2/4
✓ Branch 1 taken 44300 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 44300 times.
✗ Branch 6 not taken.
44300 OS_ASSERT(!group.empty());
242 44300 }
243
244
1/1
✓ Branch 1 taken 8 times.
8 this->emitChangeSignals();
245
246 8 return true;
247 8 }
248
249 } // namespace detail
250
251 8 ScheduleVariableInterval::ScheduleVariableInterval(const Model& model) : ScheduleInterval(ScheduleVariableInterval::iddObjectType(), model) {
252
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 5 not taken.
8 OS_ASSERT(getImpl<detail::ScheduleVariableInterval_Impl>());
253 8 }
254
255 7615 IddObjectType ScheduleVariableInterval::iddObjectType() {
256
1/1
✓ Branch 1 taken 7615 times.
7615 IddObjectType result(IddObjectType::OS_Schedule_VariableInterval);
257 7615 return result;
258 }
259
260 2 bool ScheduleVariableInterval::interpolatetoTimestep() const {
261
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::ScheduleVariableInterval_Impl>()->interpolatetoTimestep();
262 }
263
264 ✗ bool ScheduleVariableInterval::isInterpolatetoTimestepDefaulted() const {
265 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->isInterpolatetoTimestepDefaulted();
266 }
267
268 ✗ int ScheduleVariableInterval::startMonth() const {
269 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->startMonth();
270 }
271
272 ✗ int ScheduleVariableInterval::startDay() const {
273 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->startDay();
274 }
275
276 ✗ double ScheduleVariableInterval::outOfRangeValue() const {
277 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->outOfRangeValue();
278 }
279
280 ✗ bool ScheduleVariableInterval::isOutOfRangeValueDefaulted() const {
281 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->isOutOfRangeValueDefaulted();
282 }
283
284 ✗ bool ScheduleVariableInterval::setInterpolatetoTimestep(bool interpolatetoTimestep) {
285 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->setInterpolatetoTimestep(interpolatetoTimestep);
286 }
287
288 ✗ void ScheduleVariableInterval::resetInterpolatetoTimestep() {
289 ✗ getImpl<detail::ScheduleVariableInterval_Impl>()->resetInterpolatetoTimestep();
290 ✗ }
291
292 ✗ bool ScheduleVariableInterval::setStartMonth(int startMonth) {
293 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->setStartMonth(startMonth);
294 }
295
296 ✗ bool ScheduleVariableInterval::setStartDay(int startDay) {
297 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->setStartDay(startDay);
298 }
299
300 ✗ bool ScheduleVariableInterval::setOutOfRangeValue(double outOfRangeValue) {
301 ✗ return getImpl<detail::ScheduleVariableInterval_Impl>()->setOutOfRangeValue(outOfRangeValue);
302 }
303
304 ✗ void ScheduleVariableInterval::resetOutOfRangeValue() {
305 ✗ getImpl<detail::ScheduleVariableInterval_Impl>()->resetOutOfRangeValue();
306 ✗ }
307
308 /// @cond
309 7 ScheduleVariableInterval::ScheduleVariableInterval(std::shared_ptr<detail::ScheduleVariableInterval_Impl> impl)
310
1/1
✓ Branch 3 taken 7 times.
7 : ScheduleInterval(std::move(impl)) {}
311 /// @endcond
312
313 } // namespace model
314 } // namespace openstudio
315