src/model/ScheduleFile.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 "ScheduleFile.hpp" | ||
| 7 | #include "ScheduleFile_Impl.hpp" | ||
| 8 | |||
| 9 | #include "ScheduleTypeLimits.hpp" | ||
| 10 | #include "ScheduleTypeLimits_Impl.hpp" | ||
| 11 | #include "ExternalFile.hpp" | ||
| 12 | #include "ExternalFile_Impl.hpp" | ||
| 13 | #include "Model.hpp" | ||
| 14 | #include "Model_Impl.hpp" | ||
| 15 | |||
| 16 | #include <utilities/idd/IddFactory.hxx> | ||
| 17 | #include <utilities/idd/IddEnums.hxx> | ||
| 18 | #include <utilities/idd/OS_Schedule_File_FieldEnums.hxx> | ||
| 19 | |||
| 20 | #include "../utilities/units/Unit.hpp" | ||
| 21 | #include "../utilities/data/TimeSeries.hpp" | ||
| 22 | #include "../utilities/core/Assert.hpp" | ||
| 23 | #include "../utilities/filetypes/CSVFile.hpp" | ||
| 24 | |||
| 25 | #include "../utilities/core/DeprecatedHelpers.hpp" | ||
| 26 | |||
| 27 | #include <unordered_map> | ||
| 28 | |||
| 29 | namespace openstudio { | ||
| 30 | namespace model { | ||
| 31 | |||
| 32 | namespace detail { | ||
| 33 | |||
| 34 | 13 | ScheduleFile_Impl::ScheduleFile_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 35 | 13 | : ScheduleInterval_Impl(idfObject, model, keepHandle) { | |
| 36 |
4/6✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 13 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 13 times.
✗ Branch 13 not taken.
|
13 | OS_ASSERT(idfObject.iddObject().type() == ScheduleFile::iddObjectType()); |
| 37 | 13 | } | |
| 38 | |||
| 39 | ✗ | ScheduleFile_Impl::ScheduleFile_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 40 | ✗ | : ScheduleInterval_Impl(other, model, keepHandle) { | |
| 41 | ✗ | OS_ASSERT(other.iddObject().type() == ScheduleFile::iddObjectType()); | |
| 42 | ✗ | } | |
| 43 | |||
| 44 | 4 | ScheduleFile_Impl::ScheduleFile_Impl(const ScheduleFile_Impl& other, Model_Impl* model, bool keepHandle) | |
| 45 | 4 | : ScheduleInterval_Impl(other, model, keepHandle) {} | |
| 46 | |||
| 47 | ✗ | const std::vector<std::string>& ScheduleFile_Impl::outputVariableNames() const { | |
| 48 | ✗ | static const std::vector<std::string> result; | |
| 49 | ✗ | if (result.empty()) { | |
| 50 | } | ||
| 51 | ✗ | return result; | |
| 52 | } | ||
| 53 | |||
| 54 | ✗ | IddObjectType ScheduleFile_Impl::iddObjectType() const { | |
| 55 | ✗ | return ScheduleFile::iddObjectType(); | |
| 56 | } | ||
| 57 | |||
| 58 | ✗ | std::vector<ResourceObject> ScheduleFile_Impl::resources() const { | |
| 59 | ✗ | std::vector<ResourceObject> result; | |
| 60 | ✗ | result.push_back(externalFile()); | |
| 61 | ✗ | return result; | |
| 62 | ✗ | } | |
| 63 | |||
| 64 | 5 | boost::optional<ScheduleTypeLimits> ScheduleFile_Impl::scheduleTypeLimits() const { | |
| 65 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
5 | return getObject<ModelObject>().getModelObjectTarget<ScheduleTypeLimits>(OS_Schedule_FileFields::ScheduleTypeLimitsName); |
| 66 | } | ||
| 67 | |||
| 68 | 21 | ExternalFile ScheduleFile_Impl::externalFile() const { | |
| 69 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | auto value = getObject<ModelObject>().getModelObjectTarget<ExternalFile>(OS_Schedule_FileFields::ExternalFileName); |
| 70 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 4 not taken.
|
21 | OS_ASSERT(value); |
| 71 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
42 | return value.get(); |
| 72 | 21 | } | |
| 73 | |||
| 74 | 21 | int ScheduleFile_Impl::columnNumber() const { | |
| 75 |
1/1✓ Branch 1 taken 21 times.
|
21 | boost::optional<int> value = getInt(OS_Schedule_FileFields::ColumnNumber, true); |
| 76 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 4 not taken.
|
21 | OS_ASSERT(value); |
| 77 |
1/1✓ Branch 1 taken 21 times.
|
42 | return value.get(); |
| 78 | } | ||
| 79 | |||
| 80 | 21 | int ScheduleFile_Impl::rowstoSkipatTop() const { | |
| 81 |
1/1✓ Branch 1 taken 21 times.
|
21 | boost::optional<int> value = getInt(OS_Schedule_FileFields::RowstoSkipatTop, true); |
| 82 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 4 not taken.
|
21 | OS_ASSERT(value); |
| 83 |
1/1✓ Branch 1 taken 21 times.
|
42 | return value.get(); |
| 84 | } | ||
| 85 | |||
| 86 | ✗ | int ScheduleFile_Impl::numberofHoursofData() const { | |
| 87 | ✗ | boost::optional<int> value = getInt(OS_Schedule_FileFields::NumberofHoursofData, true); | |
| 88 | ✗ | OS_ASSERT(value); | |
| 89 | ✗ | return value.get(); | |
| 90 | } | ||
| 91 | |||
| 92 | 13 | bool ScheduleFile_Impl::isNumberofHoursofDataDefaulted() const { | |
| 93 | 13 | return isEmpty(OS_Schedule_FileFields::NumberofHoursofData); | |
| 94 | } | ||
| 95 | |||
| 96 | 11 | std::string ScheduleFile_Impl::columnSeparator() const { | |
| 97 |
1/1✓ Branch 1 taken 11 times.
|
11 | boost::optional<std::string> value = getString(OS_Schedule_FileFields::ColumnSeparator, true); |
| 98 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 4 not taken.
|
11 | OS_ASSERT(value); |
| 99 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
|
22 | return value.get(); |
| 100 | 11 | } | |
| 101 | |||
| 102 | ✗ | char ScheduleFile_Impl::columnSeparatorChar() const { | |
| 103 | ✗ | static const std::unordered_map<std::string, char> lookup({{"Comma", ','}, {"Tab", '\t'}, {"Fixed", ' '}, {"Space", ' '}, {"Semicolon", ';'}}); | |
| 104 | ✗ | boost::optional<std::string> value = getString(OS_Schedule_FileFields::ColumnSeparator, true); | |
| 105 | ✗ | OS_ASSERT(value); | |
| 106 | ✗ | auto it = lookup.find(value.get()); | |
| 107 | ✗ | if (it == std::end(lookup)) { | |
| 108 | // Invalid separator | ||
| 109 | ✗ | return '\0'; | |
| 110 | } | ||
| 111 | ✗ | return it->second; | |
| 112 | ✗ | } | |
| 113 | |||
| 114 | 3 | bool ScheduleFile_Impl::isColumnSeparatorDefaulted() const { | |
| 115 | 3 | return isEmpty(OS_Schedule_FileFields::ColumnSeparator); | |
| 116 | } | ||
| 117 | |||
| 118 | 9 | bool ScheduleFile_Impl::interpolatetoTimestep() const { | |
| 119 |
1/1✓ Branch 1 taken 9 times.
|
9 | boost::optional<std::string> value = getString(OS_Schedule_FileFields::InterpolatetoTimestep, true); |
| 120 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 4 not taken.
|
9 | OS_ASSERT(value); |
| 121 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
18 | return openstudio::istringEqual(value.get(), "Yes"); |
| 122 | 9 | } | |
| 123 | |||
| 124 | 6 | bool ScheduleFile_Impl::isInterpolatetoTimestepDefaulted() const { | |
| 125 | 6 | return isEmpty(OS_Schedule_FileFields::InterpolatetoTimestep); | |
| 126 | } | ||
| 127 | |||
| 128 | 12 | int ScheduleFile_Impl::minutesperItem() const { | |
| 129 |
1/1✓ Branch 1 taken 12 times.
|
12 | boost::optional<int> value = getInt(OS_Schedule_FileFields::MinutesperItem, true); |
| 130 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 4 not taken.
|
12 | OS_ASSERT(value); |
| 131 |
1/1✓ Branch 1 taken 12 times.
|
24 | return value.get(); |
| 132 | } | ||
| 133 | |||
| 134 | 9 | bool ScheduleFile_Impl::isMinutesperItemDefaulted() const { | |
| 135 | 9 | return isEmpty(OS_Schedule_FileFields::MinutesperItem); | |
| 136 | } | ||
| 137 | |||
| 138 | 9 | bool ScheduleFile_Impl::adjustScheduleforDaylightSavings() const { | |
| 139 |
1/1✓ Branch 1 taken 9 times.
|
9 | boost::optional<std::string> value = getString(OS_Schedule_FileFields::AdjustScheduleforDaylightSavings, true); |
| 140 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 4 not taken.
|
9 | OS_ASSERT(value); |
| 141 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
18 | return openstudio::istringEqual(value.get(), "Yes"); |
| 142 | 9 | } | |
| 143 | |||
| 144 | 6 | bool ScheduleFile_Impl::isAdjustScheduleforDaylightSavingsDefaulted() const { | |
| 145 | 6 | return isEmpty(OS_Schedule_FileFields::AdjustScheduleforDaylightSavings); | |
| 146 | } | ||
| 147 | |||
| 148 | ✗ | bool ScheduleFile_Impl::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) { | |
| 149 | ✗ | bool result = setPointer(OS_Schedule_FileFields::ScheduleTypeLimitsName, scheduleTypeLimits.handle()); | |
| 150 | ✗ | return result; | |
| 151 | } | ||
| 152 | |||
| 153 | ✗ | bool ScheduleFile_Impl::resetScheduleTypeLimits() { | |
| 154 | ✗ | bool result = setString(OS_Schedule_FileFields::ScheduleTypeLimitsName, ""); | |
| 155 | ✗ | OS_ASSERT(result); | |
| 156 | ✗ | return result; | |
| 157 | } | ||
| 158 | |||
| 159 | 21 | bool ScheduleFile_Impl::setColumnNumber(int columnNumber) { | |
| 160 | 21 | bool result = setInt(OS_Schedule_FileFields::ColumnNumber, columnNumber); | |
| 161 | 21 | return result; | |
| 162 | } | ||
| 163 | |||
| 164 | 21 | bool ScheduleFile_Impl::setRowstoSkipatTop(int rowstoSkipatTop) { | |
| 165 | 21 | bool result = setInt(OS_Schedule_FileFields::RowstoSkipatTop, rowstoSkipatTop); | |
| 166 | 21 | return result; | |
| 167 | } | ||
| 168 | |||
| 169 | ✗ | bool ScheduleFile_Impl::setNumberofHoursofData(int numberofHours) { | |
| 170 | ✗ | bool result = setInt(OS_Schedule_FileFields::NumberofHoursofData, numberofHours); | |
| 171 | ✗ | return result; | |
| 172 | } | ||
| 173 | |||
| 174 | 3 | bool ScheduleFile_Impl::setColumnSeparator(const std::string& columnSeparator) { | |
| 175 | 3 | bool result = setString(OS_Schedule_FileFields::ColumnSeparator, columnSeparator); | |
| 176 | 3 | return result; | |
| 177 | } | ||
| 178 | |||
| 179 | ✗ | void ScheduleFile_Impl::resetColumnSeparator() { | |
| 180 | ✗ | bool result = setString(OS_Schedule_FileFields::ColumnSeparator, ""); | |
| 181 | ✗ | OS_ASSERT(result); | |
| 182 | ✗ | } | |
| 183 | |||
| 184 | 3 | bool ScheduleFile_Impl::setInterpolatetoTimestep(bool interpolatetoTimestep) { | |
| 185 | 3 | bool result = false; | |
| 186 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
|
3 | if (interpolatetoTimestep) { |
| 187 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
6 | result = setString(OS_Schedule_FileFields::InterpolatetoTimestep, "Yes"); |
| 188 | } else { | ||
| 189 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
3 | result = setString(OS_Schedule_FileFields::InterpolatetoTimestep, "No"); |
| 190 | } | ||
| 191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | OS_ASSERT(result); |
| 192 | 3 | return result; | |
| 193 | } | ||
| 194 | |||
| 195 | 2 | void ScheduleFile_Impl::resetInterpolatetoTimestep() { | |
| 196 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
4 | bool result = setString(OS_Schedule_FileFields::InterpolatetoTimestep, ""); |
| 197 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | OS_ASSERT(result); |
| 198 | 2 | } | |
| 199 | |||
| 200 | 4 | bool ScheduleFile_Impl::setMinutesperItem(int minutesperItem) { | |
| 201 | 4 | bool result = setInt(OS_Schedule_FileFields::MinutesperItem, minutesperItem); | |
| 202 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (!result) { |
| 203 |
9/9✓ 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.
✓ Branch 16 taken 2 times.
✓ Branch 20 taken 2 times.
✓ Branch 23 taken 2 times.
✓ Branch 26 taken 2 times.
|
2 | LOG(Warn, "Invalid 'Minutes per Item' (=" << minutesperItem << ") supplied for " << briefDescription()); |
| 204 | } | ||
| 205 | 4 | return result; | |
| 206 | } | ||
| 207 | |||
| 208 | 2 | void ScheduleFile_Impl::resetMinutesperItem() { | |
| 209 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
4 | bool result = setString(OS_Schedule_FileFields::MinutesperItem, ""); |
| 210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | OS_ASSERT(result); |
| 211 | 2 | } | |
| 212 | |||
| 213 | 2 | bool ScheduleFile_Impl::setAdjustScheduleforDaylightSavings(bool adjustScheduleforDaylightSavings) { | |
| 214 | 2 | bool result = false; | |
| 215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (adjustScheduleforDaylightSavings) { |
| 216 | ✗ | result = setString(OS_Schedule_FileFields::AdjustScheduleforDaylightSavings, "Yes"); | |
| 217 | } else { | ||
| 218 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
6 | result = setString(OS_Schedule_FileFields::AdjustScheduleforDaylightSavings, "No"); |
| 219 | } | ||
| 220 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | OS_ASSERT(result); |
| 221 | 2 | return result; | |
| 222 | } | ||
| 223 | |||
| 224 | 2 | void ScheduleFile_Impl::resetAdjustScheduleforDaylightSavings() { | |
| 225 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
4 | bool result = setString(OS_Schedule_FileFields::AdjustScheduleforDaylightSavings, ""); |
| 226 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | OS_ASSERT(result); |
| 227 | 2 | } | |
| 228 | |||
| 229 | ✗ | boost::optional<CSVFile> ScheduleFile_Impl::csvFile() const { | |
| 230 | ✗ | boost::optional<CSVFile> csvFile; | |
| 231 | ✗ | ExternalFile externalFile = this->externalFile(); | |
| 232 | ✗ | csvFile = CSVFile::load(externalFile.filePath()); | |
| 233 | ✗ | return csvFile; | |
| 234 | ✗ | } | |
| 235 | |||
| 236 | 19 | bool ScheduleFile_Impl::translateFileWithRelativePath() const { | |
| 237 |
1/1✓ Branch 1 taken 19 times.
|
19 | boost::optional<std::string> value = getString(OS_Schedule_FileFields::TranslateFileWithRelativePath, true); |
| 238 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 4 not taken.
|
19 | OS_ASSERT(value); |
| 239 |
3/3✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
✓ Branch 7 taken 19 times.
|
38 | return openstudio::istringEqual(value.get(), "Yes"); |
| 240 | 19 | } | |
| 241 | |||
| 242 | 6 | bool ScheduleFile_Impl::isTranslateFileWithRelativePathDefaulted() const { | |
| 243 | 6 | return isEmpty(OS_Schedule_FileFields::TranslateFileWithRelativePath); | |
| 244 | } | ||
| 245 | |||
| 246 | /* FIXME! | ||
| 247 | openstudio::TimeSeries ScheduleFile_Impl::timeSeries(unsigned columnIndex) const | ||
| 248 | { | ||
| 249 | // need to catch integers less than or equal to 0 | ||
| 250 | // need to ensure that first column is dateTimes | ||
| 251 | |||
| 252 | boost::optional<CSVFile> csvFile; | ||
| 253 | ExternalFile externalFile = this->externalFile(); | ||
| 254 | csvFile = CSVFile::load(externalFile.filePath()); | ||
| 255 | |||
| 256 | std::vector<DateTime> dateTimes = csvFile->getColumnAsDateTimes(0); | ||
| 257 | std::vector<double> values = csvFile->getColumnAsDoubleVector(columnIndex); | ||
| 258 | Vector vectorValues(values.size()); | ||
| 259 | unsigned i = 0; | ||
| 260 | for (double value : values) { | ||
| 261 | vectorValues[i] = value; | ||
| 262 | ++i; | ||
| 263 | } | ||
| 264 | |||
| 265 | Time delta = dateTimes[1] - dateTimes[0]; | ||
| 266 | Time intervalLength(delta.days(), delta.hours(), delta.minutes(), delta.seconds()); | ||
| 267 | TimeSeries result(dateTimes[0].date(), intervalLength, vectorValues, ""); | ||
| 268 | |||
| 269 | return result; | ||
| 270 | } | ||
| 271 | */ | ||
| 272 | |||
| 273 | /* FIXME! | ||
| 274 | unsigned ScheduleFile_Impl::addTimeSeries(const openstudio::TimeSeries& timeSeries) | ||
| 275 | { | ||
| 276 | // need to ensure that first column is dateTimes | ||
| 277 | // need to ensure that length of timeSeries equals length of dateTimes | ||
| 278 | |||
| 279 | boost::optional<CSVFile> csvFile; | ||
| 280 | ExternalFile externalFile = this->externalFile(); | ||
| 281 | csvFile = CSVFile::load(externalFile.filePath()); | ||
| 282 | unsigned columnIndex = csvFile->addColumn(timeSeries.values()); | ||
| 283 | // save? | ||
| 284 | |||
| 285 | return columnIndex; | ||
| 286 | } | ||
| 287 | */ | ||
| 288 | |||
| 289 | ✗ | openstudio::TimeSeries ScheduleFile_Impl::timeSeries() const { | |
| 290 | ✗ | openstudio::TimeSeries result; | |
| 291 | /* FIXME! | ||
| 292 | Date startDate(openstudio::MonthOfYear(this->startMonth()), this->startDay()); | ||
| 293 | Time intervalLength(0, 0, this->intervalLength()); | ||
| 294 | Vector values(this->numExtensibleGroups()); | ||
| 295 | unsigned i = 0; | ||
| 296 | for (const ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(extensibleGroups())) { | ||
| 297 | OptionalDouble x = group.getDouble(0); | ||
| 298 | OS_ASSERT(x); | ||
| 299 | values[i] = *x; | ||
| 300 | ++i; | ||
| 301 | } | ||
| 302 | TimeSeries result(startDate, intervalLength, values, ""); | ||
| 303 | result.setOutOfRangeValue(this->outOfRangeValue()); | ||
| 304 | */ | ||
| 305 | ✗ | return result; | |
| 306 | } | ||
| 307 | |||
| 308 | ✗ | bool ScheduleFile_Impl::setTimeSeries(const openstudio::TimeSeries& /*timeSeries*/) { | |
| 309 | /* FIXME! | ||
| 310 | // check the interval | ||
| 311 | boost::optional<openstudio::Time> intervalTime = timeSeries.intervalLength(); | ||
| 312 | if (!intervalTime) { | ||
| 313 | return false; | ||
| 314 | } | ||
| 315 | // check the interval | ||
| 316 | double intervalLength = intervalTime->totalMinutes(); | ||
| 317 | if (intervalLength - std::floor(intervalLength) > 0) { | ||
| 318 | return false; | ||
| 319 | } | ||
| 320 | // check the interval | ||
| 321 | if (intervalTime->totalDays() > 1) { | ||
| 322 | return false; | ||
| 323 | } | ||
| 324 | // check that first report is whole number of intervals from start date | ||
| 325 | DateTime firstReportDateTime = timeSeries.firstReportDateTime(); | ||
| 326 | Date startDate = firstReportDateTime.date(); | ||
| 327 | Time firstReportTime = firstReportDateTime.time(); | ||
| 328 | double numIntervalsToFirstReport = std::max(1.0, firstReportTime.totalMinutes() / intervalLength); | ||
| 329 | if (numIntervalsToFirstReport - std::floor(numIntervalsToFirstReport) > 0) { | ||
| 330 | return false; | ||
| 331 | } | ||
| 332 | // check the values | ||
| 333 | openstudio::Vector values = timeSeries.values(); | ||
| 334 | for (const auto& value : values) { | ||
| 335 | // Get the position | ||
| 336 | int pos = &value - &values[0]; | ||
| 337 | // Check validity, cannot be NaN, Inf, etc | ||
| 338 | if (std::isinf(value)) { | ||
| 339 | LOG(Warn, "There is Infinity on position " << pos << " in the timeSeries provided for " << this->briefDescription()); | ||
| 340 | return false; | ||
| 341 | } else if (std::isnan(value)) { | ||
| 342 | LOG(Warn, "There is a NaN on position " << pos << " in the timeSeries provided for " << this->briefDescription()); | ||
| 343 | return false; | ||
| 344 | } | ||
| 345 | } | ||
| 346 | // at this point we are going to change the object | ||
| 347 | clearExtensibleGroups(false); | ||
| 348 | // set the interval | ||
| 349 | this->setIntervalLength(intervalLength, false); | ||
| 350 | // set the start date | ||
| 351 | this->setStartMonth(startDate.monthOfYear().value(), false); | ||
| 352 | this->setStartDay(startDate.dayOfMonth(), false); | ||
| 353 | // set the out of range value | ||
| 354 | double outOfRangeValue = timeSeries.outOfRangeValue(); | ||
| 355 | // add in numIntervalsToFirstReport-1 outOfRangeValues to pad the timeseries | ||
| 356 | for (unsigned i = 0; i < numIntervalsToFirstReport - 1; ++i) { | ||
| 357 | std::vector<std::string> temp; | ||
| 358 | temp.push_back(toString(outOfRangeValue)); | ||
| 359 | ModelExtensibleGroup group = pushExtensibleGroup(temp, false).cast<ModelExtensibleGroup>(); | ||
| 360 | OS_ASSERT(!group.empty()); | ||
| 361 | } | ||
| 362 | // set the values | ||
| 363 | for (unsigned i = 0; i < values.size(); ++i) { | ||
| 364 | std::vector<std::string> temp; | ||
| 365 | temp.push_back(toString(values[i])); | ||
| 366 | ModelExtensibleGroup group = pushExtensibleGroup(temp, false).cast<ModelExtensibleGroup>(); | ||
| 367 | OS_ASSERT(!group.empty()); | ||
| 368 | } | ||
| 369 | this->emitChangeSignals(); | ||
| 370 | return true; | ||
| 371 | */ | ||
| 372 | ✗ | return false; | |
| 373 | } | ||
| 374 | |||
| 375 | ✗ | void ScheduleFile_Impl::ensureNoLeapDays() { | |
| 376 | /* FIXME! | ||
| 377 | boost::optional<int> month; | ||
| 378 | boost::optional<int> day; | ||
| 379 | |||
| 380 | month = getInt(OS_Schedule_FixedIntervalFields::StartMonth); | ||
| 381 | if (month && (month.get() == 2)) { | ||
| 382 | day = this->getInt(OS_Schedule_FixedIntervalFields::StartDay); | ||
| 383 | if (day && (day.get() == 29)) { | ||
| 384 | this->setInt(OS_Schedule_FixedIntervalFields::StartDay, 28); | ||
| 385 | } | ||
| 386 | }*/ | ||
| 387 | ✗ | } | |
| 388 | |||
| 389 | 6 | bool ScheduleFile_Impl::setTranslateFileWithRelativePath(bool translateFileWithRelativePath) { | |
| 390 | 6 | bool result = false; | |
| 391 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (translateFileWithRelativePath) { |
| 392 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
18 | result = setString(OS_Schedule_FileFields::TranslateFileWithRelativePath, "Yes"); |
| 393 | } else { | ||
| 394 | ✗ | result = setString(OS_Schedule_FileFields::TranslateFileWithRelativePath, "No"); | |
| 395 | } | ||
| 396 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | OS_ASSERT(result); |
| 397 | 6 | return result; | |
| 398 | } | ||
| 399 | |||
| 400 | 2 | void ScheduleFile_Impl::resetTranslateFileWithRelativePath() { | |
| 401 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
4 | const bool result = setString(OS_Schedule_FileFields::TranslateFileWithRelativePath, ""); |
| 402 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | OS_ASSERT(result); |
| 403 | 2 | } | |
| 404 | |||
| 405 | 9 | openstudio::path ScheduleFile_Impl::translatedFilePath() const { | |
| 406 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 3 times.
|
9 | if (translateFileWithRelativePath()) { |
| 407 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | return toPath(externalFile().fileName()); |
| 408 | } | ||
| 409 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | openstudio::path filePath = externalFile().filePath(); |
| 410 |
2/3✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
|
3 | if (!exists(filePath)) { |
| 411 | ✗ | LOG(Warn, "Cannot find file \"" << filePath << "\""); | |
| 412 | } else { | ||
| 413 | // make the path correct for this system | ||
| 414 |
1/1✓ Branch 1 taken 3 times.
|
3 | filePath = system_complete(filePath); |
| 415 | } | ||
| 416 | 3 | return filePath; | |
| 417 | 3 | } | |
| 418 | |||
| 419 | } // namespace detail | ||
| 420 | |||
| 421 | 9 | ScheduleFile::ScheduleFile(const ExternalFile& externalfile, int column, int rowsToSkip) | |
| 422 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | : ScheduleInterval(ScheduleFile::iddObjectType(), externalfile.model()) { |
| 423 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✗ Branch 5 not taken.
|
9 | OS_ASSERT(getImpl<detail::ScheduleFile_Impl>()); |
| 424 | bool ok; | ||
| 425 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | ok = setPointer(OS_Schedule_FileFields::ExternalFileName, externalfile.handle()); |
| 426 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
|
9 | OS_ASSERT(ok); |
| 427 |
1/1✓ Branch 1 taken 9 times.
|
9 | ok = setColumnNumber(column); |
| 428 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
|
9 | OS_ASSERT(ok); |
| 429 |
1/1✓ Branch 1 taken 9 times.
|
9 | ok = setRowstoSkipatTop(rowsToSkip); |
| 430 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
|
9 | OS_ASSERT(ok); |
| 431 | 9 | } | |
| 432 | |||
| 433 | 4 | ScheduleFile::ScheduleFile(const Model& model, const openstudio::path& filePath, int column, int rowsToSkip) | |
| 434 | 4 | : ScheduleInterval(ScheduleFile::iddObjectType(), model) { | |
| 435 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 5 not taken.
|
4 | OS_ASSERT(getImpl<detail::ScheduleFile_Impl>()); |
| 436 | |||
| 437 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | boost::optional<ExternalFile> externalfile = ExternalFile::getExternalFile(model, toString(filePath), false); |
| 438 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (!externalfile) { |
| 439 | ✗ | remove(); | |
| 440 | ✗ | LOG_AND_THROW("Couldn't find the ExternalFile at " << filePath); | |
| 441 | } | ||
| 442 | |||
| 443 | bool ok; | ||
| 444 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | ok = setPointer(OS_Schedule_FileFields::ExternalFileName, externalfile->handle()); |
| 445 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
|
4 | OS_ASSERT(ok); |
| 446 |
1/1✓ Branch 1 taken 4 times.
|
4 | ok = setColumnNumber(column); |
| 447 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
|
4 | OS_ASSERT(ok); |
| 448 |
1/1✓ Branch 1 taken 4 times.
|
4 | ok = setRowstoSkipatTop(rowsToSkip); |
| 449 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
|
4 | OS_ASSERT(ok); |
| 450 | 4 | } | |
| 451 | |||
| 452 | 7777 | IddObjectType ScheduleFile::iddObjectType() { | |
| 453 |
1/1✓ Branch 1 taken 7777 times.
|
7777 | return {IddObjectType::OS_Schedule_File}; |
| 454 | } | ||
| 455 | |||
| 456 | ✗ | std::vector<std::string> ScheduleFile::columnSeparatorValues() { | |
| 457 | ✗ | return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Schedule_FileFields::ColumnSeparator); | |
| 458 | } | ||
| 459 | |||
| 460 | ✗ | std::vector<std::string> ScheduleFile::minutesperItemValues() { | |
| 461 | ✗ | return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Schedule_FileFields::MinutesperItem); | |
| 462 | } | ||
| 463 | |||
| 464 | 5 | boost::optional<ScheduleTypeLimits> ScheduleFile::scheduleTypeLimits() const { | |
| 465 |
1/1✓ Branch 3 taken 5 times.
|
5 | return getImpl<detail::ScheduleFile_Impl>()->scheduleTypeLimits(); |
| 466 | } | ||
| 467 | |||
| 468 | 12 | ExternalFile ScheduleFile::externalFile() const { | |
| 469 |
1/1✓ Branch 3 taken 12 times.
|
12 | return getImpl<detail::ScheduleFile_Impl>()->externalFile(); |
| 470 | } | ||
| 471 | |||
| 472 | 21 | int ScheduleFile::columnNumber() const { | |
| 473 |
1/1✓ Branch 3 taken 21 times.
|
21 | return getImpl<detail::ScheduleFile_Impl>()->columnNumber(); |
| 474 | } | ||
| 475 | |||
| 476 | 21 | int ScheduleFile::rowstoSkipatTop() const { | |
| 477 |
1/1✓ Branch 3 taken 21 times.
|
21 | return getImpl<detail::ScheduleFile_Impl>()->rowstoSkipatTop(); |
| 478 | } | ||
| 479 | |||
| 480 | ✗ | boost::optional<int> ScheduleFile::numberofHoursofData() const { | |
| 481 | ✗ | return getImpl<detail::ScheduleFile_Impl>()->numberofHoursofData(); | |
| 482 | } | ||
| 483 | |||
| 484 | 13 | bool ScheduleFile::isNumberofHoursofDataDefaulted() const { | |
| 485 |
1/1✓ Branch 3 taken 13 times.
|
13 | return getImpl<detail::ScheduleFile_Impl>()->isNumberofHoursofDataDefaulted(); |
| 486 | } | ||
| 487 | |||
| 488 | 11 | std::string ScheduleFile::columnSeparator() const { | |
| 489 |
1/1✓ Branch 3 taken 11 times.
|
11 | return getImpl<detail::ScheduleFile_Impl>()->columnSeparator(); |
| 490 | } | ||
| 491 | |||
| 492 | 3 | bool ScheduleFile::isColumnSeparatorDefaulted() const { | |
| 493 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::ScheduleFile_Impl>()->isColumnSeparatorDefaulted(); |
| 494 | } | ||
| 495 | |||
| 496 | 9 | bool ScheduleFile::interpolatetoTimestep() const { | |
| 497 |
1/1✓ Branch 3 taken 9 times.
|
9 | return getImpl<detail::ScheduleFile_Impl>()->interpolatetoTimestep(); |
| 498 | } | ||
| 499 | |||
| 500 | 6 | bool ScheduleFile::isInterpolatetoTimestepDefaulted() const { | |
| 501 |
1/1✓ Branch 3 taken 6 times.
|
6 | return getImpl<detail::ScheduleFile_Impl>()->isInterpolatetoTimestepDefaulted(); |
| 502 | } | ||
| 503 | |||
| 504 | 12 | boost::optional<std::string> ScheduleFile::minutesperItem() const { | |
| 505 |
2/2✓ Branch 3 taken 12 times.
✓ Branch 7 taken 12 times.
|
12 | return std::to_string(getImpl<detail::ScheduleFile_Impl>()->minutesperItem()); |
| 506 | } | ||
| 507 | |||
| 508 | 9 | bool ScheduleFile::isMinutesperItemDefaulted() const { | |
| 509 |
1/1✓ Branch 3 taken 9 times.
|
9 | return getImpl<detail::ScheduleFile_Impl>()->isMinutesperItemDefaulted(); |
| 510 | } | ||
| 511 | |||
| 512 | 9 | bool ScheduleFile::adjustScheduleforDaylightSavings() const { | |
| 513 |
1/1✓ Branch 3 taken 9 times.
|
9 | return getImpl<detail::ScheduleFile_Impl>()->adjustScheduleforDaylightSavings(); |
| 514 | } | ||
| 515 | |||
| 516 | 6 | bool ScheduleFile::isAdjustScheduleforDaylightSavingsDefaulted() const { | |
| 517 |
1/1✓ Branch 3 taken 6 times.
|
6 | return getImpl<detail::ScheduleFile_Impl>()->isAdjustScheduleforDaylightSavingsDefaulted(); |
| 518 | } | ||
| 519 | |||
| 520 | ✗ | boost::optional<CSVFile> ScheduleFile::csvFile() const { | |
| 521 | ✗ | return getImpl<detail::ScheduleFile_Impl>()->csvFile(); | |
| 522 | } | ||
| 523 | |||
| 524 | 10 | bool ScheduleFile::translateFileWithRelativePath() const { | |
| 525 |
1/1✓ Branch 3 taken 10 times.
|
10 | return getImpl<detail::ScheduleFile_Impl>()->translateFileWithRelativePath(); |
| 526 | } | ||
| 527 | |||
| 528 | 6 | bool ScheduleFile::isTranslateFileWithRelativePathDefaulted() const { | |
| 529 |
1/1✓ Branch 3 taken 6 times.
|
6 | return getImpl<detail::ScheduleFile_Impl>()->isTranslateFileWithRelativePathDefaulted(); |
| 530 | } | ||
| 531 | |||
| 532 | /* FIXME! | ||
| 533 | openstudio::TimeSeries ScheduleFile::timeSeries(unsigned columnIndex) const { | ||
| 534 | return getImpl<detail::ScheduleFile_Impl>()->timeSeries(columnIndex); | ||
| 535 | } | ||
| 536 | */ | ||
| 537 | |||
| 538 | /* FIXME! | ||
| 539 | unsigned ScheduleFile::addTimeSeries(const openstudio::TimeSeries& timeSeries) { | ||
| 540 | return getImpl<detail::ScheduleFile_Impl>()->addTimeSeries(timeSeries); | ||
| 541 | } | ||
| 542 | */ | ||
| 543 | |||
| 544 | ✗ | bool ScheduleFile::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) { | |
| 545 | ✗ | return getImpl<detail::ScheduleFile_Impl>()->setScheduleTypeLimits(scheduleTypeLimits); | |
| 546 | } | ||
| 547 | |||
| 548 | ✗ | bool ScheduleFile::resetScheduleTypeLimits() { | |
| 549 | ✗ | return getImpl<detail::ScheduleFile_Impl>()->resetScheduleTypeLimits(); | |
| 550 | } | ||
| 551 | |||
| 552 | 21 | bool ScheduleFile::setColumnNumber(int columnNumber) { | |
| 553 |
1/1✓ Branch 3 taken 21 times.
|
21 | return getImpl<detail::ScheduleFile_Impl>()->setColumnNumber(columnNumber); |
| 554 | } | ||
| 555 | |||
| 556 | 21 | bool ScheduleFile::setRowstoSkipatTop(int rowstoSkipatTop) { | |
| 557 |
1/1✓ Branch 3 taken 21 times.
|
21 | return getImpl<detail::ScheduleFile_Impl>()->setRowstoSkipatTop(rowstoSkipatTop); |
| 558 | } | ||
| 559 | |||
| 560 | ✗ | bool ScheduleFile::setNumberofHoursofData(int numberofHours) { | |
| 561 | ✗ | return getImpl<detail::ScheduleFile_Impl>()->setNumberofHoursofData(numberofHours); | |
| 562 | } | ||
| 563 | |||
| 564 | 3 | bool ScheduleFile::setColumnSeparator(const std::string& columnSeparator) { | |
| 565 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::ScheduleFile_Impl>()->setColumnSeparator(columnSeparator); |
| 566 | } | ||
| 567 | |||
| 568 | ✗ | void ScheduleFile::resetColumnSeparator() { | |
| 569 | ✗ | getImpl<detail::ScheduleFile_Impl>()->resetColumnSeparator(); | |
| 570 | ✗ | } | |
| 571 | |||
| 572 | 3 | bool ScheduleFile::setInterpolatetoTimestep(bool interpolatetoTimestep) { | |
| 573 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::ScheduleFile_Impl>()->setInterpolatetoTimestep(interpolatetoTimestep); |
| 574 | } | ||
| 575 | |||
| 576 | 2 | void ScheduleFile::resetInterpolatetoTimestep() { | |
| 577 |
1/1✓ Branch 3 taken 2 times.
|
2 | getImpl<detail::ScheduleFile_Impl>()->resetInterpolatetoTimestep(); |
| 578 | 2 | } | |
| 579 | |||
| 580 | ✗ | bool ScheduleFile::setMinutesperItem(const std::string& minutesperItem) { | |
| 581 | ✗ | DEPRECATED_AT_MSG(3, 2, 0, "Use the setMinutesperItem(int) instead"); | |
| 582 | try { | ||
| 583 | // TODO: remove the Impl too | ||
| 584 | ✗ | return getImpl<detail::ScheduleFile_Impl>()->setMinutesperItem(std::stoi(minutesperItem)); | |
| 585 | ✗ | } catch (...) { | |
| 586 | ✗ | return false; | |
| 587 | ✗ | } | |
| 588 | } | ||
| 589 | |||
| 590 | 4 | bool ScheduleFile::setMinutesperItem(int minutesperItem) { | |
| 591 |
1/1✓ Branch 3 taken 4 times.
|
4 | return getImpl<detail::ScheduleFile_Impl>()->setMinutesperItem(minutesperItem); |
| 592 | } | ||
| 593 | |||
| 594 | 2 | void ScheduleFile::resetMinutesperItem() { | |
| 595 |
1/1✓ Branch 3 taken 2 times.
|
2 | getImpl<detail::ScheduleFile_Impl>()->resetMinutesperItem(); |
| 596 | 2 | } | |
| 597 | |||
| 598 | 2 | bool ScheduleFile::setAdjustScheduleforDaylightSavings(bool adjustScheduleforDaylightSavings) { | |
| 599 |
1/1✓ Branch 3 taken 2 times.
|
2 | return getImpl<detail::ScheduleFile_Impl>()->setAdjustScheduleforDaylightSavings(adjustScheduleforDaylightSavings); |
| 600 | } | ||
| 601 | |||
| 602 | 2 | void ScheduleFile::resetAdjustScheduleforDaylightSavings() { | |
| 603 |
1/1✓ Branch 3 taken 2 times.
|
2 | getImpl<detail::ScheduleFile_Impl>()->resetAdjustScheduleforDaylightSavings(); |
| 604 | 2 | } | |
| 605 | |||
| 606 | 6 | bool ScheduleFile::setTranslateFileWithRelativePath(bool translateFileWithRelativePath) { | |
| 607 |
1/1✓ Branch 3 taken 6 times.
|
6 | return getImpl<detail::ScheduleFile_Impl>()->setTranslateFileWithRelativePath(translateFileWithRelativePath); |
| 608 | } | ||
| 609 | |||
| 610 | 2 | void ScheduleFile::resetTranslateFileWithRelativePath() { | |
| 611 |
1/1✓ Branch 3 taken 2 times.
|
2 | getImpl<detail::ScheduleFile_Impl>()->resetTranslateFileWithRelativePath(); |
| 612 | 2 | } | |
| 613 | |||
| 614 | 9 | openstudio::path ScheduleFile::translatedFilePath() const { | |
| 615 |
1/1✓ Branch 3 taken 9 times.
|
9 | return getImpl<detail::ScheduleFile_Impl>()->translatedFilePath(); |
| 616 | } | ||
| 617 | |||
| 618 | /// @cond | ||
| 619 |
1/1✓ Branch 3 taken 55 times.
|
55 | ScheduleFile::ScheduleFile(std::shared_ptr<detail::ScheduleFile_Impl> impl) : ScheduleInterval(std::move(impl)) {} |
| 620 | /// @endcond | ||
| 621 | |||
| 622 | } // namespace model | ||
| 623 | } // namespace openstudio | ||
| 624 |