src/utilities/data/TimeSeries.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 "TimeSeries.hpp" | ||
| 7 | #include "../core/Assert.hpp" | ||
| 8 | |||
| 9 | using namespace std; | ||
| 10 | using namespace boost; | ||
| 11 | |||
| 12 | namespace openstudio { | ||
| 13 | |||
| 14 | namespace detail { | ||
| 15 | |||
| 16 |
2/2✓ Branch 4 taken 4902 times.
✓ Branch 8 taken 4902 times.
|
4902 | TimeSeries_Impl::TimeSeries_Impl() : m_outOfRangeValue(0.0), m_wrapAround(false) {} |
| 17 | |||
| 18 | 38 | TimeSeries_Impl::TimeSeries_Impl(const Date& startDate, const Time& intervalLength, const Vector& values, const std::string& units) | |
| 19 |
2/2✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
|
76 | : m_secondsFromFirstReport(values.size()), |
| 20 |
2/2✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
|
76 | m_secondsFromStart(values.size()), |
| 21 |
1/1✓ Branch 1 taken 38 times.
|
38 | m_values(values), |
| 22 |
1/1✓ Branch 1 taken 38 times.
|
38 | m_units(units), |
| 23 |
1/1✓ Branch 1 taken 38 times.
|
38 | m_intervalLength(intervalLength), |
| 24 | 38 | m_outOfRangeValue(0.0), | |
| 25 |
1/1✓ Branch 3 taken 38 times.
|
76 | m_wrapAround(false) { |
| 26 |
3/3✓ Branch 1 taken 38 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 36 times.
|
38 | if (values.empty()) { |
| 27 |
5/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
|
2 | LOG(Warn, "Creating empty timeseries"); |
| 28 | } | ||
| 29 | |||
| 30 | // length of interval in seconds | ||
| 31 |
1/1✓ Branch 1 taken 38 times.
|
38 | int secondsPerInterval = intervalLength.totalSeconds(); |
| 32 | |||
| 33 | // date and time of first report, end of the first reporting interval | ||
| 34 | // DLM: startDate may or may not have baseYear defined | ||
| 35 |
2/2✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
|
38 | m_firstReportDateTime = DateTime(startDate, intervalLength); |
| 36 | |||
| 37 |
3/3✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 7 taken 38 times.
|
38 | m_startDateTime = DateTime(startDate, Time(0)); |
| 38 | |||
| 39 |
3/3✓ Branch 1 taken 205217 times.
✓ Branch 3 taken 205179 times.
✓ Branch 4 taken 38 times.
|
205217 | for (size_t i = 0; i < values.size(); ++i) { |
| 40 | 205179 | m_secondsFromFirstReport[i] = i * secondsPerInterval; | |
| 41 | 205179 | m_secondsFromStart[i] = (i + 1) * secondsPerInterval; | |
| 42 | } | ||
| 43 |
2/2✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
|
38 | m_secondsFromFirstReportAsVector = createVector(m_secondsFromFirstReport); |
| 44 | |||
| 45 | 38 | long durationSeconds = 0; | |
| 46 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 2 taken 2 times.
|
38 | if (!m_secondsFromFirstReport.empty()) { |
| 47 | 36 | durationSeconds = m_secondsFromFirstReport.back(); | |
| 48 | } | ||
| 49 | |||
| 50 | // check for wrap around | ||
| 51 |
2/2✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
|
38 | boost::optional<int> calendarYear = m_firstReportDateTime.date().baseYear(); |
| 52 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 28 times.
|
38 | if (!calendarYear) { |
| 53 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | DateTime lastDateTime = m_firstReportDateTime + Time(0, 0, 0, durationSeconds); |
| 54 |
5/5✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
✓ Branch 10 taken 10 times.
✓ Branch 13 taken 10 times.
|
10 | Date lastDate(lastDateTime.date().monthOfYear(), lastDateTime.date().dayOfMonth()); |
| 55 |
10/10✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 3 times.
✓ Branch 9 taken 7 times.
✓ Branch 12 taken 7 times.
✓ Branch 14 taken 1 time.
✓ Branch 15 taken 6 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 6 times.
|
10 | if ((durationSeconds > Time(366.0).totalSeconds()) || (lastDate < m_firstReportDateTime.date())) { |
| 56 | 4 | m_wrapAround = true; | |
| 57 | } | ||
| 58 | } | ||
| 59 | 38 | } | |
| 60 | |||
| 61 | 103 | TimeSeries_Impl::TimeSeries_Impl(const DateTime& firstReportDateTime, const Time& intervalLength, const Vector& values, const std::string& units) | |
| 62 |
2/2✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
|
206 | : m_secondsFromFirstReport(values.size()), |
| 63 |
2/2✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
|
206 | m_secondsFromStart(values.size()), |
| 64 |
1/1✓ Branch 1 taken 103 times.
|
103 | m_values(values), |
| 65 |
1/1✓ Branch 1 taken 103 times.
|
103 | m_units(units), |
| 66 |
1/1✓ Branch 1 taken 103 times.
|
103 | m_intervalLength(intervalLength), |
| 67 | 103 | m_outOfRangeValue(0.0), | |
| 68 |
1/1✓ Branch 3 taken 103 times.
|
206 | m_wrapAround(false) { |
| 69 |
2/3✓ Branch 1 taken 103 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 103 times.
|
103 | if (values.empty()) { |
| 70 | ✗ | LOG(Warn, "Creating empty timeseries"); | |
| 71 | } | ||
| 72 | |||
| 73 | // length of interval in seconds | ||
| 74 |
1/1✓ Branch 1 taken 103 times.
|
103 | int secondsPerInterval = intervalLength.totalSeconds(); |
| 75 | |||
| 76 | // DLM: startDate may or may not have baseYear defined | ||
| 77 |
4/4✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
✓ Branch 7 taken 103 times.
✓ Branch 10 taken 103 times.
|
103 | m_firstReportDateTime = DateTime(firstReportDateTime.date(), firstReportDateTime.time()); |
| 78 | |||
| 79 |
2/2✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
|
103 | m_startDateTime = m_firstReportDateTime - intervalLength; |
| 80 | |||
| 81 |
3/3✓ Branch 1 taken 1868625 times.
✓ Branch 3 taken 1868522 times.
✓ Branch 4 taken 103 times.
|
1868625 | for (size_t i = 0; i < values.size(); ++i) { |
| 82 | 1868522 | m_secondsFromFirstReport[i] = i * secondsPerInterval; | |
| 83 | 1868522 | m_secondsFromStart[i] = (i + 1) * secondsPerInterval; | |
| 84 | } | ||
| 85 |
2/2✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
|
103 | m_secondsFromFirstReportAsVector = createVector(m_secondsFromFirstReport); |
| 86 | |||
| 87 | 103 | long durationSeconds = 0; | |
| 88 |
1/2✓ Branch 1 taken 103 times.
✗ Branch 2 not taken.
|
103 | if (!m_secondsFromFirstReport.empty()) { |
| 89 | 103 | durationSeconds = m_secondsFromFirstReport.back(); | |
| 90 | } | ||
| 91 | |||
| 92 | // check for wrap around | ||
| 93 |
2/2✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
|
103 | boost::optional<int> calendarYear = m_firstReportDateTime.date().baseYear(); |
| 94 |
2/2✓ Branch 1 taken 51 times.
✓ Branch 2 taken 52 times.
|
103 | if (!calendarYear) { |
| 95 |
2/2✓ Branch 1 taken 51 times.
✓ Branch 4 taken 51 times.
|
51 | DateTime lastDateTime = m_firstReportDateTime + Time(0, 0, 0, durationSeconds); |
| 96 |
5/5✓ Branch 1 taken 51 times.
✓ Branch 4 taken 51 times.
✓ Branch 7 taken 51 times.
✓ Branch 10 taken 51 times.
✓ Branch 13 taken 51 times.
|
51 | Date lastDate(lastDateTime.date().monthOfYear(), lastDateTime.date().dayOfMonth()); |
| 97 |
9/10✓ Branch 1 taken 51 times.
✓ Branch 4 taken 51 times.
✓ Branch 6 taken 51 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 51 times.
✓ Branch 12 taken 51 times.
✓ Branch 14 taken 15 times.
✓ Branch 15 taken 36 times.
✓ Branch 16 taken 15 times.
✓ Branch 17 taken 36 times.
|
51 | if ((durationSeconds > Time(366.0).totalSeconds()) || (lastDate < m_firstReportDateTime.date())) { |
| 98 | 15 | m_wrapAround = true; | |
| 99 | } | ||
| 100 | } | ||
| 101 | 103 | } | |
| 102 | |||
| 103 | 3 | TimeSeries_Impl::TimeSeries_Impl(const DateTime& firstReportDateTime, const Vector& timeInDays, const Vector& values, const std::string& units) | |
| 104 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
6 | : m_secondsFromFirstReport(values.size()), |
| 105 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
6 | m_secondsFromStart(values.size()), |
| 106 |
1/1✓ Branch 1 taken 3 times.
|
3 | m_values(values), |
| 107 |
1/1✓ Branch 1 taken 3 times.
|
3 | m_units(units), |
| 108 | 3 | m_outOfRangeValue(0.0), | |
| 109 |
1/1✓ Branch 3 taken 3 times.
|
9 | m_wrapAround(false) { |
| 110 |
3/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
|
3 | if (timeInDays.size() != values.size()) { |
| 111 | ✗ | LOG_AND_THROW("Length of values (" << values.size() << ") must match length of times (" << timeInDays.size() << ")"); | |
| 112 | } | ||
| 113 | |||
| 114 |
5/8✓ Branch 1 taken 3 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
|
3 | if (values.empty() || timeInDays.empty()) { |
| 115 | ✗ | LOG(Warn, "Creating empty timeseries"); | |
| 116 | ✗ | m_startDateTime = firstReportDateTime; | |
| 117 | ✗ | m_firstReportDateTime = firstReportDateTime; | |
| 118 | } else { | ||
| 119 | |||
| 120 | // DLM: firstReportDateTime may or may not have baseYear defined | ||
| 121 |
1/1✓ Branch 1 taken 3 times.
|
3 | m_firstReportDateTime = firstReportDateTime; |
| 122 | |||
| 123 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | std::copy(values.begin(), values.end(), m_values.begin()); |
| 124 | |||
| 125 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 time.
|
3 | if (timeInDays[0] == 0) { // This is the old, BROKEN way |
| 126 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | int firstIntervalSeconds = firstReportDateTime.time().totalSeconds(); |
| 127 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2 | if (firstIntervalSeconds == 0) { |
| 128 |
13/13✓ 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 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
|
1 | LOG_AND_THROW("Cannot calculate the series start date for first report at the beginning of a day"); |
| 129 | } | ||
| 130 |
5/5✓ 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.
|
1 | LOG(Warn, "Assuming time series begins at the start of the day of first report. This behavior is deprecated and will instead be an error in " |
| 131 | "the future."); | ||
| 132 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | m_startDateTime = DateTime(m_firstReportDateTime.date()); |
| 133 | |||
| 134 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 time.
|
4 | for (unsigned i = 0; i < values.size(); ++i) { |
| 135 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | m_secondsFromFirstReport[i] = Time(timeInDays[i]).totalSeconds(); |
| 136 | 3 | m_secondsFromStart[i] = m_secondsFromFirstReport[i] + firstIntervalSeconds; | |
| 137 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
|
3 | if (i > 0) { |
| 138 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (m_secondsFromFirstReport[i] < m_secondsFromFirstReport[i - 1]) { |
| 139 | ✗ | LOG_AND_THROW("Days from first report must be monotonically increasing"); | |
| 140 | } | ||
| 141 | } | ||
| 142 | } | ||
| 143 | } else { // This is the new way | ||
| 144 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | m_startDateTime = m_firstReportDateTime - Time(timeInDays[0]); |
| 145 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 time.
|
4 | for (unsigned i = 0; i < values.size(); ++i) { |
| 146 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | m_secondsFromStart[i] = Time(timeInDays[i]).totalSeconds(); |
| 147 | 3 | m_secondsFromFirstReport[i] = m_secondsFromStart[i] - m_secondsFromStart[0]; | |
| 148 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
|
3 | if (i > 0) { |
| 149 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (m_secondsFromFirstReport[i] < m_secondsFromFirstReport[i - 1]) { |
| 150 | ✗ | LOG_AND_THROW("Days from first report must be monotonically increasing"); | |
| 151 | } | ||
| 152 | } | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | m_secondsFromFirstReportAsVector = createVector(m_secondsFromFirstReport); |
| 157 | |||
| 158 | 2 | long durationSeconds = 0; | |
| 159 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if (!m_secondsFromFirstReport.empty()) { |
| 160 | 2 | durationSeconds = m_secondsFromFirstReport.back(); | |
| 161 | } | ||
| 162 | |||
| 163 | // check for wrap around | ||
| 164 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | boost::optional<int> calendarYear = m_firstReportDateTime.date().baseYear(); |
| 165 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if (!calendarYear) { |
| 166 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | DateTime lastDateTime = m_firstReportDateTime + Time(0, 0, 0, durationSeconds); |
| 167 |
5/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
|
2 | Date lastDate(lastDateTime.date().monthOfYear(), lastDateTime.date().dayOfMonth()); |
| 168 |
7/10✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2 times.
✓ Branch 12 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 2 times.
|
2 | if ((durationSeconds > Time(366.0).totalSeconds()) || (lastDate < m_firstReportDateTime.date())) { |
| 169 | ✗ | m_wrapAround = true; | |
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | 8 | } | |
| 174 | |||
| 175 | 7 | TimeSeries_Impl::TimeSeries_Impl(const DateTime& firstReportDateTime, const std::vector<double>& timeInDays, const std::vector<double>& values, | |
| 176 | 7 | const std::string& units) | |
| 177 |
1/1✓ Branch 2 taken 7 times.
|
14 | : m_secondsFromFirstReport(timeInDays.size()), |
| 178 |
1/1✓ Branch 2 taken 7 times.
|
14 | m_secondsFromStart(values.size()), |
| 179 |
1/1✓ Branch 2 taken 7 times.
|
7 | m_values(values.size()), |
| 180 |
1/1✓ Branch 1 taken 7 times.
|
7 | m_units(units), |
| 181 | 7 | m_outOfRangeValue(0.0), | |
| 182 |
1/1✓ Branch 3 taken 7 times.
|
21 | m_wrapAround(false) { |
| 183 | |||
| 184 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
|
7 | if (timeInDays.size() != values.size()) { |
| 185 | ✗ | LOG_AND_THROW("Length of values (" << values.size() << ") must match length of times (" << timeInDays.size() << ")"); | |
| 186 | } | ||
| 187 | |||
| 188 |
3/6✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 7 times.
|
7 | if (values.empty() || timeInDays.empty()) { |
| 189 | ✗ | LOG(Warn, "Creating empty timeseries"); | |
| 190 | ✗ | m_startDateTime = firstReportDateTime; | |
| 191 | ✗ | m_firstReportDateTime = firstReportDateTime; | |
| 192 | } else { | ||
| 193 | |||
| 194 | // DLM: firstReportDateTime may or may not have baseYear defined | ||
| 195 |
1/1✓ Branch 1 taken 7 times.
|
7 | m_firstReportDateTime = firstReportDateTime; |
| 196 | |||
| 197 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 6 taken 7 times.
|
7 | std::copy(values.begin(), values.end(), m_values.begin()); |
| 198 | |||
| 199 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3 times.
|
7 | if (timeInDays[0] == 0) { // This is the old, BROKEN way |
| 200 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | int firstIntervalSeconds = firstReportDateTime.time().totalSeconds(); |
| 201 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
|
4 | if (firstIntervalSeconds == 0) { |
| 202 |
13/13✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 19 taken 3 times.
✓ Branch 22 taken 3 times.
✓ Branch 25 taken 3 times.
✓ Branch 28 taken 3 times.
✓ Branch 31 taken 3 times.
✓ Branch 34 taken 3 times.
✓ Branch 38 taken 3 times.
✓ Branch 41 taken 3 times.
|
3 | LOG_AND_THROW("Cannot calculate the series start date for first report at the beginning of a day"); |
| 203 | } | ||
| 204 |
5/5✓ 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.
|
1 | LOG(Warn, "Assuming time series begins at the start of the day of first report. This behavior is deprecated and will instead be an error in " |
| 205 | "the future."); | ||
| 206 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | m_startDateTime = DateTime(m_firstReportDateTime.date()); |
| 207 | |||
| 208 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 time.
|
4 | for (unsigned i = 0; i < values.size(); ++i) { |
| 209 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
|
3 | m_secondsFromFirstReport[i] = Time(timeInDays[i]).totalSeconds(); |
| 210 | 3 | m_secondsFromStart[i] = m_secondsFromFirstReport[i] + firstIntervalSeconds; | |
| 211 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
|
3 | if (i > 0) { |
| 212 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (m_secondsFromFirstReport[i] < m_secondsFromFirstReport[i - 1]) { |
| 213 | ✗ | LOG_AND_THROW("Days from first report must be monotonically increasing"); | |
| 214 | } | ||
| 215 | } | ||
| 216 | } | ||
| 217 | } else { // This is the new way | ||
| 218 |
3/3✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 8 taken 3 times.
|
3 | m_startDateTime = m_firstReportDateTime - Time(timeInDays[0]); |
| 219 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 2 taken 3 times.
|
19 | for (unsigned i = 0; i < values.size(); ++i) { |
| 220 |
2/2✓ Branch 2 taken 16 times.
✓ Branch 5 taken 16 times.
|
16 | m_secondsFromStart[i] = Time(timeInDays[i]).totalSeconds(); |
| 221 | 16 | m_secondsFromFirstReport[i] = m_secondsFromStart[i] - m_secondsFromStart[0]; | |
| 222 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
|
16 | if (i > 0) { |
| 223 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
|
13 | if (m_secondsFromFirstReport[i] < m_secondsFromFirstReport[i - 1]) { |
| 224 | ✗ | LOG_AND_THROW("Days from first report must be monotonically increasing"); | |
| 225 | } | ||
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | m_secondsFromFirstReportAsVector = createVector(m_secondsFromFirstReport); |
| 231 | |||
| 232 | 4 | long durationSeconds = 0; | |
| 233 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | if (!m_secondsFromFirstReport.empty()) { |
| 234 | 4 | durationSeconds = m_secondsFromFirstReport.back(); | |
| 235 | } | ||
| 236 | |||
| 237 | // check for wrap around | ||
| 238 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | boost::optional<int> calendarYear = m_firstReportDateTime.date().baseYear(); |
| 239 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | if (!calendarYear) { |
| 240 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | DateTime lastDateTime = m_firstReportDateTime + Time(0, 0, 0, durationSeconds); |
| 241 |
5/5✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
|
4 | Date lastDate(lastDateTime.date().monthOfYear(), lastDateTime.date().dayOfMonth()); |
| 242 |
9/10✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 4 times.
✓ Branch 12 taken 4 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 2 times.
|
4 | if ((durationSeconds > Time(366.0).totalSeconds()) || (lastDate < m_firstReportDateTime.date())) { |
| 243 | 2 | m_wrapAround = true; | |
| 244 | } | ||
| 245 | } | ||
| 246 | } | ||
| 247 | 22 | } | |
| 248 | |||
| 249 | 62 | TimeSeries_Impl::TimeSeries_Impl(const DateTimeVector& inDateTimes, const Vector& values, const std::string& units) | |
| 250 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
|
124 | : m_secondsFromFirstReport(values.size()), |
| 251 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
|
124 | m_secondsFromStart(values.size()), |
| 252 |
1/1✓ Branch 1 taken 62 times.
|
62 | m_values(values), |
| 253 |
1/1✓ Branch 1 taken 62 times.
|
62 | m_units(units), |
| 254 | 62 | m_outOfRangeValue(0.0), | |
| 255 |
1/1✓ Branch 3 taken 62 times.
|
186 | m_wrapAround(false) { |
| 256 | // DLM: this seems to be a pretty fragile constructor with a lot going on | ||
| 257 | |||
| 258 |
4/7✓ Branch 1 taken 62 times.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 62 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 62 times.
|
62 | if (values.empty() || inDateTimes.empty()) { |
| 259 | ✗ | LOG(Warn, "Creating empty timeseries"); | |
| 260 | } else { | ||
| 261 | |||
| 262 | 62 | bool extraTime(false); | |
| 263 |
1/1✓ Branch 1 taken 62 times.
|
62 | DateTimeVector dateTimes = inDateTimes; |
| 264 |
3/3✓ Branch 2 taken 62 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 46 times.
|
62 | if (dateTimes.size() != values.size()) { |
| 265 |
2/3✓ Branch 2 taken 16 times.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 | if (dateTimes.size() - 1 == values.size()) { |
| 266 | 16 | extraTime = true; | |
| 267 |
1/1✓ Branch 2 taken 16 times.
|
16 | m_startDateTime = inDateTimes.front(); |
| 268 |
1/1✓ Branch 4 taken 16 times.
|
16 | dateTimes = DateTimeVector(inDateTimes.cbegin() + 1, inDateTimes.cend()); |
| 269 | } else { | ||
| 270 | ✗ | LOG_AND_THROW("Length of values (" << values.size() << ") must match length of times (" << dateTimes.size() << ")"); | |
| 271 | } | ||
| 272 | } | ||
| 273 | |||
| 274 | // DLM: startDate may or may not have baseYear defined | ||
| 275 |
1/1✓ Branch 2 taken 62 times.
|
62 | m_firstReportDateTime = dateTimes.front(); |
| 276 | // unsigned numDateTimes = dateTimes.size(); | ||
| 277 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
|
62 | boost::optional<int> calendarYear = m_firstReportDateTime.date().baseYear(); |
| 278 | |||
| 279 | // Check for wrap around | ||
| 280 | 62 | m_wrapAround = false; | |
| 281 |
2/2✓ Branch 1 taken 61 times.
✓ Branch 2 taken 1 time.
|
62 | if (!calendarYear) { |
| 282 |
2/2✓ Branch 1 taken 240578 times.
✓ Branch 2 taken 49 times.
|
240627 | for (unsigned i = 1; i < dateTimes.size(); i++) { |
| 283 |
3/3✓ Branch 3 taken 240578 times.
✓ Branch 5 taken 12 times.
✓ Branch 6 taken 240566 times.
|
240578 | if (dateTimes[i] < dateTimes[i - 1]) { |
| 284 | 12 | m_wrapAround = true; | |
| 285 | 12 | break; | |
| 286 | } | ||
| 287 | } | ||
| 288 | } | ||
| 289 | |||
| 290 | // Compute the seconds from first report | ||
| 291 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 50 times.
|
62 | if (m_wrapAround) { |
| 292 | 12 | m_secondsFromFirstReport[0] = 0; | |
| 293 | 12 | m_secondsFromStart[0] = 0; | |
| 294 | 12 | int delta = 0; | |
| 295 | DateTime firstReportDateTimeWithYear = | ||
| 296 |
7/7✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 10 taken 12 times.
✓ Branch 13 taken 12 times.
✓ Branch 16 taken 12 times.
✓ Branch 19 taken 12 times.
|
12 | DateTime(Date(m_firstReportDateTime.date().monthOfYear(), m_firstReportDateTime.date().dayOfMonth(), m_firstReportDateTime.date().year()), |
| 297 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
24 | m_firstReportDateTime.time()); |
| 298 |
2/2✓ Branch 1 taken 88453 times.
✓ Branch 2 taken 12 times.
|
88465 | for (unsigned i = 1; i < dateTimes.size(); i++) { |
| 299 | DateTime wrappedDateTime = | ||
| 300 |
7/7✓ Branch 1 taken 88453 times.
✓ Branch 4 taken 88453 times.
✓ Branch 8 taken 88453 times.
✓ Branch 11 taken 88453 times.
✓ Branch 15 taken 88453 times.
✓ Branch 18 taken 88453 times.
✓ Branch 21 taken 88453 times.
|
88453 | DateTime(Date(dateTimes[i].date().monthOfYear(), dateTimes[i].date().dayOfMonth(), m_firstReportDateTime.date().year() + delta), |
| 301 |
2/2✓ Branch 2 taken 88453 times.
✓ Branch 5 taken 88453 times.
|
176906 | dateTimes[i].time()); |
| 302 |
3/3✓ Branch 2 taken 88453 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 88441 times.
|
88453 | if (wrappedDateTime < dateTimes[i - 1]) { |
| 303 | 12 | ++delta; | |
| 304 | wrappedDateTime = | ||
| 305 |
8/8✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 8 taken 12 times.
✓ Branch 11 taken 12 times.
✓ Branch 15 taken 12 times.
✓ Branch 18 taken 12 times.
✓ Branch 21 taken 12 times.
✓ Branch 24 taken 12 times.
|
12 | DateTime(Date(dateTimes[i].date().monthOfYear(), dateTimes[i].date().dayOfMonth(), m_firstReportDateTime.date().year() + delta), |
| 306 |
2/2✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
|
24 | dateTimes[i].time()); |
| 307 | } | ||
| 308 |
2/2✓ Branch 1 taken 88453 times.
✓ Branch 4 taken 88453 times.
|
88453 | m_secondsFromFirstReport[i] = (wrappedDateTime - firstReportDateTimeWithYear).totalSeconds(); |
| 309 |
2/2✓ Branch 1 taken 88453 times.
✓ Branch 4 taken 88453 times.
|
88453 | m_secondsFromStart[i] = (wrappedDateTime - firstReportDateTimeWithYear).totalSeconds(); |
| 310 | } | ||
| 311 | } else { | ||
| 312 | 50 | m_secondsFromFirstReport[0] = 0; | |
| 313 | 50 | m_secondsFromStart[0] = 0; | |
| 314 |
2/2✓ Branch 1 taken 161007 times.
✓ Branch 2 taken 50 times.
|
161057 | for (unsigned i = 1; i < dateTimes.size(); i++) { |
| 315 |
2/2✓ Branch 2 taken 161007 times.
✓ Branch 5 taken 161007 times.
|
161007 | m_secondsFromFirstReport[i] = (dateTimes[i] - m_firstReportDateTime).totalSeconds(); |
| 316 |
2/2✓ Branch 2 taken 161007 times.
✓ Branch 5 taken 161007 times.
|
161007 | m_secondsFromStart[i] = (dateTimes[i] - m_firstReportDateTime).totalSeconds(); |
| 317 | } | ||
| 318 | } | ||
| 319 | |||
| 320 |
2/2✓ Branch 1 taken 249460 times.
✓ Branch 2 taken 62 times.
|
249522 | for (unsigned i = 1; i < dateTimes.size(); i++) { |
| 321 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 249460 times.
|
249460 | if (m_secondsFromStart[i] < m_secondsFromStart[i - 1]) { |
| 322 | ✗ | LOG_AND_THROW("Dates from first report must be monotonically increasing"); | |
| 323 | } | ||
| 324 | } | ||
| 325 | |||
| 326 | // Try to get a start time if we don't have one already | ||
| 327 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 16 times.
|
62 | if (!extraTime) { |
| 328 | int delta; | ||
| 329 | 46 | bool foundInterval = false; | |
| 330 |
1/2✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 | if (m_secondsFromStart.size() > 1) { |
| 331 | // check if all data is reported at a constant interval | ||
| 332 | 46 | delta = m_secondsFromStart[1] - m_secondsFromStart[0]; | |
| 333 | 46 | foundInterval = true; | |
| 334 |
1/2✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 | for (unsigned i = 2; i < m_secondsFromStart.size(); i++) { |
| 335 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 46 times.
|
46 | if (delta != m_secondsFromStart[i] - m_secondsFromStart[i - 1]) { |
| 336 | ✗ | foundInterval = false; | |
| 337 | } | ||
| 338 | 46 | break; | |
| 339 | } | ||
| 340 | } | ||
| 341 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | if (foundInterval) { |
| 342 | // DLM: shouldn't we also set m_intervalLength here? | ||
| 343 | // DLM: we could but some behavior seems to expect this to stay unset, TEST_F(DataFixture,TimeSeries_DetailedConstructor_WrapAroundDates) | ||
| 344 | //m_intervalLength = Time(0, 0, 0, delta); | ||
| 345 |
3/3✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
✓ Branch 7 taken 46 times.
|
46 | m_startDateTime = m_firstReportDateTime - Time(0, 0, 0, delta); |
| 346 | } else { | ||
| 347 | ✗ | if (m_firstReportDateTime.time().totalSeconds() == 0) { | |
| 348 | ✗ | LOG_AND_THROW("Cannot calculate the series start date for first report at the beginning of a day"); | |
| 349 | } | ||
| 350 | ✗ | LOG(Warn, "Assuming time series begins at the start of the day of first report. This behavior is deprecated and will instead be an error " | |
| 351 | "in the future."); | ||
| 352 | ✗ | m_startDateTime = DateTime(m_firstReportDateTime.date()); | |
| 353 | } | ||
| 354 | } | ||
| 355 | |||
| 356 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
|
62 | int firstIntervalSeconds = (m_firstReportDateTime - m_startDateTime).totalSeconds(); |
| 357 | |||
| 358 | // Compute the seconds from start | ||
| 359 | 62 | m_secondsFromStart[0] = firstIntervalSeconds; | |
| 360 |
2/2✓ Branch 1 taken 249460 times.
✓ Branch 2 taken 62 times.
|
249522 | for (unsigned i = 1; i < dateTimes.size(); i++) { |
| 361 | 249460 | m_secondsFromStart[i] = m_secondsFromStart[i] + firstIntervalSeconds; | |
| 362 | } | ||
| 363 | |||
| 364 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
|
62 | m_secondsFromFirstReportAsVector = createVector(m_secondsFromFirstReport); |
| 365 | 62 | } | |
| 366 | 62 | } | |
| 367 | |||
| 368 | 112 | TimeSeries_Impl::TimeSeries_Impl(const DateTime& firstReportDateTime, const std::vector<long>& timeInSeconds, const Vector& values, | |
| 369 | 112 | const std::string& units) | |
| 370 |
2/2✓ Branch 1 taken 112 times.
✓ Branch 4 taken 112 times.
|
224 | : m_secondsFromFirstReport(values.size()), |
| 371 |
2/2✓ Branch 1 taken 112 times.
✓ Branch 4 taken 112 times.
|
224 | m_secondsFromStart(values.size()), |
| 372 |
1/1✓ Branch 1 taken 112 times.
|
112 | m_values(values), |
| 373 |
1/1✓ Branch 1 taken 112 times.
|
112 | m_units(units), |
| 374 | 112 | m_outOfRangeValue(0.0), | |
| 375 |
1/1✓ Branch 3 taken 112 times.
|
336 | m_wrapAround(false) { |
| 376 |
2/3✓ Branch 2 taken 112 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 112 times.
|
112 | if (timeInSeconds.size() != values.size()) { |
| 377 | ✗ | LOG_AND_THROW("Length of values (" << values.size() << ") must match length of times (" << timeInSeconds.size() << ")"); | |
| 378 | } | ||
| 379 |
4/7✓ Branch 1 taken 112 times.
✓ Branch 3 taken 112 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 112 times.
|
112 | if (values.empty() || timeInSeconds.empty()) { |
| 380 | ✗ | LOG(Warn, "Creating empty timeseries"); | |
| 381 | ✗ | m_startDateTime = firstReportDateTime; | |
| 382 | ✗ | m_firstReportDateTime = firstReportDateTime; | |
| 383 | } else { | ||
| 384 | // Check that seconds are monotonic | ||
| 385 |
2/2✓ Branch 1 taken 1577596 times.
✓ Branch 2 taken 112 times.
|
1577708 | for (unsigned i = 1; i < timeInSeconds.size(); ++i) { |
| 386 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1577596 times.
|
1577596 | if (timeInSeconds[i] < timeInSeconds[i - 1]) { |
| 387 | ✗ | LOG_AND_THROW("Seconds from first report/start of series must be monotonically increasing"); | |
| 388 | } | ||
| 389 | } | ||
| 390 | |||
| 391 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 108 times.
|
112 | if (timeInSeconds[0] == 0) { // This is the old, BROKEN way |
| 392 |
4/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 3 times.
|
4 | if (firstReportDateTime.time().totalSeconds() == 0) { |
| 393 |
13/13✓ 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 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
|
1 | LOG_AND_THROW("Cannot calculate the series start date for first report at the beginning of a day"); |
| 394 | } | ||
| 395 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
3 | LOG(Warn, "Assuming time series begins at the start of the day of first report. This behavior is deprecated and will instead be an error in " |
| 396 | "the future."); | ||
| 397 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | m_startDateTime = DateTime(firstReportDateTime.date()); |
| 398 |
1/1✓ Branch 1 taken 3 times.
|
3 | m_firstReportDateTime = firstReportDateTime; |
| 399 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | int firstIntervalSeconds = m_firstReportDateTime.time().totalSeconds(); |
| 400 |
1/1✓ Branch 1 taken 3 times.
|
3 | m_secondsFromStart = timeInSeconds; |
| 401 |
2/2✓ Branch 1 taken 8768 times.
✓ Branch 2 taken 3 times.
|
8771 | for (unsigned i = 0; i < m_secondsFromStart.size(); i++) { |
| 402 | 8768 | m_secondsFromStart[i] += firstIntervalSeconds; | |
| 403 | } | ||
| 404 |
1/1✓ Branch 1 taken 3 times.
|
3 | m_secondsFromFirstReport = timeInSeconds; |
| 405 | |||
| 406 | } else { // This is the new behavior | ||
| 407 |
3/3✓ Branch 2 taken 108 times.
✓ Branch 5 taken 108 times.
✓ Branch 8 taken 108 times.
|
108 | m_startDateTime = firstReportDateTime - Time(0, 0, 0, timeInSeconds[0]); |
| 408 |
1/1✓ Branch 1 taken 108 times.
|
108 | m_firstReportDateTime = firstReportDateTime; |
| 409 |
1/1✓ Branch 1 taken 108 times.
|
108 | m_secondsFromStart = timeInSeconds; |
| 410 | |||
| 411 | // Get rid of this later | ||
| 412 | 108 | m_secondsFromFirstReport[0] = 0; | |
| 413 |
3/3✓ Branch 1 taken 1568937 times.
✓ Branch 3 taken 1568829 times.
✓ Branch 4 taken 108 times.
|
1568937 | for (unsigned i = 1; i < values.size(); ++i) { |
| 414 | 1568829 | m_secondsFromFirstReport[i] = timeInSeconds[i] - timeInSeconds[0]; | |
| 415 | } | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 |
2/2✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
|
111 | m_secondsFromFirstReportAsVector = createVector(m_secondsFromFirstReport); |
| 420 | |||
| 421 | 111 | long durationSeconds = 0; | |
| 422 |
1/2✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
|
111 | if (!m_secondsFromFirstReport.empty()) { |
| 423 | 111 | durationSeconds = m_secondsFromFirstReport.back(); | |
| 424 | } | ||
| 425 | |||
| 426 | // check for wrap around | ||
| 427 |
2/2✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
|
111 | boost::optional<int> calendarYear = m_firstReportDateTime.date().baseYear(); |
| 428 |
2/2✓ Branch 1 taken 46 times.
✓ Branch 2 taken 65 times.
|
111 | if (!calendarYear) { |
| 429 |
2/2✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
|
46 | DateTime lastDateTime = m_firstReportDateTime + Time(0, 0, 0, durationSeconds); |
| 430 |
5/5✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
✓ Branch 7 taken 46 times.
✓ Branch 10 taken 46 times.
✓ Branch 13 taken 46 times.
|
46 | Date lastDate(lastDateTime.date().monthOfYear(), lastDateTime.date().dayOfMonth()); |
| 431 |
9/10✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
✓ Branch 6 taken 46 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 46 times.
✓ Branch 12 taken 46 times.
✓ Branch 14 taken 27 times.
✓ Branch 15 taken 19 times.
✓ Branch 16 taken 27 times.
✓ Branch 17 taken 19 times.
|
46 | if ((durationSeconds > Time(366.0).totalSeconds()) || (lastDate < m_firstReportDateTime.date())) { |
| 432 | 27 | m_wrapAround = true; | |
| 433 | } | ||
| 434 | } | ||
| 435 | 117 | } | |
| 436 | |||
| 437 | /// interval length if any | ||
| 438 | 60 | OptionalTime TimeSeries_Impl::intervalLength() const { | |
| 439 | 60 | return m_intervalLength; | |
| 440 | } | ||
| 441 | |||
| 442 | 195 | DateTimeVector TimeSeries_Impl::dateTimes() const { | |
| 443 |
1/1✓ Branch 2 taken 195 times.
|
195 | DateTimeVector dateTimeObjs(m_secondsFromFirstReport.size()); |
| 444 |
2/2✓ Branch 1 taken 266300 times.
✓ Branch 2 taken 195 times.
|
266495 | for (unsigned i = 0; i < m_secondsFromFirstReport.size(); i++) { |
| 445 |
3/3✓ Branch 2 taken 266300 times.
✓ Branch 5 taken 266300 times.
✓ Branch 9 taken 266300 times.
|
266300 | dateTimeObjs[i] = m_firstReportDateTime + openstudio::Time(0, 0, 0, m_secondsFromFirstReport[i]); |
| 446 | } | ||
| 447 | 195 | return dateTimeObjs; | |
| 448 | ✗ | } | |
| 449 | |||
| 450 | /// time in days from end of the first reporting interval | ||
| 451 | 619 | Vector TimeSeries_Impl::daysFromFirstReport() const { | |
| 452 | 619 | Vector daysFromFirstReport(m_secondsFromFirstReport.size()); | |
| 453 |
2/2✓ Branch 1 taken 8505719 times.
✓ Branch 2 taken 619 times.
|
8506338 | for (unsigned i = 0; i < m_secondsFromFirstReport.size(); i++) { |
| 454 |
3/3✓ Branch 2 taken 8505719 times.
✓ Branch 5 taken 8505719 times.
✓ Branch 8 taken 8505719 times.
|
8505719 | daysFromFirstReport[i] = Time(0, 0, 0, m_secondsFromFirstReport[i]).totalDays(); |
| 455 | } | ||
| 456 | 619 | return daysFromFirstReport; | |
| 457 | ✗ | } | |
| 458 | |||
| 459 | /// time in days from end of the first reporting interval at index i | ||
| 460 | 16 | double TimeSeries_Impl::daysFromFirstReport(unsigned int i) const { | |
| 461 | 16 | double value = m_outOfRangeValue; | |
| 462 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | if (i < m_secondsFromFirstReport.size()) { |
| 463 |
2/2✓ Branch 2 taken 16 times.
✓ Branch 5 taken 16 times.
|
16 | value = Time(0, 0, 0, m_secondsFromFirstReport[i]).totalDays(); |
| 464 | } | ||
| 465 | 16 | return value; | |
| 466 | } | ||
| 467 | |||
| 468 | /// time in seconds from end of the first reporting interval | ||
| 469 | 20 | std::vector<long> TimeSeries_Impl::secondsFromFirstReport() const { | |
| 470 | 20 | return m_secondsFromFirstReport; | |
| 471 | } | ||
| 472 | |||
| 473 | /// time in seconds from end of the first reporting interval at index i | ||
| 474 | ✗ | long TimeSeries_Impl::secondsFromFirstReport(unsigned int i) const { | |
| 475 | //double value = m_outOfRangeValue; // JWD: Shouldn't the out of range value be for values only? | ||
| 476 | ✗ | long value = 0; | |
| 477 | ✗ | if (i < m_secondsFromFirstReport.size()) { | |
| 478 | ✗ | value = m_secondsFromFirstReport[i]; | |
| 479 | } | ||
| 480 | ✗ | return value; | |
| 481 | } | ||
| 482 | |||
| 483 | /// values | ||
| 484 | 1155 | Vector TimeSeries_Impl::values() const { | |
| 485 | 1155 | return m_values; | |
| 486 | } | ||
| 487 | |||
| 488 | /// values at index i | ||
| 489 | ✗ | double TimeSeries_Impl::values(unsigned int i) const { | |
| 490 | ✗ | double value = m_outOfRangeValue; | |
| 491 | ✗ | if (i < m_values.size()) { | |
| 492 | ✗ | value = m_values[i]; | |
| 493 | } | ||
| 494 | ✗ | return value; | |
| 495 | } | ||
| 496 | |||
| 497 | /// units | ||
| 498 | 17 | const std::string TimeSeries_Impl::units() const { | |
| 499 | 17 | return m_units; | |
| 500 | } | ||
| 501 | |||
| 502 | /// first report date | ||
| 503 | 678 | openstudio::DateTime TimeSeries_Impl::firstReportDateTime() const { | |
| 504 | 678 | return m_firstReportDateTime; | |
| 505 | } | ||
| 506 | |||
| 507 | /// start date | ||
| 508 | 19 | openstudio::DateTime TimeSeries_Impl::startDateTime() const { | |
| 509 | 19 | return m_startDateTime; | |
| 510 | } | ||
| 511 | |||
| 512 | /// get value at number of seconds from start date and time | ||
| 513 | 422609 | double TimeSeries_Impl::valueAtSecondsFromFirstReport(long secondsFromFirstReport) const { | |
| 514 | 422609 | double result = m_outOfRangeValue; | |
| 515 | |||
| 516 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 422609 times.
|
422609 | if (m_secondsFromFirstReport.empty()) { |
| 517 | ✗ | LOG(Debug, "Cannot compute value because timeseries is empty"); | |
| 518 | ✗ | return result; | |
| 519 | } | ||
| 520 | |||
| 521 | 422609 | long duration = m_secondsFromFirstReport.back(); | |
| 522 | |||
| 523 |
2/2✓ Branch 1 taken 71240 times.
✓ Branch 2 taken 351369 times.
|
845218 | if (m_intervalLength) { |
| 524 | |||
| 525 | // before the start of the first interval | ||
| 526 |
2/2✓ Branch 2 taken 49 times.
✓ Branch 3 taken 71191 times.
|
71240 | if (secondsFromFirstReport <= -m_intervalLength->totalSeconds()) { |
| 527 |
9/9✓ Branch 1 taken 49 times.
✓ Branch 4 taken 49 times.
✓ Branch 7 taken 49 times.
✓ Branch 10 taken 49 times.
✓ Branch 13 taken 49 times.
✓ Branch 16 taken 49 times.
✓ Branch 19 taken 49 times.
✓ Branch 22 taken 49 times.
✓ Branch 25 taken 49 times.
|
49 | LOG(Debug, "Cannot compute value " << secondsFromFirstReport << " seconds before first reporting time when interval length is " |
| 528 | << *m_intervalLength); | ||
| 529 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 71136 times.
|
71191 | } else if (secondsFromFirstReport > duration) { |
| 530 | // after end of time series | ||
| 531 |
9/9✓ Branch 1 taken 55 times.
✓ Branch 4 taken 55 times.
✓ Branch 7 taken 55 times.
✓ Branch 10 taken 55 times.
✓ Branch 13 taken 55 times.
✓ Branch 16 taken 55 times.
✓ Branch 19 taken 55 times.
✓ Branch 22 taken 55 times.
✓ Branch 25 taken 55 times.
|
55 | LOG(Debug, |
| 532 | "Cannot compute value " << secondsFromFirstReport << " seconds after first reporting time when duration is " << duration << " seconds"); | ||
| 533 | } else { | ||
| 534 | // faster look up if know we have fixed interval | ||
| 535 | 71136 | unsigned numIntervals = secondsFromFirstReport / m_intervalLength->totalSeconds(); | |
| 536 | 71136 | unsigned remainder = secondsFromFirstReport % m_intervalLength->totalSeconds(); | |
| 537 | unsigned index; | ||
| 538 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 71130 times.
|
71136 | if (secondsFromFirstReport < 0) { |
| 539 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | OS_ASSERT(numIntervals == 0); |
| 540 | 6 | index = numIntervals; | |
| 541 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 71091 times.
|
71130 | } else if (remainder > 0) { |
| 542 | 39 | index = numIntervals + 1; | |
| 543 | } else { | ||
| 544 | 71091 | index = numIntervals; | |
| 545 | } | ||
| 546 | |||
| 547 | // issue with daily, hourly flood plots when index == m_values.size() | ||
| 548 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 71136 times.
|
71136 | if (index >= m_values.size()) { |
| 549 | ✗ | LOG(Warn, | |
| 550 | "Timeseries index " << index << " is greater than or equal to values size " << m_values.size() << " and has been set to size - 1."); | ||
| 551 | ✗ | index = index - 1; | |
| 552 | } | ||
| 553 | 71136 | result = m_values(index); | |
| 554 | } | ||
| 555 | |||
| 556 | } else { | ||
| 557 | |||
| 558 | // before the end of the first interval, do not know when start is | ||
| 559 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 351354 times.
|
351369 | if (secondsFromFirstReport < 0) { |
| 560 |
7/7✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
✓ Branch 10 taken 15 times.
✓ Branch 13 taken 15 times.
✓ Branch 16 taken 15 times.
✓ Branch 19 taken 15 times.
|
15 | LOG(Debug, "Cannot compute value " << secondsFromFirstReport << " seconds before first reporting time when interval length is unknown"); |
| 561 | |||
| 562 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 351313 times.
|
351354 | } else if (secondsFromFirstReport > duration) { |
| 563 | // after end of time series | ||
| 564 |
9/9✓ Branch 1 taken 41 times.
✓ Branch 4 taken 41 times.
✓ Branch 7 taken 41 times.
✓ Branch 10 taken 41 times.
✓ Branch 13 taken 41 times.
✓ Branch 16 taken 41 times.
✓ Branch 19 taken 41 times.
✓ Branch 22 taken 41 times.
✓ Branch 25 taken 41 times.
|
41 | LOG(Debug, |
| 565 | "Cannot compute value " << secondsFromFirstReport << " seconds after first reporting time when duration is " << duration << " seconds"); | ||
| 566 | } else { | ||
| 567 | // normal interpolation | ||
| 568 | 351313 | result = interp(m_secondsFromFirstReportAsVector, m_values, secondsFromFirstReport, HoldNextInterp, NoneExtrap); | |
| 569 | } | ||
| 570 | } | ||
| 571 | |||
| 572 | 422609 | return result; | |
| 573 | } | ||
| 574 | |||
| 575 | /// get value at number of days from start date | ||
| 576 | 104 | double TimeSeries_Impl::value(double daysFromFirstReport) const { | |
| 577 |
3/3✓ Branch 1 taken 104 times.
✓ Branch 4 taken 104 times.
✓ Branch 7 taken 104 times.
|
104 | return valueAtSecondsFromFirstReport(Time(daysFromFirstReport).totalSeconds()); |
| 578 | } | ||
| 579 | |||
| 580 | /// get value at time from first report date and time | ||
| 581 | 422505 | double TimeSeries_Impl::value(const Time& timeFromFirstReport) const { | |
| 582 | 422505 | return valueAtSecondsFromFirstReport(timeFromFirstReport.totalSeconds()); | |
| 583 | } | ||
| 584 | |||
| 585 | /// get value at date and time | ||
| 586 | 422471 | double TimeSeries_Impl::value(const DateTime& dateTime) const { | |
| 587 |
2/2✓ Branch 1 taken 422471 times.
✓ Branch 4 taken 422471 times.
|
422471 | boost::optional<int> calendarYear = m_firstReportDateTime.date().baseYear(); |
| 588 | |||
| 589 | // If our timeseries doesn't have a year, we force it to the assumed one | ||
| 590 |
1/1✓ Branch 1 taken 422471 times.
|
422471 | DateTime firstReportDateTimeWithYear = m_firstReportDateTime; |
| 591 |
2/2✓ Branch 1 taken 422471 times.
✓ Branch 4 taken 422471 times.
|
422471 | int timeSeriesYear = m_firstReportDateTime.date().year(); |
| 592 |
2/2✓ Branch 1 taken 422282 times.
✓ Branch 2 taken 189 times.
|
422471 | if (!calendarYear) { |
| 593 |
1/1✓ Branch 1 taken 422282 times.
|
422282 | firstReportDateTimeWithYear = DateTime( |
| 594 |
7/7✓ Branch 1 taken 422282 times.
✓ Branch 4 taken 422282 times.
✓ Branch 7 taken 422282 times.
✓ Branch 10 taken 422282 times.
✓ Branch 13 taken 422282 times.
✓ Branch 16 taken 422282 times.
✓ Branch 19 taken 422282 times.
|
844564 | Date(m_firstReportDateTime.date().monthOfYear(), m_firstReportDateTime.date().dayOfMonth(), timeSeriesYear), m_firstReportDateTime.time()); |
| 595 | } | ||
| 596 | |||
| 597 | // If our requested datetime doesn't have an assigned year, we default to the one of the **TimeSeries** (whether hard assigned or not) | ||
| 598 | // Or the one right after in case it ends up before the start (try wrap-around) | ||
| 599 |
1/1✓ Branch 1 taken 422471 times.
|
422471 | DateTime dateTimeWithYear = dateTime; |
| 600 |
4/4✓ Branch 1 taken 422471 times.
✓ Branch 4 taken 422471 times.
✓ Branch 7 taken 422210 times.
✓ Branch 8 taken 261 times.
|
422471 | if (!dateTimeWithYear.date().baseYear()) { |
| 601 | // Starts by assuming same year as timeseries, then use that to compare, and if before, then assume wrap-around | ||
| 602 | // Even if it doesn't really wrap-around, it'll just return nothing so it's fine | ||
| 603 | // (and valueAtSecondsFromFirstReport will also add Debug message) | ||
| 604 |
8/8✓ Branch 1 taken 422210 times.
✓ Branch 4 taken 422210 times.
✓ Branch 7 taken 422210 times.
✓ Branch 10 taken 422210 times.
✓ Branch 13 taken 422210 times.
✓ Branch 16 taken 422210 times.
✓ Branch 19 taken 422210 times.
✓ Branch 22 taken 422210 times.
|
422210 | dateTimeWithYear = DateTime(Date(dateTime.date().monthOfYear(), dateTime.date().dayOfMonth(), timeSeriesYear), dateTime.time()); |
| 605 | |||
| 606 |
2/2✓ Branch 1 taken 422210 times.
✓ Branch 4 taken 422210 times.
|
422210 | int secondsFromFirstReport = (dateTimeWithYear - firstReportDateTimeWithYear).totalSeconds(); |
| 607 | |||
| 608 | // If it's negative, then: if m_intervalLength exist we check that it's even bigger than intervalLength, | ||
| 609 | // in which case we do shift to next year, otherwise we do nothing | ||
| 610 | // This allows passing "2005-01-01 00:01:00" to report at "2005-01-01 01:00:00" (historical behavior) | ||
| 611 | // cf valueAtSecondsFromFirstReport which will allow it | ||
| 612 |
10/10✓ Branch 0 taken 338 times.
✓ Branch 1 taken 421872 times.
✓ Branch 3 taken 164 times.
✓ Branch 4 taken 174 times.
✓ Branch 6 taken 164 times.
✓ Branch 9 taken 164 times.
✓ Branch 11 taken 162 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 336 times.
✓ Branch 14 taken 421874 times.
|
422210 | if (secondsFromFirstReport < 0 && (!m_intervalLength || secondsFromFirstReport <= -m_intervalLength->totalSeconds())) { |
| 613 |
8/8✓ Branch 1 taken 336 times.
✓ Branch 4 taken 336 times.
✓ Branch 7 taken 336 times.
✓ Branch 10 taken 336 times.
✓ Branch 13 taken 336 times.
✓ Branch 16 taken 336 times.
✓ Branch 19 taken 336 times.
✓ Branch 22 taken 336 times.
|
336 | dateTimeWithYear = DateTime(Date(dateTime.date().monthOfYear(), dateTime.date().dayOfMonth(), timeSeriesYear + 1), dateTime.time()); |
| 614 | } | ||
| 615 | } | ||
| 616 | |||
| 617 |
8/8✓ Branch 1 taken 422471 times.
✓ Branch 4 taken 422471 times.
✓ Branch 7 taken 422471 times.
✓ Branch 10 taken 422471 times.
✓ Branch 13 taken 422471 times.
✓ Branch 16 taken 422471 times.
✓ Branch 19 taken 422471 times.
✓ Branch 22 taken 422471 times.
|
422471 | LOG(Debug, "Initial: dateTime=" << dateTime << ", m_firstReportDateTime=" << m_firstReportDateTime); |
| 618 |
8/8✓ Branch 1 taken 422471 times.
✓ Branch 4 taken 422471 times.
✓ Branch 7 taken 422471 times.
✓ Branch 10 taken 422471 times.
✓ Branch 13 taken 422471 times.
✓ Branch 16 taken 422471 times.
✓ Branch 19 taken 422471 times.
✓ Branch 22 taken 422471 times.
|
422471 | LOG(Debug, "Querying with dateTimeWithYear=" << dateTimeWithYear << ", firstReportDateTimeWithYear=" << firstReportDateTimeWithYear); |
| 619 | |||
| 620 |
2/2✓ Branch 1 taken 422471 times.
✓ Branch 4 taken 422471 times.
|
422471 | return value(dateTimeWithYear - firstReportDateTimeWithYear); |
| 621 | } | ||
| 622 | |||
| 623 | /// get values between start and end date times | ||
| 624 | 151 | Vector TimeSeries_Impl::values(const DateTime& startDateTime, const DateTime& endDateTime) const { | |
| 625 |
2/2✓ Branch 1 taken 151 times.
✓ Branch 4 taken 151 times.
|
151 | boost::optional<int> calendarYear = m_firstReportDateTime.date().baseYear(); |
| 626 | |||
| 627 | // If our timeseries doesn't have a year, we force it to the assumed one | ||
| 628 |
1/1✓ Branch 1 taken 151 times.
|
151 | DateTime firstReportDateTimeWithYear = m_firstReportDateTime; |
| 629 |
2/2✓ Branch 1 taken 151 times.
✓ Branch 4 taken 151 times.
|
151 | int timeSeriesYear = m_firstReportDateTime.date().year(); |
| 630 |
2/2✓ Branch 1 taken 71 times.
✓ Branch 2 taken 80 times.
|
151 | if (!calendarYear) { |
| 631 |
1/1✓ Branch 1 taken 71 times.
|
71 | firstReportDateTimeWithYear = DateTime( |
| 632 |
7/7✓ Branch 1 taken 71 times.
✓ Branch 4 taken 71 times.
✓ Branch 7 taken 71 times.
✓ Branch 10 taken 71 times.
✓ Branch 13 taken 71 times.
✓ Branch 16 taken 71 times.
✓ Branch 19 taken 71 times.
|
142 | Date(m_firstReportDateTime.date().monthOfYear(), m_firstReportDateTime.date().dayOfMonth(), timeSeriesYear), m_firstReportDateTime.time()); |
| 633 | } | ||
| 634 | |||
| 635 | // If our requested start doen't have an assigned year, we default to the one of the **TimeSeries** (whether hard assigned or not) | ||
| 636 |
1/1✓ Branch 1 taken 151 times.
|
151 | DateTime startDateTimeWithYear = startDateTime; |
| 637 |
4/4✓ Branch 1 taken 151 times.
✓ Branch 4 taken 151 times.
✓ Branch 7 taken 35 times.
✓ Branch 8 taken 116 times.
|
151 | if (!startDateTime.date().baseYear()) { |
| 638 | startDateTimeWithYear = | ||
| 639 |
8/8✓ Branch 1 taken 35 times.
✓ Branch 4 taken 35 times.
✓ Branch 7 taken 35 times.
✓ Branch 10 taken 35 times.
✓ Branch 13 taken 35 times.
✓ Branch 16 taken 35 times.
✓ Branch 19 taken 35 times.
✓ Branch 22 taken 35 times.
|
35 | DateTime(Date(startDateTime.date().monthOfYear(), startDateTime.date().dayOfMonth(), timeSeriesYear), startDateTime.time()); |
| 640 | } | ||
| 641 | |||
| 642 | // Then if our end doesn't have an assigned year, we default it based on the start one | ||
| 643 |
1/1✓ Branch 1 taken 151 times.
|
151 | DateTime endDateTimeWithYear = endDateTime; |
| 644 |
4/4✓ Branch 1 taken 151 times.
✓ Branch 4 taken 151 times.
✓ Branch 7 taken 35 times.
✓ Branch 8 taken 116 times.
|
151 | if (!endDateTime.date().baseYear()) { |
| 645 | |||
| 646 | // Compare on a Month/Day basis only | ||
| 647 |
7/7✓ Branch 1 taken 35 times.
✓ Branch 4 taken 35 times.
✓ Branch 7 taken 35 times.
✓ Branch 10 taken 35 times.
✓ Branch 13 taken 35 times.
✓ Branch 16 taken 35 times.
✓ Branch 19 taken 35 times.
|
35 | DateTime startDateTimeCompare = DateTime(Date(startDateTime.date().monthOfYear(), startDateTime.date().dayOfMonth()), startDateTime.time()); |
| 648 |
7/7✓ Branch 1 taken 35 times.
✓ Branch 4 taken 35 times.
✓ Branch 7 taken 35 times.
✓ Branch 10 taken 35 times.
✓ Branch 13 taken 35 times.
✓ Branch 16 taken 35 times.
✓ Branch 19 taken 35 times.
|
35 | DateTime endDateTimeCompare = DateTime(Date(endDateTime.date().monthOfYear(), endDateTime.date().dayOfMonth()), endDateTime.time()); |
| 649 | |||
| 650 |
3/3✓ Branch 1 taken 35 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 28 times.
|
35 | if (endDateTimeCompare <= startDateTimeCompare) { |
| 651 |
1/1✓ Branch 1 taken 7 times.
|
7 | endDateTimeWithYear = DateTime( |
| 652 |
9/9✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
✓ Branch 10 taken 7 times.
✓ Branch 13 taken 7 times.
✓ Branch 16 taken 7 times.
✓ Branch 19 taken 7 times.
✓ Branch 22 taken 7 times.
✓ Branch 25 taken 7 times.
|
14 | Date(endDateTime.date().monthOfYear(), endDateTime.date().dayOfMonth(), startDateTimeWithYear.date().year() + 1), endDateTime.time()); |
| 653 | } else { | ||
| 654 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | int totalSeconds = (endDateTimeCompare - startDateTimeCompare).totalSeconds(); |
| 655 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | endDateTimeWithYear = startDateTimeWithYear + Time(0, 0, 0, totalSeconds); |
| 656 | // endDateTimeWithYear = DateTime(Date(endDateTime.date().monthOfYear(), endDateTime.date().dayOfMonth(), timeSeriesYear), endDateTime.time()); | ||
| 657 | } | ||
| 658 | } | ||
| 659 | |||
| 660 | // After our thing, we ensure that we do end up with dates that make sense | ||
| 661 |
3/3✓ Branch 1 taken 151 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 149 times.
|
151 | if (endDateTimeWithYear < startDateTimeWithYear) { |
| 662 |
5/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
|
2 | LOG(Warn, "Incorrect DateTimes passed, ensure that the start and end dates are coherent"); |
| 663 | } | ||
| 664 | |||
| 665 |
10/10✓ Branch 1 taken 151 times.
✓ Branch 4 taken 151 times.
✓ Branch 7 taken 151 times.
✓ Branch 10 taken 151 times.
✓ Branch 13 taken 151 times.
✓ Branch 16 taken 151 times.
✓ Branch 19 taken 151 times.
✓ Branch 22 taken 151 times.
✓ Branch 25 taken 151 times.
✓ Branch 28 taken 151 times.
|
151 | LOG(Debug, "Initial: startDateTime=" << startDateTime << ", endDateTime=" << endDateTime << ", m_firstReportDateTime=" << m_firstReportDateTime); |
| 666 |
10/10✓ Branch 1 taken 151 times.
✓ Branch 4 taken 151 times.
✓ Branch 7 taken 151 times.
✓ Branch 10 taken 151 times.
✓ Branch 13 taken 151 times.
✓ Branch 16 taken 151 times.
✓ Branch 19 taken 151 times.
✓ Branch 22 taken 151 times.
✓ Branch 25 taken 151 times.
✓ Branch 28 taken 151 times.
|
151 | LOG(Debug, "Querying with startDateTimeWithYear=" << startDateTimeWithYear << ", endDateTimeWithYear=" << endDateTimeWithYear |
| 667 | << ", firstReportDateTimeWithYear=" << firstReportDateTimeWithYear); | ||
| 668 | |||
| 669 |
2/2✓ Branch 1 taken 151 times.
✓ Branch 4 taken 151 times.
|
151 | double startSecondsFromFirstReport = (startDateTimeWithYear - firstReportDateTimeWithYear).totalSeconds(); |
| 670 |
2/2✓ Branch 1 taken 151 times.
✓ Branch 4 taken 151 times.
|
151 | double endSecondsFromFirstReport = (endDateTimeWithYear - firstReportDateTimeWithYear).totalSeconds(); |
| 671 | |||
| 672 |
1/1✓ Branch 1 taken 151 times.
|
151 | unsigned numValues = m_values.size(); |
| 673 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 151 times.
✗ Branch 4 not taken.
|
151 | OS_ASSERT(numValues == m_secondsFromFirstReport.size()); |
| 674 | |||
| 675 |
1/1✓ Branch 1 taken 151 times.
|
151 | Vector result(numValues); |
| 676 | 151 | unsigned resultSize = 0; | |
| 677 |
2/2✓ Branch 0 taken 2052644 times.
✓ Branch 1 taken 151 times.
|
2052795 | for (unsigned i = 0; i < numValues; ++i) { |
| 678 |
6/6✓ Branch 1 taken 1240460 times.
✓ Branch 2 taken 812184 times.
✓ Branch 4 taken 118536 times.
✓ Branch 5 taken 1121924 times.
✓ Branch 6 taken 118536 times.
✓ Branch 7 taken 1934108 times.
|
2052644 | if ((m_secondsFromFirstReport[i] >= startSecondsFromFirstReport) && (m_secondsFromFirstReport[i] <= endSecondsFromFirstReport)) { |
| 679 |
2/2✓ Branch 1 taken 118536 times.
✓ Branch 4 taken 118536 times.
|
118536 | result[resultSize] = m_values[i]; |
| 680 | 118536 | ++resultSize; | |
| 681 | } | ||
| 682 | } | ||
| 683 | |||
| 684 |
1/1✓ Branch 1 taken 151 times.
|
151 | result.resize(resultSize, true); |
| 685 | // Warn if empty | ||
| 686 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 149 times.
|
151 | if (resultSize == 0) { |
| 687 |
5/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
|
2 | LOG(Warn, "The combination of start and end DateTimes you passed resulted in zero values"); |
| 688 | } | ||
| 689 | |||
| 690 | 302 | return result; | |
| 691 | ✗ | } | |
| 692 | |||
| 693 | /// get the value used for out of range data | ||
| 694 | 25 | double TimeSeries_Impl::outOfRangeValue() const { | |
| 695 | 25 | return m_outOfRangeValue; | |
| 696 | } | ||
| 697 | |||
| 698 | /// set the value used for out of range data, defaults to 0 | ||
| 699 | 29 | void TimeSeries_Impl::setOutOfRangeValue(double value) { | |
| 700 | 29 | m_outOfRangeValue = value; | |
| 701 | 29 | } | |
| 702 | |||
| 703 | /// add timeseries | ||
| 704 | 9 | std::shared_ptr<TimeSeries_Impl> TimeSeries_Impl::operator+(const TimeSeries_Impl& other) const { | |
| 705 |
2/4✓ Branch 2 taken 9 times.
✓ Branch 5 taken 9 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
9 | std::shared_ptr<TimeSeries_Impl> result(new TimeSeries_Impl()); |
| 706 | |||
| 707 | // if same units | ||
| 708 |
2/3✓ Branch 1 taken 9 times.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
|
9 | if (m_units == other.units()) { |
| 709 | |||
| 710 | // make unique, ordered set of all date times | ||
| 711 | 9 | std::set<DateTime> dateTimesSet; | |
| 712 |
1/1✓ Branch 1 taken 9 times.
|
9 | DateTimeVector dateTimes1 = dateTimes(); |
| 713 |
1/1✓ Branch 1 taken 9 times.
|
9 | DateTimeVector dateTimes2 = other.dateTimes(); |
| 714 |
1/1✓ Branch 3 taken 9 times.
|
9 | dateTimesSet.insert(dateTimes1.begin(), dateTimes1.end()); |
| 715 |
1/1✓ Branch 3 taken 9 times.
|
9 | dateTimesSet.insert(dateTimes2.begin(), dateTimes2.end()); |
| 716 | |||
| 717 | // create vector out of set | ||
| 718 |
1/1✓ Branch 3 taken 9 times.
|
9 | DateTimeVector dateTimes(dateTimesSet.begin(), dateTimesSet.end()); |
| 719 | |||
| 720 | // compute value at each date time | ||
| 721 |
1/1✓ Branch 2 taken 9 times.
|
9 | Vector values(dateTimesSet.size()); |
| 722 | 9 | unsigned valueIndex = 0; | |
| 723 |
2/2✓ Branch 4 taken 52575 times.
✓ Branch 5 taken 9 times.
|
52584 | for (const DateTime& dt : dateTimes) { |
| 724 |
3/3✓ Branch 1 taken 52575 times.
✓ Branch 4 taken 52575 times.
✓ Branch 7 taken 52575 times.
|
52575 | values[valueIndex] = value(dt) + other.value(dt); |
| 725 | |||
| 726 |
15/15✓ Branch 1 taken 52575 times.
✓ Branch 4 taken 52575 times.
✓ Branch 7 taken 52575 times.
✓ Branch 10 taken 52575 times.
✓ Branch 13 taken 52575 times.
✓ Branch 16 taken 52575 times.
✓ Branch 19 taken 52575 times.
✓ Branch 22 taken 52575 times.
✓ Branch 25 taken 52575 times.
✓ Branch 28 taken 52575 times.
✓ Branch 31 taken 52575 times.
✓ Branch 34 taken 52575 times.
✓ Branch 37 taken 52575 times.
✓ Branch 40 taken 52575 times.
✓ Branch 43 taken 52575 times.
|
52575 | LOG(Debug, "At '" << dt << "' " << value(dt) << " + " << other.value(dt) << " = " << values[valueIndex]); |
| 727 | |||
| 728 | 52575 | ++valueIndex; | |
| 729 | } | ||
| 730 | |||
| 731 | // make new result | ||
| 732 |
3/5✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
9 | result = std::shared_ptr<TimeSeries_Impl>(new TimeSeries_Impl(dateTimes, values, m_units)); |
| 733 | |||
| 734 | 9 | } else { | |
| 735 | ✗ | LOG(Warn, "Adding timeseries with different units returns an empty timeseries"); | |
| 736 | } | ||
| 737 | |||
| 738 | 9 | return result; | |
| 739 | ✗ | } | |
| 740 | |||
| 741 | /// subtract timeseries | ||
| 742 | 8 | std::shared_ptr<TimeSeries_Impl> TimeSeries_Impl::operator-(const TimeSeries_Impl& other) const { | |
| 743 |
2/4✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
8 | std::shared_ptr<TimeSeries_Impl> result(new TimeSeries_Impl()); |
| 744 | |||
| 745 | // if same units | ||
| 746 |
2/3✓ Branch 1 taken 8 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
8 | if (m_units == other.units()) { |
| 747 | |||
| 748 | // make unique, ordered set of all date times | ||
| 749 | 8 | std::set<DateTime> dateTimesSet; | |
| 750 |
1/1✓ Branch 1 taken 8 times.
|
8 | DateTimeVector dateTimes1 = dateTimes(); |
| 751 |
1/1✓ Branch 1 taken 8 times.
|
8 | DateTimeVector dateTimes2 = other.dateTimes(); |
| 752 |
1/1✓ Branch 3 taken 8 times.
|
8 | dateTimesSet.insert(dateTimes1.begin(), dateTimes1.end()); |
| 753 |
1/1✓ Branch 3 taken 8 times.
|
8 | dateTimesSet.insert(dateTimes2.begin(), dateTimes2.end()); |
| 754 | |||
| 755 | // create vector out of set | ||
| 756 |
1/1✓ Branch 3 taken 8 times.
|
8 | DateTimeVector dateTimes(dateTimesSet.begin(), dateTimesSet.end()); |
| 757 | |||
| 758 | // compute value at each date time | ||
| 759 |
1/1✓ Branch 2 taken 8 times.
|
8 | Vector values(dateTimesSet.size()); |
| 760 | 8 | unsigned valueIndex = 0; | |
| 761 |
2/2✓ Branch 4 taken 52570 times.
✓ Branch 5 taken 8 times.
|
52578 | for (const DateTime& dt : dateTimes) { |
| 762 |
3/3✓ Branch 1 taken 52570 times.
✓ Branch 4 taken 52570 times.
✓ Branch 7 taken 52570 times.
|
52570 | values[valueIndex] = value(dt) - other.value(dt); |
| 763 | |||
| 764 |
15/15✓ Branch 1 taken 52570 times.
✓ Branch 4 taken 52570 times.
✓ Branch 7 taken 52570 times.
✓ Branch 10 taken 52570 times.
✓ Branch 13 taken 52570 times.
✓ Branch 16 taken 52570 times.
✓ Branch 19 taken 52570 times.
✓ Branch 22 taken 52570 times.
✓ Branch 25 taken 52570 times.
✓ Branch 28 taken 52570 times.
✓ Branch 31 taken 52570 times.
✓ Branch 34 taken 52570 times.
✓ Branch 37 taken 52570 times.
✓ Branch 40 taken 52570 times.
✓ Branch 43 taken 52570 times.
|
52570 | LOG(Debug, "At '" << dt << "' " << value(dt) << " - " << other.value(dt) << " = " << values[valueIndex]); |
| 765 | |||
| 766 | 52570 | ++valueIndex; | |
| 767 | } | ||
| 768 | |||
| 769 | // make new result | ||
| 770 |
3/5✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
8 | result = std::shared_ptr<TimeSeries_Impl>(new TimeSeries_Impl(dateTimes, values, m_units)); |
| 771 | |||
| 772 | 8 | } else { | |
| 773 | ✗ | LOG(Warn, "Subtracting timeseries with different units returns an empty timeseries"); | |
| 774 | } | ||
| 775 | |||
| 776 | 8 | return result; | |
| 777 | ✗ | } | |
| 778 | |||
| 779 | 3 | std::shared_ptr<TimeSeries_Impl> TimeSeries_Impl::operator*(double d) const { | |
| 780 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 2 times.
|
6 | if (m_intervalLength) { |
| 781 |
5/7✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 11 taken 1 time.
✓ Branch 14 taken 1 time.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | return std::shared_ptr<TimeSeries_Impl>(new TimeSeries_Impl(m_firstReportDateTime, m_intervalLength.get(), m_values * d, m_units)); |
| 782 | } | ||
| 783 |
4/6✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 11 taken 2 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
2 | return std::shared_ptr<TimeSeries_Impl>(new TimeSeries_Impl(m_firstReportDateTime, m_secondsFromFirstReport, m_values * d, m_units)); |
| 784 | } | ||
| 785 | |||
| 786 | 23 | double TimeSeries_Impl::integrate() const { | |
| 787 | 23 | double result = 0; | |
| 788 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 19 times.
|
46 | if (m_intervalLength) { |
| 789 | 4 | int secs = m_intervalLength.get().totalSeconds(); | |
| 790 | // Use a Riemann sum to integrate under the curve | ||
| 791 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 4 times.
|
12 | for (unsigned i = 0; i < m_values.size(); i++) { |
| 792 | 8 | result += secs * m_values[i]; | |
| 793 | } | ||
| 794 | } else { | ||
| 795 | 19 | double lastTime = 0; | |
| 796 | // Use a Riemann sum to integrate under the curve | ||
| 797 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 2 taken 19 times.
|
81 | for (unsigned i = 0; i < m_values.size(); i++) { |
| 798 | 62 | result += (m_secondsFromStart[i] - lastTime) * m_values[i]; | |
| 799 | 62 | lastTime = m_secondsFromStart[i]; | |
| 800 | } | ||
| 801 | } | ||
| 802 | 23 | return result; | |
| 803 | } | ||
| 804 | |||
| 805 | 11 | double TimeSeries_Impl::averageValue() const { | |
| 806 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | if (!m_secondsFromStart.empty()) { |
| 807 | 11 | return integrate() / m_secondsFromStart.back(); | |
| 808 | } | ||
| 809 | ✗ | return 0; | |
| 810 | } | ||
| 811 | |||
| 812 | } // namespace detail | ||
| 813 | |||
| 814 |
2/4✓ Branch 2 taken 4885 times.
✓ Branch 5 taken 4885 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
4885 | TimeSeries::TimeSeries() : m_impl(std::shared_ptr<detail::TimeSeries_Impl>(new detail::TimeSeries_Impl())) {} |
| 815 | |||
| 816 | 38 | TimeSeries::TimeSeries(const Date& startDate, const Time& intervalLength, const Vector& values, const std::string& units) | |
| 817 |
2/4✓ Branch 2 taken 38 times.
✓ Branch 5 taken 38 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
38 | : m_impl(std::shared_ptr<detail::TimeSeries_Impl>(new detail::TimeSeries_Impl(startDate, intervalLength, values, units))) {} |
| 818 | |||
| 819 | 102 | TimeSeries::TimeSeries(const DateTime& firstReportDateTime, const Time& intervalLength, const Vector& values, const std::string& units) | |
| 820 |
2/4✓ Branch 2 taken 102 times.
✓ Branch 5 taken 102 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
102 | : m_impl(std::shared_ptr<detail::TimeSeries_Impl>(new detail::TimeSeries_Impl(firstReportDateTime, intervalLength, values, units))) {} |
| 821 | |||
| 822 | 3 | TimeSeries::TimeSeries(const DateTime& firstReportDateTime, const Vector& timeInDays, const Vector& values, const std::string& units) | |
| 823 |
3/4✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
|
3 | : m_impl(std::shared_ptr<detail::TimeSeries_Impl>(new detail::TimeSeries_Impl(firstReportDateTime, timeInDays, values, units))) {} |
| 824 | |||
| 825 | 7 | TimeSeries::TimeSeries(const DateTime& firstReportDateTime, const std::vector<double>& timeInDays, const std::vector<double>& values, | |
| 826 | 7 | const std::string& units) | |
| 827 |
3/4✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
7 | : m_impl(std::shared_ptr<detail::TimeSeries_Impl>(new detail::TimeSeries_Impl(firstReportDateTime, timeInDays, values, units))) {} |
| 828 | |||
| 829 | 45 | TimeSeries::TimeSeries(const DateTimeVector& dateTimes, const Vector& values, const std::string& units) | |
| 830 |
2/4✓ Branch 2 taken 45 times.
✓ Branch 5 taken 45 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
45 | : m_impl(std::shared_ptr<detail::TimeSeries_Impl>(new detail::TimeSeries_Impl(dateTimes, values, units))) {} |
| 831 | |||
| 832 | 110 | TimeSeries::TimeSeries(const DateTime& firstReportDateTime, const std::vector<long>& timeInSeconds, const Vector& values, const std::string& units) | |
| 833 |
3/4✓ Branch 2 taken 109 times.
✓ Branch 5 taken 109 times.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
|
110 | : m_impl(std::shared_ptr<detail::TimeSeries_Impl>(new detail::TimeSeries_Impl(firstReportDateTime, timeInSeconds, values, units))) {} |
| 834 | |||
| 835 | 60 | openstudio::OptionalTime TimeSeries::intervalLength() const { | |
| 836 | 60 | return m_impl->intervalLength(); | |
| 837 | } | ||
| 838 | |||
| 839 | 161 | openstudio::DateTimeVector TimeSeries::dateTimes() const { | |
| 840 | 161 | return m_impl->dateTimes(); | |
| 841 | } | ||
| 842 | |||
| 843 | 678 | openstudio::DateTime TimeSeries::firstReportDateTime() const { | |
| 844 | 678 | return m_impl->firstReportDateTime(); | |
| 845 | } | ||
| 846 | |||
| 847 | 19 | openstudio::DateTime TimeSeries::startDateTime() const { | |
| 848 | 19 | return m_impl->startDateTime(); | |
| 849 | } | ||
| 850 | |||
| 851 | 619 | openstudio::Vector TimeSeries::daysFromFirstReport() const { | |
| 852 | 619 | return m_impl->daysFromFirstReport(); | |
| 853 | } | ||
| 854 | |||
| 855 | 16 | double TimeSeries::daysFromFirstReport(unsigned int i) const { | |
| 856 | 16 | return m_impl->daysFromFirstReport(i); | |
| 857 | } | ||
| 858 | |||
| 859 | 20 | std::vector<long> TimeSeries::secondsFromFirstReport() const { | |
| 860 | 20 | return m_impl->secondsFromFirstReport(); | |
| 861 | } | ||
| 862 | |||
| 863 | ✗ | long TimeSeries::secondsFromFirstReport(unsigned int i) const { | |
| 864 | ✗ | return m_impl->secondsFromFirstReport(i); | |
| 865 | } | ||
| 866 | |||
| 867 | 1155 | openstudio::Vector TimeSeries::values() const { | |
| 868 | 1155 | return m_impl->values(); | |
| 869 | } | ||
| 870 | |||
| 871 | ✗ | double TimeSeries::values(unsigned int i) const { | |
| 872 | ✗ | return m_impl->values(i); | |
| 873 | } | ||
| 874 | |||
| 875 | ✗ | const std::string TimeSeries::units() const { | |
| 876 | ✗ | return m_impl->units(); | |
| 877 | } | ||
| 878 | |||
| 879 | 104 | double TimeSeries::value(double daysFromFirstReport) const { | |
| 880 | 104 | return m_impl->value(daysFromFirstReport); | |
| 881 | } | ||
| 882 | |||
| 883 | 34 | double TimeSeries::value(const Time& timeFromFirstReport) const { | |
| 884 | 34 | return m_impl->value(timeFromFirstReport); | |
| 885 | } | ||
| 886 | |||
| 887 | 1891 | double TimeSeries::value(const DateTime& dateTime) const { | |
| 888 | 1891 | return m_impl->value(dateTime); | |
| 889 | } | ||
| 890 | |||
| 891 | 151 | Vector TimeSeries::values(const DateTime& startDateTime, const DateTime& endDateTime) const { | |
| 892 | 151 | return m_impl->values(startDateTime, endDateTime); | |
| 893 | } | ||
| 894 | |||
| 895 | 25 | double TimeSeries::outOfRangeValue() const { | |
| 896 | 25 | return m_impl->outOfRangeValue(); | |
| 897 | } | ||
| 898 | |||
| 899 | 29 | void TimeSeries::setOutOfRangeValue(double value) { | |
| 900 | 29 | m_impl->setOutOfRangeValue(value); | |
| 901 | 29 | } | |
| 902 | |||
| 903 | 9 | TimeSeries TimeSeries::operator+(const TimeSeries& other) const { | |
| 904 |
1/1✓ Branch 3 taken 9 times.
|
9 | std::shared_ptr<detail::TimeSeries_Impl> impl = (*m_impl) + *(other.m_impl); |
| 905 |
1/1✓ Branch 2 taken 9 times.
|
18 | return {impl}; |
| 906 | 9 | } | |
| 907 | |||
| 908 | 8 | TimeSeries TimeSeries::operator-(const TimeSeries& other) const { | |
| 909 |
1/1✓ Branch 3 taken 8 times.
|
8 | std::shared_ptr<detail::TimeSeries_Impl> impl = (*m_impl) - *(other.m_impl); |
| 910 |
1/1✓ Branch 2 taken 8 times.
|
16 | return {impl}; |
| 911 | 8 | } | |
| 912 | |||
| 913 | 2 | TimeSeries TimeSeries::operator*(double d) const { | |
| 914 |
1/1✓ Branch 2 taken 2 times.
|
2 | std::shared_ptr<detail::TimeSeries_Impl> impl = (*m_impl) * d; |
| 915 |
1/1✓ Branch 2 taken 2 times.
|
4 | return {impl}; |
| 916 | 2 | } | |
| 917 | |||
| 918 | 1 | TimeSeries TimeSeries::operator/(double d) const { | |
| 919 |
1/1✓ Branch 2 taken 1 time.
|
1 | std::shared_ptr<detail::TimeSeries_Impl> impl = (*m_impl) * (1.0 / d); |
| 920 |
1/1✓ Branch 2 taken 1 time.
|
2 | return {impl}; |
| 921 | 1 | } | |
| 922 | |||
| 923 | 12 | double TimeSeries::integrate() const { | |
| 924 | 12 | return m_impl->integrate(); | |
| 925 | } | ||
| 926 | |||
| 927 | 11 | double TimeSeries::averageValue() const { | |
| 928 | 11 | return m_impl->averageValue(); | |
| 929 | } | ||
| 930 | |||
| 931 | 20 | TimeSeries::TimeSeries(std::shared_ptr<detail::TimeSeries_Impl> impl) : m_impl(impl) {} | |
| 932 | |||
| 933 | 2 | TimeSeries operator*(double d, const TimeSeries& series) { | |
| 934 | 2 | return series * d; | |
| 935 | } | ||
| 936 | |||
| 937 | 1 | TimeSeries sum(const std::vector<TimeSeries>& timeSeriesVector) { | |
| 938 | 1 | TimeSeries result; | |
| 939 | 1 | bool first = true; | |
| 940 |
2/2✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 time.
|
4 | for (const TimeSeries& ts : timeSeriesVector) { |
| 941 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
|
3 | if (first) { |
| 942 | 1 | result = ts; | |
| 943 | } else { | ||
| 944 |
1/1✓ Branch 1 taken 2 times.
|
2 | result = result + ts; |
| 945 | } | ||
| 946 |
3/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
|
3 | if (result.values().empty()) { |
| 947 | ✗ | LOG_FREE(Info, "zero.sum", "Could not sum the timeSeriesVector. Either the first series is empty, or the " << "units are incompatible."); | |
| 948 | ✗ | break; | |
| 949 | } | ||
| 950 | 3 | first = false; | |
| 951 | } | ||
| 952 | 1 | return result; | |
| 953 | ✗ | } | |
| 954 | |||
| 955 | ✗ | boost::function1<TimeSeries, const std::vector<TimeSeries>&> sumTimeSeriesFunctor() { | |
| 956 | using functype = TimeSeries (*)(const std::vector<TimeSeries>&); | ||
| 957 | ✗ | return std::function<TimeSeries(const std::vector<TimeSeries>&)>(functype(&sum)); | |
| 958 | } | ||
| 959 | |||
| 960 | ✗ | TimeSeries evaluateTimeSeriesFromTimeSeriesVectorFunctor(const boost::function1<TimeSeries, const std::vector<TimeSeries>&>& functor, | |
| 961 | const std::vector<TimeSeries>& timeSeriesVector) { | ||
| 962 | ✗ | return functor(timeSeriesVector); | |
| 963 | } | ||
| 964 | |||
| 965 | } // namespace openstudio | ||
| 966 |