void RecipeIngredient::initialize()
{
    if(!_ingredient->type().compare("Grain", Qt::CaseInsensitive)) {
        if(_quantity.value() == 0 && _quantity.type() == Quantity::QuantityType_item)
            _quantity = Quantity(1, Quantity::QuantityType_pound);
        if(_minutes == 0)
            _minutes = 0;
    } else if(!_ingredient->type().compare("Hops", Qt::CaseInsensitive)) {
        if(_quantity.value() == 0 && _quantity.type() == Quantity::QuantityType_item)
            _quantity = Quantity(1, Quantity::QuantityType_ounce);
        if(_minutes == 0)
            _minutes = 60;
    } else if(!_ingredient->type().compare("Yeast", Qt::CaseInsensitive)) {
        if(_quantity.value() == 0 && _quantity.type() == Quantity::QuantityType_item)
            _quantity = Quantity(1, Quantity::QuantityType_item);
        if(_minutes == 0)
            _minutes = 0;
    } else {
        if(_quantity.value() == 0 && _quantity.type() == Quantity::QuantityType_item)
            _quantity = Quantity();
        if(_minutes == 0)
            _minutes = 0;
    }

}
 Quantity UnitOfMeasureConversion::convert(const Quantity& quantity) const {
     switch (data_->type) {
       case Direct:
         if (quantity.unitOfMeasure() == data_->source)
             return Quantity(quantity.commodityType(),
                             data_->target,
                             quantity.amount()*data_->conversionFactor);
         else if (quantity.unitOfMeasure() == data_->target)
             return Quantity(quantity.commodityType(),
                             data_->source,
                             quantity.amount()/data_->conversionFactor);
         else
             QL_FAIL("direct conversion not applicable");
       case Derived:
         if (quantity.unitOfMeasure()
             == data_->conversionFactorChain.first->source() ||
             quantity.unitOfMeasure()
             == data_->conversionFactorChain.first->target())
             return data_->conversionFactorChain.second->convert(
                    data_->conversionFactorChain.first->convert(quantity));
         else if (quantity.unitOfMeasure()
                  == data_->conversionFactorChain.second->source() ||
                  quantity.unitOfMeasure()
                  == data_->conversionFactorChain.second->target())
             return data_->conversionFactorChain.first->convert(
                   data_->conversionFactorChain.second->convert(quantity));
         else
             QL_FAIL("derived conversion factor not applicable");
       default:
         QL_FAIL("unknown conversion-factor type");
     }
 }
std::vector<Quantity> OSQuantityVector::quantities() const {
  QuantityVector result;
  for (double value : values()) {
    result.push_back(Quantity(value,units()));
  }
  return result;
}
boost::optional<double> convert(double original, const std::string& originalUnits, const std::string& finalUnits)
{
  if (originalUnits == finalUnits){
    return original;
  }

  //create the units from the strings
  boost::optional<Unit> originalUnit = UnitFactory::instance().createUnit(originalUnits);
  boost::optional<Unit> finalUnit = UnitFactory::instance().createUnit(finalUnits);

  //make sure both unit strings were valid
  if (originalUnit && finalUnit) {

    //make the original quantity
    Quantity originalQuant = Quantity(original, *originalUnit);

    //convert to final units
    boost::optional<Quantity> finalQuant = QuantityConverter::instance().convert(originalQuant, *finalUnit);
  
    //if the conversion 
    if (finalQuant) {
      return finalQuant->value();
    }
  }

  return boost::none;
}
void SchedulesTabController::onDayScheduleSceneChanged( DayScheduleScene * scene, double lowerLimitValue, double upperLimitValue )
{
  std::vector<CalendarSegmentItem *> segments = scene->segments();

  model::ScheduleDay scheduleDay = scene->scheduleDay();

  OptionalUnit units = scene->scheduleDayView()->units();

  scheduleDay.clearValues();

  for( std::vector<CalendarSegmentItem *>::iterator it = segments.begin();
       it < segments.end();
       ++it )
  {
    openstudio::Time time(0,0,0,(*it)->endTime());

    float scaledvalue = (*it)->value();

    float value = lowerLimitValue + scaledvalue * (upperLimitValue - lowerLimitValue);

    if (units) {
      scheduleDay.addValue(time,Quantity(value,*units)); // going to be slower than it has to be
                                                         // better to assemble all values into OSQuantityVector and then set
    }
    else {
      scheduleDay.addValue(time,value);
    }
  }
}
Exemple #6
0
Quantity TrafficMatrix::getFlow(const std::pair<std::string, std::string> &nodes) const {
	matrixType::const_iterator it = this->matrix.find(nodes);

	if(it == this->matrix.end())
		return Quantity(0, Units::Bandwidth);
	return it->second;
}
RecipeIngredient::RecipeIngredient(Ingredient *ingredient, QObject *parent) :
    QObject(parent)
{
    setIngredient(ingredient);
    _quantity = Quantity();
    _minutes = 0;
    initialize();
}
Exemple #8
0
 inline void
 Depth<SIZE>::change_qty_order(
     Price price,
     int32_t qty_delta,
     bool is_bid
 )
 {
     DepthLevel* level = find_level(price, is_bid, false);
     if (level && qty_delta) {
         if (qty_delta > 0) {
             level->increase_qty(Quantity(qty_delta));
         } else {
             level->decrease_qty(Quantity(std::abs(qty_delta)));
         }
         level->last_change(++last_change_);
     }
     // Ignore if not found - may be beyond our depth size
 }
Exemple #9
0
Recipe::Recipe(QObject *parent) :
    QObject(parent)
{
    _name = tr("New Recipe");
    _volume = Quantity(5.5, Quantity::QuantityType_gallon);
    _efficiency = 0.75;
    _id = QUuid::createUuid();
    _style = tr("Beer");
}
Exemple #10
0
void TrafficMatrix::setFlow(const std::pair<std::string, std::string> &nodes,
							const Quantity &volume) {
	matrixType::iterator it = this->matrix.find(nodes);

	if(it != this->matrix.end())
		this->matrix.erase(it);	//Avoid using operator[].

	if(volume > Quantity(0, Units::Bandwidth))
		this->matrix.insert(std::make_pair(nodes, volume));
}
void HistoryEntry::deSerialize(const QJsonObject & json)
{
    *this = HistoryEntry();

    if (json.contains("expression"))
        m_expr = json["expression"].toString();

    if (json.contains("result"))
        m_result = Quantity(json["result"].toObject());
    return;
}
Exemple #12
0
boost::optional<Quantity> QuantityFactorySingleton::createQuantity(
    double value,
    const std::string& unitString,
    UnitSystem system) const
{
  // create return variable, and try to create unit
  OptionalQuantity result;
  OptionalUnit unit = UnitFactory::instance().createUnit(unitString,system);
  if (unit) {
    result = Quantity(value,*unit);
  }
  return result;
}
 boost::optional<Quantity> ScheduleBase_Impl::toQuantity(double value, bool returnIP) const {
   OptionalQuantity result;
   if (OptionalScheduleTypeLimits scheduleTypeLimits = this->scheduleTypeLimits()) {
     if (OptionalUnit siUnits = ScheduleTypeLimits::units(scheduleTypeLimits->unitType(),false)) {
       result = Quantity(value,*siUnits);
       if (returnIP) {
         OptionalUnit ipUnits = ScheduleTypeLimits::units(scheduleTypeLimits->unitType(),returnIP);
         OS_ASSERT(ipUnits);
         if (ipUnits.get() != siUnits.get()) {
           result = convert(*result,*ipUnits);
         }
       }
     }
   }
   return result;
 }
Quantity dot(OSQuantityVector lVector, const OSQuantityVector& rVector) {
  Unit lUnits(lVector.units()), rUnits(rVector.units());
  OptionalTemperatureUnit ltu = lUnits.optionalCast<TemperatureUnit>();
  OptionalTemperatureUnit rtu = rUnits.optionalCast<TemperatureUnit>();
  Unit resultUnits;
  if (ltu && rtu) {
    resultUnits = ltu.get() * rtu.get();
  }
  else {
    resultUnits = lUnits * rUnits;
  }
  ScaleOpReturnType resultScale = lVector.scale() * rVector.scale();
  lVector *= resultScale.second;
  DoubleVector lValues(lVector.values()), rValues(rVector.values());
  double resultValue = dot(createVector(lValues),createVector(rValues));
  return Quantity(resultValue,resultUnits);
}
int main()
{
  int value; 
  int array[SIZE];
  int array2[SIZE]; //duplicate array
  int quantity;
  int funds;
  int maxCombination;
  int minCombination;
  int firstDesired;

//Function Call
value = Input(array); //value is number of item prices input
duplicate(value, array, array2); //creates a duplicate array to be used to check for min combination
quantity = Quantity(array, value); //gets number of items wanted
funds = Funds(array, value, quantity); //gets funds available
firstDesired = firstSum(array, quantity);
maxCombination = maxAmount(array, value, quantity); //finds max combination
minCombination = minAmount(array2, value, quantity);
result(funds, maxCombination, firstDesired, minCombination, quantity);
  return 0;
}
Exemple #16
0
Quantity OSRunner::getQuantityArgumentValue(const std::string& argument_name,
        const std::map<std::string,OSArgument>& user_arguments)
{
    std::stringstream ss;

    auto it = user_arguments.find(argument_name);
    if (it != user_arguments.end()) {
        if (it->second.hasValue()) {
            return it->second.valueAsQuantity();
        }
        else if (it->second.hasDefaultValue()) {
            return it->second.defaultValueAsQuantity();
        }
    }

    ss << "No value found for argument '" << argument_name << "'.";
    if (it != user_arguments.end()) {
        ss << " Full argument as passed in by user:" << std::endl << it->second;
    }
    registerError(ss.str());
    LOG_AND_THROW(ss.str());
    return Quantity();
}
Exemple #17
0
 static constexpr Quantity meters(double v)
 { return Quantity(v,1,0,0); }    
Exemple #18
0
 static constexpr Quantity seconds(double v)
 { return Quantity(v,0,1,0); }    
Exemple #19
0
 static constexpr Quantity grams(double v)
 { return Quantity(v,0,0,1); }
void RecipeIngredient::fromXml(QDomElement element)
{
    setIngredient(Ingredient::createIngredient(element.elementsByTagName("Ingredient").at(0).toElement()));
    setQuantity(Quantity(element.elementsByTagName("Quantity").at(0).toElement()));
    setMinutes(element.attribute("minutes", QString().setNum(minutes())).toDouble());
}
 bool FFactorGroundFloorConstruction_Impl::setFFactor(double fFactor) {
   OSOptionalQuantity temp = getQuantity(OS_Construction_FfactorGroundFloorFields::FFactor,true,false);
   bool result = setFFactor(Quantity(fFactor,temp.units()));
   return result;
 }
Exemple #22
0
 Run::Run( float time, float speed ) : Run(Quantity(time, MINUTES),
     Quantity(speed, MPH)) {
 }
Exemple #23
0
 inline Quantity Quantity::rounded() const {
     return Quantity(commodityType_,
                     unitOfMeasure_,
                     unitOfMeasure_.rounding()(amount_));
 }
Quantity OSQuantityVector::getQuantity(unsigned i) const {
  return Quantity(m_values[i],units());
}
 bool FFactorGroundFloorConstruction_Impl::setPerimeterExposed(double perimeterExposed) {
   OSOptionalQuantity temp = getQuantity(OS_Construction_FfactorGroundFloorFields::PerimeterExposed,true,false);
   bool result = setPerimeterExposed(Quantity(perimeterExposed,temp.units()));
   return result;
 }
Exemple #26
0
 static constexpr Quantity joules(double v)
 { return Quantity(v*1000,2,-2,1); }
double SchedulesTabController::defaultStartingValue(const model::ScheduleDay& scheduleDay) {
  double result(0.3);
  if (model::OptionalScheduleTypeLimits typeLimits = scheduleDay.scheduleTypeLimits()) {
    OptionalUnit siU = model::ScheduleTypeLimits::units(typeLimits->unitType(),false);
    if (siU) {
      std::string unitType = typeLimits->unitType();
      boost::to_lower(unitType);
      char firstLetter = unitType[0];
      OptionalQuantity siQ;
      switch (firstLetter) {
      case 'a' :
        { 
          if (unitType == "activitylevel") {          
            siQ = Quantity(100.0,*siU);
          }
          else if (unitType == "angle") {
            siQ = Quantity(0.0,*siU);
          }
          else if (unitType == "availability") {
            siQ = Quantity(1.0,*siU);
          }
          break;
        }
      case 'c' :
        {
          if (unitType == "capacity") {
            siQ = Quantity(100.0,*siU);
          }
          else if (unitType == "clothinginsulation") {
            siQ = Quantity(0.5,*siU);
          }
          else if (unitType == "controlmode") {
            siQ = Quantity(0.0,*siU);
          }
          else if (unitType == "convectioncoefficient") {
            siQ = Quantity(10.0,*siU);
          }
          break;
        }
      case 'd' :
        {
          if (unitType == "deltatemperature") {
            siQ = Quantity(3.0,*siU);
          }
          break;
        }
      case 'm' :
        {
          if (unitType == "massflowrate") {
            siQ = Quantity(1.0,*siU);
          }
          break;
        }
      case 'p' :
        {
          if (unitType == "percent") {
            siQ = Quantity(50.0,*siU);
          }
          else if (unitType == "power") {
            siQ = Quantity(100.0,*siU);
          }
          else if (unitType == "precipitationrate") {
            siQ = Quantity(0.01,*siU);
          }
          else if (unitType == "pressure") {
            siQ = Quantity(100.0,*siU);
          }
          break;
        }
      case 'r' :
        {
          siQ = Quantity(1500.0,*siU);
          break;
        }
      case 's' :
        {
          if (unitType == "solarenergy") {
            siQ = Quantity(1000.0,*siU);
          }
          break;
        }
      case 't' :
        {
          if (unitType == "temperature") {
            siQ = Quantity(23.5,*siU);
          }
          break;
        }
      case 'v' :
        {
          if (unitType == "velocity") {
            siQ = Quantity(1.0,*siU);
          }
          if (unitType == "volumetricflowrate") {
            siQ = Quantity(1.0E-4,*siU);
          }
          break;
        }
      default :
        break;
      } // switch
      if (siQ) {
        result = siQ->value();
      }
    } // if siU
  }
  return result;
}
Exemple #28
0
 Run::Run( Quantity time, Quantity speed ) : time(time), speed(speed),
 distance( Quantity( time.convert(HOURS).magnitude() *
       speed.convert(MPH).magnitude(), MILES )) {
 }
 bool FFactorGroundFloorConstruction_Impl::setArea(double area) {
   OSOptionalQuantity temp = getQuantity(OS_Construction_FfactorGroundFloorFields::Area,true,false);
   bool result = setArea(Quantity(area,temp.units()));
   return result;
 }
Exemple #30
0
 inline Quantity Quantity::operator-() const {
     return Quantity(commodityType_, unitOfMeasure_, -amount_);
 }