MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / setTimeSeries

Method setTimeSeries

src/model/ScheduleFixedInterval.cpp:92–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90 }
91
92 bool ScheduleFixedInterval_Impl::setTimeSeries(const openstudio::TimeSeries& timeSeries) {
93 // check the interval
94 boost::optional<openstudio::Time> intervalTime = timeSeries.intervalLength();
95 if (!intervalTime) {
96 return false;
97 }
98
99 auto intervalLengthAsInteger = [](const double value) -> int {
100 double integralPart = 0.0;
101 if (std::modf(value, &integralPart) == 0.0) {
102 // The intervalLength is actually an int, not a double
103 return static_cast<int>(integralPart);
104 }
105 return -1;
106 };
107
108 // check the interval
109 const double intervalLengthDouble = intervalTime->totalMinutes();
110 const int intervalLength = intervalLengthAsInteger(intervalLengthDouble);
111 if (intervalLength < 0) {
112 return false;
113 }
114
115 // check that first report is whole number of intervals from start date
116 const DateTime firstReportDateTime = timeSeries.firstReportDateTime();
117 const DateTime startDateTime = timeSeries.startDateTime();
118 const Date startDate = startDateTime.date();
119
120 const Time firstReportTime = firstReportDateTime.time();
121
122 const double numIntervalsToFirstReportDouble = std::max(1.0, firstReportTime.totalMinutes() / intervalLengthDouble);
123 const int numIntervalsToFirstReport = intervalLengthAsInteger(numIntervalsToFirstReportDouble);
124 if (numIntervalsToFirstReport < 0) {
125 return false;
126 }
127
128 // check the values
129 const openstudio::Vector values = timeSeries.values();
130 for (size_t pos = 0; const auto& value : values) {
131 // Check validity, cannot be NaN, Inf, etc
132 if (std::isinf(value)) {
133 LOG(Warn, "There is Infinity on position " << pos << " in the timeSeries provided for " << this->briefDescription());
134 return false;
135 } else if (std::isnan(value)) {
136 LOG(Warn, "There is a NaN on position " << pos << " in the timeSeries provided for " << this->briefDescription());
137 return false;
138 }
139 ++pos;
140 }
141
142 // at this point we are going to change the object
143 clearExtensibleGroups(false);
144
145 // set the interval
146 this->setIntervalLength(intervalLength, false);
147
148 // set the start date
149 this->setStartMonth(startDate.monthOfYear().value(), false);

Callers

nothing calls this directly

Calls 15

setIntervalLengthMethod · 0.95
setStartMonthMethod · 0.95
setStartDayMethod · 0.95
totalMinutesMethod · 0.80
firstReportDateTimeMethod · 0.80
briefDescriptionMethod · 0.80
monthOfYearMethod · 0.80
toStringFunction · 0.50
intervalLengthMethod · 0.45
startDateTimeMethod · 0.45
dateMethod · 0.45
timeMethod · 0.45

Tested by

no test coverage detected