void DiscomfortIndexSensorResource::onUpdatedInputResource(const std::string attributeName,
        std::vector<RCSResourceAttributes::Value> values)
{
    double sum = 0;
    double dConvert;
    int inputCount = 0;
    std::string itString;

    for (auto it : values)
    {
        itString = it.toString();
        std::stringstream ss(itString); //turn the string into a stream
        ss >> dConvert; //convert
        sum += dConvert;
        ++inputCount;
    }

    double result = sum / inputCount;
    std::string indexCount;//string which will contain the indexCount
    std::stringstream convert; // stringstream used for the conversion
    convert << result;//add the value of Number to the characters in the stream
    indexCount = convert.str();//set indexCount to the content of the stream

    m_mapInputData[attributeName] = indexCount;

    // execute logic only if all the input data are ready
    if (m_mapInputData.find("temperature") != m_mapInputData.end()
        && m_mapInputData.find("humidity") != m_mapInputData.end())
    {
        executeLogic();
    }
}
Esempio n. 2
0
void BMISensorResource::onUpdatedInputResource(const std::string attributeName,
        std::vector<RCSResourceAttributes::Value> values)
{
    // remove all existing data
    m_mapInputData.clear();

    if (!attributeName.compare("weight"))
        m_mapInputData.insert(std::make_pair("weight", values.back().get< std::string >()));

    if (!attributeName.compare("height"))
        m_mapInputData.insert(std::make_pair("height", values.back().get< std::string >()));

    executeLogic();
}