diff --git a/doc/user/bodymeasures-format-example-date.csv b/doc/user/bodymeasures-format-example-date.csv new file mode 100644 index 000000000..7ea6f349e --- /dev/null +++ b/doc/user/bodymeasures-format-example-date.csv @@ -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" \ No newline at end of file diff --git a/doc/user/bodymeasures-format-example-ts.csv b/doc/user/bodymeasures-format-example-ts.csv new file mode 100644 index 000000000..e7c3a86b4 --- /dev/null +++ b/doc/user/bodymeasures-format-example-ts.csv @@ -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" \ No newline at end of file diff --git a/doc/user/bodymeasures-format.csv b/doc/user/bodymeasures-format.csv deleted file mode 100644 index 83ba1ba30..000000000 --- a/doc/user/bodymeasures-format.csv +++ /dev/null @@ -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 diff --git a/doc/user/bodymeasures-format.txt b/doc/user/bodymeasures-format.txt index bd85ba744..5468e9765 100644 --- a/doc/user/bodymeasures-format.txt +++ b/doc/user/bodymeasures-format.txt @@ -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 There are very strict format checks when importing. Only if the whole diff --git a/src/FileIO/BodyMeasuresCsvImport.cpp b/src/FileIO/BodyMeasuresCsvImport.cpp index baca4ee5d..fed1394cb 100644 --- a/src/FileIO/BodyMeasuresCsvImport.cpp +++ b/src/FileIO/BodyMeasuresCsvImport.cpp @@ -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) { diff --git a/test/bodymeasures/bodymeasures-format-example-date.csv b/test/bodymeasures/bodymeasures-format-example-date.csv new file mode 100644 index 000000000..7ea6f349e --- /dev/null +++ b/test/bodymeasures/bodymeasures-format-example-date.csv @@ -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" \ No newline at end of file diff --git a/test/bodymeasures/bodymeasures-format-example-ts.csv b/test/bodymeasures/bodymeasures-format-example-ts.csv new file mode 100644 index 000000000..e7c3a86b4 --- /dev/null +++ b/test/bodymeasures/bodymeasures-format-example-ts.csv @@ -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" \ No newline at end of file