Exemplo n.º 1
0
void plot_analytics::plotAnalyze( QCPGraph *target, plotStats *stats, QCPRange keyRange)
{
    QCPGraphDataContainer::const_iterator plotIterator = target->data().data()->findBegin(keyRange.lower,true);
    QCPGraphDataContainer::const_iterator targetDataEnd = target->data().data()->findEnd(keyRange.upper,true);
    QCPGraphData currentPoint, prevPoint;

    //Find the data ranges
    currentPoint.key = keyRange.lower;
    prevPoint = QCPGraphData(plotIterator->key, plotIterator->value);

    while(plotIterator != targetDataEnd && (keyRange.contains(plotIterator->key) || stats->totalData_entrys < 2))
    {
        currentPoint = QCPGraphData(plotIterator->key, plotIterator->value);
        handlePoints(currentPoint, prevPoint, stats);

        //Value is weighted to account for datapoints that may not be equally spaced
        if(!isInvalidData(currentPoint.value) && !isInvalidData(prevPoint.value))
            stats->avgValue += currentPoint.value*(currentPoint.key-prevPoint.key);

        prevPoint = QCPGraphData(plotIterator->key, plotIterator->value);
        ++plotIterator;
    }
    //Divide by total seconds
    stats->avgValue /= stats->totalData_seconds;
}
Exemplo n.º 2
0
bool plot_analytics::handlePoints(QCPGraphData target, QCPGraphData reference, plotStats *stats)
{
    if( (!isInvalidData(target.key, target.value)) && (!isInvalidData(reference.key, reference.value)) )
    {
        //Determine how much time was betwen points
        double dataKeyDeltaP2P = qAbs(target.key-reference.key);

        //Determine how much the value changed
        double dataValueDeltaP2P = target.value-reference.value;

        //qDebug() << dataKeyDeltaP2P << dataValueDeltaP2P << stats->totalValue_Sum;

        stats->totalValue_DeltaP2P += qAbs(dataValueDeltaP2P)*dataKeyDeltaP2P;
        stats->totalData_seconds += dataKeyDeltaP2P;
        stats->totalData_entrys++;

        if(dataValueDeltaP2P > stats->maxPosValue_DeltaP2P)
            stats->maxPosValue_DeltaP2P = dataValueDeltaP2P;

        if(dataValueDeltaP2P < stats->maxNegValue_DeltaP2P)
            stats->maxNegValue_DeltaP2P = dataValueDeltaP2P;

        if(qAbs(dataValueDeltaP2P) < stats->minValue_DeltaP2P)
            stats->minValue_DeltaP2P = qAbs(dataValueDeltaP2P);

        if(target.value > stats->maxValue)
            stats->maxValue = target.value;

        if(target.value < stats->minValue)
            stats->minValue = target.value;

        if(target.key!=0)
            stats->totalNonZeroData_seconds += dataKeyDeltaP2P;

        if(dataValueDeltaP2P == 0)
        {
            stats->totalTimeNoDelta_seconds += dataKeyDeltaP2P;
            stats->currentTimeDelta_seconds += dataKeyDeltaP2P;
            stats->currentTimeNoDelta_seconds = 0;

            if(stats->currentTimeDelta_seconds > stats->longestTimeDelta_seconds)
                stats->longestTimeDelta_seconds = stats->currentTimeDelta_seconds;
        }
        else
        {
            stats->totalTimeDelta_seconds += dataKeyDeltaP2P;
            stats->currentTimeDelta_seconds = 0;
            stats->currentTimeNoDelta_seconds += dataKeyDeltaP2P;

            if(stats->currentTimeNoDelta_seconds > stats->longestTimeNoDelta_seconds)
                stats->longestTimeNoDelta_seconds = stats->currentTimeNoDelta_seconds;
        }

        return true;
    }
    return false;
}
Exemplo n.º 3
0
void flagInvalidData(char* buf){
    if(isInvalidData(buf))
        return;
    Msg* m = (Msg*) buf;
    m->flags |= FRAME_NOT_VALID;
    m->checksum += FRAME_NOT_VALID;
}