#1966 Observed Data : Use first item in DATE column as startdate for YEARS

This commit is contained in:
Magne Sjaastad 2017-10-05 08:10:34 +02:00
parent 4016681286
commit 56cd53a5f0
5 changed files with 83 additions and 18 deletions

View File

@ -66,19 +66,42 @@ bool RifColumnBasedUserData::parse(const QString& data, const QString& customWel
for (size_t tableIndex = 0; tableIndex < m_parser->tables().size(); tableIndex++)
{
size_t timeColumnIndex = m_parser->tables()[tableIndex].size();
// Find time index
size_t dateColumnIndex = m_parser->tables()[tableIndex].size();
size_t dayOrYearColumnIndex = m_parser->tables()[tableIndex].size();
for (size_t columIndex = 0; columIndex < m_parser->tables()[tableIndex].size(); columIndex++)
{
const ColumnInfo& ci = m_parser->tables()[tableIndex][columIndex];
if (!ci.isAVector)
{
timeColumnIndex = columIndex;
break;
QString unit = QString::fromStdString(ci.unitName).trimmed().toUpper();
if (unit == "DATE" ||
unit == "DATES")
{
dateColumnIndex = columIndex;
}
else if (unit == "DAY" ||
unit == "DAYS" ||
unit == "YEAR" ||
unit == "YEARS")
{
dayOrYearColumnIndex = columIndex;
break;
}
}
}
size_t timeColumnIndex = m_parser->tables()[tableIndex].size();
if (dayOrYearColumnIndex < m_parser->tables()[tableIndex].size())
{
timeColumnIndex = dayOrYearColumnIndex;
}
else if (dateColumnIndex < m_parser->tables()[tableIndex].size())
{
timeColumnIndex = dateColumnIndex;
}
if (timeColumnIndex == m_parser->tables()[tableIndex].size())
{
RiaLogging::warning(QString("Failed to find time data for table %1 in file %2").arg(tableIndex));
@ -88,16 +111,23 @@ bool RifColumnBasedUserData::parse(const QString& data, const QString& customWel
{
const ColumnInfo& ci = m_parser->tables()[tableIndex][timeColumnIndex];
QDateTime startDate;
QString startDateString = QString::fromStdString(ci.startDate);
if (!startDateString.isEmpty())
if (ci.startQDateTime.isValid())
{
QString dateFormatString = "ddMMyyyy";
startDate = RiaQDateTimeTools::fromString(startDateString, dateFormatString);
startDate = ci.startQDateTime;
}
else
{
startDate = RiaQDateTimeTools::epoch();
QString startDateString = QString::fromStdString(ci.startDateString);
if (!startDateString.isEmpty())
{
QString dateFormatString = "ddMMyyyy";
startDate = RiaQDateTimeTools::fromString(startDateString, dateFormatString);
}
else
{
startDate = RiaQDateTimeTools::epoch();
}
}
m_timeSteps.resize(m_timeSteps.size() + 1);

View File

@ -20,6 +20,7 @@
#include "RifEclipseUserDataParserTools.h"
#include "RiaDateStringParser.h"
#include "RiaLogging.h"
#include "cvfAssert.h"
@ -62,6 +63,21 @@ void RifColumnBasedUserDataParser::parseData(const QString& data)
std::string line;
std::getline(streamData, line);
size_t dateColumnIndex = table.size();
for (size_t i = 0; i < columnCount; i++)
{
if (table[i].summaryAddress.quantityName() == "DATE" ||
table[i].summaryAddress.quantityName() == "DATES")
{
dateColumnIndex = i;
}
}
// If a DATE column is present, use the first date as the start date of the samples
// This date is then used as basis for times defined by days or years given as double values
QDateTime startDate;
startDate.setTimeSpec(Qt::UTC);
std::vector<double> values;
QString qLine;
do
@ -73,12 +89,30 @@ void RifColumnBasedUserDataParser::parseData(const QString& data)
for (size_t i = 0; i < columnCount; i++)
{
if (dateColumnIndex < columnCount && !startDate.isValid())
{
QDate candidate = RiaDateStringParser::parseDateString(entries[static_cast<int>(dateColumnIndex)].toStdString());
if (candidate.isValid())
{
startDate.setDate(candidate);
}
}
double entry = entries.at(static_cast<int>(i)).toDouble();
table[i].values.push_back(entry);
}
} while (std::getline(streamData, line));
if (startDate.isValid())
{
for (auto& ci : table)
{
ci.startQDateTime = startDate;
}
}
m_tables.push_back(table);
} while (streamData.good());
}

View File

@ -379,8 +379,8 @@ std::vector<ColumnInfo> RifEclipseUserDataParserTools::columnInfoForTable(std::s
ColumnInfo columnInfo;
columnInfo.unitName = unit;
columnInfo.origin = origin;
columnInfo.dateFormat = dateFormat;
columnInfo.startDate = startDate;
columnInfo.dateFormatString = dateFormat;
columnInfo.startDateString = startDate;
table.push_back(columnInfo);
}

View File

@ -35,9 +35,10 @@ struct ColumnInfo
std::string unitName;
double scaleFactor;
std::vector<double> values;
std::string dateFormat;
std::string startDate;
std::string origin;
std::string dateFormatString;
std::string startDateString;
QDateTime startQDateTime;
};
//==================================================================================================

View File

@ -291,13 +291,13 @@ TEST(RifColumnBasedRsmspecParserTest, TestKeywordsAndMissingUnitName)
std::vector< std::vector<ColumnInfo> > tables = parser.tables();
ASSERT_EQ(2, tables.size());
EXPECT_EQ("112000", tables[0].at(0).startDate);
EXPECT_EQ("112000", tables[0].at(0).startDateString);
EXPECT_EQ("OP-1_TR", tables[0].at(0).origin);
EXPECT_EQ("DD/MM/YY", tables[0].at(0).dateFormat);
EXPECT_EQ("DD/MM/YY", tables[0].at(0).dateFormatString);
EXPECT_EQ("112000", tables[1].at(0).startDate);
EXPECT_EQ("112000", tables[1].at(0).startDateString);
EXPECT_EQ("OP-2_TR", tables[1].at(0).origin);
EXPECT_EQ("DD/MM/YY", tables[1].at(0).dateFormat);
EXPECT_EQ("DD/MM/YY", tables[1].at(0).dateFormatString);
// Assume missing units at start of row
EXPECT_EQ("", tables[0].at(0).unitName);