From 470885df5031ef8bd58a293049bc1a2b024b6e7f Mon Sep 17 00:00:00 2001 From: Damien Date: Sun, 23 Jan 2011 14:23:56 +0100 Subject: [PATCH] Modify csv import for ergomo file with comma or semicolon separator Fixes #244. --- src/CsvRideFile.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/CsvRideFile.cpp b/src/CsvRideFile.cpp index f3531ee1b..afcaa684c 100644 --- a/src/CsvRideFile.cpp +++ b/src/CsvRideFile.cpp @@ -46,6 +46,8 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors) const */ QRegExp ergomoCSV("(ZEIT|STRECKE)", Qt::CaseInsensitive); bool ergomo = false; + + QChar ergomo_separator; int unitsHeader = 1; int total_pause = 0; int currentInterval = 0; @@ -97,6 +99,14 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors) const ergomo = true; rideFile->setDeviceType("Ergomo CSV"); unitsHeader = 2; + + QStringList headers = line.split(';'); + + if (headers.size()>1) + ergomo_separator = ';'; + else + ergomo_separator = ','; + ++lineno; continue; } @@ -201,20 +211,24 @@ RideFile *CsvFileReader::openRideFile(QFile &file, QStringList &errors) const } else { // for ergomo formatted CSV files - minutes = line.section(',', 0, 0).toDouble() + total_pause; - km = line.section(',', 1, 1).toDouble(); - watts = line.section(',', 2, 2).toDouble(); - cad = line.section(',', 3, 3).toDouble(); - kph = line.section(',', 4, 4).toDouble(); - hr = line.section(',', 5, 5).toDouble(); - alt = line.section(',', 6, 6).toDouble(); + minutes = line.section(ergomo_separator, 0, 0).toDouble() + total_pause; + QString km_string = line.section(ergomo_separator, 1, 1); + km_string.replace(",","."); + km = km_string.toDouble(); + watts = line.section(ergomo_separator, 2, 2).toDouble(); + cad = line.section(ergomo_separator, 3, 3).toDouble(); + QString kph_string = line.section(ergomo_separator, 4, 4); + kph_string.replace(",","."); + kph = kph_string.toDouble(); + hr = line.section(ergomo_separator, 5, 5).toDouble(); + alt = line.section(ergomo_separator, 6, 6).toDouble(); interval = line.section(',', 8, 8).toInt(); if (interval != prevInterval) { prevInterval = interval; if (interval != 0) currentInterval++; } if (interval != 0) interval = currentInterval; - pause = line.section(',', 9, 9).toInt(); + pause = line.section(ergomo_separator, 9, 9).toInt(); total_pause += pause; nm = NULL; // torque is not provided in the Ergomo file