mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Parse txt formatted log files
This parses .txt log files produced by Dataplus and Oceanlog software. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
98741c864c
commit
30976c05a4
2 changed files with 74 additions and 2 deletions
|
@ -342,6 +342,7 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDia
|
|||
column = 0;
|
||||
delta = "0";
|
||||
hw = "";
|
||||
txtLog = false;
|
||||
|
||||
/* Add indexes of XSLTs requiring special handling to the list */
|
||||
specialCSV << SENSUS;
|
||||
|
@ -489,8 +490,21 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
|
|||
ui->knownImports->setCurrentText("DL7");
|
||||
ui->CSVUnits->setCurrentText(units);
|
||||
blockSignals(false);
|
||||
} else if (firstLine.contains("Life Time Dive")) {
|
||||
txtLog = true;
|
||||
|
||||
while ((firstLine = f.readLine().trimmed()).length() >= 0 && !f.atEnd()) {
|
||||
if (firstLine.contains("Dive Profile")) {
|
||||
f.readLine();
|
||||
break;
|
||||
}
|
||||
}
|
||||
firstLine = f.readLine().trimmed();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Special handling for APD Log Viewer
|
||||
if ((triggeredBy == KNOWNTYPES && (value == APD || value == APD2)) || (triggeredBy == INITIAL && fileNames.first().endsWith(".apd", Qt::CaseInsensitive))) {
|
||||
apd=true;
|
||||
|
@ -694,6 +708,13 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else if (txtLog) {
|
||||
while ((firstLine = f.readLine().trimmed()).length() >= 0 && !f.atEnd()) {
|
||||
if (firstLine.contains("Dive Profile")) {
|
||||
firstLine = f.readLine().trimmed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (rows < 10 && !f.atEnd()) {
|
||||
|
@ -768,6 +789,51 @@ int DiveLogImportDialog::setup_csv_params(QStringList r, char **params, int pnr)
|
|||
|
||||
return pnr;
|
||||
}
|
||||
int DiveLogImportDialog::parseTxtHeader(QString fileName, char **params, int pnr)
|
||||
{
|
||||
QFile f(fileNames.first());
|
||||
QString date;
|
||||
QString time;
|
||||
QString line;
|
||||
|
||||
f.open(QFile::ReadOnly);
|
||||
while ((line = f.readLine().trimmed()).length() >= 0 && !f.atEnd()) {
|
||||
if (line.contains("Dive Profile")) {
|
||||
f.readLine();
|
||||
break;
|
||||
} else if (line.contains("Dive Date: ")) {
|
||||
date = line.replace(QString::fromLatin1("Dive Date: "), QString::fromLatin1(""));
|
||||
|
||||
if (date.contains('-')) {
|
||||
QStringList fmtDate = date.split('-');
|
||||
date = fmtDate[0] + fmtDate[1] + fmtDate[2];
|
||||
} else if (date.contains('/')) {
|
||||
QStringList fmtDate = date.split('/');
|
||||
date = fmtDate[2] + fmtDate[0] + fmtDate[1];
|
||||
} else {
|
||||
QStringList fmtDate = date.split('.');
|
||||
date = fmtDate[2] + fmtDate[1] + fmtDate[0];
|
||||
}
|
||||
} else if (line.contains("Elapsed Dive Time: ")) {
|
||||
// Skipping dive duration for now
|
||||
} else if (line.contains("Dive Time: ")) {
|
||||
time = line.replace(QString::fromLatin1("Dive Time: "), QString::fromLatin1(""));
|
||||
|
||||
if (time.contains(':')) {
|
||||
QStringList fmtTime = time.split(':');
|
||||
time = fmtTime[0] + fmtTime[1];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
|
||||
params[pnr++] = strdup("date");
|
||||
params[pnr++] = strdup(date.toLatin1());
|
||||
params[pnr++] = strdup("time");
|
||||
params[pnr++] = strdup(time.toLatin1());
|
||||
return pnr;
|
||||
}
|
||||
|
||||
void DiveLogImportDialog::on_buttonBox_accepted()
|
||||
{
|
||||
|
@ -832,7 +898,9 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
int pnr = 0;
|
||||
|
||||
QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd");
|
||||
if (apdRe.exactMatch(fileNames[i])) {
|
||||
if (txtLog) {
|
||||
pnr = parseTxtHeader(fileNames[i], params, pnr);
|
||||
} else if (apdRe.exactMatch(fileNames[i])) {
|
||||
params[pnr++] = strdup("date");
|
||||
params[pnr++] = strdup("20" + apdRe.cap(1).toLatin1());
|
||||
params[pnr++] = strdup("time");
|
||||
|
@ -906,7 +974,9 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
int pnr = 0;
|
||||
|
||||
QRegExp apdRe("^.*[/\\][0-9a-zA-Z]*_([0-9]{6})_([0-9]{6})\\.apd");
|
||||
if (apdRe.exactMatch(fileNames[i])) {
|
||||
if (txtLog) {
|
||||
pnr = parseTxtHeader(fileNames[i], params, pnr);
|
||||
} else if (apdRe.exactMatch(fileNames[i])) {
|
||||
params[pnr++] = strdup("date");
|
||||
params[pnr++] = strdup("20" + apdRe.cap(1).toLatin1());
|
||||
params[pnr++] = strdup("time");
|
||||
|
|
|
@ -87,6 +87,7 @@ slots:
|
|||
void loadFileContentsKnownTypesSelected(int value);
|
||||
void loadFileContents(int value, enum whatChanged triggeredBy);
|
||||
int setup_csv_params(QStringList r, char **params, int pnr);
|
||||
int parseTxtHeader(QString fileName, char **params, int pnr);
|
||||
|
||||
private:
|
||||
bool selector;
|
||||
|
@ -97,6 +98,7 @@ private:
|
|||
ColumnNameResult *resultModel;
|
||||
QString delta;
|
||||
QString hw;
|
||||
bool txtLog;
|
||||
|
||||
struct CSVAppConfig {
|
||||
QString name;
|
||||
|
|
Loading…
Reference in a new issue