mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Merge pull request #2443 from Joern-R/bmcsv
Improve BodyMeasures - CSV Import
This commit is contained in:
4
doc/user/bodymeasures-format-example-date.csv
Normal file
4
doc/user/bodymeasures-format-example-date.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
date,weightkg,fatkg,boneskg,musclekg,leankg,fatpercent,comment
|
||||
2017-01-01T12:00:00Z,2,3,4,5,6,7,Useless data - but valid format
|
||||
2017-01-02T12:00:00Z,80.15,12.10,5.4,0,32.5,11.57,Test Value
|
||||
2017-01-03T12:00:00Z,81.15,12.10,5.4,0,32.5,12.57,"Here the comment text contain commas itself, so it needs quotes"
|
||||
|
4
doc/user/bodymeasures-format-example-ts.csv
Normal file
4
doc/user/bodymeasures-format-example-ts.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
ts,weightkg,fatkg,boneskg,musclekg,leankg,fatpercent,comment
|
||||
1,2,3,4,5,6,7,Is a technically valid entry but the timestamp is 1 second of Epoch so it will never be in the possible time range
|
||||
1479632565,80.15,12.10,5.4,0,32.5,11.57,Test Value
|
||||
1479632865,81.15,12.10,5.4,0,32.5,12.57,"Here the comment text contain commas itself, so it needs quotes"
|
||||
|
@@ -1,3 +0,0 @@
|
||||
ts,weightkg,fatkg,boneskg,musclekg,leankg,fatpercent,comment
|
||||
1,2,3,4,5,6,7,Is a technically valid entry, but the timestamp is 1 second of Epoch
|
||||
1479632565,80.15,12.10,5.4,0,32.5,1157,Test Value
|
||||
|
@@ -1,21 +1,34 @@
|
||||
Description of File-Format for "Body Measures - .CSV Import" function
|
||||
---------------------------------------------------------------------
|
||||
|
||||
Example is provided here:
|
||||
Example for Timestamp is provided here:
|
||||
|
||||
----
|
||||
ts,weightkg,fatkg,boneskg,musclekg,leankg,fatpercent,comment
|
||||
1,2,3,4,5,6,7,Is a technically valid entry, but the timestamp is 1 second of Epoch
|
||||
1479632565,80.15,12.10,5.4,0,32.5,1157,Test Value
|
||||
1479632865,80.15,12.10,5.4,0,32.5,1157,"Here the comment text contain commas itself, so it needs quotes"
|
||||
|
||||
----
|
||||
Example for Date/Time is provided here:
|
||||
|
||||
date,weightkg,fatkg,boneskg,musclekg,leankg,fatpercent,comment
|
||||
2017-01-01T12:00:00Z,2,3,4,5,6,7,Useless data - but valid format
|
||||
2017-01-02T12:00:00Z,80.15,12.10,5.4,0,32.5,1157,Test Value
|
||||
2017-01-02T12:00:00Z,80.15,12.10,5.4,0,32.5,1157,"Here the comment text contain commas itself, so it needs quotes"
|
||||
|
||||
|
||||
a) Header Line
|
||||
First Line of a valid file has to contain header information. This has to be a comma-separated
|
||||
list of the measures provided in the data lines. You do not need to provide all possible measures,
|
||||
but at least "ts" and "weightkg".
|
||||
|
||||
The mandatory measures are:
|
||||
As mandatory field you need time/date of the measures. There are 2 options:
|
||||
- "ts" - Unix timestamp (in seconds) since Epoch. The value can be calcuated in XLS - just Google how-to.
|
||||
OR
|
||||
- "date" - ISO8601 formatted Date/Time String
|
||||
|
||||
The mandatory measure is:
|
||||
- "weightkg" - Athlete weight in kilograms
|
||||
|
||||
The optional measures are:
|
||||
@@ -29,7 +42,8 @@ The optional measures are:
|
||||
Data formats:
|
||||
|
||||
- "ts" is a 64Bit Integer - any other time will be rejected
|
||||
- "comment" is a String
|
||||
- "date" is a ISO8601 formated date/time
|
||||
- "comment" is a String - if it contains "commas" itself the string must be enclosed by "string with comma, and more comment"
|
||||
- all other measures are float/double in format <xxxxxxx.yyy>
|
||||
|
||||
There are very strict format checks when importing. Only if the whole
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
BodyMeasuresCsvImport::BodyMeasuresCsvImport(Context *context) : context(context) {
|
||||
|
||||
allowedHeaders << "ts" << "weightkg" << "fatkg" << "boneskg" << "musclekg" << "leankg"
|
||||
allowedHeaders << "ts" << "date" << "weightkg" << "fatkg" << "boneskg" << "musclekg" << "leankg"
|
||||
<< "fatpercent" << "comment";
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ BodyMeasuresCsvImport::getBodyMeasures(QString &error, QDateTime from, QDateTime
|
||||
|
||||
// all variables to be defined here (to allow :goto - for simplified error handling/less redundant code)
|
||||
bool tsExists = false;
|
||||
bool dateExists = false;
|
||||
bool weightkgExists = false;
|
||||
int lineNo = 0;
|
||||
|
||||
@@ -72,6 +73,7 @@ BodyMeasuresCsvImport::getBodyMeasures(QString &error, QDateTime from, QDateTime
|
||||
|
||||
foreach(QString h, headers) {
|
||||
if (h == "ts") tsExists = true;
|
||||
if (h == "date") dateExists = true;
|
||||
if (h == "weightkg") weightkgExists = true;
|
||||
if (!allowedHeaders.contains(h)) {
|
||||
if (error.isEmpty()) error = tr("Unknown column header: ");
|
||||
@@ -82,8 +84,12 @@ BodyMeasuresCsvImport::getBodyMeasures(QString &error, QDateTime from, QDateTime
|
||||
if (error.length() > 0) {
|
||||
goto error;
|
||||
}
|
||||
if (!tsExists) {
|
||||
error = tr("Column 'ts' - Timestamp - is missing");
|
||||
if (!(tsExists || dateExists)) {
|
||||
error = tr("Date and Timestamp are missing - Column 'ts' for timestamp - Colum 'date' for Date/Time.");
|
||||
goto error;
|
||||
}
|
||||
if (tsExists && dateExists) {
|
||||
error = tr("Both column 'ts' - Timestamp and 'date' - Date/Time are defined.");
|
||||
goto error;
|
||||
}
|
||||
if (!weightkgExists) {
|
||||
@@ -124,6 +130,19 @@ BodyMeasuresCsvImport::getBodyMeasures(QString &error, QDateTime from, QDateTime
|
||||
error = tr("Invalid 'ts' - Timestamp - in line %1").arg(lineNo);
|
||||
goto error;
|
||||
}
|
||||
} else if (h == "date") {
|
||||
// parse date ISO 8601
|
||||
m.when = QDateTime::fromString(i, Qt::ISODate);
|
||||
if (m.when.isValid()) {
|
||||
// skip line if not in date range
|
||||
if (m.when < from || m.when > to) {
|
||||
m.when = QDateTime::fromMSecsSinceEpoch(0);
|
||||
break; // stop analysing the data items of the line
|
||||
}
|
||||
} else {
|
||||
error = tr("Invalid 'date' - Date/Time not ISO 8601 format - in line %1").arg(lineNo);
|
||||
goto error;
|
||||
}
|
||||
} else if (h == "weightkg") {
|
||||
m.weightkg = i.toDouble(&ok);
|
||||
if (!ok) {
|
||||
|
||||
4
test/bodymeasures/bodymeasures-format-example-date.csv
Normal file
4
test/bodymeasures/bodymeasures-format-example-date.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
date,weightkg,fatkg,boneskg,musclekg,leankg,fatpercent,comment
|
||||
2017-01-01T12:00:00Z,2,3,4,5,6,7,Useless data - but valid format
|
||||
2017-01-02T12:00:00Z,80.15,12.10,5.4,0,32.5,11.57,Test Value
|
||||
2017-01-03T12:00:00Z,81.15,12.10,5.4,0,32.5,12.57,"Here the comment text contain commas itself, so it needs quotes"
|
||||
|
4
test/bodymeasures/bodymeasures-format-example-ts.csv
Normal file
4
test/bodymeasures/bodymeasures-format-example-ts.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
ts,weightkg,fatkg,boneskg,musclekg,leankg,fatpercent,comment
|
||||
1,2,3,4,5,6,7,Is a technically valid entry but the timestamp is 1 second of Epoch so it will never be in the possible time range
|
||||
1479632565,80.15,12.10,5.4,0,32.5,11.57,Test Value
|
||||
1479632865,81.15,12.10,5.4,0,32.5,12.57,"Here the comment text contain commas itself, so it needs quotes"
|
||||
|
Reference in New Issue
Block a user