mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
remove tabs and eol spaces, no functional change
This commit is contained in:
@@ -965,7 +965,6 @@ MainWindow::intervalTreeWidgetSelectionChanged()
|
||||
|
||||
void MainWindow::getBSFactors(float &timeBS, float &distanceBS)
|
||||
{
|
||||
|
||||
int rides;
|
||||
double seconds, distance, bs;
|
||||
RideItem * lastRideItem;
|
||||
@@ -977,73 +976,68 @@ void MainWindow::getBSFactors(float &timeBS, float &distanceBS)
|
||||
|
||||
QVariant BSdays = settings->value(GC_BIKESCOREDAYS);
|
||||
if (BSdays.isNull() || BSdays.toInt() == 0)
|
||||
BSdays.setValue(30); // by default look back no more than 30 days
|
||||
BSdays.setValue(30); // by default look back no more than 30 days
|
||||
|
||||
// if there are rides, find most recent ride so we count back from there:
|
||||
if (allRides->childCount() > 0)
|
||||
lastRideItem = (RideItem*) allRides->child(allRides->childCount() - 1);
|
||||
lastRideItem = (RideItem*) allRides->child(allRides->childCount() - 1);
|
||||
else
|
||||
lastRideItem = ride; // not enough rides, use current ride
|
||||
lastRideItem = ride; // not enough rides, use current ride
|
||||
|
||||
// set up progress bar
|
||||
progress = new QProgressDialog(QString(tr("Computing bike score estimating factors.\n")),
|
||||
tr("Abort"),0,BSdays.toInt(),this);
|
||||
tr("Abort"),0,BSdays.toInt(),this);
|
||||
int endingOffset = progress->labelText().size();
|
||||
|
||||
|
||||
for (int i = 0; i < allRides->childCount(); ++i) {
|
||||
RideItem *item = (RideItem*) allRides->child(i);
|
||||
int days = item->dateTime.daysTo(lastRideItem->dateTime);
|
||||
if (
|
||||
(item->type() == RIDE_TYPE) &&
|
||||
// (item->ride) &&
|
||||
(days >= 0) &&
|
||||
(days < BSdays.toInt())
|
||||
) {
|
||||
RideItem *item = (RideItem*) allRides->child(i);
|
||||
int days = item->dateTime.daysTo(lastRideItem->dateTime);
|
||||
if ((item->type() == RIDE_TYPE) &&
|
||||
// (item->ride) &&
|
||||
(days >= 0) && (days < BSdays.toInt())) {
|
||||
|
||||
RideMetricPtr m;
|
||||
item->computeMetrics();
|
||||
RideMetricPtr m;
|
||||
item->computeMetrics();
|
||||
|
||||
QString existing = progress->labelText();
|
||||
QString existing = progress->labelText();
|
||||
existing.chop(progress->labelText().size() - endingOffset);
|
||||
progress->setLabelText(
|
||||
existing + QString(tr("Processing %1...")).arg(item->fileName));
|
||||
existing + QString(tr("Processing %1...")).arg(item->fileName));
|
||||
|
||||
|
||||
// only count rides with BS > 0
|
||||
// only count rides with BS > 0
|
||||
if ((m = item->metrics.value("skiba_bike_score")) &&
|
||||
m->value(true)) {
|
||||
bs += m->value(true);
|
||||
m->value(true)) {
|
||||
bs += m->value(true);
|
||||
|
||||
if ((m = item->metrics.value("time_riding"))) {
|
||||
seconds += m->value(true);
|
||||
}
|
||||
if ((m = item->metrics.value("time_riding"))) {
|
||||
seconds += m->value(true);
|
||||
}
|
||||
|
||||
if ((m = item->metrics.value("total_distance"))) {
|
||||
distance += m->value(true);
|
||||
}
|
||||
if ((m = item->metrics.value("total_distance"))) {
|
||||
distance += m->value(true);
|
||||
}
|
||||
|
||||
rides++;
|
||||
}
|
||||
// check progress
|
||||
QCoreApplication::processEvents();
|
||||
rides++;
|
||||
}
|
||||
// check progress
|
||||
QCoreApplication::processEvents();
|
||||
if (progress->wasCanceled()) {
|
||||
aborted = true;
|
||||
goto done;
|
||||
}
|
||||
// set progress from 0 to BSdays
|
||||
aborted = true;
|
||||
goto done;
|
||||
}
|
||||
// set progress from 0 to BSdays
|
||||
progress->setValue(BSdays.toInt() - days);
|
||||
|
||||
}
|
||||
}
|
||||
if (rides) {
|
||||
if (!useMetricUnits)
|
||||
if (!useMetricUnits)
|
||||
distance *= MILES_PER_KM;
|
||||
timeBS = (bs * 3600) / seconds; // BS per hour
|
||||
distanceBS = bs / distance; // BS per mile or km
|
||||
timeBS = (bs * 3600) / seconds; // BS per hour
|
||||
distanceBS = bs / distance; // BS per mile or km
|
||||
}
|
||||
done:
|
||||
if (aborted) {
|
||||
timeBS = distanceBS = 0;
|
||||
timeBS = distanceBS = 0;
|
||||
}
|
||||
|
||||
delete progress;
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/*
|
||||
* $Id:$
|
||||
*
|
||||
* Copyright (c) 2009 Eric Murray (ericm@lne.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
@@ -28,18 +26,15 @@
|
||||
#include <math.h>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
||||
ManualRideDialog::ManualRideDialog(MainWindow *mainWindow,
|
||||
const QDir &home, bool useMetric) :
|
||||
const QDir &home, bool useMetric) :
|
||||
mainWindow(mainWindow), home(home)
|
||||
{
|
||||
useMetricUnits = useMetric;
|
||||
int row;
|
||||
|
||||
|
||||
mainWindow->getBSFactors(timeBS,distanceBS);
|
||||
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowTitle(tr("Manually Enter Ride Data"));
|
||||
|
||||
@@ -56,7 +51,7 @@ ManualRideDialog::ManualRideDialog(MainWindow *mainWindow,
|
||||
hrslbl->setFrameStyle(QFrame::Panel | QFrame::Sunken);
|
||||
hrsentry = new QLineEdit(this);
|
||||
QIntValidator * hoursValidator = new QIntValidator(0,99,this);
|
||||
//hrsentry->setInputMask("09");
|
||||
//hrsentry->setInputMask("09");
|
||||
hrsentry->setValidator(hoursValidator);
|
||||
manualLengthLayout->addWidget(hrslbl);
|
||||
manualLengthLayout->addWidget(hrsentry);
|
||||
@@ -81,9 +76,9 @@ ManualRideDialog::ManualRideDialog(MainWindow *mainWindow,
|
||||
// ride distance
|
||||
QString *DistanceString = new QString(tr("Distance "));
|
||||
if (useMetricUnits)
|
||||
DistanceString->append("(" + tr("km") + "):");
|
||||
DistanceString->append("(" + tr("km") + "):");
|
||||
else
|
||||
DistanceString->append("(" + tr("miles") + "):");
|
||||
DistanceString->append("(" + tr("miles") + "):");
|
||||
|
||||
QLabel *DistanceLabel = new QLabel(*DistanceString, this);
|
||||
QDoubleValidator * distanceValidator = new QDoubleValidator(0,1000,2,this);
|
||||
@@ -92,7 +87,7 @@ ManualRideDialog::ManualRideDialog(MainWindow *mainWindow,
|
||||
distanceentry->setValidator(distanceValidator);
|
||||
|
||||
// AvgHR
|
||||
QLabel *HRLabel = new QLabel(tr("Average HR: "), this);
|
||||
QLabel *HRLabel = new QLabel(tr("Average HR: "), this);
|
||||
HRentry = new QLineEdit(this);
|
||||
QIntValidator *hrValidator = new QIntValidator(0,200,this);
|
||||
//HRentry->setInputMask("099");
|
||||
@@ -101,25 +96,24 @@ ManualRideDialog::ManualRideDialog(MainWindow *mainWindow,
|
||||
// how to estimate BikeScore:
|
||||
QLabel *BSEstLabel;
|
||||
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
|
||||
|
||||
|
||||
QVariant BSmode = settings->value(GC_BIKESCOREMODE);
|
||||
|
||||
|
||||
estBSbyTimeButton = NULL;
|
||||
estBSbyDistButton = NULL;
|
||||
if (timeBS || distanceBS) {
|
||||
BSEstLabel = new QLabel(tr("Estimate BikeScore by: "));
|
||||
if (timeBS) {
|
||||
estBSbyTimeButton = new QRadioButton(tr("Time"));
|
||||
// default to time based unless no timeBS factor
|
||||
if (BSmode.toString() != "distance")
|
||||
estBSbyTimeButton->setDown(true);
|
||||
}
|
||||
if (distanceBS) {
|
||||
estBSbyDistButton = new QRadioButton(tr("Distance"));
|
||||
if (BSmode.toString() == "distance" || ! timeBS)
|
||||
estBSbyDistButton->setDown(true);
|
||||
}
|
||||
BSEstLabel = new QLabel(tr("Estimate BikeScore by: "));
|
||||
if (timeBS) {
|
||||
estBSbyTimeButton = new QRadioButton(tr("Time"));
|
||||
// default to time based unless no timeBS factor
|
||||
if (BSmode.toString() != "distance")
|
||||
estBSbyTimeButton->setDown(true);
|
||||
}
|
||||
if (distanceBS) {
|
||||
estBSbyDistButton = new QRadioButton(tr("Distance"));
|
||||
if (BSmode.toString() == "distance" || ! timeBS)
|
||||
estBSbyDistButton->setDown(true);
|
||||
}
|
||||
}
|
||||
|
||||
// BikeScore
|
||||
@@ -155,12 +149,12 @@ ManualRideDialog::ManualRideDialog(MainWindow *mainWindow,
|
||||
row++;
|
||||
|
||||
if (timeBS || distanceBS) {
|
||||
glayout->addWidget(BSEstLabel,row,0);
|
||||
if (estBSbyTimeButton)
|
||||
glayout->addWidget(estBSbyTimeButton,row,1,1,-1);
|
||||
if (estBSbyDistButton)
|
||||
glayout->addWidget(estBSbyDistButton,row,2,1,-1);
|
||||
row++;
|
||||
glayout->addWidget(BSEstLabel,row,0);
|
||||
if (estBSbyTimeButton)
|
||||
glayout->addWidget(estBSbyTimeButton,row,1,1,-1);
|
||||
if (estBSbyDistButton)
|
||||
glayout->addWidget(estBSbyDistButton,row,2,1,-1);
|
||||
row++;
|
||||
}
|
||||
|
||||
glayout->addWidget(ManualBSLabel,row,0);
|
||||
@@ -179,9 +173,9 @@ ManualRideDialog::ManualRideDialog(MainWindow *mainWindow,
|
||||
connect(minsentry, SIGNAL(editingFinished()), this, SLOT(setBsEst()));
|
||||
connect(distanceentry, SIGNAL(editingFinished()), this, SLOT(setBsEst()));
|
||||
if (estBSbyTimeButton)
|
||||
connect(estBSbyTimeButton,SIGNAL(clicked()),this, SLOT(bsEstChanged()));
|
||||
connect(estBSbyTimeButton,SIGNAL(clicked()),this, SLOT(bsEstChanged()));
|
||||
if (estBSbyDistButton)
|
||||
connect(estBSbyDistButton,SIGNAL(clicked()),this, SLOT(bsEstChanged()));
|
||||
connect(estBSbyDistButton,SIGNAL(clicked()),this, SLOT(bsEstChanged()));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -190,42 +184,38 @@ ManualRideDialog::estBSFromDistance()
|
||||
// calculate distance-based BS estimate
|
||||
double bs = 0;
|
||||
if (distanceBS) {
|
||||
bs = distanceentry->text().toFloat() * distanceBS;
|
||||
QString text = QString("%1").arg((int)bs);
|
||||
// cast to int so QLineEdit doesn't interpret "51.3" as "513"
|
||||
BSentry->clear();
|
||||
BSentry->insert(text);
|
||||
bs = distanceentry->text().toFloat() * distanceBS;
|
||||
QString text = QString("%1").arg((int)bs);
|
||||
// cast to int so QLineEdit doesn't interpret "51.3" as "513"
|
||||
BSentry->clear();
|
||||
BSentry->insert(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ManualRideDialog::estBSFromTime()
|
||||
{
|
||||
// calculate time-based BS estimate
|
||||
double bs = 0;
|
||||
if (timeBS) {
|
||||
bs = (hrsentry->text().toInt() * timeBS ) +
|
||||
((minsentry->text().toInt() * timeBS) / 60) +
|
||||
((secsentry->text().toInt() * timeBS) / 3600);
|
||||
QString text = QString("%1").arg((int)bs);
|
||||
BSentry->clear();
|
||||
BSentry->insert(text);
|
||||
bs = (hrsentry->text().toInt() * timeBS ) +
|
||||
((minsentry->text().toInt() * timeBS) / 60) +
|
||||
((secsentry->text().toInt() * timeBS) / 3600);
|
||||
QString text = QString("%1").arg((int)bs);
|
||||
BSentry->clear();
|
||||
BSentry->insert(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ManualRideDialog::bsEstChanged()
|
||||
{
|
||||
if (estBSbyDistButton) {
|
||||
if (estBSbyDistButton->isChecked()) {
|
||||
estBSFromDistance();
|
||||
}
|
||||
else {
|
||||
estBSFromTime();
|
||||
}
|
||||
if (estBSbyDistButton->isChecked())
|
||||
estBSFromDistance();
|
||||
else
|
||||
estBSFromTime();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,12 +223,10 @@ void
|
||||
ManualRideDialog::setBsEst()
|
||||
{
|
||||
if (estBSbyDistButton) {
|
||||
if (estBSbyDistButton->isChecked()) {
|
||||
if (estBSbyDistButton->isChecked())
|
||||
estBSFromDistance();
|
||||
}
|
||||
else {
|
||||
else
|
||||
estBSFromTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,99 +240,98 @@ ManualRideDialog::cancelClicked()
|
||||
void
|
||||
ManualRideDialog::enterClicked()
|
||||
{
|
||||
// write data to manual entry file
|
||||
|
||||
// write data to manual entry file
|
||||
|
||||
if (filename == "") {
|
||||
char tmp[32];
|
||||
char tmp[32];
|
||||
|
||||
// use user's time for file:
|
||||
QDateTime lt = dateTimeEdit->dateTime().toLocalTime();
|
||||
// use user's time for file:
|
||||
QDateTime lt = dateTimeEdit->dateTime().toLocalTime();
|
||||
|
||||
sprintf(tmp, "%04d_%02d_%02d_%02d_%02d_%02d.man",
|
||||
lt.date().year(), lt.date().month(),
|
||||
lt.date().day(), lt.time().hour(),
|
||||
lt.time().minute(),
|
||||
lt.time().second());
|
||||
sprintf(tmp, "%04d_%02d_%02d_%02d_%02d_%02d.man",
|
||||
lt.date().year(), lt.date().month(),
|
||||
lt.date().day(), lt.time().hour(),
|
||||
lt.time().minute(),
|
||||
lt.time().second());
|
||||
|
||||
filename = tmp;
|
||||
filepath = home.absolutePath() + "/" + filename;
|
||||
FILE *out = fopen(filepath.toAscii().constData(), "r");
|
||||
if (out) {
|
||||
fclose(out);
|
||||
if (QMessageBox::warning(
|
||||
this,
|
||||
tr("Ride Already Downloaded"),
|
||||
tr("This ride appears to have already ")
|
||||
+ tr("been downloaded. Do you want to ")
|
||||
+ tr("download it again and overwrite ")
|
||||
+ tr("the previous download?"),
|
||||
tr("&Overwrite"), tr("&Cancel"),
|
||||
QString(), 1, 1) == 1) {
|
||||
reject();
|
||||
return ;
|
||||
}
|
||||
}
|
||||
filename = tmp;
|
||||
filepath = home.absolutePath() + "/" + filename;
|
||||
FILE *out = fopen(filepath.toAscii().constData(), "r");
|
||||
if (out) {
|
||||
fclose(out);
|
||||
if (QMessageBox::warning(
|
||||
this,
|
||||
tr("Ride Already Downloaded"),
|
||||
tr("This ride appears to have already ")
|
||||
+ tr("been downloaded. Do you want to ")
|
||||
+ tr("download it again and overwrite ")
|
||||
+ tr("the previous download?"),
|
||||
tr("&Overwrite"), tr("&Cancel"),
|
||||
QString(), 1, 1) == 1) {
|
||||
reject();
|
||||
return ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString tmpname;
|
||||
{
|
||||
// QTemporaryFile doesn't actually close the file on .close(); it
|
||||
// closes the file when in its destructor. On Windows, we can't
|
||||
// rename an open file. So let tmp go out of scope before calling
|
||||
// rename.
|
||||
// QTemporaryFile doesn't actually close the file on .close(); it
|
||||
// closes the file when in its destructor. On Windows, we can't
|
||||
// rename an open file. So let tmp go out of scope before calling
|
||||
// rename.
|
||||
|
||||
QString tmpl = home.absoluteFilePath(".ptdl.XXXXXX");
|
||||
QTemporaryFile tmp(tmpl);
|
||||
tmp.setAutoRemove(false);
|
||||
if (!tmp.open()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Failed to create temporary file ")
|
||||
+ tmpl + ": " + tmp.error());
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
QTextStream out(&tmp);
|
||||
QString tmpl = home.absoluteFilePath(".ptdl.XXXXXX");
|
||||
QTemporaryFile tmp(tmpl);
|
||||
tmp.setAutoRemove(false);
|
||||
if (!tmp.open()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Failed to create temporary file ")
|
||||
+ tmpl + ": " + tmp.error());
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
QTextStream out(&tmp);
|
||||
|
||||
tmpname = tmp.fileName(); // after close(), tmp.fileName() is ""
|
||||
tmpname = tmp.fileName(); // after close(), tmp.fileName() is ""
|
||||
|
||||
/*
|
||||
* File format:
|
||||
* "manual"
|
||||
* "minutes,mph,watts,miles,hr,bikescore" # header (metric or imperial)
|
||||
* minutes,mph,watts,miles,hr,bikeScore # data
|
||||
*/
|
||||
/*
|
||||
* File format:
|
||||
* "manual"
|
||||
* "minutes,mph,watts,miles,hr,bikescore" # header (metric or imperial)
|
||||
* minutes,mph,watts,miles,hr,bikeScore # data
|
||||
*/
|
||||
|
||||
out << "manual\n";
|
||||
if (useMetricUnits)
|
||||
out << "minutes,kmh,watts,km,hr,bikescore\n";
|
||||
else
|
||||
out << "minutes,mph,watts,miles,hr,bikescore\n";
|
||||
|
||||
// data
|
||||
double secs = (hrsentry->text().toInt() * 3600) +
|
||||
(minsentry->text().toInt() * 60) +
|
||||
(secsentry->text().toInt());
|
||||
out << secs/60.0;
|
||||
out << ",";
|
||||
out << distanceentry->text().toFloat() / (secs / 3600.0);
|
||||
out << ",";
|
||||
out << 0.0; // watts
|
||||
out << ",";
|
||||
out << distanceentry->text().toFloat();
|
||||
out << ",";
|
||||
out << HRentry->text().toInt();
|
||||
out << ",";
|
||||
out << BSentry->text().toInt();
|
||||
out << "\n";
|
||||
out << "manual\n";
|
||||
if (useMetricUnits)
|
||||
out << "minutes,kmh,watts,km,hr,bikescore\n";
|
||||
else
|
||||
out << "minutes,mph,watts,miles,hr,bikescore\n";
|
||||
|
||||
// data
|
||||
double secs = (hrsentry->text().toInt() * 3600) +
|
||||
(minsentry->text().toInt() * 60) +
|
||||
(secsentry->text().toInt());
|
||||
out << secs/60.0;
|
||||
out << ",";
|
||||
out << distanceentry->text().toFloat() / (secs / 3600.0);
|
||||
out << ",";
|
||||
out << 0.0; // watts
|
||||
out << ",";
|
||||
out << distanceentry->text().toFloat();
|
||||
out << ",";
|
||||
out << HRentry->text().toInt();
|
||||
out << ",";
|
||||
out << BSentry->text().toInt();
|
||||
out << "\n";
|
||||
|
||||
tmp.close();
|
||||
tmp.close();
|
||||
|
||||
// QTemporaryFile initially has permissions set to 0600.
|
||||
// Make it readable by everyone.
|
||||
tmp.setPermissions(tmp.permissions()
|
||||
| QFile::ReadOwner | QFile::ReadUser
|
||||
| QFile::ReadGroup | QFile::ReadOther);
|
||||
// QTemporaryFile initially has permissions set to 0600.
|
||||
// Make it readable by everyone.
|
||||
tmp.setPermissions(tmp.permissions()
|
||||
| QFile::ReadOwner | QFile::ReadUser
|
||||
| QFile::ReadGroup | QFile::ReadOther);
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
@@ -352,9 +339,9 @@ ManualRideDialog::enterClicked()
|
||||
if (QFile::exists(filepath)) {
|
||||
QFile old(filepath);
|
||||
if (!old.remove()) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Failed to remove existing file ")
|
||||
+ filepath + ": " + old.error());
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Failed to remove existing file ")
|
||||
+ filepath + ": " + old.error());
|
||||
QFile::remove(tmpname);
|
||||
reject();
|
||||
}
|
||||
@@ -363,7 +350,7 @@ ManualRideDialog::enterClicked()
|
||||
|
||||
// Use ::rename() instead of QFile::rename() to get forced overwrite.
|
||||
if (rename(QFile::encodeName(tmpname), QFile::encodeName(filepath)) < 0) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Failed to rename ") + tmpname + tr(" to ")
|
||||
+ filepath + ": " + strerror(errno));
|
||||
QFile::remove(tmpname);
|
||||
@@ -375,4 +362,3 @@ ManualRideDialog::enterClicked()
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user