src/sdd/MapSchedules.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 | #include "Helpers.hpp" | ||
| 8 | |||
| 9 | #include "../model/Model.hpp" | ||
| 10 | #include "../model/ScheduleDay.hpp" | ||
| 11 | #include "../model/ScheduleDay_Impl.hpp" | ||
| 12 | #include "../model/ScheduleWeek.hpp" | ||
| 13 | #include "../model/ScheduleWeek_Impl.hpp" | ||
| 14 | #include "../model/ScheduleYear.hpp" | ||
| 15 | #include "../model/ScheduleYear_Impl.hpp" | ||
| 16 | #include "../model/ScheduleTypeLimits.hpp" | ||
| 17 | #include "../model/ScheduleTypeLimits_Impl.hpp" | ||
| 18 | #include "../model/RunPeriodControlSpecialDays.hpp" | ||
| 19 | #include "../model/RunPeriodControlSpecialDays_Impl.hpp" | ||
| 20 | #include "../model/YearDescription.hpp" | ||
| 21 | #include "../model/YearDescription_Impl.hpp" | ||
| 22 | |||
| 23 | #include "../utilities/time/Time.hpp" | ||
| 24 | #include "../utilities/time/Date.hpp" | ||
| 25 | #include "../utilities/core/Assert.hpp" | ||
| 26 | |||
| 27 | #include <pugixml.hpp> | ||
| 28 | |||
| 29 | namespace openstudio { | ||
| 30 | namespace sdd { | ||
| 31 | |||
| 32 | 48 | boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateScheduleDay(const pugi::xml_node& element, | |
| 33 | openstudio::model::Model& model) { | ||
| 34 |
1/1✓ Branch 1 taken 48 times.
|
48 | pugi::xml_node nameElement = element.child("Name"); |
| 35 |
1/1✓ Branch 1 taken 48 times.
|
48 | pugi::xml_node typeElement = element.child("Type"); |
| 36 | |||
| 37 | 48 | std::string name; | |
| 38 |
2/3✓ Branch 1 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
|
48 | if (!nameElement) { |
| 39 | ✗ | LOG(Error, "SchDay element 'Name' is empty.") | |
| 40 | } else { | ||
| 41 |
4/4✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
|
48 | name = escapeName(nameElement.text().as_string()); |
| 42 | } | ||
| 43 | |||
| 44 |
2/3✓ Branch 1 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
|
48 | if (!typeElement) { |
| 45 | ✗ | LOG(Error, "SchDay element 'Type' is empty for SchDay named '" << name << "'. ScheduleDay will not be created"); | |
| 46 | ✗ | return boost::none; | |
| 47 | } | ||
| 48 |
4/4✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
|
48 | std::string type = escapeName(typeElement.text().as_string()); |
| 49 | |||
| 50 |
1/1✓ Branch 1 taken 48 times.
|
48 | std::vector<pugi::xml_node> hrElements = makeVectorOfChildren(element, "Hr"); |
| 51 | |||
| 52 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
|
48 | if (hrElements.size() != 24) { |
| 53 | ✗ | LOG(Error, "SchDay does not have 24 'Hr' elements empty for SchDay named '" << name << "'. ScheduleDay will not be created"); | |
| 54 | ✗ | return boost::none; | |
| 55 | } | ||
| 56 | |||
| 57 |
1/1✓ Branch 1 taken 48 times.
|
48 | model::ScheduleDay scheduleDay(model); |
| 58 |
1/1✓ Branch 1 taken 48 times.
|
48 | scheduleDay.setName(name); |
| 59 | |||
| 60 |
1/1✓ Branch 1 taken 48 times.
|
48 | boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getConcreteModelObjectByName<model::ScheduleTypeLimits>(type); |
| 61 | 48 | bool isTemperature = false; | |
| 62 |
3/3✓ Branch 1 taken 48 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 30 times.
|
48 | if (type == "Temperature") { |
| 63 | 18 | isTemperature = true; | |
| 64 | } | ||
| 65 | |||
| 66 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 45 times.
|
48 | if (!scheduleTypeLimits) { |
| 67 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 2 times.
|
3 | if (type == "Fraction") { |
| 68 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | scheduleTypeLimits = model::ScheduleTypeLimits(model); |
| 69 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
2 | scheduleTypeLimits->setName("Fraction"); |
| 70 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | scheduleTypeLimits->setLowerLimitValue(0); |
| 71 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | scheduleTypeLimits->setUpperLimitValue(1); |
| 72 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
2 | scheduleTypeLimits->setNumericType("Continuous"); |
| 73 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | scheduleTypeLimits->setUnitType("Dimensionless"); |
| 74 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | } else if (type == "Temperature") { |
| 75 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | scheduleTypeLimits = model::ScheduleTypeLimits(model); |
| 76 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
2 | scheduleTypeLimits->setName("Temperature"); |
| 77 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | scheduleTypeLimits->setUnitType("Temperature"); |
| 78 |
2/3✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
1 | } else if (type == "OnOff") { |
| 79 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | scheduleTypeLimits = model::ScheduleTypeLimits(model); |
| 80 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
2 | scheduleTypeLimits->setName("OnOff"); |
| 81 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | scheduleTypeLimits->setLowerLimitValue(0); |
| 82 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | scheduleTypeLimits->setUpperLimitValue(1); |
| 83 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
2 | scheduleTypeLimits->setNumericType("Discrete"); |
| 84 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | scheduleTypeLimits->setUnitType("Availability"); |
| 85 | } else { | ||
| 86 | ✗ | LOG(Error, "Unknown schedule type '" << type << "'"); | |
| 87 | } | ||
| 88 | } | ||
| 89 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (scheduleTypeLimits) { |
| 90 |
2/2✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
|
48 | scheduleDay.setScheduleTypeLimits(*scheduleTypeLimits); |
| 91 | } | ||
| 92 | |||
| 93 |
2/2✓ Branch 1 taken 1152 times.
✓ Branch 2 taken 48 times.
|
1200 | for (std::vector<pugi::xml_node>::size_type i = 0; i < hrElements.size(); ++i) { |
| 94 | 1152 | pugi::xml_node hrElement = hrElements[i]; | |
| 95 |
2/2✓ Branch 1 taken 1152 times.
✓ Branch 4 taken 1152 times.
|
1152 | double value = hrElement.text().as_double(); |
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 432 times.
✓ Branch 1 taken 720 times.
|
1152 | if (isTemperature) { |
| 98 | 432 | value = (value - 32.0) / 1.8; // deg F to deg C | |
| 99 | } | ||
| 100 | |||
| 101 |
2/2✓ Branch 1 taken 1152 times.
✓ Branch 4 taken 1152 times.
|
1152 | scheduleDay.addValue(openstudio::Time(0, i + 1, 0, 0), value); |
| 102 | } | ||
| 103 | |||
| 104 |
1/1✓ Branch 1 taken 48 times.
|
48 | return scheduleDay; |
| 105 | 48 | } | |
| 106 | |||
| 107 | 28 | boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateScheduleWeek(const pugi::xml_node& element, | |
| 108 | openstudio::model::Model& model) { | ||
| 109 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node nameElement = element.child("Name"); |
| 110 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node typeElement = element.child("Type"); |
| 111 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDaySunRefElement = element.child("SchDaySunRef"); |
| 112 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDayMonRefElement = element.child("SchDayMonRef"); |
| 113 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDayTueRefElement = element.child("SchDayTueRef"); |
| 114 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDayWedRefElement = element.child("SchDayWedRef"); |
| 115 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDayThuRefElement = element.child("SchDayThuRef"); |
| 116 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDayFriRefElement = element.child("SchDayFriRef"); |
| 117 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDaySatRefElement = element.child("SchDaySatRef"); |
| 118 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDayHolRefElement = element.child("SchDayHolRef"); |
| 119 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDayClgDDRefElement = element.child("SchDayClgDDRef"); |
| 120 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_node schDayHtgDDRefElement = element.child("SchDayHtgDDRef"); |
| 121 | |||
| 122 | 28 | std::string name; | |
| 123 |
2/3✓ Branch 1 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
|
28 | if (!nameElement) { |
| 124 | ✗ | LOG(Error, "SchWeek element 'Name' is empty.") | |
| 125 | } else { | ||
| 126 |
4/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
|
28 | name = escapeName(nameElement.text().as_string()); |
| 127 | } | ||
| 128 | |||
| 129 |
2/3✓ Branch 1 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
|
28 | if (!typeElement) { |
| 130 | ✗ | LOG(Error, "SchWeek element 'Type' is empty for SchWeek named '" << name << "'. ScheduleWeek will not be created"); | |
| 131 | ✗ | return boost::none; | |
| 132 | } | ||
| 133 |
4/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
|
28 | std::string type = escapeName(typeElement.text().as_string()); |
| 134 | |||
| 135 |
1/1✓ Branch 1 taken 28 times.
|
28 | model::ScheduleWeek scheduleWeek(model); |
| 136 |
1/1✓ Branch 1 taken 28 times.
|
28 | scheduleWeek.setName(name); |
| 137 | |||
| 138 |
1/1✓ Branch 1 taken 28 times.
|
28 | boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getConcreteModelObjectByName<model::ScheduleTypeLimits>(type); |
| 139 | 28 | if (scheduleTypeLimits) { | |
| 140 | //scheduleWeek.setScheduleTypeLimits(*scheduleTypeLimits); | ||
| 141 | } | ||
| 142 | |||
| 143 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDaySunRefElement) { |
| 144 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 145 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDaySunRefElement.text().as_string())); |
| 146 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 147 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setSundaySchedule(*scheduleDay); |
| 148 | } else { | ||
| 149 | ✗ | LOG(Error, "No Sunday schedule found for week schedule '" << name << "'"); | |
| 150 | } | ||
| 151 | 28 | } | |
| 152 | |||
| 153 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDayMonRefElement) { |
| 154 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 155 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDayMonRefElement.text().as_string())); |
| 156 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 157 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setMondaySchedule(*scheduleDay); |
| 158 | } else { | ||
| 159 | ✗ | LOG(Error, "No Monday schedule found for week schedule '" << name << "'"); | |
| 160 | } | ||
| 161 | 28 | } | |
| 162 | |||
| 163 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDayTueRefElement) { |
| 164 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 165 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDayTueRefElement.text().as_string())); |
| 166 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 167 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setTuesdaySchedule(*scheduleDay); |
| 168 | } else { | ||
| 169 | ✗ | LOG(Error, "No Tuesday schedule found for week schedule '" << name << "'"); | |
| 170 | } | ||
| 171 | 28 | } | |
| 172 | |||
| 173 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDayWedRefElement) { |
| 174 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 175 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDayWedRefElement.text().as_string())); |
| 176 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 177 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setWednesdaySchedule(*scheduleDay); |
| 178 | } else { | ||
| 179 | ✗ | LOG(Error, "No Wednesday schedule found for week schedule '" << name << "'"); | |
| 180 | } | ||
| 181 | 28 | } | |
| 182 | |||
| 183 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDayThuRefElement) { |
| 184 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 185 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDayThuRefElement.text().as_string())); |
| 186 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 187 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setThursdaySchedule(*scheduleDay); |
| 188 | } else { | ||
| 189 | ✗ | LOG(Error, "No Thursday schedule found for week schedule '" << name << "'"); | |
| 190 | } | ||
| 191 | 28 | } | |
| 192 | |||
| 193 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDayFriRefElement) { |
| 194 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 195 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDayFriRefElement.text().as_string())); |
| 196 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 197 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setFridaySchedule(*scheduleDay); |
| 198 | } else { | ||
| 199 | ✗ | LOG(Error, "No Friday schedule found for week schedule '" << name << "'"); | |
| 200 | } | ||
| 201 | 28 | } | |
| 202 | |||
| 203 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDaySatRefElement) { |
| 204 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 205 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDaySatRefElement.text().as_string())); |
| 206 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 207 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setSaturdaySchedule(*scheduleDay); |
| 208 | } else { | ||
| 209 | ✗ | LOG(Error, "No Saturday schedule found for week schedule '" << name << "'"); | |
| 210 | } | ||
| 211 | 28 | } | |
| 212 | |||
| 213 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDayHolRefElement) { |
| 214 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 215 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDayHolRefElement.text().as_string())); |
| 216 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 217 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setHolidaySchedule(*scheduleDay); |
| 218 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setCustomDay1Schedule(*scheduleDay); |
| 219 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setCustomDay2Schedule(*scheduleDay); |
| 220 | } else { | ||
| 221 | ✗ | LOG(Error, "No Holiday schedule found for week schedule '" << name << "'"); | |
| 222 | } | ||
| 223 | 28 | } | |
| 224 | |||
| 225 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDayClgDDRefElement) { |
| 226 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 227 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDayClgDDRefElement.text().as_string())); |
| 228 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 229 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setSummerDesignDaySchedule(*scheduleDay); |
| 230 | } else { | ||
| 231 | ✗ | LOG(Error, "No Summer Design Day schedule found for week schedule '" << name << "'"); | |
| 232 | } | ||
| 233 | 28 | } | |
| 234 | |||
| 235 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (schDayHtgDDRefElement) { |
| 236 | boost::optional<model::ScheduleDay> scheduleDay = | ||
| 237 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model.getConcreteModelObjectByName<model::ScheduleDay>(escapeName(schDayHtgDDRefElement.text().as_string())); |
| 238 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (scheduleDay) { |
| 239 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | scheduleWeek.setWinterDesignDaySchedule(*scheduleDay); |
| 240 | } else { | ||
| 241 | ✗ | LOG(Error, "No Winter Design Day schedule found for week schedule '" << name << "'"); | |
| 242 | } | ||
| 243 | 28 | } | |
| 244 | |||
| 245 |
1/1✓ Branch 1 taken 28 times.
|
28 | return scheduleWeek; |
| 246 | 28 | } | |
| 247 | |||
| 248 | 14 | boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateSchedule(const pugi::xml_node& element, | |
| 249 | openstudio::model::Model& model) { | ||
| 250 |
1/1✓ Branch 1 taken 14 times.
|
14 | pugi::xml_node nameElement = element.child("Name"); |
| 251 |
1/1✓ Branch 1 taken 14 times.
|
14 | pugi::xml_node typeElement = element.child("Type"); |
| 252 | |||
| 253 | 14 | std::string name; | |
| 254 |
2/3✓ Branch 1 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
|
14 | if (!nameElement) { |
| 255 | ✗ | LOG(Error, "Sch element 'Name' is empty.") | |
| 256 | } else { | ||
| 257 |
4/4✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
✓ Branch 10 taken 14 times.
|
14 | name = escapeName(nameElement.text().as_string()); |
| 258 | } | ||
| 259 | |||
| 260 |
2/3✓ Branch 1 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
|
14 | if (!typeElement) { |
| 261 | ✗ | LOG(Error, "Sch element 'Type' is empty for Sch named '" << name << "'. ScheduleYear will not be created"); | |
| 262 | ✗ | return boost::none; | |
| 263 | } | ||
| 264 |
4/4✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
✓ Branch 10 taken 14 times.
|
14 | std::string type = escapeName(typeElement.text().as_string()); |
| 265 | |||
| 266 |
1/1✓ Branch 1 taken 14 times.
|
14 | std::vector<pugi::xml_node> endMonthElements = makeVectorOfChildren(element, "EndMonth"); |
| 267 |
1/1✓ Branch 1 taken 14 times.
|
14 | std::vector<pugi::xml_node> endDayElements = makeVectorOfChildren(element, "EndDay"); |
| 268 |
1/1✓ Branch 1 taken 14 times.
|
14 | std::vector<pugi::xml_node> schWeekRefElements = makeVectorOfChildren(element, "SchWeekRef"); |
| 269 | |||
| 270 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
|
14 | if (endMonthElements.size() != endDayElements.size()) { |
| 271 | ✗ | LOG(Error, | |
| 272 | "Number of 'EndMonth' elements not equal to number of 'EndDay' elements for Sch named '" << name << "'. ScheduleYear will not be created"); | ||
| 273 | ✗ | return boost::none; | |
| 274 | } | ||
| 275 | |||
| 276 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
|
14 | if (endMonthElements.size() != schWeekRefElements.size()) { |
| 277 | ✗ | LOG(Error, "Number of 'EndMonth' elements not equal to number of 'SchWeekRef' elements for Sch named '" | |
| 278 | << name << "'. ScheduleYear will not be created"); | ||
| 279 | ✗ | return boost::none; | |
| 280 | } | ||
| 281 | |||
| 282 |
1/1✓ Branch 1 taken 14 times.
|
14 | model::ScheduleYear scheduleYear(model); |
| 283 |
1/1✓ Branch 1 taken 14 times.
|
14 | scheduleYear.setName(name); |
| 284 | |||
| 285 |
1/1✓ Branch 1 taken 14 times.
|
14 | boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getConcreteModelObjectByName<model::ScheduleTypeLimits>(type); |
| 286 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | if (scheduleTypeLimits) { |
| 287 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | scheduleYear.setScheduleTypeLimits(*scheduleTypeLimits); |
| 288 | } | ||
| 289 | |||
| 290 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 2 taken 14 times.
|
45 | for (std::vector<pugi::xml_node>::size_type i = 0; i < endMonthElements.size(); ++i) { |
| 291 | 31 | pugi::xml_node endMonthElement = endMonthElements[i]; | |
| 292 | 31 | pugi::xml_node endDayElement = endDayElements[i]; | |
| 293 | 31 | pugi::xml_node schWeekRefElement = schWeekRefElements[i]; | |
| 294 | |||
| 295 | boost::optional<model::ScheduleWeek> scheduleWeek = | ||
| 296 |
5/5✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
✓ Branch 7 taken 31 times.
✓ Branch 10 taken 31 times.
✓ Branch 13 taken 31 times.
|
31 | model.getConcreteModelObjectByName<model::ScheduleWeek>(escapeName(schWeekRefElement.text().as_string())); |
| 297 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (scheduleWeek) { |
| 298 | |||
| 299 |
1/1✓ Branch 1 taken 31 times.
|
31 | boost::optional<model::YearDescription> yearDescription = model.getOptionalUniqueModelObject<model::YearDescription>(); |
| 300 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (yearDescription) { |
| 301 |
3/3✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
✓ Branch 7 taken 31 times.
|
31 | MonthOfYear monthOfYear(endMonthElement.text().as_uint()); |
| 302 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
|
31 | unsigned dayOfMonth = endDayElement.text().as_uint(); |
| 303 |
3/3✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
✓ Branch 7 taken 31 times.
|
31 | Date untilDate(monthOfYear, dayOfMonth, yearDescription->assumedYear()); |
| 304 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
|
31 | scheduleYear.addScheduleWeek(untilDate, *scheduleWeek); |
| 305 | } else { | ||
| 306 | ✗ | MonthOfYear monthOfYear(endMonthElement.text().as_uint()); | |
| 307 | ✗ | unsigned dayOfMonth = endDayElement.text().as_uint(); | |
| 308 | ✗ | Date untilDate(monthOfYear, dayOfMonth); | |
| 309 | ✗ | scheduleYear.addScheduleWeek(untilDate, *scheduleWeek); | |
| 310 | } | ||
| 311 | 31 | } | |
| 312 | 31 | } | |
| 313 | |||
| 314 |
1/1✓ Branch 1 taken 14 times.
|
14 | return scheduleYear; |
| 315 | 14 | } | |
| 316 | |||
| 317 | 10 | boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateHoliday(const pugi::xml_node& element, | |
| 318 | openstudio::model::Model& model) { | ||
| 319 | //<Name>Thanksgiving Day</Name> | ||
| 320 | //<SpecMthd>Fourth</SpecMthd> | ||
| 321 | //<DayOfWeek>Thursday</DayOfWeek> | ||
| 322 | //<Month>November</Month> | ||
| 323 | |||
| 324 | //<Name>Christmas Day</Name> | ||
| 325 | //<SpecMthd>Date</SpecMthd> | ||
| 326 | //<Month>December</Month> | ||
| 327 | //<Day>25</Day> | ||
| 328 | |||
| 329 | 10 | boost::optional<openstudio::model::ModelObject> result; | |
| 330 | |||
| 331 |
1/1✓ Branch 1 taken 10 times.
|
10 | pugi::xml_node nameElement = element.child("Name"); |
| 332 | 10 | std::string name; | |
| 333 |
2/3✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
|
10 | if (!nameElement) { |
| 334 | ✗ | LOG(Error, "Hol element 'Name' is empty.") | |
| 335 | } else { | ||
| 336 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
✓ Branch 10 taken 10 times.
|
10 | name = escapeName(nameElement.text().as_string()); |
| 337 | } | ||
| 338 | |||
| 339 |
1/1✓ Branch 1 taken 10 times.
|
10 | pugi::xml_node specificationMethodElement = element.child("SpecMthd"); |
| 340 |
2/3✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
|
10 | if (!specificationMethodElement) { |
| 341 | ✗ | LOG(Error, "Hol element 'SpecMthd' is empty for Hol named '" << name << "'. Holiday will not be created"); | |
| 342 | ✗ | return boost::none; | |
| 343 | } | ||
| 344 | |||
| 345 |
7/7✓ 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.
✓ Branch 17 taken 4 times.
✓ Branch 18 taken 6 times.
|
30 | if (openstudio::istringEqual(specificationMethodElement.text().as_string(), "Date")) { |
| 346 |
1/1✓ Branch 1 taken 4 times.
|
4 | pugi::xml_node monthElement = element.child("Month"); |
| 347 |
1/1✓ Branch 1 taken 4 times.
|
4 | pugi::xml_node dayElement = element.child("Day"); |
| 348 | |||
| 349 |
2/3✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
4 | if (!monthElement) { |
| 350 | ✗ | LOG(Error, "Hol element 'Month' is empty for Hol named '" << name << "'. Holiday will not be created"); | |
| 351 | ✗ | return boost::none; | |
| 352 | } | ||
| 353 | |||
| 354 |
2/3✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
4 | if (!dayElement) { |
| 355 | ✗ | LOG(Error, "Hol element 'Day' is empty for Hol named '" << name << "'. Holiday will not be created"); | |
| 356 | ✗ | return boost::none; | |
| 357 | } | ||
| 358 | |||
| 359 |
4/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
|
4 | MonthOfYear monthOfYear(monthElement.text().as_string()); |
| 360 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | unsigned day = dayElement.text().as_uint(); |
| 361 | |||
| 362 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | result = model::RunPeriodControlSpecialDays(monthOfYear, day, model); |
| 363 |
6/6✓ 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.
✓ Branch 16 taken 4 times.
|
8 | result->setName(escapeName(nameElement.text().as_string())); |
| 364 | |||
| 365 | } else { | ||
| 366 |
1/1✓ Branch 1 taken 6 times.
|
6 | pugi::xml_node dayOfWeekElement = element.child("DayOfWeek"); |
| 367 |
1/1✓ Branch 1 taken 6 times.
|
6 | pugi::xml_node monthElement = element.child("Month"); |
| 368 | |||
| 369 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
6 | if (!dayOfWeekElement) { |
| 370 | ✗ | LOG(Error, "Hol element 'DayOfWeek' is empty for Hol named '" << name << "'. Holiday will not be created"); | |
| 371 | ✗ | return boost::none; | |
| 372 | } | ||
| 373 | |||
| 374 |
2/3✓ Branch 1 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
6 | if (!monthElement) { |
| 375 | ✗ | LOG(Error, "Hol element 'Month' is empty for Hol named '" << name << "'. Holiday will not be created"); | |
| 376 | ✗ | return boost::none; | |
| 377 | } | ||
| 378 | |||
| 379 | // fifth is treated equivalently to last | ||
| 380 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | std::string specificationMethod = specificationMethodElement.text().as_string(); |
| 381 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 5 times.
|
6 | if (specificationMethod == "Last") { |
| 382 |
1/1✓ Branch 1 taken 1 time.
|
1 | specificationMethod = "Fifth"; |
| 383 | } | ||
| 384 | |||
| 385 |
1/1✓ Branch 1 taken 6 times.
|
6 | NthDayOfWeekInMonth nth(specificationMethod); |
| 386 |
4/4✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
|
6 | DayOfWeek dayOfWeek(dayOfWeekElement.text().as_string()); |
| 387 |
4/4✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
|
6 | MonthOfYear monthOfYear(monthElement.text().as_string()); |
| 388 | |||
| 389 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | result = model::RunPeriodControlSpecialDays(nth, dayOfWeek, monthOfYear, model); |
| 390 |
6/6✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
|
12 | result->setName(escapeName(nameElement.text().as_string())); |
| 391 | 6 | } | |
| 392 | |||
| 393 | 10 | return result; | |
| 394 | 10 | } | |
| 395 | |||
| 396 | } // namespace sdd | ||
| 397 | } // namespace openstudio | ||
| 398 |