Ejemplo n.º 1
0
void
PfPvPlot::setData(RideItem *_rideItem)
{
    // clear out any interval curves which are presently defined
    if (intervalCurves.size()) {
       QListIterator<QwtPlotCurve *> i(intervalCurves);
       while (i.hasNext()) {
           QwtPlotCurve *curve = i.next();
           curve->detach();
           delete curve;
       }
    }
    intervalCurves.clear();

    rideItem = _rideItem;
    RideFile *ride = rideItem->ride();

    if (ride) {

        // quickly erase old data
        curve->setVisible(false);


        // due to the discrete power and cadence values returned by the
        // power meter, there will very likely be many duplicate values.
        // Rather than pass them all to the curve, use a set to strip
        // out duplicates.
        std::set<std::pair<double, double> > dataSet;
        std::set<std::pair<double, double> > dataSetSelected;

        long tot_cad = 0;
        long tot_cad_points = 0;

        foreach(const RideFilePoint *p1, ride->dataPoints()) {

            if (p1->watts != 0 && p1->cad != 0) {

                double aepf = (p1->watts * 60.0) / (p1->cad * cl_ * 2.0 * PI);
                double cpv = (p1->cad * cl_ * 2.0 * PI) / 60.0;

                if (aepf <= 2500) { // > 2500 newtons is our out of bounds
                    dataSet.insert(std::make_pair<double, double>(aepf, cpv));
                    tot_cad += p1->cad;
                    tot_cad_points++;
                }
            }
        }

        setCAD(tot_cad_points ? tot_cad / tot_cad_points : 0);

        if (tot_cad_points == 0) {
            //setTitle(tr("no cadence"));
            refreshZoneItems();
            curve->setVisible(false);

        } else {
            // Now that we have the set of points, transform them into the
            // QwtArrays needed to set the curve's data.
            QwtArray<double> aepfArray;
            QwtArray<double> cpvArray;

            std::set<std::pair<double, double> >::const_iterator j(dataSet.begin());
            while (j != dataSet.end()) {
                const std::pair<double, double>& dataPoint = *j;

                aepfArray.push_back(dataPoint.first);
                cpvArray.push_back(dataPoint.second);

                ++j;
            }

            curve->setData(cpvArray, aepfArray);
            QwtSymbol sym;
            sym.setStyle(QwtSymbol::Ellipse);
            sym.setSize(6);
            sym.setBrush(QBrush(Qt::NoBrush));

            // now show the data (zone shading would already be visible)
            refreshZoneItems();
            curve->setVisible(true);
        }
    } else {
Ejemplo n.º 2
0
void
PfPvPlot::setData(RideItem *_rideItem)
{
    rideItem = _rideItem;

    RideFile *ride = rideItem->ride;

    if (ride) {
	setTitle(ride->startTime().toString(GC_DATETIME_FORMAT));

	// quickly erase old data
	curve->setVisible(false);

	// handle zone stuff
	refreshZoneItems();

	// due to the discrete power and cadence values returned by the
	// power meter, there will very likely be many duplicate values.
	// Rather than pass them all to the curve, use a set to strip
	// out duplicates.
	std::set<std::pair<double, double> > dataSet;

	long tot_cad = 0;
	long tot_cad_points = 0;


        foreach(const RideFilePoint *p1, ride->dataPoints()) {

	    if (p1->watts != 0 && p1->cad != 0) {
		double aepf = (p1->watts * 60.0) / (p1->cad * cl_ * 2.0 * PI);
		double cpv = (p1->cad * cl_ * 2.0 * PI) / 60.0;

		dataSet.insert(std::make_pair<double, double>(aepf, cpv));
            
		tot_cad += p1->cad;
		tot_cad_points++;

        
	    }
	}

	if (tot_cad_points == 0) {
	    setTitle("no cadence");
	    refreshZoneItems();
	    curve->setVisible(false);
	}
	    
	else {
	    // Now that we have the set of points, transform them into the
	    // QwtArrays needed to set the curve's data.
	    QwtArray<double> aepfArray;
	    QwtArray<double> cpvArray;
	    std::set<std::pair<double, double> >::const_iterator j(dataSet.begin());
	    while (j != dataSet.end()) {
		const std::pair<double, double>& dataPoint = *j;

		aepfArray.push_back(dataPoint.first);
		cpvArray.push_back(dataPoint.second);

		++j;
	    }
	
	    setCAD(tot_cad / tot_cad_points);
        
	    curve->setData(cpvArray, aepfArray);

	    // now show the data (zone shading would already be visible)
	    curve->setVisible(true);
	}
    }
    else {