mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Strava upload: Use TCX format to handle stationary trainer ride
This commit is contained in:
@@ -318,77 +318,102 @@ StravaUploadDialog::requestUpload()
|
||||
|
||||
connect(&networkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestUploadFinished(QNetworkReply*)));
|
||||
connect(&networkMgr, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
|
||||
QString out;
|
||||
|
||||
QVector<RideFilePoint*> vectorPoints = ride->ride()->dataPoints();
|
||||
int totalSize = vectorPoints.size();
|
||||
bool json = false;
|
||||
|
||||
int size = 0;
|
||||
if (json) {
|
||||
QString out;
|
||||
|
||||
out += "{\"token\": \"" + token + "\",\"data\":[";
|
||||
foreach (const RideFilePoint *point, ride->ride()->dataPoints())
|
||||
{
|
||||
size++;
|
||||
QVector<RideFilePoint*> vectorPoints = ride->ride()->dataPoints();
|
||||
int totalSize = vectorPoints.size();
|
||||
|
||||
if (point->secs == 0.0)
|
||||
continue;
|
||||
int size = 0;
|
||||
|
||||
diffSecs = point->secs - prevSecs;
|
||||
prevSecs = point->secs;
|
||||
rideDateTime = rideDateTime.addSecs(diffSecs);
|
||||
out += "{\"token\": \"" + token + "\",\"data\":[";
|
||||
foreach (const RideFilePoint *point, ride->ride()->dataPoints())
|
||||
{
|
||||
size++;
|
||||
|
||||
out += "[\"";
|
||||
out += rideDateTime.toUTC().toString(Qt::ISODate);
|
||||
out += "\",";
|
||||
out += QString("%1").arg(point->lat,0,'f',GPS_COORD_TO_STRING);
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->lon,0,'f',GPS_COORD_TO_STRING);
|
||||
if (point->secs == 0.0)
|
||||
continue;
|
||||
|
||||
if (altitudeChk->isChecked()) {
|
||||
diffSecs = point->secs - prevSecs;
|
||||
prevSecs = point->secs;
|
||||
rideDateTime = rideDateTime.addSecs(diffSecs);
|
||||
|
||||
out += "[\"";
|
||||
out += rideDateTime.toUTC().toString(Qt::ISODate);
|
||||
out += "\",";
|
||||
out += QString("%1").arg(point->lat,0,'f',GPS_COORD_TO_STRING);
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->alt);
|
||||
out += QString("%1").arg(point->lon,0,'f',GPS_COORD_TO_STRING);
|
||||
|
||||
if (altitudeChk->isChecked()) {
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->alt);
|
||||
|
||||
}
|
||||
if (powerChk->isChecked()) {
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->watts);
|
||||
}
|
||||
if (altitudeChk->isChecked()) {
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->cad);
|
||||
}
|
||||
if (heartrateChk->isChecked()) {
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->hr);
|
||||
}
|
||||
out += "]";
|
||||
if(totalSize == size)
|
||||
out += "],";
|
||||
else
|
||||
out += ",";
|
||||
}
|
||||
if (powerChk->isChecked()) {
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->watts);
|
||||
}
|
||||
if (altitudeChk->isChecked()) {
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->cad);
|
||||
}
|
||||
if (heartrateChk->isChecked()) {
|
||||
out += ",";
|
||||
out += QString("%1").arg(point->hr);
|
||||
}
|
||||
out += "]";
|
||||
if(totalSize == size)
|
||||
out += "],";
|
||||
else
|
||||
out += ",";
|
||||
out += "\"type\": \"json\", ";
|
||||
out += "\"data_fields\": \[\"time\", \"latitude\", \"longitude\"";
|
||||
|
||||
if (altitudeChk->isChecked())
|
||||
out += ", \"elevation\"";
|
||||
if (powerChk->isChecked())
|
||||
out += ", \"watts\"";
|
||||
if (cadenceChk->isChecked())
|
||||
out += ", \"cadence\"";
|
||||
if (heartrateChk->isChecked())
|
||||
out += ", \"heartrate\"";
|
||||
out += "]}";
|
||||
|
||||
QUrl url = QUrl(STRAVA_URL2 + "/upload");
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
progressBar->setValue(40);
|
||||
progressLabel->setText(tr("Upload ride... Sending"));
|
||||
|
||||
networkMgr.post( request, out.toAscii());
|
||||
} else {
|
||||
QByteArray data;
|
||||
QUrl params;
|
||||
TcxFileReader reader;
|
||||
|
||||
params.addQueryItem("token", token);
|
||||
params.addQueryItem("type", "tcx");
|
||||
params.addQueryItem("data", reader.toByteArray(mainWindow, ride->ride()));
|
||||
data = params.encodedQuery();
|
||||
|
||||
QUrl url = QUrl(STRAVA_URL2 + "/upload");
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
|
||||
|
||||
progressBar->setValue(40);
|
||||
progressLabel->setText(tr("Upload ride... Sending"));
|
||||
|
||||
networkMgr.post( request, data);
|
||||
}
|
||||
out += "\"type\": \"json\", ";
|
||||
out += "\"data_fields\": \[\"time\", \"latitude\", \"longitude\"";
|
||||
|
||||
if (altitudeChk->isChecked())
|
||||
out += ", \"elevation\"";
|
||||
if (powerChk->isChecked())
|
||||
out += ", \"watts\"";
|
||||
if (cadenceChk->isChecked())
|
||||
out += ", \"cadence\"";
|
||||
if (heartrateChk->isChecked())
|
||||
out += ", \"heartrate\"";
|
||||
out += "]}";
|
||||
|
||||
QUrl url = QUrl(STRAVA_URL2 + "/upload");
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
//qDebug() << out;
|
||||
progressBar->setValue(40);
|
||||
progressLabel->setText(tr("Upload ride... Sending"));
|
||||
|
||||
networkMgr.post( request, out.toAscii());
|
||||
eventLoop.exec();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ RideFile *TcxFileReader::openRideFile(QFile &file, QStringList &errors, QList<Ri
|
||||
return rideFile;
|
||||
}
|
||||
|
||||
bool
|
||||
TcxFileReader::writeRideFile(MainWindow *mainWindow, const RideFile *ride, QFile &file) const
|
||||
QByteArray
|
||||
TcxFileReader::toByteArray(MainWindow *mainWindow, const RideFile *ride) const
|
||||
{
|
||||
QDomText text;
|
||||
QDomDocument doc;
|
||||
@@ -204,7 +204,7 @@ TcxFileReader::writeRideFile(MainWindow *mainWindow, const RideFile *ride, QFile
|
||||
}
|
||||
|
||||
// HeartRate hack for Garmin Training Center
|
||||
// It needs an hr datapoint for every trackpoint or else the
|
||||
// It needs an hr datapoint for every trackpoint or else the
|
||||
// hr graph in TC won't display. Schema defines the datapoint
|
||||
// as a positive int (> 0)
|
||||
|
||||
@@ -390,7 +390,14 @@ TcxFileReader::writeRideFile(MainWindow *mainWindow, const RideFile *ride, QFile
|
||||
author.appendChild(author_part_number);
|
||||
|
||||
|
||||
QByteArray xml = doc.toByteArray(4);
|
||||
return doc.toByteArray(4);
|
||||
}
|
||||
|
||||
bool
|
||||
TcxFileReader::writeRideFile(MainWindow *mainWindow, const RideFile *ride, QFile &file) const
|
||||
{
|
||||
QByteArray xml = toByteArray(mainWindow, ride);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly)) return(false);
|
||||
if (file.write(xml) != xml.size()) return(false);
|
||||
file.close();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
struct TcxFileReader : public RideFileReader {
|
||||
virtual RideFile *openRideFile(QFile &file, QStringList &errors, QList<RideFile*>* = 0) const;
|
||||
QByteArray toByteArray(MainWindow *mainWindow, const RideFile *ride) const;
|
||||
bool writeRideFile(MainWindow *mainWindow, const RideFile *ride, QFile &file) const;
|
||||
bool hasWrite() const { return true; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user