From 105d1d6c30d7a4710af7b2b4eabc89e3b9b2b10c Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Thu, 8 Nov 2012 18:37:39 +0100 Subject: [PATCH] Fixed zero order hold for logging --- src/LogCompressor.cc | 54 +++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/LogCompressor.cc b/src/LogCompressor.cc index ea9e63b31..28b73aebd 100644 --- a/src/LogCompressor.cc +++ b/src/LogCompressor.cc @@ -107,9 +107,10 @@ void LogCompressor::run() QString headerLine = "timestamp_ms" + delimiter + headerList.join(delimiter) + "\n"; // Clean header names from symbols Matlab considers as Latex syntax - headerLine = headerLine.replace(":", "-"); - headerLine = headerLine.replace("_", "-"); - headerLine = headerLine.replace(".", "-"); + headerLine = headerLine.replace("timestamp", "TIMESTAMP"); + headerLine = headerLine.replace(":", ""); + headerLine = headerLine.replace("_", ""); + headerLine = headerLine.replace(".", ""); outTmpFile.write(headerLine.toLocal8Bit()); emit logProcessingStatusChanged(tr("Log compressor: Dataset contains dimensions: ") + headerLine); @@ -121,22 +122,32 @@ void LogCompressor::run() } - // Reset our position in the input file before we start the main processing loop. - in.seek(0); - - QMap timestampMap; - - while (!in.atEnd()) { - quint64 timestamp = in.readLine().split(delimiter).at(0).toULongLong(); - timestampMap.insert(timestamp, templateList); - } +// // Reset our position in the input file before we start the main processing loop. +// in.seek(0); +// // Search through all lines and build a list of unique timestamps +// QMap timestampMap; +// while (!in.atEnd()) { +// quint64 timestamp = in.readLine().split(delimiter).at(0).toULongLong(); +// timestampMap.insert(timestamp, templateList); +// } + // Jump back to start of file in.seek(0); + // Map of final output lines, key is time + QMap timestampMap; + + // Run through the whole file and fill map of timestamps while (!in.atEnd()) { QStringList newLine = in.readLine().split(delimiter); quint64 timestamp = newLine.at(0).toULongLong(); + + // Check if timestamp does exist - if not, add it + if (!timestampMap.contains(timestamp)) { + timestampMap.insert(timestamp, templateList); + } + QStringList list = timestampMap.value(timestamp); QString currentDataName = newLine.at(2); @@ -147,13 +158,30 @@ void LogCompressor::run() int lineCounter = 0; + QStringList lastList = timestampMap.values().at(1); + foreach (QStringList list, timestampMap.values()) { // Write this current time set out to the file // only do so from the 2nd line on, since the first // line could be incomplete - if (lineCounter > 0) { + if (lineCounter > 1) { // Set the timestamp list.replace(0,QString("%1").arg(timestampMap.keys().at(lineCounter))); + + // Fill holes if necessary + if (holeFillingEnabled) { + int index = 0; + foreach (QString str, list) { + if (str == "" || str == "NaN") { + list.replace(index, lastList.at(index)); + } + index++; + } + } + + // Set last list + lastList = list; + // Write data columns QString output = list.join(delimiter) + "\n"; outTmpFile.write(output.toLocal8Bit()); -- 2.22.0