예제 #1
0
int ReadStarDrop::compute(const char *)
{
    int numSteps; // number of steps we use : Param or automatic
    float *timeFrame; // starting Time for this step index
    int *meshIdx; // we use grid index [] first for the given step

    // retrieve filename parameter
    const char *fileName = p_filename->getValue();

    // Retrieve and test Mesh obj: Must be a set of USGs with REALTIME attribs
    const coDistributedObject *const *meshSet;
    int numGridSteps;
    float *gridTime;
    if (retrieveMeshes(meshSet, numGridSteps, gridTime) == FAIL)
        return FAIL;

    // if already read, do not read again
    if (!d_lastFileName || strcmp(fileName, d_lastFileName) || d_dropArr == NULL)
    {
        if (readFile(fileName) == FAIL)
            return FAIL;
    }

    // get numSteps, build timeFrame and meshIdx arrays
    if (timeArray(numGridSteps, gridTime, numSteps, timeFrame, meshIdx) == FAIL)
        return FAIL;

    // this is the loppThrough data: meshes are akready open, rest opened inside
    if (createLoopThrough(meshSet, numGridSteps, numSteps, meshIdx) == FAIL)
        return FAIL;

    if (createDropletObj(numSteps, timeFrame) == FAIL)
        return FAIL;

    return SUCCESS;
}
예제 #2
0
void
CpintPlot::calculate(RideItem *rideItem)
{
    if (!rideItem) return;

    QString fileName = rideItem->fileName;
    QDateTime dateTime = rideItem->dateTime;
    QDir dir(path);
    QFileInfo file(fileName);

    // get current ride statistics
    current = new RideFileCache(mainWindow, mainWindow->home.absolutePath() + "/" + fileName);

    // get aggregates - incase not initialised from date change
    if (bests == NULL) bests = new RideFileCache(mainWindow, startDate, endDate, isFiltered, files);

    //
    // PLOT MODEL CURVE (DERIVED)
    //
    curveTitle.setLabel(QwtText("", QwtText::PlainText)); // default to no title
    if (series == RideFile::xPower || series == RideFile::NP || series == RideFile::watts  || series == RideFile::wattsKg || series == RideFile::none) {

        if (bests->meanMaxArray(series).size() > 1) {
            // calculate CP model from all-time best data
            cp  = tau = t0  = 0;
            deriveCPParameters();
        }

        //
        // CP curve only relevant for Energy or Watts (?)
        //
        if (series == RideFile::watts || series == RideFile::wattsKg || series == RideFile::none) {
            if (!CPCurve) plot_CP_curve(this, cp, tau, t0);
            else {
                // make sure color reflects latest config
                QPen pen(GColor(CCP));
                pen.setWidth(2.0);
                pen.setStyle(Qt::DashLine);
                CPCurve->setPen(pen);
            }
        }

        //
        // PLOT ZONE (RAINBOW) AGGREGATED CURVE
        //
        if (bests->meanMaxArray(series).size()) {
            int maxNonZero = 0;
            for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) {
                if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i;
            }
            plot_allCurve(this, maxNonZero, bests->meanMaxArray(series).constData() + 1);
        }
    } else {

        //
        // PLOT BESTS IN SERIES COLOR
        //
        if (allCurve) {
            delete allCurve;
            allCurve = NULL;
        }
        if (bests->meanMaxArray(series).size()) {

            int maxNonZero = 0;
            QVector<double> timeArray(bests->meanMaxArray(series).size());
            for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) {
                timeArray[i] = i / 60.0;
                if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i;
            }

            if (maxNonZero > 1) {

                allCurve = new QwtPlotCurve(dateTime.toString(tr("ddd MMM d, yyyy h:mm AP")));
                allCurve->setRenderHint(QwtPlotItem::RenderAntialiased);

                QPen line;
                QColor fill;
                switch (series) {

                    case RideFile::kph:
                        line.setColor(GColor(CSPEED).darker(200));
                        fill = (GColor(CSPEED));
                        break;

                    case RideFile::cad:
                        line.setColor(GColor(CCADENCE).darker(200));
                        fill = (GColor(CCADENCE));
                        break;

                    case RideFile::nm:
                        line.setColor(GColor(CTORQUE).darker(200));
                        fill = (GColor(CTORQUE));
                        break;

                    case RideFile::hr:
                        line.setColor(GColor(CHEARTRATE).darker(200));
                        fill = (GColor(CHEARTRATE));
                        break;

                    case RideFile::vam:
                        line.setColor(GColor(CALTITUDE).darker(200));
                        fill = (GColor(CALTITUDE));
                        break;

                    default:
                    case RideFile::watts: // won't ever get here
                    case RideFile::NP:
                    case RideFile::xPower:
                        line.setColor(GColor(CPOWER).darker(200));
                        fill = (GColor(CPOWER));
                        break;
                }

                // wow, QVector really doesn't have a max/min method!
                double ymax = 0;
                double ymin = 100000;
                foreach(double v, current->meanMaxArray(series)) {
                    if (v > ymax) ymax = v;
                    if (v && v < ymin) ymin = v;
                }
                foreach(double v, bests->meanMaxArray(series)) {
                    if (v > ymax) ymax = v;
                    if (v&& v < ymin) ymin = v;
                }
                if (ymin == 100000) ymin = 0;

                // VAM is a bit special
                if (series == RideFile::vam) {
                    if (bests->meanMaxArray(series).size() > 300)
                        ymax = bests->meanMaxArray(series)[300];
                    else
                        ymax = 2000;
                }

                ymax *= 1.1; // bit of headroom
                ymin *= 0.9;

                // xmax is directly related to the size of the arrays
                double xmax = current->meanMaxArray(series).size();
                if (bests->meanMaxArray(series).size() > xmax)
                    xmax = bests->meanMaxArray(series).size();
                xmax /= 60; // its in minutes not seconds

                setAxisScale(yLeft, ymin, ymax);

                if (series == RideFile::vam)
                    setAxisScale(xBottom, 4.993, xmax);
                else
                    setAxisScale(xBottom, 0.017, xmax);

                allCurve->setPen(line);
                fill.setAlpha(64);
                // use a linear gradient
                fill.setAlpha(240);
                QColor fill1 = fill;
                fill1.setAlpha(40);
                QLinearGradient linearGradient(0, 0, 0, height());
                linearGradient.setColorAt(0.0, fill);
                linearGradient.setColorAt(1.0, fill1);
                linearGradient.setSpread(QGradient::PadSpread);
                allCurve->setBrush(linearGradient);
                allCurve->attach(this);
                allCurve->setData(timeArray.data() + 1, bests->meanMaxArray(series).constData() + 1, maxNonZero - 1);
            }
        }
예제 #3
0
void
CpintPlot::calculate(RideItem *rideItem)
{
    if (!rideItem) return;

    QString fileName = rideItem->fileName;
    QDateTime dateTime = rideItem->dateTime;
    QDir dir(path);
    QFileInfo file(fileName);

    // zap any existing ridefilecache then get new one
    if (current) delete current;
    current = new RideFileCache(context, context->athlete->home.absolutePath() + "/" + fileName);

    // get aggregates - incase not initialised from date change
    if (bests == NULL) bests = new RideFileCache(context, startDate, endDate, isFiltered, files, rangemode);

    //
    // PLOT MODEL CURVE (DERIVED)
    //
    if (series == RideFile::aPower || series == RideFile::xPower || series == RideFile::NP || series == RideFile::watts  || series == RideFile::wattsKg || series == RideFile::none) {

        if (bests->meanMaxArray(series).size() > 1) {
            // calculate CP model from all-time best data
            cp  = tau = t0  = 0;
            deriveCPParameters();

            if (useExtendedCP) {
                // calculate extended CP model from all-time best data
                //athleteModeleCP2 = ecp->deriveExtendedCP_2_3_Parameters(bests, series, sanI1, sanI2, anI1, anI2, aeI1, aeI2, laeI1, laeI2);

                athleteModeleCP4 = ecp->deriveExtendedCP_4_3_Parameters(true, bests, series, sanI1, sanI2, anI1, anI2, aeI1, aeI2, laeI1, laeI2);


                /*double best5sec = context->ride->ride()->getWeight() * 24.04;
                double best1min = context->ride->ride()->getWeight() * 11.50;
                double best5min = context->ride->ride()->getWeight() * 7.60;
                double best1hour = context->ride->ride()->getWeight() * 6.40;
                //worldClassModeleCP2 = ecp->deriveExtendedCP_2_3_ParametersForBest(best5sec, best1min, best5min, best1hour);
                worldClassModeleCP4 = ecp->deriveExtendedCP_4_3_ParametersForBest(best5sec, best1min, best5min, best1hour);*/
            }
        }

        //
        // CP curve only relevant for Energy or Watts (?)
        //
        if (series == RideFile::aPower || series == RideFile::NP || series == RideFile::xPower ||
            series == RideFile::watts || series == RideFile::wattsKg || series == RideFile::none) {

            if (!CPCurve) plot_CP_curve(this, cp, tau, t0);
            else {
                // make sure color reflects latest config
                QPen pen(GColor(CCP));
                pen.setWidth(1.0);
                pen.setStyle(Qt::DashLine);
                CPCurve->setPen(pen);
            }

            if (useExtendedCP && CPCurve) CPCurve->setVisible(false);
            else if (CPCurve) CPCurve->setVisible(true);
        }

        //
        // PLOT ZONE (RAINBOW) AGGREGATED CURVE
        //
        if (bests->meanMaxArray(series).size()) {
            int maxNonZero = 0;
            for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) {
                if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i;
            }
            plot_allCurve(this, maxNonZero, bests->meanMaxArray(series).constData() + 1);
        }
    } else {

        //
        // PLOT BESTS IN SERIES COLOR
        //
        if (allCurve) {
            delete allCurve;
            allCurve = NULL;
        }
        if (bests->meanMaxArray(series).size()) {

            int maxNonZero = 0;
            QVector<double> timeArray(bests->meanMaxArray(series).size());
            for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) {
                timeArray[i] = i / 60.0;
                if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i;
            }

            if (maxNonZero > 1) {

                allCurve = new QwtPlotCurve(dateTime.toString(tr("ddd MMM d, yyyy h:mm AP")));
                allCurve->setRenderHint(QwtPlotItem::RenderAntialiased);

                QPen line;
                QColor fill;
                switch (series) {

                    case RideFile::kph:
                        line.setColor(GColor(CSPEED).darker(200));
                        fill = (GColor(CSPEED));
                        break;

                    case RideFile::cad:
                        line.setColor(GColor(CCADENCE).darker(200));
                        fill = (GColor(CCADENCE));
                        break;

                    case RideFile::nm:
                        line.setColor(GColor(CTORQUE).darker(200));
                        fill = (GColor(CTORQUE));
                        break;

                    case RideFile::hr:
                        line.setColor(GColor(CHEARTRATE).darker(200));
                        fill = (GColor(CHEARTRATE));
                        break;

                    case RideFile::vam:
                        line.setColor(GColor(CALTITUDE).darker(200));
                        fill = (GColor(CALTITUDE));
                        break;

                    default:
                    case RideFile::watts: // won't ever get here
                    case RideFile::NP:
                    case RideFile::xPower:
                        line.setColor(GColor(CPOWER).darker(200));
                        fill = (GColor(CPOWER));
                        break;
                }

                // wow, QVector really doesn't have a max/min method!
                double ymax = 0;
                double ymin = 100000;
                foreach(double v, current->meanMaxArray(series)) {
                    if (v > ymax) ymax = v;
                    if (v && v < ymin) ymin = v;
                }
                foreach(double v, bests->meanMaxArray(series)) {
                    if (v > ymax) ymax = v;
                    if (v&& v < ymin) ymin = v;
                }
                if (ymin == 100000) ymin = 0;

                // VAM is a bit special
                if (series == RideFile::vam) {
                    if (bests->meanMaxArray(series).size() > 300)
                        ymax = bests->meanMaxArray(series)[300];
                    else
                        ymax = 2000;
                }

                ymax *= 1.1; // bit of headroom
                ymin *= 0.9;

                // xmax is directly related to the size of the arrays
                double xmax = current->meanMaxArray(series).size();
                if (bests->meanMaxArray(series).size() > xmax)
                    xmax = bests->meanMaxArray(series).size();
                xmax /= 60; // its in minutes not seconds

                setAxisScale(yLeft, ymin, ymax);

                QwtScaleDiv div((series == RideFile::vam ? (double) 4.993: (double) 0.017), (double)xmax);
                div.setTicks(QwtScaleDiv::MajorTick, LogTimeScaleDraw::ticks);
                setAxisScaleDiv(QwtPlot::xBottom, div);

                allCurve->setPen(line);
                fill.setAlpha(64);
                // use a linear gradient
                fill.setAlpha(64);
                QColor fill1 = fill.darker();
                QLinearGradient linearGradient(0, 0, 0, height());
                linearGradient.setColorAt(0.0, fill);
                linearGradient.setColorAt(1.0, fill1);
                linearGradient.setSpread(QGradient::PadSpread);
                allCurve->setBrush(linearGradient);
                allCurve->attach(this);
                allCurve->setSamples(timeArray.data() + 1, bests->meanMaxArray(series).constData() + 1, maxNonZero - 1);
            }
        }