mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
CSV import. Replaced old ASCII parser by the new RifCsvUserDataParser
This commit is contained in:
parent
3b1775ad4d
commit
6d4820a691
@ -29,8 +29,6 @@
|
||||
#include "RimAsciiDataCurve.h"
|
||||
#include "RimSummaryCurveAppearanceCalculator.h"
|
||||
|
||||
#include "RifColumnBasedAsciiParser.h"
|
||||
|
||||
#include "cafPdmDefaultObjectFactory.h"
|
||||
#include "cafPdmDocument.h"
|
||||
#include "cafPdmObjectGroup.h"
|
||||
@ -84,35 +82,39 @@ void RicPasteAsciiDataToSummaryPlotFeature::onActionTriggered(bool isChecked)
|
||||
QString text = getPastedData();
|
||||
|
||||
RicPasteAsciiDataToSummaryPlotFeatureUi pasteOptions;
|
||||
caf::PdmSettings::readFieldsFromApplicationStore(&pasteOptions);
|
||||
if (!summaryPlot) pasteOptions.createNewPlot();
|
||||
pasteOptions.setUiModePasteText(text);
|
||||
caf::PdmSettings::readFieldsFromApplicationStore(&pasteOptions);
|
||||
|
||||
caf::PdmUiPropertyViewDialog propertyDialog(NULL, &pasteOptions, "Set Paste Options", "");
|
||||
if (propertyDialog.exec() != QDialog::Accepted) return;
|
||||
|
||||
if (!summaryPlot)
|
||||
{
|
||||
RimSummaryPlotCollection* summaryPlotCollection = nullptr;
|
||||
destinationObject->firstAncestorOrThisOfType(summaryPlotCollection);
|
||||
if (!summaryPlotCollection)
|
||||
{
|
||||
return;
|
||||
}
|
||||
summaryPlot = createSummaryPlotAndAddToPlotCollection(summaryPlotCollection);
|
||||
}
|
||||
|
||||
caf::PdmSettings::writeFieldsToApplicationStore(&pasteOptions);
|
||||
|
||||
std::vector<RimAsciiDataCurve*> curves = parseCurves(text, pasteOptions);
|
||||
|
||||
for (RimAsciiDataCurve* curve : curves)
|
||||
{
|
||||
summaryPlot->addAsciiDataCruve(curve);
|
||||
}
|
||||
|
||||
summaryPlot->updateConnectedEditors();
|
||||
summaryPlot->loadDataAndUpdate();
|
||||
if (curves.size() > 0)
|
||||
{
|
||||
if (!summaryPlot)
|
||||
{
|
||||
RimSummaryPlotCollection* summaryPlotCollection = nullptr;
|
||||
destinationObject->firstAncestorOrThisOfType(summaryPlotCollection);
|
||||
if (!summaryPlotCollection)
|
||||
{
|
||||
return;
|
||||
}
|
||||
summaryPlot = createSummaryPlotAndAddToPlotCollection(summaryPlotCollection);
|
||||
summaryPlotCollection->updateConnectedEditors();
|
||||
}
|
||||
|
||||
caf::PdmSettings::writeFieldsToApplicationStore(&pasteOptions);
|
||||
|
||||
for (RimAsciiDataCurve* curve : curves)
|
||||
{
|
||||
summaryPlot->addAsciiDataCruve(curve);
|
||||
}
|
||||
|
||||
summaryPlot->updateConnectedEditors();
|
||||
summaryPlot->loadDataAndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -162,9 +164,14 @@ std::vector<RimAsciiDataCurve*> RicPasteAsciiDataToSummaryPlotFeature::parseCurv
|
||||
{
|
||||
std::vector<RimAsciiDataCurve*> curves;
|
||||
const AsciiDataParseOptions& parseOptions = settings.parseOptions();
|
||||
RifColumnBasedAsciiParser parser = RifColumnBasedAsciiParser(data, parseOptions.dateTimeFormat, parseOptions.locale, parseOptions.cellSeparator);
|
||||
RifCsvUserDataPastedTextParser parser = RifCsvUserDataPastedTextParser(data);
|
||||
|
||||
if (parser.headers().empty())
|
||||
if (!parser.parse(parseOptions))
|
||||
{
|
||||
return curves;
|
||||
}
|
||||
|
||||
if (parser.tableData().columnInfos().empty() || !parser.dateTimeColumn())
|
||||
{
|
||||
return curves;
|
||||
}
|
||||
@ -173,24 +180,27 @@ std::vector<RimAsciiDataCurve*> RicPasteAsciiDataToSummaryPlotFeature::parseCurv
|
||||
|
||||
QString curvePrefix = parseOptions.curvePrefix;
|
||||
|
||||
for (size_t i = 0; i < parser.headers().size(); i++)
|
||||
for (size_t i = 0; i < parser.tableData().columnInfos().size(); i++)
|
||||
{
|
||||
const ColumnInfo* col = parser.columnInfo(i);
|
||||
if (col->dataType != ColumnInfo::NUMERIC) continue;
|
||||
|
||||
RimAsciiDataCurve* curve = new RimAsciiDataCurve();
|
||||
curve->setTimeSteps(parser.timeSteps());
|
||||
curve->setValues(parser.columnValues(i));
|
||||
curve->setTimeSteps(parser.dateTimeColumn()->dateTimeValues);
|
||||
curve->setValues(parser.columnInfo(i)->values);
|
||||
if (curvePrefix.isEmpty())
|
||||
{
|
||||
curve->setTitle(parser.headers()[i]);
|
||||
curve->setTitle(QString::fromStdString(col->columnName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
curve->setTitle(QString("%1: %2").arg(curvePrefix).arg(parser.headers()[i]));
|
||||
curve->setTitle(QString("%1: %2").arg(curvePrefix).arg(QString::fromStdString(col->columnName())));
|
||||
}
|
||||
// Appearance
|
||||
curve->setSymbol(parseOptions.curveSymbol);
|
||||
curve->setLineStyle(parseOptions.curveLineStyle);
|
||||
curve->setSymbolSkipDinstance(parseOptions.curveSymbolSkipDistance);
|
||||
curveToTypeMap[guessCurveType(parser.headers()[i])].push_back(curve);
|
||||
curveToTypeMap[guessCurveType(QString::fromStdString(col->columnName()))].push_back(curve);
|
||||
curves.push_back(curve);
|
||||
}
|
||||
|
||||
|
@ -304,7 +304,7 @@ QList<caf::PdmOptionItemInfo> RicPasteAsciiDataToSummaryPlotFeatureUi::calculate
|
||||
|
||||
for (const ColumnInfo& columnInfo : columnInfoList)
|
||||
{
|
||||
QString columnName = QString::fromStdString(columnInfo.summaryAddress.quantityName());
|
||||
QString columnName = QString::fromStdString(columnInfo.columnName());
|
||||
options.push_back(caf::PdmOptionItemInfo(columnName, columnName));
|
||||
}
|
||||
}
|
||||
@ -362,7 +362,7 @@ void RicPasteAsciiDataToSummaryPlotFeatureUi::initialize(RifCsvUserDataParser* p
|
||||
parser->parseColumnInfo(parseOptions().cellSeparator);
|
||||
if (parser->tableData().columnInfos().size() > 0)
|
||||
{
|
||||
m_timeSeriesColumnName = QString::fromStdString(parser->tableData().columnInfos()[0].summaryAddress.quantityName());
|
||||
m_timeSeriesColumnName = QString::fromStdString(parser->tableData().columnInfos()[0].columnName());
|
||||
}
|
||||
|
||||
m_previewText = parser->previewText(PREVIEW_TEXT_LINE_COUNT, cellSep);
|
||||
|
@ -16,7 +16,6 @@ ${CEE_CURRENT_LIST_DIR}RifPerforationIntervalReader.h
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderEclipseInput.h
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput.h
|
||||
${CEE_CURRENT_LIST_DIR}RifSummaryReaderInterface.h
|
||||
${CEE_CURRENT_LIST_DIR}RifColumnBasedAsciiParser.h
|
||||
${CEE_CURRENT_LIST_DIR}RifEclipseUserDataParserTools.h
|
||||
${CEE_CURRENT_LIST_DIR}RifColumnBasedUserDataParser.h
|
||||
${CEE_CURRENT_LIST_DIR}RifKeywordVectorParser.h
|
||||
@ -63,7 +62,6 @@ ${CEE_CURRENT_LIST_DIR}RifPerforationIntervalReader.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderEclipseInput.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifSummaryReaderInterface.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifColumnBasedAsciiParser.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifEclipseUserDataParserTools.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifColumnBasedUserDataParser.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifKeywordVectorParser.cpp
|
||||
|
@ -1,129 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifColumnBasedAsciiParser.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifColumnBasedAsciiParser::RifColumnBasedAsciiParser(QString& data, const QString dateFormat, QLocale decimalLocale, QString cellSeparator)
|
||||
{
|
||||
parseData(data, dateFormat, decimalLocale, cellSeparator);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<QString>& RifColumnBasedAsciiParser::headers() const
|
||||
{
|
||||
return m_data.m_headers;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<QDateTime>& RifColumnBasedAsciiParser::timeSteps() const
|
||||
{
|
||||
return m_data.m_timeSteps;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<double>& RifColumnBasedAsciiParser::columnValues(size_t columnIndex) const
|
||||
{
|
||||
CVF_TIGHT_ASSERT(columnIndex < m_data.m_values.size());
|
||||
|
||||
return m_data.m_values[columnIndex];
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifColumnBasedAsciiParser::parseData(QString& data, QString dateFormat, QLocale decimalLocale, QString cellSeparator)
|
||||
{
|
||||
QTextStream tableData(&data);
|
||||
|
||||
QString header;
|
||||
|
||||
do {
|
||||
header = tableData.readLine();
|
||||
} while (header.isEmpty() && !tableData.atEnd());
|
||||
|
||||
// No header row found
|
||||
if (header.isEmpty()) return;
|
||||
|
||||
QStringList columnHeaders = header.split(cellSeparator);
|
||||
|
||||
for (int i = 1; i < columnHeaders.size(); ++i)
|
||||
{
|
||||
m_data.m_headers.push_back(columnHeaders[i]);
|
||||
}
|
||||
|
||||
// No columns found
|
||||
if (m_data.m_headers.empty()) return;
|
||||
|
||||
|
||||
int numColumns = static_cast<int>(m_data.m_headers.size());
|
||||
|
||||
m_data.m_values.resize(numColumns);
|
||||
|
||||
size_t row = 0;
|
||||
while (!tableData.atEnd())
|
||||
{
|
||||
++row;
|
||||
QString line = tableData.readLine();
|
||||
|
||||
// Skip empty lines
|
||||
if (line.isEmpty()) continue;
|
||||
|
||||
QStringList columns = line.split(cellSeparator);
|
||||
|
||||
if (columns.size() != numColumns + 1)
|
||||
{
|
||||
RiaLogging::warning(QString("Invalid number of columns in row %1").arg(row));
|
||||
continue;
|
||||
}
|
||||
|
||||
QDateTime date = QDateTime::fromString(columns[0], dateFormat);
|
||||
if (!date.isValid())
|
||||
{
|
||||
RiaLogging::warning(QString("First column of row %1 could not be parsed as a date: %2").arg(row).arg(columns[0]));
|
||||
continue;
|
||||
}
|
||||
m_data.m_timeSteps.push_back(date);
|
||||
|
||||
for (int col = 1; col < columns.size(); ++col)
|
||||
{
|
||||
bool ok;
|
||||
m_data.m_values[col - 1].push_back(decimalLocale.toDouble(columns[col], &ok));
|
||||
if (!ok)
|
||||
{
|
||||
RiaLogging::warning(QString("Could not parse value at row %1 column %2 as double: %3. Defaulting to 0.0").arg(row).arg(col).arg(columns[col]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QLocale>
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RifColumnBasedAsciiParser
|
||||
{
|
||||
public:
|
||||
RifColumnBasedAsciiParser(QString& data, const QString dateFormat, QLocale decimalLocale, QString cellSeparator);
|
||||
|
||||
const std::vector<QString>& headers() const;
|
||||
const std::vector<QDateTime>& timeSteps() const;
|
||||
const std::vector<double>& columnValues(size_t columnIndex) const;
|
||||
|
||||
private:
|
||||
void parseData(QString& data, QString dateFormat, QLocale decimalLocale, QString cellSeparator);
|
||||
|
||||
private:
|
||||
|
||||
struct AsciiData
|
||||
{
|
||||
std::vector<QString> m_headers;
|
||||
std::vector<QDateTime> m_timeSteps;
|
||||
std::vector< std::vector<double> > m_values;
|
||||
};
|
||||
|
||||
AsciiData m_data;
|
||||
};
|
@ -79,6 +79,21 @@ const ColumnInfo* RifCsvUserDataParser::columnInfo(size_t columnIndex) const
|
||||
return &(m_tableData.columnInfos()[columnIndex]);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const ColumnInfo* RifCsvUserDataParser::dateTimeColumn() const
|
||||
{
|
||||
for (const ColumnInfo& col : m_tableData.columnInfos())
|
||||
{
|
||||
if (col.dataType == ColumnInfo::DATETIME)
|
||||
{
|
||||
return &col;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
const TableData& tableData() const;
|
||||
|
||||
const ColumnInfo* columnInfo(size_t columnIndex) const;
|
||||
const ColumnInfo* dateTimeColumn() const;
|
||||
|
||||
bool parseColumnInfo(const QString& cellSeparator);
|
||||
QString previewText(int lineCount, const QString& cellSeparator);
|
||||
|
@ -918,24 +918,13 @@ bool RifEclipseUserDataParserTools::isScalingText(const std::string& word)
|
||||
return word.find_first_of('*') != std::string::npos;
|
||||
}
|
||||
|
||||
////--------------------------------------------------------------------------------------------------
|
||||
/////
|
||||
////--------------------------------------------------------------------------------------------------
|
||||
//ColumnInfo::~ColumnInfo()
|
||||
//{
|
||||
// if (values)
|
||||
// {
|
||||
// delete values;
|
||||
// }
|
||||
// if (textValues)
|
||||
// {
|
||||
// delete textValues;
|
||||
// }
|
||||
// if (dateTimeValues)
|
||||
// {
|
||||
// delete dateTimeValues;
|
||||
// }
|
||||
//}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string ColumnInfo::columnName() const
|
||||
{
|
||||
return summaryAddress.quantityName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
|
@ -56,6 +56,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
std::string columnName() const;
|
||||
size_t itemCount() const;
|
||||
|
||||
public:
|
||||
|
@ -18,8 +18,10 @@
|
||||
|
||||
#include "RifReaderObservedData.h"
|
||||
|
||||
#include "RifColumnBasedAsciiParser.h"
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
#include "RifCsvUserDataParser.h"
|
||||
|
||||
#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QTextStream>
|
||||
@ -47,9 +49,10 @@ bool RifReaderObservedData::open(const QString& headerFileName,
|
||||
const QString& identifierName,
|
||||
RifEclipseSummaryAddress::SummaryVarCategory summaryCategory)
|
||||
{
|
||||
QString dateFormat = "yyyy-MM-dd";
|
||||
QString cellSeparator = "\t";
|
||||
QLocale decimalLocale = QLocale::Norwegian;
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.dateFormat = "yyyy-MM-dd";
|
||||
parseOptions.cellSeparator = "\t";
|
||||
parseOptions.locale = QLocale::Norwegian;
|
||||
|
||||
QString data;
|
||||
QTextStream out(&data);
|
||||
@ -60,27 +63,29 @@ bool RifReaderObservedData::open(const QString& headerFileName,
|
||||
out << "1994-05-23" << "\t" << "40" << "\t" << "4" << "\n";
|
||||
|
||||
|
||||
m_asciiParser = std::unique_ptr<RifColumnBasedAsciiParser>(new RifColumnBasedAsciiParser(data, dateFormat, decimalLocale, cellSeparator));
|
||||
m_asciiParser = std::unique_ptr<RifCsvUserDataParser>(new RifCsvUserDataPastedTextParser(data));
|
||||
|
||||
m_timeSteps.clear();
|
||||
if (m_asciiParser)
|
||||
if (m_asciiParser->parse(parseOptions))
|
||||
{
|
||||
for (QDateTime timeStep : m_asciiParser->timeSteps())
|
||||
if (m_asciiParser && m_asciiParser->dateTimeColumn())
|
||||
{
|
||||
time_t t = timeStep.toTime_t();
|
||||
m_timeSteps.push_back(t);
|
||||
for (QDateTime timeStep : m_asciiParser->dateTimeColumn()->dateTimeValues)
|
||||
{
|
||||
time_t t = timeStep.toTime_t();
|
||||
m_timeSteps.push_back(t);
|
||||
}
|
||||
|
||||
m_allResultAddresses.clear();
|
||||
for (auto s : m_asciiParser->tableData().columnInfos())
|
||||
{
|
||||
m_allResultAddresses.push_back(s.summaryAddress);
|
||||
}
|
||||
}
|
||||
|
||||
m_allResultAddresses.clear();
|
||||
for (auto s : m_asciiParser->headers())
|
||||
{
|
||||
m_allResultAddresses.push_back(address(s, identifierName, summaryCategory));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!m_asciiParser) return false;
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -100,9 +105,13 @@ bool RifReaderObservedData::values(const RifEclipseSummaryAddress& resultAddress
|
||||
|
||||
if (columnIndex != m_allResultAddresses.size())
|
||||
{
|
||||
for (auto& v : m_asciiParser->columnValues(columnIndex))
|
||||
const ColumnInfo* col = m_asciiParser->columnInfo(columnIndex);
|
||||
if (col && col->dataType == ColumnInfo::NUMERIC)
|
||||
{
|
||||
values->push_back(v);
|
||||
for (auto& v : col->values)
|
||||
{
|
||||
values->push_back(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ class QString;
|
||||
|
||||
class RifColumnBasedAsciiParser;
|
||||
class RifEclipseSummaryAddress;
|
||||
class RifCsvUserDataParser;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@ -58,7 +59,7 @@ private:
|
||||
RifEclipseSummaryAddress::SummaryVarCategory summaryCategory);
|
||||
|
||||
private:
|
||||
std::unique_ptr<RifColumnBasedAsciiParser> m_asciiParser;
|
||||
std::unique_ptr<RifCsvUserDataParser> m_asciiParser;
|
||||
std::vector<time_t> m_timeSteps;
|
||||
};
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RifColumnBasedAsciiParser.h"
|
||||
#include "RifColumnBasedUserData.h"
|
||||
#include "RifColumnBasedUserDataParser.h"
|
||||
#include "RifKeywordVectorParser.h"
|
||||
#include "RifEclipseUserDataParserTools.h"
|
||||
#include "RifCsvUserDataParser.h"
|
||||
#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"
|
||||
|
||||
#include <vector>
|
||||
#include <QTextStream>
|
||||
@ -17,9 +18,11 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifColumnBasedAsciiParserTest, TestDateFormatYyyymmddWithDash)
|
||||
{
|
||||
QString dateFormat = "yyyy-MM-dd";
|
||||
QString cellSeparator = "\t";
|
||||
QLocale decimalLocale = QLocale::Norwegian;
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.dateFormat = "yyyy-MM-dd";
|
||||
parseOptions.cellSeparator = "\t";
|
||||
parseOptions.locale = QLocale::Norwegian;
|
||||
parseOptions.timeSeriesColumnName = "Date";
|
||||
|
||||
QString data;
|
||||
QTextStream out(&data);
|
||||
@ -29,15 +32,17 @@ TEST(RifColumnBasedAsciiParserTest, TestDateFormatYyyymmddWithDash)
|
||||
out << "1994-02-26" << "\t" << "30" << "\t" << "3" << "\n";
|
||||
out << "1994-05-23" << "\t" << "40" << "\t" << "4" << "\n";
|
||||
|
||||
RifColumnBasedAsciiParser parser = RifColumnBasedAsciiParser(data, dateFormat, decimalLocale, cellSeparator);
|
||||
|
||||
std::vector<QDateTime> timeSteps = parser.timeSteps();
|
||||
RifCsvUserDataPastedTextParser parser = RifCsvUserDataPastedTextParser(data);
|
||||
ASSERT_TRUE(parser.parse(parseOptions));
|
||||
ASSERT_TRUE(parser.dateTimeColumn() != nullptr);
|
||||
|
||||
ASSERT_EQ(size_t(4), parser.timeSteps().size());
|
||||
EXPECT_EQ("1993-02-23", timeSteps[0].toString(dateFormat).toStdString());
|
||||
EXPECT_EQ("1993-06-15", timeSteps[1].toString(dateFormat).toStdString());
|
||||
EXPECT_EQ("1994-02-26", timeSteps[2].toString(dateFormat).toStdString());
|
||||
EXPECT_EQ("1994-05-23", timeSteps[3].toString(dateFormat).toStdString());
|
||||
std::vector<QDateTime> timeSteps = parser.dateTimeColumn()->dateTimeValues;
|
||||
|
||||
ASSERT_EQ(size_t(4), timeSteps.size());
|
||||
EXPECT_EQ("1993-02-23", timeSteps[0].toString(parseOptions.dateFormat).toStdString());
|
||||
EXPECT_EQ("1993-06-15", timeSteps[1].toString(parseOptions.dateFormat).toStdString());
|
||||
EXPECT_EQ("1994-02-26", timeSteps[2].toString(parseOptions.dateFormat).toStdString());
|
||||
EXPECT_EQ("1994-05-23", timeSteps[3].toString(parseOptions.dateFormat).toStdString());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -45,9 +50,11 @@ TEST(RifColumnBasedAsciiParserTest, TestDateFormatYyyymmddWithDash)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifColumnBasedAsciiParserTest, TestDateFormatYymmddWithDot)
|
||||
{
|
||||
QString dateFormat = "yy.MM.dd";
|
||||
QString cellSeparator = "\t";
|
||||
QLocale decimalLocale = QLocale::Norwegian;
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.dateFormat = "yy.MM.dd";
|
||||
parseOptions.cellSeparator = "\t";
|
||||
parseOptions.locale = QLocale::Norwegian;
|
||||
parseOptions.timeSeriesColumnName = "Date";
|
||||
|
||||
QString data;
|
||||
QTextStream out(&data);
|
||||
@ -57,12 +64,15 @@ TEST(RifColumnBasedAsciiParserTest, TestDateFormatYymmddWithDot)
|
||||
out << "94.02.26" << "\t" << "30" << "\t" << "3" << "\n";
|
||||
out << "94.05.23" << "\t" << "40" << "\t" << "4" << "\n";
|
||||
|
||||
RifColumnBasedAsciiParser parser = RifColumnBasedAsciiParser(data, dateFormat, decimalLocale, cellSeparator);
|
||||
RifCsvUserDataPastedTextParser parser = RifCsvUserDataPastedTextParser(data);
|
||||
|
||||
std::vector<QDateTime> timeSteps = parser.timeSteps();
|
||||
ASSERT_TRUE(parser.parse(parseOptions));
|
||||
ASSERT_TRUE(parser.dateTimeColumn() != nullptr);
|
||||
|
||||
ASSERT_EQ(size_t(4), parser.timeSteps().size());
|
||||
EXPECT_EQ("93.02.23", timeSteps[0].toString(dateFormat).toStdString());
|
||||
std::vector<QDateTime> timeSteps = parser.dateTimeColumn()->dateTimeValues;
|
||||
|
||||
ASSERT_EQ(size_t(4), timeSteps.size());
|
||||
EXPECT_EQ("93.02.23", timeSteps[0].toString(parseOptions.dateFormat).toStdString());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -70,9 +80,11 @@ TEST(RifColumnBasedAsciiParserTest, TestDateFormatYymmddWithDot)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifColumnBasedAsciiParserTest, TestDateFormatDdmmyyWithDot)
|
||||
{
|
||||
QString dateFormat = "dd.MM.yy";
|
||||
QString cellSeparator = "\t";
|
||||
QLocale decimalLocale = QLocale::Norwegian;
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.dateFormat = "dd.MM.yy";
|
||||
parseOptions.cellSeparator = "\t";
|
||||
parseOptions.locale = QLocale::Norwegian;
|
||||
parseOptions.timeSeriesColumnName = "Date";
|
||||
|
||||
QString data;
|
||||
QTextStream out(&data);
|
||||
@ -82,12 +94,14 @@ TEST(RifColumnBasedAsciiParserTest, TestDateFormatDdmmyyWithDot)
|
||||
out << "26.02.94" << "\t" << "30" << "\t" << "3" << "\n";
|
||||
out << "23.05.94" << "\t" << "40" << "\t" << "4" << "\n";
|
||||
|
||||
RifColumnBasedAsciiParser parser = RifColumnBasedAsciiParser(data, dateFormat, decimalLocale, cellSeparator);
|
||||
RifCsvUserDataPastedTextParser parser = RifCsvUserDataPastedTextParser(data);
|
||||
ASSERT_TRUE(parser.parse(parseOptions));
|
||||
ASSERT_TRUE(parser.dateTimeColumn() != nullptr);
|
||||
|
||||
std::vector<QDateTime> timeSteps = parser.timeSteps();
|
||||
std::vector<QDateTime> timeSteps = parser.dateTimeColumn()->dateTimeValues;
|
||||
|
||||
ASSERT_EQ(size_t(4), parser.timeSteps().size());
|
||||
EXPECT_EQ("23.02.93", timeSteps[0].toString(dateFormat).toStdString());
|
||||
ASSERT_EQ(size_t(4), timeSteps.size());
|
||||
EXPECT_EQ("23.02.93", timeSteps[0].toString(parseOptions.dateFormat).toStdString());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -95,9 +109,12 @@ TEST(RifColumnBasedAsciiParserTest, TestDateFormatDdmmyyWithDot)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifColumnBasedAsciiParserTest, TestDecimalLocaleNorwegian)
|
||||
{
|
||||
QString dateFormat = "yy.MM.dd";
|
||||
QString cellSeparator = "\t";
|
||||
QLocale decimalLocale = QLocale::Norwegian;
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.dateFormat = "yy.MM.dd";
|
||||
parseOptions.cellSeparator = "\t";
|
||||
parseOptions.decimalSeparator = ",";
|
||||
parseOptions.locale = QLocale::Norwegian;
|
||||
parseOptions.timeSeriesColumnName = "Date";
|
||||
|
||||
QString data;
|
||||
QTextStream out(&data);
|
||||
@ -107,10 +124,14 @@ TEST(RifColumnBasedAsciiParserTest, TestDecimalLocaleNorwegian)
|
||||
out << "94.02.26" << "\t" << "30,2" << "\t" << "3,09" << "\n";
|
||||
out << "94.05.23" << "\t" << "40,8" << "\t" << "4,44" << "\n";
|
||||
|
||||
RifColumnBasedAsciiParser parser = RifColumnBasedAsciiParser(data, dateFormat, decimalLocale, cellSeparator);
|
||||
RifCsvUserDataPastedTextParser parser = RifCsvUserDataPastedTextParser(data);
|
||||
|
||||
std::vector<double> oilValues = parser.columnValues(0);
|
||||
std::vector<double> pwValues = parser.columnValues(1);
|
||||
ASSERT_TRUE(parser.parse(parseOptions));
|
||||
ASSERT_TRUE(parser.columnInfo(1) != nullptr);
|
||||
ASSERT_TRUE(parser.columnInfo(2) != nullptr);
|
||||
|
||||
std::vector<double> oilValues = parser.columnInfo(1)->values;
|
||||
std::vector<double> pwValues = parser.columnInfo(2)->values;
|
||||
|
||||
ASSERT_EQ(size_t(4), oilValues.size());
|
||||
EXPECT_EQ(10.1, oilValues[0]);
|
||||
@ -131,9 +152,11 @@ TEST(RifColumnBasedAsciiParserTest, TestDecimalLocaleNorwegian)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifColumnBasedAsciiParserTest, TestDecimalLocaleC)
|
||||
{
|
||||
QString dateFormat = "yy.MM.dd";
|
||||
QString cellSeparator = "\t";
|
||||
QLocale decimalLocale = QLocale::c();
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.dateFormat = "yy.MM.dd";
|
||||
parseOptions.cellSeparator = "\t";
|
||||
parseOptions.locale = QLocale::c();
|
||||
parseOptions.timeSeriesColumnName = "Date";
|
||||
|
||||
QString data;
|
||||
QTextStream out(&data);
|
||||
@ -143,11 +166,16 @@ TEST(RifColumnBasedAsciiParserTest, TestDecimalLocaleC)
|
||||
out << "94.02.26" << "\t" << "30.2" << "\t" << "3.09" << "\t" << "2.1" << "\n";
|
||||
out << "94.05.23" << "\t" << "40.8" << "\t" << "4.44" << "\t" << "1.0" << "\n";
|
||||
|
||||
RifColumnBasedAsciiParser parser = RifColumnBasedAsciiParser(data, dateFormat, decimalLocale, cellSeparator);
|
||||
RifCsvUserDataPastedTextParser parser = RifCsvUserDataPastedTextParser(data);
|
||||
|
||||
std::vector<double> oilValues = parser.columnValues(0);
|
||||
std::vector<double> pwValues = parser.columnValues(1);
|
||||
std::vector<double> h2sValues = parser.columnValues(2);
|
||||
ASSERT_TRUE(parser.parse(parseOptions));
|
||||
ASSERT_TRUE(parser.columnInfo(1) != nullptr);
|
||||
ASSERT_TRUE(parser.columnInfo(2) != nullptr);
|
||||
ASSERT_TRUE(parser.columnInfo(3) != nullptr);
|
||||
|
||||
std::vector<double> oilValues = parser.columnInfo(1)->values;
|
||||
std::vector<double> pwValues = parser.columnInfo(2)->values;
|
||||
std::vector<double> h2sValues = parser.columnInfo(3)->values;
|
||||
|
||||
ASSERT_EQ(size_t(4), oilValues.size());
|
||||
EXPECT_EQ(10.1, oilValues[0]);
|
||||
@ -173,9 +201,11 @@ TEST(RifColumnBasedAsciiParserTest, TestDecimalLocaleC)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifColumnBasedAsciiParserTest, TestCellSeparatorComma)
|
||||
{
|
||||
QString dateFormat = "yy.MM.dd";
|
||||
QString cellSeparator = ",";
|
||||
QLocale decimalLocale = QLocale::c();
|
||||
AsciiDataParseOptions parseOptions;
|
||||
parseOptions.dateFormat = "yy.MM.dd";
|
||||
parseOptions.cellSeparator = ",";
|
||||
parseOptions.locale = QLocale::c();
|
||||
parseOptions.timeSeriesColumnName = "Date";
|
||||
|
||||
QString data;
|
||||
QTextStream out(&data);
|
||||
@ -186,10 +216,14 @@ TEST(RifColumnBasedAsciiParserTest, TestCellSeparatorComma)
|
||||
out << "94.02.26" << "," << "30.2" << "," << "3.09" << "\n";
|
||||
out << "94.05.23" << "," << "40.8" << "," << "4.44" << "\n";
|
||||
|
||||
RifColumnBasedAsciiParser parser = RifColumnBasedAsciiParser(data, dateFormat, decimalLocale, cellSeparator);
|
||||
RifCsvUserDataPastedTextParser parser = RifCsvUserDataPastedTextParser(data);
|
||||
|
||||
std::vector<double> oilValues = parser.columnValues(0);
|
||||
std::vector<double> pwValues = parser.columnValues(1);
|
||||
ASSERT_TRUE(parser.parse(parseOptions));
|
||||
ASSERT_TRUE(parser.columnInfo(1) != nullptr);
|
||||
ASSERT_TRUE(parser.columnInfo(2) != nullptr);
|
||||
|
||||
std::vector<double> oilValues = parser.columnInfo(1)->values;
|
||||
std::vector<double> pwValues = parser.columnInfo(2)->values;
|
||||
|
||||
ASSERT_EQ(size_t(4), oilValues.size());
|
||||
EXPECT_EQ(10.1, oilValues[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user