mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#9773 Import data from Reveal and StimPlan as summary case.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "RifCsvUserDataParser.h"
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
#include "RifEclipseUserDataKeywordTools.h"
|
||||
#include "RifEclipseUserDataParserTools.h"
|
||||
#include "RifFileParseTools.h"
|
||||
@@ -276,7 +277,9 @@ QStringList RifCsvUserDataParser::timeColumnPreviewData( int lineCount, const As
|
||||
RifCsvUserDataParser::CsvLayout RifCsvUserDataParser::determineCsvLayout()
|
||||
{
|
||||
QTextStream* dataStream = openDataStream();
|
||||
QString firstLine;
|
||||
if ( !dataStream ) return LineBased;
|
||||
|
||||
QString firstLine;
|
||||
|
||||
QStringList headers;
|
||||
while ( !dataStream->atEnd() )
|
||||
@@ -309,7 +312,19 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
while ( !headerFound )
|
||||
{
|
||||
QString line = dataStream->readLine();
|
||||
if ( line.trimmed().isEmpty() ) continue;
|
||||
if ( line.trimmed().isEmpty() )
|
||||
{
|
||||
if ( !headerFound && dataStream->atEnd() )
|
||||
{
|
||||
// Handle empty stream
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Empty lines are skipped.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList columnHeaders = RifFileParseTools::splitLineAndTrim( line, parseOptions.cellSeparator );
|
||||
|
||||
@@ -317,8 +332,9 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
QStringList unitTexts;
|
||||
QStringList names;
|
||||
|
||||
auto startOfLineWithDataValues = dataStream->pos();
|
||||
bool hasDataValues = false;
|
||||
auto startOfLineWithDataValues = dataStream->pos();
|
||||
bool hasDataValues = false;
|
||||
QString nameFromData;
|
||||
while ( !hasDataValues )
|
||||
{
|
||||
QString candidateLine = dataStream->readLine();
|
||||
@@ -327,7 +343,14 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
for ( const auto& text : candidateColumnHeaders )
|
||||
{
|
||||
if ( RiaStdStringTools::isNumber( text.toStdString(), parseOptions.locale.decimalPoint().toLatin1() ) )
|
||||
{
|
||||
hasDataValues = true;
|
||||
}
|
||||
else if ( nameFromData.isEmpty() )
|
||||
{
|
||||
// Keep the first non-number data field as a possible name.
|
||||
nameFromData = text;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !hasDataValues && candidateColumnHeaders.size() == columnHeaders.size() )
|
||||
@@ -353,6 +376,23 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
{
|
||||
QString colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( columnHeaders[iCol] );
|
||||
|
||||
QString unit;
|
||||
|
||||
// Check if unit is part of the column name in parentheses, e.g. "VECTOR (unit)".
|
||||
QRegExp exp( "\\((.*)\\)" );
|
||||
if ( exp.indexIn( colName ) >= 0 )
|
||||
{
|
||||
// "VECTOR (unit)" ==> "(unit)"
|
||||
QString fullCapture = exp.cap( 0 );
|
||||
// "VECTOR (unit)" ==> "unit"
|
||||
QString unitCapture = exp.cap( 1 );
|
||||
|
||||
unit = unitCapture;
|
||||
|
||||
// Remove unit from name
|
||||
colName = RiaTextStringTools::trimAndRemoveDoubleSpaces( colName.remove( fullCapture ) );
|
||||
}
|
||||
|
||||
if ( iCol < names.size() )
|
||||
{
|
||||
QString name = RiaTextStringTools::trimAndRemoveDoubleSpaces( names[iCol] );
|
||||
@@ -363,12 +403,17 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
|
||||
}
|
||||
}
|
||||
|
||||
QString unit;
|
||||
if ( iCol < unitTexts.size() ) unit = unitTexts[iCol];
|
||||
|
||||
RifEclipseSummaryAddress addr = RifEclipseSummaryAddress::fromEclipseTextAddressParseErrorTokens( colName.toStdString() );
|
||||
Column col = Column::createColumnInfoFromCsvData( addr, unit.toStdString() );
|
||||
|
||||
// Create address of a give category if provided
|
||||
if ( parseOptions.defaultCategory == RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_WELL )
|
||||
addr = RifEclipseSummaryAddress::wellAddress( colName.toStdString(), nameFromData.toStdString() );
|
||||
else if ( parseOptions.defaultCategory == RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_FIELD )
|
||||
addr = RifEclipseSummaryAddress::fieldAddress( colName.toStdString() );
|
||||
|
||||
Column col = Column::createColumnInfoFromCsvData( addr, unit.toStdString() );
|
||||
columnInfoList->push_back( col );
|
||||
}
|
||||
|
||||
@@ -484,20 +529,22 @@ bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& pa
|
||||
}
|
||||
else if ( col.dataType == Column::DATETIME )
|
||||
{
|
||||
QDateTime dt;
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.dateTimeFormat );
|
||||
QDateTime dt = tryParseDateTime( colData.toStdString(), parseOptions.dateTimeFormat );
|
||||
|
||||
if ( !dt.isValid() && !parseOptions.useCustomDateTimeFormat )
|
||||
// Try to match date format only
|
||||
if ( !dt.isValid() && parseOptions.dateFormat != parseOptions.dateTimeFormat )
|
||||
{
|
||||
// Try to match date format only
|
||||
if ( parseOptions.dateFormat != parseOptions.dateTimeFormat )
|
||||
{
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.dateFormat );
|
||||
}
|
||||
if ( !dt.isValid() && !parseOptions.fallbackDateTimeFormat.isEmpty() )
|
||||
{
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.fallbackDateTimeFormat );
|
||||
}
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.dateFormat );
|
||||
}
|
||||
if ( !dt.isValid() && !parseOptions.fallbackDateTimeFormat.isEmpty() )
|
||||
{
|
||||
dt = tryParseDateTime( colData.toStdString(), parseOptions.fallbackDateTimeFormat );
|
||||
}
|
||||
|
||||
if ( !dt.isValid() && parseOptions.startDateTime.isValid() )
|
||||
{
|
||||
double minutes = colData.toDouble();
|
||||
dt = parseOptions.startDateTime.addSecs( minutes * 60 );
|
||||
}
|
||||
|
||||
if ( !dt.isValid() )
|
||||
@@ -532,7 +579,12 @@ bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& pa
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifCsvUserDataParser::parseLineBasedData()
|
||||
{
|
||||
QTextStream* dataStream = openDataStream();
|
||||
QTextStream* dataStream = openDataStream();
|
||||
if ( !dataStream )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::map<RifEclipseSummaryAddress, std::vector<std::pair<time_t, double>>> addressesAndData;
|
||||
std::vector<int> colIndexes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user