void convertcmTomm(std::string& returnString, const shared::CDataContainer& valueContainer, const std::string& label) { double temp = 0; if (!convertDouble(temp, valueContainer, label)) returnString = "--"; else returnString = boost::lexical_cast<std::string>(temp * 10); }
void VariantToBsonConverter::convertElement(bson_t *bson, const char *key, Variant v) { switch (v.getType()) { case KindOfUninit: case KindOfNull: convertNull(bson, key); break; case KindOfBoolean: convertBoolean(bson, key, v.toBoolean()); break; case KindOfInt64: convertInt64(bson, key, v.toInt64()); break; case KindOfDouble: convertDouble(bson, key, v.toDouble()); break; #if HIPPO_HHVM_VERSION >= 31200 case KindOfPersistentString: #else case KindOfStaticString: #endif case KindOfString: convertString(bson, key, v.toString()); break; case KindOfArray: #if HIPPO_HHVM_VERSION >= 31100 case KindOfPersistentArray: #endif case KindOfObject: convertDocument(bson, key, v); break; case KindOfRef: convertElement(bson, key, *v.getRefData()); break; case KindOfResource: throw MongoDriver::Utils::throwUnexpectedValueException("Got unsupported type 'resource'"); return; case KindOfClass: not_reached(); } }
string SCStat::GetTransitionTime( int i ) { string type = ""; if( TIME_ABS == g_allTrans[i]->GetTimeType() ) type += convertDouble( g_allTrans[i]->GetTime() ); else if( TIME_EXP == g_allTrans[i]->GetTimeType() ) type += "exp(" + convertDouble( g_allTrans[i]->GetTime() ) + ")"; else if( TIME_POIS == g_allTrans[i]->GetTimeType() ) type += "pois(" + convertDouble( g_allTrans[i]->GetTime() ) + ")"; else if( TIME_NORM == g_allTrans[i]->GetTimeType() ) type += "gauss" + convertDouble( g_allTrans[i]->GetTime() ) + "-" + convertDouble( g_allTrans[i]->GetTimeEnd()) + ")"; else if( TIME_ROV == g_allTrans[i]->GetTimeType() ) type += convertDouble( g_allTrans[i]->GetTime() ) + "-" + convertDouble( g_allTrans[i]->GetTimeEnd()); else type = ""; return type; }
IssuerEntry::IssuerEntry(const vector<string>& cells) : name(sanitizeString(cells.at(0))), rating(sanitizeString(cells.at(1))), industry(sanitizeString(cells.at(2))), correl(convertDouble(cells.at(3))) {}
oret_t owatchConvertValue(const oval_t * src_val, oval_t * dst_val, char *data_buf, int data_buf_len) { oret_t rc = ERROR; char src_type, dst_type; int len; if (src_val == NULL || dst_val == NULL) return ERROR; src_type = src_val->type; dst_type = dst_val->type; if (dst_type == 's') { if (src_type == 's') { if (src_val->v.v_str == NULL) { dst_val->v.v_str = NULL; dst_val->len = 0; dst_val->time = src_val->time; if (data_buf && data_buf_len) *data_buf = 0; return OK; } if (src_val->len == 0) { dst_val->v.v_str = data_buf; dst_val->len = 0; dst_val->time = src_val->time; if (data_buf && data_buf_len) *data_buf = 0; return OK; } if (src_val->len < 0) return ERROR; if (data_buf == NULL || data_buf_len < src_val->len) return ERROR; oxbcopy(src_val->v.v_str, data_buf, src_val->len); if (src_val->len < data_buf_len) data_buf[src_val->len] = 0; dst_val->v.v_str = data_buf; dst_val->len = src_val->len; dst_val->time = src_val->time; return OK; } len = convertToString(src_type, src_val, data_buf, data_buf_len); if (len < 0) return ERROR; dst_val->v.v_str = data_buf; dst_val->len = len; dst_val->time = src_val->time; return OK; } switch (src_type) { case 'b': rc = convertSignedChar(src_val->v.v_char, dst_type, dst_val); break; case 'B': rc = convertUnsignedChar(src_val->v.v_uchar, dst_type, dst_val); break; case 'h': rc = convertSignedShort(src_val->v.v_short, dst_type, dst_val); break; case 'H': rc = convertUnsignedShort(src_val->v.v_ushort, dst_type, dst_val); break; case 'i': rc = convertSignedInt(src_val->v.v_int, dst_type, dst_val); break; case 'I': rc = convertUnsignedInt(src_val->v.v_uint, dst_type, dst_val); break; case 'l': rc = convertSignedLong(src_val->v.v_long, dst_type, dst_val); break; case 'L': rc = convertUnsignedLong(src_val->v.v_ulong, dst_type, dst_val); break; case 'f': rc = convertFloat(src_val->v.v_float, dst_type, dst_val); break; case 'd': rc = convertDouble(src_val->v.v_double, dst_type, dst_val); break; case 'E': rc = convertEnum(src_val->v.v_enum, dst_type, dst_val); break; case 's': rc = convertFromString(src_val->v.v_str, dst_type, dst_val); break; default: return ERROR; } if (rc == ERROR) return ERROR; switch (dst_val->type) { case 'b': dst_val->len = 1; break; case 'B': dst_val->len = 1; break; case 'h': dst_val->len = 2; break; case 'H': dst_val->len = 2; break; case 'i': dst_val->len = 4; break; case 'I': dst_val->len = 4; break; case 'l': dst_val->len = 4; break; case 'L': dst_val->len = 4; break; case 'q': dst_val->len = 16; break; case 'Q': dst_val->len = 16; break; case 'f': dst_val->len = 4; break; case 'd': dst_val->len = 8; break; case 'D': dst_val->len = 16; break; case 'p': dst_val->len = 4; break; case 'E': dst_val->len = 4; break; case 'v': return ERROR; case 's': return ERROR; default: return ERROR; } dst_val->time = src_val->time; return OK; }
std::shared_ptr<GContainer> Transformation::transform(std::shared_ptr<GContainer>* inputs) { auto target = this->factory.lock()->makeInstance(this->targetRepresentation); for (auto operation : this->operations) { switch (operation->type) { case (DEFAULT): target->set(operation->targetDimension, operation->value); break; case (USE): { auto value = inputs[operation->sourceIndex]->get(operation->sourceDimension); if (value == nullptr) { return nullptr; } else { target->set(operation->targetDimension, value); } break; } case (FORMULA): { int nvars = operation->varmap.size(); if (nvars <= 0) { /* no mapping set -> use single variable mode by adding it to map */ operation->varmap.insert(std::make_pair(operation->varname, std::make_pair(operation->sourceDimension, operation->sourceIndex))); nvars++; } mu::Parser parser; parser.SetExpr(operation->formula); void *in_raw; double in[nvars]; int i = 0; for(auto const &var: operation->varmap) { in_raw = inputs[var.second.second]->get(var.second.first); in[i] = convertDouble(in_raw, operation->valueType); parser.DefineVar(var.first, &in[i]); i++; } const double out = parser.Eval(); target->set(operation->targetDimension, convertVoid(out, operation->valueType)); } break; default: //TODO break; } } return target; }
void CForecastDays::parse(boost::shared_ptr<yApi::IYPluginApi> api, const IWUConfiguration& wuConfiguration, const shared::CDataContainer dataToParse) const { if (!m_isDesactivated && !m_isUserDesactivated) { try { if (wuConfiguration.IsForecast10DaysEnabled()) { auto result = dataToParse.get<std::vector<shared::CDataContainer> >("forecast.simpleforecast.forecastday"); std::vector<shared::CDataContainer>::iterator i; m_forecast->clearAllPeriods(); unsigned char counter = 0; for (i = result.begin(); i != result.end(); ++i) { m_forecast->addPeriod(*i, "date.year", "date.month", "date.day", "icon", "high.celsius", "low.celsius", "maxwind.kph", "avewind.kph", "avewind.degrees", "avehumidity", "qpf_allday.mm", "snow_allday.cm"); if (counter == 0) { double temp = 0; if (convertDouble(temp, *i, "low.celsius")) m_temp->set(temp); } if (wuConfiguration.IsRainIndividualKeywordsEnabled()) { if (counter < NB_RAIN_FORECAST_DAY) { double rainRate1h = 0; if (convertDouble(rainRate1h, *i, "qpf_allday.mm")) m_forecastRain[counter]->set(rainRate1h); } } ++counter; } } api->historizeData(m_deviceName, m_keywords); std::cout << "Refresh Forecast Information" << std::endl; } catch (shared::exception::CException& e) { std::cout << "Error during parsing the element ! : " << e.what() << std::endl; } } }