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

Method addEndUse

src/utilities/data/EndUses.cpp:141–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141void EndUses::addEndUse(double value, const EndUseFuelType& fuelType, const EndUseCategoryType& category, const std::string& subCategory) {
142 std::string units = this->getUnitsForFuelType(fuelType);
143
144 // Try to find an existing fuelType attribute
145 boost::optional<Attribute> fuelTypeAttribute = m_attribute.findChildByName(fuelType.valueName());
146 if (!fuelTypeAttribute) {
147 // If you can't, then add a new Attribute to the std::vector of Attribute
148 std::vector<Attribute> fuelTypeAttributes = m_attribute.valueAsAttributeVector();
149 fuelTypeAttributes.push_back(Attribute(fuelType.valueName(), std::vector<Attribute>()));
150 std::sort(fuelTypeAttributes.begin(), fuelTypeAttributes.end(), FuelTypeAttributeSorter());
151 m_attribute.setValue(fuelTypeAttributes);
152 fuelTypeAttribute = m_attribute.findChildByName(fuelType.valueName());
153 }
154 OS_ASSERT(fuelTypeAttribute);
155
156 // Within the FuelTypeAttribute, we look if the EndUseCategory actually exists
157 boost::optional<Attribute> categoryAttribute = fuelTypeAttribute->findChildByName(category.valueName());
158 if (!categoryAttribute) {
159 // Otherwise we add it
160 std::vector<Attribute> categoryAttributes = fuelTypeAttribute->valueAsAttributeVector();
161 categoryAttributes.push_back(Attribute(category.valueName(), std::vector<Attribute>()));
162 std::sort(categoryAttributes.begin(), categoryAttributes.end(), CategoryAttributeSorter());
163 fuelTypeAttribute->setValue(categoryAttributes);
164 categoryAttribute = fuelTypeAttribute->findChildByName(category.valueName());
165 }
166 OS_ASSERT(categoryAttribute);
167
168 // Within that category, if we find an existing SubCategory, then we add our value that category
169 bool found = false;
170 std::vector<Attribute> subCategories = categoryAttribute->valueAsAttributeVector();
171 std::vector<Attribute> newSubCategories = subCategories;
172 for (unsigned i = 0; i < subCategories.size(); ++i) {
173 if (subCategories[i].name() == subCategory) {
174 OS_ASSERT(!found);
175 newSubCategories[i] = Attribute(subCategory, subCategories[i].valueAsDouble() + value, subCategories[i].units());
176 found = true;
177 }
178 }
179
180 // If we didn't find the proper Subcategory, we create it
181 if (!found) {
182 newSubCategories.push_back(Attribute(subCategory, value, units));
183 std::sort(newSubCategories.begin(), newSubCategories.end(), SubCategoryAttributeSorter());
184 }
185
186 categoryAttribute->setValue(newSubCategories);
187}
188
189double EndUses::getEndUse(const EndUseFuelType& fuelType, const EndUseCategoryType& category, const std::string& subCategory) const {
190 double result = 0;

Callers 3

endUsesMethod · 0.80
TEST_FFunction · 0.80
outputGenerationMethod · 0.80

Calls 15

getUnitsForFuelTypeMethod · 0.95
findChildByNameMethod · 0.80
valueNameMethod · 0.80
beginMethod · 0.80
AttributeClass · 0.70
push_backMethod · 0.45
endMethod · 0.45
setValueMethod · 0.45

Tested by 1

TEST_FFunction · 0.64