mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
added import from SRM menu item and made cpint not crash when it can't find
cpint data for a ride (until we get it working with srm data)
This commit is contained in:
@@ -137,26 +137,28 @@ CpintPlot::calculate(QString fileName, QDateTime dateTime)
|
||||
|
||||
if (!needToScanRides) {
|
||||
delete thisCurve;
|
||||
thisCurve = NULL;
|
||||
int i;
|
||||
double *bests;
|
||||
int bestlen;
|
||||
read_cpi_file(dir, file, &bests, &bestlen);
|
||||
double *timeArray = new double[bestlen];
|
||||
int maxNonZero = 0;
|
||||
for (i = 0; i < bestlen; ++i) {
|
||||
timeArray[i] = i * 0.021;
|
||||
if (bests[i] > 0) maxNonZero = i;
|
||||
if (read_cpi_file(dir, file, &bests, &bestlen) == 0) {
|
||||
double *timeArray = new double[bestlen];
|
||||
int maxNonZero = 0;
|
||||
for (i = 0; i < bestlen; ++i) {
|
||||
timeArray[i] = i * 0.021;
|
||||
if (bests[i] > 0) maxNonZero = i;
|
||||
}
|
||||
if (maxNonZero > 1) {
|
||||
thisCurve = new QwtPlotCurve(
|
||||
dateTime.toString("ddd MMM d, yyyy h:mm AP"));
|
||||
thisCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
|
||||
thisCurve->setPen(QPen(Qt::green));
|
||||
thisCurve->attach(this);
|
||||
thisCurve->setData(timeArray + 1, bests + 1, maxNonZero - 1);
|
||||
}
|
||||
delete [] timeArray;
|
||||
free(bests);
|
||||
}
|
||||
if (maxNonZero > 1) {
|
||||
thisCurve = new QwtPlotCurve(
|
||||
dateTime.toString("ddd MMM d, yyyy h:mm AP"));
|
||||
thisCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
|
||||
thisCurve->setPen(QPen(Qt::green));
|
||||
thisCurve->attach(this);
|
||||
thisCurve->setData(timeArray + 1, bests + 1, maxNonZero - 1);
|
||||
}
|
||||
delete [] timeArray;
|
||||
free(bests);
|
||||
}
|
||||
|
||||
replot();
|
||||
|
||||
@@ -6,7 +6,7 @@ TEMPLATE = app
|
||||
TARGET +=
|
||||
DEPENDPATH += .
|
||||
INCLUDEPATH += /home/srhea/src/qwt-20060130/include ../lib ../srm
|
||||
CONFIG += static
|
||||
CONFIG += static debug
|
||||
LIBS += /home/srhea/src/qwt-20060130/lib/libqwt.a ../lib/libgc.a
|
||||
LIBS += ../srm/libsrm.a
|
||||
LIBS += -lm -lz
|
||||
|
||||
@@ -255,6 +255,8 @@ MainWindow::MainWindow(const QDir &home) :
|
||||
SLOT(downloadRide()), tr("Ctrl+D"));
|
||||
rideMenu->addAction(tr("&Export to CSV..."), this,
|
||||
SLOT(exportCSV()), tr("Ctrl+E"));
|
||||
rideMenu->addAction(tr("&Import from SRM..."), this,
|
||||
SLOT(importSRM()), tr("Ctrl+I"));
|
||||
|
||||
if (last != NULL)
|
||||
treeWidget->setCurrentItem(last);
|
||||
@@ -264,9 +266,11 @@ void
|
||||
MainWindow::addRide(QString name)
|
||||
{
|
||||
QRegExp rx(rideFileRegExp);
|
||||
if (!rx.exactMatch(name))
|
||||
if (!rx.exactMatch(name)) {
|
||||
fprintf(stderr, "bad name: %s\n", name.toAscii().constData());
|
||||
assert(false);
|
||||
assert(rx.numCaptures() == 6);
|
||||
}
|
||||
assert(rx.numCaptures() == 7);
|
||||
QDate date(rx.cap(1).toInt(), rx.cap(2).toInt(),rx.cap(3).toInt());
|
||||
QTime time(rx.cap(4).toInt(), rx.cap(5).toInt(),rx.cap(6).toInt());
|
||||
QDateTime dt(date, time);
|
||||
@@ -367,6 +371,52 @@ MainWindow::exportCSV()
|
||||
file.close();
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::importSRM()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(
|
||||
this, tr("Import SRM"), QDir::homePath(),
|
||||
tr("SRM Binary Format (*.srm)"));
|
||||
if (fileName.length() == 0)
|
||||
return;
|
||||
|
||||
QFile file(fileName);
|
||||
QStringList errors;
|
||||
RawFile *raw = RawFile::readFile(file, errors);
|
||||
if (!raw || !errors.empty()) {
|
||||
QString all = (raw
|
||||
? tr("Non-fatal problem(s) opening %1:")
|
||||
: tr("Fatal problem(s) opening %1:")).arg(fileName);
|
||||
QStringListIterator i(errors);
|
||||
while (i.hasNext())
|
||||
all += "\n" + i.next();
|
||||
if (raw)
|
||||
QMessageBox::warning(this, tr("Open Warning"), all);
|
||||
else {
|
||||
QMessageBox::critical(this, tr("Open Error"), all);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QChar zero = QLatin1Char('0');
|
||||
QString name = QString("%1_%2_%3_%4_%5_%6.srm")
|
||||
.arg(raw->startTime.date().year(), 4, 10, zero)
|
||||
.arg(raw->startTime.date().month(), 2, 10, zero)
|
||||
.arg(raw->startTime.date().day(), 2, 10, zero)
|
||||
.arg(raw->startTime.time().hour(), 2, 10, zero)
|
||||
.arg(raw->startTime.time().minute(), 2, 10, zero)
|
||||
.arg(raw->startTime.time().second(), 2, 10, zero);
|
||||
|
||||
if (!file.copy(home.absolutePath() + "/" + name)) {
|
||||
QMessageBox::critical(this, tr("Copy Error"),
|
||||
tr("Couldn't copy %1").arg(fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
delete raw;
|
||||
addRide(name);
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::rideSelected()
|
||||
{
|
||||
|
||||
@@ -48,6 +48,7 @@ class MainWindow : public QMainWindow
|
||||
void openCyclist();
|
||||
void downloadRide();
|
||||
void exportCSV();
|
||||
void importSRM();
|
||||
void setSmoothingFromSlider();
|
||||
void setSmoothingFromLineEdit();
|
||||
void setBinWidthFromSlider();
|
||||
|
||||
@@ -241,7 +241,7 @@ free_cpi_file_info(struct cpi_file_info *head)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
read_one(const char *inname, double *bests[], int *bestlen)
|
||||
{
|
||||
FILE *in;
|
||||
@@ -252,8 +252,8 @@ read_one(const char *inname, double *bests[], int *bestlen)
|
||||
double *tmp;
|
||||
int interval;
|
||||
|
||||
in = fopen(inname, "r");
|
||||
assert(in);
|
||||
if (!(in = fopen(inname, "r")))
|
||||
return -1;
|
||||
lineno = 1;
|
||||
while (fgets(line, sizeof(line), in) != NULL) {
|
||||
if (sscanf(line, "%lf %d\n", &mins, &watts) != 2) {
|
||||
@@ -275,23 +275,25 @@ read_one(const char *inname, double *bests[], int *bestlen)
|
||||
++lineno;
|
||||
}
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
read_cpi_file(const char *dir, const char *raw, double *bests[], int *bestlen)
|
||||
{
|
||||
char *inname;
|
||||
int result;
|
||||
|
||||
*bestlen = 1000;
|
||||
*bests = calloc(*bestlen, sizeof(double));
|
||||
inname = malloc(strlen(dir) + 25);
|
||||
sprintf(inname, "%s/%s", dir, raw);
|
||||
strcpy(inname + strlen(inname) - 4, ".cpi");
|
||||
read_one(inname, bests, bestlen);
|
||||
result = read_one(inname, bests, bestlen);
|
||||
free(inname);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
combine_cpi_files(const char *dir, double *bests[], int *bestlen)
|
||||
{
|
||||
|
||||
@@ -37,8 +37,8 @@ extern void update_cpi_file(struct cpi_file_info *info,
|
||||
|
||||
extern void free_cpi_file_info(struct cpi_file_info *head);
|
||||
|
||||
extern void read_cpi_file(const char *dir, const char *raw,
|
||||
double *bests[], int *bestlen);
|
||||
extern int read_cpi_file(const char *dir, const char *raw,
|
||||
double *bests[], int *bestlen);
|
||||
|
||||
extern void combine_cpi_files(const char *dir, double *bests[], int *bestlen);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user