Example #1
0
  void EndUses::addEndUse(double value, const EndUseFuelType& fuelType, const EndUseCategoryType& category, const std::string& subCategory)
  {
    std::string units = this->getUnitsForFuelType(fuelType);

    boost::optional<Attribute> fuelTypeAttribute = m_attribute.findChildByName(fuelType.valueName());
    if(!fuelTypeAttribute){
      std::vector<Attribute> fuelTypeAttributes = m_attribute.valueAsAttributeVector();
      fuelTypeAttributes.push_back(Attribute(fuelType.valueName(), std::vector<Attribute>()));
      std::sort(fuelTypeAttributes.begin(), fuelTypeAttributes.end(), FuelTypeAttributeSorter());
      m_attribute.setValue(QVariant::fromValue(fuelTypeAttributes));
      fuelTypeAttribute = m_attribute.findChildByName(fuelType.valueName());
    }
    OS_ASSERT(fuelTypeAttribute);

    boost::optional<Attribute> categoryAttribute = fuelTypeAttribute->findChildByName(category.valueName());
    if(!categoryAttribute){
      std::vector<Attribute> categoryAttributes = fuelTypeAttribute->valueAsAttributeVector();
      categoryAttributes.push_back(Attribute(category.valueName(), std::vector<Attribute>()));
      std::sort(categoryAttributes.begin(), categoryAttributes.end(), CategoryAttributeSorter());
      fuelTypeAttribute->setValue(QVariant::fromValue(categoryAttributes));
      categoryAttribute = fuelTypeAttribute->findChildByName(category.valueName());
    }
    OS_ASSERT(categoryAttribute);

    bool found = false;
    std::vector<Attribute> subCategories = categoryAttribute->valueAsAttributeVector();
    std::vector<Attribute> newSubCategories = subCategories;
    for(unsigned i = 0; i < subCategories.size(); ++i){
      if (subCategories[i].name() == subCategory){
        OS_ASSERT(!found);
        newSubCategories[i] = Attribute(subCategory, subCategories[i].valueAsDouble() + value, subCategories[i].units());
        found = true;
      }
    }

    if (!found){
      newSubCategories.push_back(Attribute(subCategory, value, units));
      std::sort(newSubCategories.begin(), newSubCategories.end(), SubCategoryAttributeSorter());
    }

    categoryAttribute->setValue(QVariant::fromValue(newSubCategories));
  }
Example #2
0
  double EndUses::getEndUse(const EndUseFuelType& fuelType, const EndUseCategoryType& category) const
  {
    double result = 0;

    boost::optional<Attribute> fuelTypeAttribute = m_attribute.findChildByName(fuelType.valueName());
    if(fuelTypeAttribute){
      boost::optional<Attribute> categoryAttribute = fuelTypeAttribute->findChildByName(category.valueName());
      if(categoryAttribute){
        std::vector<Attribute> subCategories = categoryAttribute->valueAsAttributeVector();
        for(unsigned i = 0; i < subCategories.size(); ++i){
          result += subCategories[i].valueAsDouble();
        }
      }
    }

    return result;
  }
Example #3
0
Table monthlyEndUsesTable(const SqlFile& sqlFile,const EndUseFuelType& fuelType,const Unit& unit)
{
  Table result;
  result.setTitle(fuelType.valueDescription() + " Consumption");
  TableElementVector row1,row2;
  TableLoadOptions loadString(false,false,false);
  std::set<int> months = MonthOfYear::getValues();

  // set header rows
  row1.push_back(TableElement("",loadString));
  row2.push_back(TableElement("",loadString));
  int numMonths = 0;
  BOOST_FOREACH(int month,months) {
    row1.push_back(TableElement(MonthOfYear(month).valueName(),loadString));
    row2.push_back(TableElement("(J)",loadString));
    ++numMonths;
    if (numMonths == 12) {
      break;
    }
  }