void PowerHist::setData(RideItem *_rideItem) { rideItem = _rideItem; RideFile *ride = rideItem->ride(); if (ride) { setTitle(ride->startTime().toString(GC_DATETIME_FORMAT)); static const int maxSize = 4096; // recording interval in minutes dt = ride->recIntSecs() / 60.0; wattsArray.resize(0); wattsZoneArray.resize(0); nmArray.resize(0); hrArray.resize(0); hrZoneArray.resize(0); kphArray.resize(0); cadArray.resize(0); wattsSelectedArray.resize(0); wattsZoneSelectedArray.resize(0); nmSelectedArray.resize(0); hrSelectedArray.resize(0); hrZoneSelectedArray.resize(0); kphSelectedArray.resize(0); cadSelectedArray.resize(0); // unit conversion factor for imperial units for selected parameters double torque_factor = (useMetricUnits ? 1.0 : 0.73756215); double speed_factor = (useMetricUnits ? 1.0 : 0.62137119); foreach(const RideFilePoint *p1, ride->dataPoints()) { bool selected = isSelected(p1, ride->recIntSecs()); // watts array int wattsIndex = int(floor(p1->watts / wattsDelta)); if (wattsIndex >= 0 && wattsIndex < maxSize) { if (wattsIndex >= wattsArray.size()) wattsArray.resize(wattsIndex + 1); wattsArray[wattsIndex]++; if (selected) { if (wattsIndex >= wattsSelectedArray.size()) wattsSelectedArray.resize(wattsIndex + 1); wattsSelectedArray[wattsIndex]++; } } // watts zoned array const Zones *zones = rideItem->zones; int zoneRange = zones ? zones->whichRange(ride->startTime().date()) : -1; // Only calculate zones if we have a valid range and check zeroes if (zoneRange > -1 && (withz || (!withz && p1->watts))) { wattsIndex = zones->whichZone(zoneRange, p1->watts); if (wattsIndex >= 0 && wattsIndex < maxSize) { if (wattsIndex >= wattsZoneArray.size()) wattsZoneArray.resize(wattsIndex + 1); wattsZoneArray[wattsIndex]++; if (selected) { if (wattsIndex >= wattsZoneSelectedArray.size()) wattsZoneSelectedArray.resize(wattsIndex + 1); wattsZoneSelectedArray[wattsIndex]++; } } } int nmIndex = int(floor(p1->nm * torque_factor / nmDelta)); if (nmIndex >= 0 && nmIndex < maxSize) { if (nmIndex >= nmArray.size()) nmArray.resize(nmIndex + 1); nmArray[nmIndex]++; if (selected) { if (nmIndex >= nmSelectedArray.size()) nmSelectedArray.resize(nmIndex + 1); nmSelectedArray[nmIndex]++; } } int hrIndex = int(floor(p1->hr / hrDelta)); if (hrIndex >= 0 && hrIndex < maxSize) { if (hrIndex >= hrArray.size()) hrArray.resize(hrIndex + 1); hrArray[hrIndex]++; if (selected) { if (hrIndex >= hrSelectedArray.size()) hrSelectedArray.resize(hrIndex + 1); hrSelectedArray[hrIndex]++; } } // hr zoned array int hrZoneRange = mainWindow->hrZones() ? mainWindow->hrZones()->whichRange(ride->startTime().date()) : -1; // Only calculate zones if we have a valid range if (hrZoneRange > -1 && (withz || (!withz && p1-hr))) { hrIndex = mainWindow->hrZones()->whichZone(hrZoneRange, p1->hr); if (hrIndex >= 0 && hrIndex < maxSize) { if (hrIndex >= hrZoneArray.size()) hrZoneArray.resize(hrIndex + 1); hrZoneArray[hrIndex]++; if (selected) { if (hrIndex >= hrZoneSelectedArray.size()) hrZoneSelectedArray.resize(hrIndex + 1); hrZoneSelectedArray[hrIndex]++; } } } int kphIndex = int(floor(p1->kph * speed_factor / kphDelta)); if (kphIndex >= 0 && kphIndex < maxSize) { if (kphIndex >= kphArray.size()) kphArray.resize(kphIndex + 1); kphArray[kphIndex]++; if (selected) { if (kphIndex >= kphSelectedArray.size()) kphSelectedArray.resize(kphIndex + 1); kphSelectedArray[kphIndex]++; } } int cadIndex = int(floor(p1->cad / cadDelta)); if (cadIndex >= 0 && cadIndex < maxSize) { if (cadIndex >= cadArray.size()) cadArray.resize(cadIndex + 1); cadArray[cadIndex]++; if (selected) { if (cadIndex >= cadSelectedArray.size()) cadSelectedArray.resize(cadIndex + 1); cadSelectedArray[cadIndex]++; } } } recalc(); } else {
RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings, QList<RideFile*>*) const { if (!file.open(QFile::ReadOnly)) { errorStrings << QString("can't open file %1").arg(file.fileName()); return NULL; } QDataStream in(&file); in.setByteOrder( QDataStream::LittleEndian ); RideFile *result = new RideFile; result->setDeviceType("SRM"); result->setFileFormat("SRM training files (srm)"); result->setTag("Sport", "Bike" ); char magic[4]; in.readRawData(magic, sizeof(magic)); if( strncmp(magic, "SRM", 3)){ errorStrings << QString("Unrecognized file type, missing magic." ); return NULL; } int version = magic[3] - '0'; switch( version ){ case 5: case 6: case 7: // ok break; default: errorStrings << QString("Unsupported SRM file format version: %1") .arg(version); return NULL; } quint16 dayssince1880 = readShort(in); quint16 wheelcirc = readShort(in); quint8 recint1 = readByte(in); quint8 recint2 = readByte(in); quint16 blockcnt = readShort(in); quint16 markercnt = readShort(in); readByte(in); // padding quint8 commentlen = readByte(in); if( commentlen > 70 ) commentlen = 70; char comment[71]; in.readRawData(comment, sizeof(comment) - 1); comment[commentlen] = '\0'; result->setTag("Notes", QString(comment) ); // assert propper markercnt to avoid segfaults if( in.status() != QDataStream::Ok ){ errorStrings << QString("failed to read file header" ); return NULL; } result->setRecIntSecs(((double) recint1) / recint2); unsigned recintms = (unsigned) round(result->recIntSecs() * 1000.0); result->setTag("Wheel Circumference", QString("%1").arg(wheelcirc) ); QDate date(1880, 1, 1); date = date.addDays(dayssince1880); QVector<marker> markers(markercnt + 1); for (int i = 0; i <= markercnt; ++i) { char mcomment[256]; size_t mcommentlen = version < 6 ? 3 : 255; assert( mcommentlen < sizeof(mcomment) ); in.readRawData(mcomment, mcommentlen ); mcomment[mcommentlen] = '\0'; quint8 active = readByte(in); quint16 start = readShort(in); quint16 end = readShort(in); quint16 avgwatts = readShort(in); quint16 avghr = readShort(in); quint16 avgcad = readShort(in); quint16 avgspeed = readShort(in); quint16 pwc150 = readShort(in); // data fixup: Although the data chunk index in srm files starts // with 1, some srmwin wrote files referencing index 0. if( end < 1 ) end = 1; if( start < 1 ) start = 1; // data fixup: some srmwin versions wrote markers with start > end if( end < start ){ markers[i].start = end; markers[i].end = start; } else { markers[i].start = start; markers[i].end = end; } markers[i].note = QString( mcomment); if( i == 0 ){ result->setTag("Athlete Name", QString(mcomment) ); } (void) active; (void) avgwatts; (void) avghr; (void) avgcad; (void) avgspeed; (void) pwc150; (void) wheelcirc; } // fail early to tell devs whats wrong with file if( in.status() != QDataStream::Ok ){ errorStrings << QString("failed to read marker" ); return NULL; } blockhdr *blockhdrs = new blockhdr[blockcnt+1]; for (int i = 0; i < blockcnt; ++i) { // In the .srm files generated by Rainer Clasen's srmcmd, // hsecsincemidn is a *signed* 32-bit integer. I haven't seen a // negative value in any .srm files generated by srmwin.exe, but // since the number of hundredths of a second in a day is << 2^31, // it seems safe to always treat this number as signed. qint32 hsecsincemidn = readLong(in); blockhdrs[i].chunkcnt = readShort(in); blockhdrs[i].dt = QDateTime(date); blockhdrs[i].dt = blockhdrs[i].dt.addMSecs(hsecsincemidn * 10); } // fail early to tell devs whats wrong with file if( in.status() != QDataStream::Ok ){ errorStrings << QString("failed to read block headers" ); return NULL; } quint16 zero = readShort(in); quint16 slope = readShort(in); quint16 datacnt = readShort(in); readByte(in); // padding // fail early to tell devs whats wrong with file if( in.status() != QDataStream::Ok ){ errorStrings << QString("failed to read calibration data" ); return NULL; } result->setTag("Slope", QString("%1") .arg( 140.0 / 42781 * slope, 0, 'f', 2) ); result->setTag("Zero Offset", QString("%1").arg(zero) ); // SRM5 files have no blocks - synthesize one if( blockcnt < 1 ){ blockcnt = 0; blockhdrs[0].chunkcnt = datacnt; blockhdrs[0].dt = QDateTime(date); } int blknum = 0, blkidx = 0, mrknum = 0, interval = 0; double km = 0.0, secs = 0.0; if (markercnt > 0) mrknum = 1; for (int i = 0; i < datacnt; ++i) { int cad, hr, watts; double kph, alt; double temp=-255; if (version < 7) { quint8 ps[3]; in.readRawData((char*) ps, sizeof(ps)); cad = readByte(in); hr = readByte(in); kph = (((((unsigned) ps[1]) & 0xf0) << 3) | (ps[0] & 0x7f)) * 3.0 / 26.0; watts = (ps[1] & 0x0f) | (ps[2] << 0x4); alt = 0.0; } else { assert(version == 7); watts = readShort(in); cad = readByte(in); hr = readByte(in); qint32 kph_tmp = readSignedLong(in); kph = kph_tmp < 0 ? 0 : kph_tmp * 3.6 / 1000.0; alt = readSignedLong(in); temp = 0.1 * readSignedShort(in); } if (i == 0) { result->setStartTime(blockhdrs[blknum].dt); } if (mrknum < markers.size() && i == markers[mrknum].end) { ++interval; ++mrknum; } // markers count from 1 if ((i > 0) && (mrknum < markers.size()) && (i == markers[mrknum].start - 1)) ++interval; km += result->recIntSecs() * kph / 3600.0; double nm = watts / 2.0 / PI / cad * 60.0; result->appendPoint(secs, cad, hr, km, kph, nm, watts, alt, 0.0, 0.0, 0.0, 0.0, temp, 0.0, interval); ++blkidx; if ((blkidx == blockhdrs[blknum].chunkcnt) && (blknum + 1 < blockcnt)) { QDateTime end = blockhdrs[blknum].dt.addMSecs( recintms * blockhdrs[blknum].chunkcnt); ++blknum; blkidx = 0; QDateTime start = blockhdrs[blknum].dt; qint64 endms = ((qint64) end.toTime_t()) * 1000 + end.time().msec(); qint64 startms = ((qint64) start.toTime_t()) * 1000 + start.time().msec(); double diff_secs = (startms - endms) / 1000.0; if (diff_secs < result->recIntSecs()) { errorStrings << QString("ERROR: time goes backwards by %1 s" " on trans " "to block %2" ).arg(diff_secs).arg(blknum); secs += result->recIntSecs(); // for lack of a better option } else { secs += diff_secs; } } else { secs += result->recIntSecs(); } } // assert some points were found. prevents segfault when looking at // the overall markers[0].start/.end // note: we're not checking in.status() to cope with truncated files if( result->dataPoints().size() < 1 ){ errorStrings << QString("file contains no data points"); return NULL; } double last = 0.0; for (int i = 1; i < markers.size(); ++i) { const marker &marker = markers[i]; int start = qMin(marker.start, result->dataPoints().size()) - 1; double start_secs = result->dataPoints()[start]->secs; int end = qMin(marker.end - 1, result->dataPoints().size() - 1); double end_secs = result->dataPoints()[end]->secs + result->recIntSecs(); if( last < start_secs ) result->addInterval(last, start_secs, ""); QString note = QString("%1").arg(i); if( marker.note.length() ) note += QString(" ") + marker.note; if( start_secs <= end_secs ) result->addInterval(start_secs, end_secs, note ); last = end_secs; } if (!markers.empty() && markers.last().end < result->dataPoints().size()) { double start_secs = result->dataPoints().last()->secs + result->recIntSecs(); result->addInterval(last, start_secs, ""); } file.close(); return result; }
RideFile *SrmFileReader::openRideFile(QFile &file, QStringList &errorStrings) const { if (!file.open(QFile::ReadOnly)) { errorStrings << QString("can't open file %1").arg(file.fileName()); return NULL; } QDataStream in(&file); RideFile *result = new RideFile; result->setDeviceType("SRM"); char magic[4]; in.readRawData(magic, sizeof(magic)); assert(strncmp(magic, "SRM", 3) == 0); int version = magic[3] - '0'; assert(version == 5 || version == 6 || version == 7); quint16 dayssince1880 = readShort(in); quint16 wheelcirc = readShort(in); quint8 recint1 = readByte(in); quint8 recint2 = readByte(in); quint16 blockcnt = readShort(in); quint16 markercnt = readShort(in); readByte(in); // padding quint8 commentlen = readByte(in); char comment[71]; in.readRawData(comment, sizeof(comment) - 1); comment[commentlen - 1] = '\0'; result->setRecIntSecs(((double) recint1) / recint2); unsigned recintms = (unsigned) round(result->recIntSecs() * 1000.0); QDate date(1880, 1, 1); date = date.addDays(dayssince1880); QVector<marker> markers(markercnt + 1); for (int i = 0; i <= markercnt; ++i) { char mcomment[256]; size_t mcommentlen = version < 6 ? 3 : 255; assert( mcommentlen < sizeof(mcomment) ); in.readRawData(mcomment, mcommentlen ); mcomment[mcommentlen] = '\0'; quint8 active = readByte(in); quint16 start = readShort(in); quint16 end = readShort(in); quint16 avgwatts = readShort(in); quint16 avghr = readShort(in); quint16 avgcad = readShort(in); quint16 avgspeed = readShort(in); quint16 pwc150 = readShort(in); // data fixup: Although the data chunk index in srm files starts // with 1, some srmwin wrote files referencing index 0. if( end < 1 ) end = 1; if( start < 1 ) start = 1; // data fixup: some srmwin versions wrote markers with start > end if( end < start ){ markers[i].start = end; markers[i].end = start; } else { markers[i].start = start; markers[i].end = end; } (void) active; (void) avgwatts; (void) avghr; (void) avgcad; (void) avgspeed; (void) pwc150; (void) wheelcirc; } blockhdr *blockhdrs = new blockhdr[blockcnt+1]; for (int i = 0; i < blockcnt; ++i) { // In the .srm files generated by Rainer Clasen's srmcmd, // hsecsincemidn is a *signed* 32-bit integer. I haven't seen a // negative value in any .srm files generated by srmwin.exe, but // since the number of hundredths of a second in a day is << 2^31, // it seems safe to always treat this number as signed. qint32 hsecsincemidn = readLong(in); blockhdrs[i].chunkcnt = readShort(in); blockhdrs[i].dt = QDateTime(date); blockhdrs[i].dt = blockhdrs[i].dt.addMSecs(hsecsincemidn * 10); } quint16 zero = readShort(in); quint16 slope = readShort(in); quint16 datacnt = readShort(in); readByte(in); // padding (void) zero; (void) slope; // SRM5 files have no blocks - synthesize one if( blockcnt < 1 ){ blockcnt = 0; blockhdrs[0].chunkcnt = datacnt; blockhdrs[0].dt = QDateTime(date); } int blknum = 0, blkidx = 0, mrknum = 0, interval = 0; double km = 0.0, secs = 0.0; if (markercnt > 0) mrknum = 1; for (int i = 0; i < datacnt; ++i) { int cad, hr, watts; double kph, alt; if (version < 7) { quint8 ps[3]; in.readRawData((char*) ps, sizeof(ps)); cad = readByte(in); hr = readByte(in); kph = (((((unsigned) ps[1]) & 0xf0) << 3) | (ps[0] & 0x7f)) * 3.0 / 26.0; watts = (ps[1] & 0x0f) | (ps[2] << 0x4); alt = 0.0; } else { assert(version == 7); watts = readShort(in); cad = readByte(in); hr = readByte(in); kph = readLong(in) * 3.6 / 1000.0; alt = readLong(in); double temp = 0.1 * (qint16) readShort(in); (void) temp; // unused for now } if (i == 0) { result->setStartTime(blockhdrs[blknum].dt); } if (mrknum < markers.size() && i == markers[mrknum].end) { ++interval; ++mrknum; } // markers count from 1 if ((i > 0) && (mrknum < markers.size()) && (i == markers[mrknum].start - 1)) ++interval; km += result->recIntSecs() * kph / 3600.0; double nm = watts / 2.0 / PI / cad * 60.0; result->appendPoint(secs, cad, hr, km, kph, nm, watts, alt, 0.0, 0.0, 0.0, interval); ++blkidx; if ((blkidx == blockhdrs[blknum].chunkcnt) && (blknum + 1 < blockcnt)) { QDateTime end = blockhdrs[blknum].dt.addMSecs( recintms * blockhdrs[blknum].chunkcnt); ++blknum; blkidx = 0; QDateTime start = blockhdrs[blknum].dt; qint64 endms = ((qint64) end.toTime_t()) * 1000 + end.time().msec(); qint64 startms = ((qint64) start.toTime_t()) * 1000 + start.time().msec(); double diff_secs = (startms - endms) / 1000.0; if (diff_secs < result->recIntSecs()) { errorStrings << QString("ERROR: time goes backwards by %1 s" " on trans " "to block %2" ).arg(diff_secs).arg(blknum); secs += result->recIntSecs(); // for lack of a better option } else { secs += diff_secs; } } else { secs += result->recIntSecs(); } } double last = 0.0; for (int i = 1; i < markers.size(); ++i) { const marker &marker = markers[i]; int start = marker.start - 1; double start_secs = result->dataPoints()[start]->secs; int end = qMin(marker.end - 1, result->dataPoints().size() - 1); double end_secs = result->dataPoints()[end]->secs + result->recIntSecs(); result->addInterval(last, start_secs, ""); result->addInterval(start_secs, end_secs, QString("%1").arg(i)); last = end_secs; } if (!markers.empty() && markers.last().end < result->dataPoints().size()) { double start_secs = result->dataPoints().last()->secs + result->recIntSecs(); result->addInterval(last, start_secs, ""); } file.close(); return result; }
void Aerolab::setData(RideItem *_rideItem, bool new_zoom) { // HARD-CODED DATA: p1->kph double vfactor = 3.600; double m = totalMass; double small_number = 0.00001; rideItem = _rideItem; RideFile *ride = rideItem->ride(); veArray.clear(); altArray.clear(); distanceArray.clear(); timeArray.clear(); if( ride ) { const RideFileDataPresent *dataPresent = ride->areDataPresent(); //setTitle(ride->startTime().toString(GC_DATETIME_FORMAT)); if( dataPresent->watts ) { // If watts are present, then we can fill the veArray data: const RideFileDataPresent *dataPresent = ride->areDataPresent(); int npoints = ride->dataPoints().size(); double dt = ride->recIntSecs(); veArray.resize(dataPresent->watts ? npoints : 0); altArray.resize(dataPresent->alt || constantAlt ? npoints : 0); timeArray.resize(dataPresent->watts ? npoints : 0); distanceArray.resize(dataPresent->watts ? npoints : 0); // quickly erase old data veCurve->setVisible(false); altCurve->setVisible(false); // detach and re-attach the ve curve: veCurve->detach(); if (!veArray.empty()) { veCurve->attach(this); veCurve->setVisible(dataPresent->watts); } // detach and re-attach the ve curve: bool have_recorded_alt_curve = false; altCurve->detach(); if (!altArray.empty()) { have_recorded_alt_curve = true; altCurve->attach(this); altCurve->setVisible(dataPresent->alt || constantAlt ); } // Fill the virtual elevation profile with data from the ride data: double t = 0.0; double vlast = 0.0; double e = 0.0; arrayLength = 0; foreach(const RideFilePoint *p1, ride->dataPoints()) { if ( arrayLength == 0 ) e = eoffset; timeArray[arrayLength] = p1->secs / 60.0; if ( have_recorded_alt_curve ) { if ( constantAlt && arrayLength > 0) { altArray[arrayLength] = altArray[arrayLength-1]; } else { if ( constantAlt && !dataPresent->alt) altArray[arrayLength] = 0; else altArray[arrayLength] = (context->athlete->useMetricUnits ? p1->alt : p1->alt * FEET_PER_METER); } } // Unpack: double power = max(0, p1->watts); double v = p1->kph/vfactor; double headwind = v; if( dataPresent->headwind ) { headwind = p1->headwind/vfactor; } double f = 0.0; double a = 0.0; // Use km data insteed of formula for file with a stop (gap). //d += v * dt; //distanceArray[arrayLength] = d/1000; distanceArray[arrayLength] = p1->km; if( v > small_number ) { f = power/v; a = ( v*v - vlast*vlast ) / ( 2.0 * dt * v ); } else { a = ( v - vlast ) / dt; } f *= eta; // adjust for drivetrain efficiency if using a crank-based meter double s = slope( f, a, m, crr, cda, rho, headwind ); double de = s * v * dt; e += de; t += dt; veArray[arrayLength] = e; vlast = v; ++arrayLength; } } else { veCurve->setVisible(false); altCurve->setVisible(false); } recalc(new_zoom); adjustEoffset(); } else {
void PowerHist::setData(RideItem *_rideItem, bool force) { // predefined deltas for each series static const double wattsDelta = 1.0; static const double wattsKgDelta = 0.01; static const double nmDelta = 0.1; static const double hrDelta = 1.0; static const double kphDelta = 0.1; static const double cadDelta = 1.0; source = Ride; // we set with this data already if (force == false && _rideItem == LASTrideItem && source == LASTsource) return; rideItem = _rideItem; if (!rideItem) return; RideFile *ride = rideItem->ride(); bool hasData = ((series == RideFile::watts || series == RideFile::wattsKg) && ride->areDataPresent()->watts) || (series == RideFile::nm && ride->areDataPresent()->nm) || (series == RideFile::kph && ride->areDataPresent()->kph) || (series == RideFile::cad && ride->areDataPresent()->cad) || (series == RideFile::aPower && ride->areDataPresent()->apower) || (series == RideFile::hr && ride->areDataPresent()->hr); if (ride && hasData) { //setTitle(ride->startTime().toString(GC_DATETIME_FORMAT)); static const int maxSize = 4096; // recording interval in minutes dt = ride->recIntSecs() / 60.0; wattsArray.resize(0); wattsZoneArray.resize(0); wattsKgArray.resize(0); aPowerArray.resize(0); nmArray.resize(0); hrArray.resize(0); hrZoneArray.resize(0); kphArray.resize(0); cadArray.resize(0); wattsSelectedArray.resize(0); wattsZoneSelectedArray.resize(0); wattsKgSelectedArray.resize(0); aPowerSelectedArray.resize(0); nmSelectedArray.resize(0); hrSelectedArray.resize(0); hrZoneSelectedArray.resize(0); kphSelectedArray.resize(0); cadSelectedArray.resize(0); // unit conversion factor for imperial units for selected parameters double torque_factor = (context->athlete->useMetricUnits ? 1.0 : 0.73756215); double speed_factor = (context->athlete->useMetricUnits ? 1.0 : 0.62137119); foreach(const RideFilePoint *p1, ride->dataPoints()) { bool selected = isSelected(p1, ride->recIntSecs()); // watts array int wattsIndex = int(floor(p1->watts / wattsDelta)); if (wattsIndex >= 0 && wattsIndex < maxSize) { if (wattsIndex >= wattsArray.size()) wattsArray.resize(wattsIndex + 1); wattsArray[wattsIndex]++; if (selected) { if (wattsIndex >= wattsSelectedArray.size()) wattsSelectedArray.resize(wattsIndex + 1); wattsSelectedArray[wattsIndex]++; } } // watts zoned array const Zones *zones = rideItem->zones; int zoneRange = zones ? zones->whichRange(ride->startTime().date()) : -1; // Only calculate zones if we have a valid range and check zeroes if (zoneRange > -1 && (withz || (!withz && p1->watts))) { wattsIndex = zones->whichZone(zoneRange, p1->watts); if (wattsIndex >= 0 && wattsIndex < maxSize) { if (wattsIndex >= wattsZoneArray.size()) wattsZoneArray.resize(wattsIndex + 1); wattsZoneArray[wattsIndex]++; if (selected) { if (wattsIndex >= wattsZoneSelectedArray.size()) wattsZoneSelectedArray.resize(wattsIndex + 1); wattsZoneSelectedArray[wattsIndex]++; } } } // aPower array int aPowerIndex = int(floor(p1->apower / wattsDelta)); if (aPowerIndex >= 0 && aPowerIndex < maxSize) { if (aPowerIndex >= aPowerArray.size()) aPowerArray.resize(aPowerIndex + 1); aPowerArray[aPowerIndex]++; if (selected) { if (aPowerIndex >= aPowerSelectedArray.size()) aPowerSelectedArray.resize(aPowerIndex + 1); aPowerSelectedArray[aPowerIndex]++; } } // wattsKg array int wattsKgIndex = int(floor(p1->watts / ride->getWeight() / wattsKgDelta)); if (wattsKgIndex >= 0 && wattsKgIndex < maxSize) { if (wattsKgIndex >= wattsKgArray.size()) wattsKgArray.resize(wattsKgIndex + 1); wattsKgArray[wattsKgIndex]++; if (selected) { if (wattsKgIndex >= wattsKgSelectedArray.size()) wattsKgSelectedArray.resize(wattsKgIndex + 1); wattsKgSelectedArray[wattsKgIndex]++; } } int nmIndex = int(floor(p1->nm * torque_factor / nmDelta)); if (nmIndex >= 0 && nmIndex < maxSize) { if (nmIndex >= nmArray.size()) nmArray.resize(nmIndex + 1); nmArray[nmIndex]++; if (selected) { if (nmIndex >= nmSelectedArray.size()) nmSelectedArray.resize(nmIndex + 1); nmSelectedArray[nmIndex]++; } } int hrIndex = int(floor(p1->hr / hrDelta)); if (hrIndex >= 0 && hrIndex < maxSize) { if (hrIndex >= hrArray.size()) hrArray.resize(hrIndex + 1); hrArray[hrIndex]++; if (selected) { if (hrIndex >= hrSelectedArray.size()) hrSelectedArray.resize(hrIndex + 1); hrSelectedArray[hrIndex]++; } } // hr zoned array int hrZoneRange = context->athlete->hrZones() ? context->athlete->hrZones()->whichRange(ride->startTime().date()) : -1; // Only calculate zones if we have a valid range if (hrZoneRange > -1 && (withz || (!withz && p1->hr))) { hrIndex = context->athlete->hrZones()->whichZone(hrZoneRange, p1->hr); if (hrIndex >= 0 && hrIndex < maxSize) { if (hrIndex >= hrZoneArray.size()) hrZoneArray.resize(hrIndex + 1); hrZoneArray[hrIndex]++; if (selected) { if (hrIndex >= hrZoneSelectedArray.size()) hrZoneSelectedArray.resize(hrIndex + 1); hrZoneSelectedArray[hrIndex]++; } } } int kphIndex = int(floor(p1->kph * speed_factor / kphDelta)); if (kphIndex >= 0 && kphIndex < maxSize) { if (kphIndex >= kphArray.size()) kphArray.resize(kphIndex + 1); kphArray[kphIndex]++; if (selected) { if (kphIndex >= kphSelectedArray.size()) kphSelectedArray.resize(kphIndex + 1); kphSelectedArray[kphIndex]++; } } int cadIndex = int(floor(p1->cad / cadDelta)); if (cadIndex >= 0 && cadIndex < maxSize) { if (cadIndex >= cadArray.size()) cadArray.resize(cadIndex + 1); cadArray[cadIndex]++; if (selected) { if (cadIndex >= cadSelectedArray.size()) cadSelectedArray.resize(cadIndex + 1); cadSelectedArray[cadIndex]++; } } } } else {