src/energyplus/ReverseTranslator/ReverseTranslateScheduleDayInterval.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 "../ReverseTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/ScheduleDay.hpp" | ||
| 9 | #include "../../model/ScheduleDay_Impl.hpp" | ||
| 10 | |||
| 11 | #include "../../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 12 | |||
| 13 | #include "../../utilities/time/Time.hpp" | ||
| 14 | |||
| 15 | #include <utilities/idd/Schedule_Day_Interval_FieldEnums.hxx> | ||
| 16 | #include <utilities/idd/OS_Schedule_Day_FieldEnums.hxx> | ||
| 17 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 18 | #include <utilities/idd/IddEnums.hxx> | ||
| 19 | #include "../../utilities/core/Exception.hpp" | ||
| 20 | |||
| 21 | #include <boost/regex.hpp> | ||
| 22 | |||
| 23 | using namespace openstudio::model; | ||
| 24 | |||
| 25 | namespace openstudio { | ||
| 26 | |||
| 27 | namespace energyplus { | ||
| 28 | |||
| 29 | 126 | OptionalModelObject ReverseTranslator::translateScheduleDayInterval(const WorkspaceObject& workspaceObject) { | |
| 30 |
4/5✓ Branch 1 taken 126 times.
✓ Branch 4 taken 126 times.
✓ Branch 7 taken 126 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 126 times.
|
126 | if (workspaceObject.iddObject().type() != IddObjectType::Schedule_Day_Interval) { |
| 31 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: Schedule:Day:Interval"); | |
| 32 | ✗ | return boost::none; | |
| 33 | } | ||
| 34 | |||
| 35 | // create the schedule | ||
| 36 |
1/1✓ Branch 1 taken 126 times.
|
126 | ScheduleDay scheduleDay(m_model); |
| 37 | |||
| 38 |
1/1✓ Branch 1 taken 126 times.
|
126 | OptionalString s = workspaceObject.name(); |
| 39 |
1/2✓ Branch 0 taken 126 times.
✗ Branch 1 not taken.
|
126 | if (s) { |
| 40 |
2/2✓ Branch 1 taken 126 times.
✓ Branch 4 taken 126 times.
|
126 | scheduleDay.setName(*s); |
| 41 | } | ||
| 42 | |||
| 43 |
1/1✓ Branch 1 taken 126 times.
|
126 | OptionalWorkspaceObject target = workspaceObject.getTarget(Schedule_Day_IntervalFields::ScheduleTypeLimitsName); |
| 44 |
2/2✓ Branch 0 taken 97 times.
✓ Branch 1 taken 29 times.
|
126 | if (target) { |
| 45 |
2/2✓ Branch 1 taken 97 times.
✓ Branch 4 taken 97 times.
|
97 | OptionalModelObject scheduleTypeLimits = translateAndMapWorkspaceObject(*target); |
| 46 |
2/2✓ Branch 0 taken 93 times.
✓ Branch 1 taken 4 times.
|
97 | if (scheduleTypeLimits) { |
| 47 |
3/3✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
✓ Branch 7 taken 93 times.
|
93 | scheduleDay.setPointer(OS_Schedule_DayFields::ScheduleTypeLimitsName, scheduleTypeLimits->handle()); |
| 48 | } | ||
| 49 | 97 | } | |
| 50 | |||
| 51 |
1/1✓ Branch 1 taken 126 times.
|
126 | s = workspaceObject.getString(Schedule_Day_IntervalFields::InterpolatetoTimestep); |
| 52 |
1/2✓ Branch 0 taken 126 times.
✗ Branch 1 not taken.
|
126 | if (s) { |
| 53 |
2/2✓ Branch 1 taken 126 times.
✓ Branch 4 taken 126 times.
|
126 | scheduleDay.setInterpolatetoTimestep(*s); |
| 54 | } | ||
| 55 | |||
| 56 | //get extensible groups | ||
| 57 |
1/1✓ Branch 1 taken 126 times.
|
126 | std::vector<IdfExtensibleGroup> extensibleGroups = workspaceObject.extensibleGroups(); |
| 58 | //loop over extensible groups | ||
| 59 |
1/1✓ Branch 1 taken 126 times.
|
126 | boost::regex timeRegex("(\\d?\\d:\\d\\d)"); |
| 60 |
1/1✓ Branch 1 taken 126 times.
|
126 | boost::smatch m; |
| 61 | 126 | unsigned n = extensibleGroups.size(); | |
| 62 |
2/2✓ Branch 0 taken 334 times.
✓ Branch 1 taken 126 times.
|
460 | for (unsigned i = 0; i < n; ++i) { |
| 63 | //read in extensible groups | ||
| 64 |
1/1✓ Branch 2 taken 334 times.
|
334 | boost::optional<std::string> timeString = extensibleGroups[i].getString(Schedule_Day_IntervalExtensibleFields::Time); |
| 65 |
1/1✓ Branch 2 taken 334 times.
|
334 | boost::optional<double> valueUntilTime = extensibleGroups[i].getDouble(Schedule_Day_IntervalExtensibleFields::ValueUntilTime); |
| 66 |
3/6✓ Branch 0 taken 334 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 334 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 334 times.
✗ Branch 5 not taken.
|
668 | if (timeString && valueUntilTime) { |
| 67 | // Time string may be prefixed with "Until: ". Extract time in HH:MM format. | ||
| 68 |
3/4✓ Branch 1 taken 334 times.
✓ Branch 4 taken 334 times.
✓ Branch 6 taken 334 times.
✗ Branch 7 not taken.
|
334 | if (boost::regex_search(*timeString, m, timeRegex)) { |
| 69 |
4/4✓ Branch 1 taken 334 times.
✓ Branch 4 taken 334 times.
✓ Branch 7 taken 334 times.
✓ Branch 10 taken 334 times.
|
668 | timeString = std::string(m[1].first, m[1].second); |
| 70 | } | ||
| 71 | try { | ||
| 72 |
2/2✓ Branch 1 taken 334 times.
✓ Branch 4 taken 334 times.
|
334 | openstudio::Time time(*timeString); |
| 73 |
2/2✓ Branch 1 taken 334 times.
✓ Branch 4 taken 334 times.
|
334 | scheduleDay.addValue(time, *valueUntilTime); |
| 74 | ✗ | } catch (std::exception& e) { | |
| 75 | ✗ | LOG(Warn, "Could not add value (" << *timeString << ", " << *valueUntilTime << ") to ScheduleDay being created from " | |
| 76 | << workspaceObject.briefDescription() << ", because " << e.what() << "."); | ||
| 77 | ✗ | } | |
| 78 | } else { | ||
| 79 | ✗ | LOG(Warn, "Encountered extensible group with incomplete or improperly formatted data in " | |
| 80 | << workspaceObject.briefDescription() << ". Therefore, a corresponding value is not " | ||
| 81 | << "being added to the ScheduleDay object under construction."); | ||
| 82 | } | ||
| 83 | 334 | } | |
| 84 | |||
| 85 |
1/1✓ Branch 1 taken 126 times.
|
126 | return scheduleDay; |
| 86 | 126 | } | |
| 87 | |||
| 88 | } // namespace energyplus | ||
| 89 | |||
| 90 | } // namespace openstudio | ||
| 91 |