Add Peripedal CSV support

.. and a test ride too.
This commit is contained in:
Mark Liversedge
2015-01-03 11:02:23 +00:00
parent 794b43c32b
commit 5991341e5f
3 changed files with 3707 additions and 2 deletions

View File

@@ -30,6 +30,31 @@ static int csvFileReaderRegistered =
RideFileFactory::instance().registerReader(
"csv","Comma-Separated Values", new CsvFileReader());
int static periMonth(QString month)
{
if (month == "jan") return 1;
if (month == "feb") return 2;
if (month == "mar") return 3;
if (month == "apr") return 4;
if (month == "may") return 5;
if (month == "jun") return 6;
if (month == "jul") return 7;
if (month == "aug") return 8;
if (month == "sep") return 9;
if (month == "oct") return 10;
if (month == "nov") return 11;
if (month == "dec") return 12;
return QDate::currentDate().month(); // no idea
}
static QDate periDate(QString date)
{
QStringList parts = date.split("-");
if (parts.count() == 2) {
return QDate(QDate::currentDate().year(), periMonth(parts[1]), parts[0].toInt());
}
return QDate::currentDate();
}
static QDate moxyDate(QString date)
{
QStringList parts = date.split("-");
@@ -93,6 +118,7 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors, QList<Ri
int total_pause = 0;
int currentInterval = 0;
int prevInterval = 0;
double lastKM=0; // when deriving distance from speed
/* Joule 1.0
Version,Date/Time,Km,Minutes,RPE,Tags,"Weight, kg","Work, kJ",FTP,"Sample Rate, s",Device Type,Firmware Version,Last Updated,Category 1,Category 2
@@ -119,6 +145,7 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors, QList<Ri
QRegExp iBikeCSV("iBike,\\d\\d?,[a-z]+", Qt::CaseInsensitive);
QRegExp moxyCSV("FW Part Number:", Qt::CaseInsensitive);
QRegExp gcCSV("secs, cad, hr, km, kph, nm, watts, alt, lon, lat, headwind, slope, temp, interval, lrbalance, lte, rte, lps, rps, smo2, thb, o2hb, hhb");
QRegExp periCSV("mm-dd,hh:mm:ss,SmO2 Live,SmO2 Averaged,THb,Target Power,Heart Rate,Speed,Power,Cadence");
QRegExp freemotionCSV("Stages Data", Qt::CaseInsensitive);
int recInterval = 1;
@@ -222,6 +249,15 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors, QList<Ri
recInterval = 1;
++lineno;
continue;
}
else if(periCSV.indexIn(line) != -1) {
csvType = peripedal;
rideFile->setDeviceType("Peripedal");
rideFile->setFileFormat("Peripedal CSV (csv)");
unitsHeader = 1;
recInterval = 1;
++lineno;
continue;
}
else if(powertapCSV.indexIn(line) != -1) {
csvType = powertap;
@@ -305,7 +341,7 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors, QList<Ri
}
}
}
else if (lineno == unitsHeader && csvType != moxy) {
else if (lineno == unitsHeader && csvType != moxy && csvType != peripedal) {
if (metricUnits.indexIn(line) != -1)
metric = true;
else if (englishUnits.indexIn(line) != -1)
@@ -392,6 +428,53 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors, QList<Ri
o2hb = line.section(',', 21, 21).toInt();
hhb = line.section(',', 22, 22).toInt();
} else if (csvType == peripedal) {
//mm-dd,hh:mm:ss,SmO2 Live,SmO2 Averaged,THb,Target Power,Heart Rate,Speed,Power,Cadence
// ignore lines with wrong number of entries
if (line.split(",").count() != 10) continue;
seconds = moxySeconds(line.section(',',1,1));
minutes = seconds / 60.0f;
if (startTime == QDateTime()) {
QDate date = periDate(line.section(',',0,0));
QTime time = QTime(0,0,0).addSecs(seconds);
startTime = QDateTime(date,time);
}
double aSmo2 = line.section(',', 3, 3).toDouble();
smo2 = line.section(',', 2, 2).toDouble();
// use average if live not available
if (aSmo2 && !smo2) smo2 = aSmo2;
thb = line.section(',', 4, 4).toDouble();
hr = line.section(',', 6, 6).toDouble();
kph = line.section(',', 7, 7).toDouble();
watts = line.section(',', 8, 8).toDouble();
cad = line.section(',', 10, 10).toDouble();
// dervice distance from speed
km = lastKM + (kph/3600.0f);
lastKM = km;
nm = 0;
alt = 0;
lon = 0;
lat = 0;
headwind = 0;
slope = 0;
temp = 0;
interval = 0;
lrbalance = 0;
lte = 0;
rte = 0;
lps = 0;
rps = 0;
o2hb = 0;
hhb = 0;
} else if (csvType == freemotion) {
if (line == "Ride_Totals") {
eof = true;

View File

@@ -22,7 +22,7 @@
#include "RideFile.h"
enum csvtypes { generic, gc, powertap, joule, ergomo, motoactv, ibike, moxy, freemotion};
enum csvtypes { generic, gc, powertap, joule, ergomo, motoactv, ibike, moxy, freemotion, peripedal };
typedef enum csvtypes CsvType;
struct CsvFileReader : public RideFileReader {

File diff suppressed because it is too large Load Diff