mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Export Metrics to CSV
A new menu option to export the ride metric data as a CSV format file for manipulation in tools like Excel. It exports all rides (no date range) and outputs the date in US format month/day/year, with time in 24hr format. Additionally, a 'hack' to export all rides in GC format has been removed since it was erroneously included in the initial v3 branch.
This commit is contained in:
@@ -546,8 +546,6 @@ MainWindow::MainWindow(const QDir &home) :
|
||||
rideMenu->addAction(tr("&Manual ride entry..."), this,
|
||||
SLOT(manualRide()), tr("Ctrl+M"));
|
||||
rideMenu->addSeparator ();
|
||||
rideMenu->addAction(tr("&Export ALL files to GC..."), this,
|
||||
SLOT(exportALL()), tr(""));
|
||||
rideMenu->addAction(tr("&Export to CSV..."), this,
|
||||
SLOT(exportCSV()), tr("Ctrl+E"));
|
||||
rideMenu->addAction(tr("Export to GC..."), this,
|
||||
@@ -562,6 +560,9 @@ MainWindow::MainWindow(const QDir &home) :
|
||||
SLOT(exportPWX()));
|
||||
#ifdef GC_HAVE_SOAP
|
||||
rideMenu->addSeparator ();
|
||||
rideMenu->addAction(tr("&Export Metrics as CSV..."), this,
|
||||
SLOT(exportMetrics()), tr(""));
|
||||
rideMenu->addSeparator ();
|
||||
rideMenu->addAction(tr("&Upload to Training Peaks"), this,
|
||||
SLOT(uploadTP()), tr("Ctrl+U"));
|
||||
rideMenu->addAction(tr("Down&load from Training Peaks..."), this,
|
||||
@@ -960,32 +961,13 @@ MainWindow::exportGC()
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::exportALL()
|
||||
MainWindow::exportMetrics()
|
||||
{
|
||||
// get a list of rides to export
|
||||
QStringList filenames = RideFileFactory::instance().listRideFiles(home);
|
||||
|
||||
QProgressBar *progress = new QProgressBar();
|
||||
progress->setMinimum(0);
|
||||
progress->setMaximum(filenames.count());
|
||||
progress->show();
|
||||
|
||||
foreach (const QString &filename, filenames) {
|
||||
progress->setValue(progress->value() + 1);
|
||||
QStringList errors;
|
||||
|
||||
QString inFileName = home.absolutePath() + '/' + filename;
|
||||
QFile inFile(inFileName);
|
||||
RideFile *p = RideFileFactory::instance().openRideFile(this, inFile, errors);
|
||||
|
||||
if (p) {
|
||||
QString outName = "/home/markl/Desktop/Daniel/" + QFileInfo(filename).baseName() + ".gc";
|
||||
QFile outFile(outName);
|
||||
GcFileReader reader;
|
||||
reader.writeRideFile(p, outFile);
|
||||
}
|
||||
}
|
||||
delete progress;
|
||||
QString fileName = QFileDialog::getSaveFileName(
|
||||
this, tr("Export Metrics"), QDir::homePath(), tr("Comma Separated Variables (*.csv)"));
|
||||
if (fileName.length() == 0)
|
||||
return;
|
||||
metricDB->writeAsCSV(fileName);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -159,7 +159,7 @@ class MainWindow : public QMainWindow
|
||||
void exportCSV();
|
||||
void exportGC();
|
||||
void exportJson();
|
||||
void exportALL();
|
||||
void exportMetrics();
|
||||
#ifdef GC_HAVE_KML
|
||||
void exportKML();
|
||||
#endif
|
||||
|
||||
@@ -206,6 +206,46 @@ MetricAggregator::importMeasure(SummaryMetrics *sm)
|
||||
/*----------------------------------------------------------------------
|
||||
* Query functions are wrappers around DBAccess functions
|
||||
*----------------------------------------------------------------------*/
|
||||
void
|
||||
MetricAggregator::writeAsCSV(QString filename)
|
||||
{
|
||||
// write all metrics as a CSV file
|
||||
QList<SummaryMetrics> all = getAllMetricsFor(QDateTime(), QDateTime());
|
||||
|
||||
// write headings
|
||||
if (!all.count()) return; // no dice
|
||||
|
||||
// open file.. truncate if exists already
|
||||
QFile file(filename);
|
||||
file.open(QFile::WriteOnly);
|
||||
file.resize(0);
|
||||
QTextStream out(&file);
|
||||
|
||||
// write headings
|
||||
out<<"date, time, filename,";
|
||||
QMapIterator<QString, double>i(all[0].values());
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
out<<i.key()<<",";
|
||||
}
|
||||
out<<"\n";
|
||||
|
||||
// write values
|
||||
foreach(SummaryMetrics x, all) {
|
||||
out<<x.getRideDate().date().toString("MM/dd/yy")<<","
|
||||
<<x.getRideDate().time().toString()<<","
|
||||
<<x.getFileName()<<",";
|
||||
|
||||
QMapIterator<QString, double>i(x.values());
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
out<<i.value()<<",";
|
||||
}
|
||||
out<<"\n";
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
QList<SummaryMetrics>
|
||||
MetricAggregator::getAllMetricsFor(QDateTime start, QDateTime end)
|
||||
{
|
||||
|
||||
@@ -48,6 +48,7 @@ class MetricAggregator : public QWidget
|
||||
QList<SummaryMetrics> getAllMetricsFor(QDateTime start, QDateTime end);
|
||||
QList<SummaryMetrics> getAllMeasuresFor(QDateTime start, QDateTime end);
|
||||
SummaryMetrics getRideMetrics(QString filename);
|
||||
void writeAsCSV(QString filename); // export all...
|
||||
|
||||
signals:
|
||||
void dataChanged(); // when metricDB table changed
|
||||
|
||||
@@ -57,6 +57,8 @@ class SummaryMetrics
|
||||
// get unit string to use for this symbol
|
||||
QString getUnitsForSymbol(QString symbol, bool UseMetric) const;
|
||||
|
||||
QMap<QString, double> &values() { return value; }
|
||||
|
||||
private:
|
||||
QString fileName;
|
||||
QDateTime rideDate;
|
||||
|
||||
Reference in New Issue
Block a user