#10130 Reveal summary import: convert to Eclipse units.

This commit is contained in:
Kristian Bendiksen 2023-04-24 11:28:38 +02:00
parent f8c1eebe01
commit 350db4d6a9
3 changed files with 43 additions and 12 deletions

View File

@ -85,10 +85,10 @@ RifCsvUserDataParser::~RifCsvUserDataParser()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifCsvUserDataParser::parse( const AsciiDataParseOptions& parseOptions )
bool RifCsvUserDataParser::parse( const AsciiDataParseOptions& parseOptions, const std::map<QString, std::pair<QString, double>>& unitMapping )
{
if ( determineCsvLayout() == LineBased ) return parseLineBasedData();
return parseColumnBasedData( parseOptions );
return parseColumnBasedData( parseOptions, unitMapping );
}
//--------------------------------------------------------------------------------------------------
@ -302,7 +302,10 @@ RifCsvUserDataParser::CsvLayout RifCsvUserDataParser::determineCsvLayout()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const AsciiDataParseOptions& parseOptions, std::vector<Column>* columnInfoList )
bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream,
const AsciiDataParseOptions& parseOptions,
std::vector<Column>* columnInfoList,
const std::map<QString, std::pair<QString, double>>& unitMapping )
{
bool headerFound = false;
@ -413,7 +416,17 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
else if ( parseOptions.defaultCategory == RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_FIELD )
addr = RifEclipseSummaryAddress::fieldAddress( colName.toStdString() );
Column col = Column::createColumnInfoFromCsvData( addr, unit.toStdString() );
double scaleFactor = 1.0;
if ( !unit.isEmpty() )
{
if ( auto it = unitMapping.find( unit ); it != unitMapping.end() )
{
std::tie( unit, scaleFactor ) = it->second;
}
}
Column col = Column::createColumnInfoFromCsvData( addr, unit.toStdString() );
col.scaleFactor = scaleFactor;
columnInfoList->push_back( col );
}
@ -426,7 +439,8 @@ bool RifCsvUserDataParser::parseColumnInfo( QTextStream* dataStream, const Ascii
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& parseOptions )
bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& parseOptions,
const std::map<QString, std::pair<QString, double>>& unitMapping )
{
bool errors = false;
enum
@ -440,7 +454,7 @@ bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& pa
QTextStream* dataStream = openDataStream();
// Parse header
if ( !parseColumnInfo( dataStream, parseOptions, &columnInfoList ) )
if ( !parseColumnInfo( dataStream, parseOptions, &columnInfoList, unitMapping ) )
{
if ( m_errorText ) m_errorText->append( "CSV import: Failed to parse header columns" );
return false;
@ -521,7 +535,7 @@ bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& pa
// Add nullptr value
value = HUGE_VAL;
}
col.values.push_back( value );
col.values.push_back( value * col.scaleFactor );
}
else if ( col.dataType == Column::TEXT )
{

View File

@ -50,7 +50,7 @@ public:
RifCsvUserDataParser( QString* errorText = nullptr );
virtual ~RifCsvUserDataParser();
bool parse( const AsciiDataParseOptions& parseOptions );
bool parse( const AsciiDataParseOptions& parseOptions, const std::map<QString, std::pair<QString, double>>& unitMapping = {} );
const TableData& tableData() const;
const Column* columnInfo( size_t columnIndex ) const;
@ -74,9 +74,13 @@ protected:
private:
std::vector<int> parseLineBasedHeader( QStringList headerCols );
bool parseColumnInfo( QTextStream* dataStream, const AsciiDataParseOptions& parseOptions, std::vector<Column>* columnInfoList );
bool parseColumnBasedData( const AsciiDataParseOptions& parseOptions );
bool parseLineBasedData();
bool parseColumnInfo( QTextStream* dataStream,
const AsciiDataParseOptions& parseOptions,
std::vector<Column>* columnInfoList,
const std::map<QString, std::pair<QString, double>>& unitMapping = {} );
bool parseColumnBasedData( const AsciiDataParseOptions& parseOptions,
const std::map<QString, std::pair<QString, double>>& unitMapping = {} );
bool parseLineBasedData();
static QDateTime tryParseDateTime( const std::string& colData, const QString& format );
private:

View File

@ -66,7 +66,20 @@ bool RifRevealCsvSectionSummaryReader::parse( const QString& text, RifEclipseSum
parseOptions.defaultCategory = defaultCategory;
m_parser = std::unique_ptr<RifCsvUserDataPastedTextParser>( new RifCsvUserDataPastedTextParser( text, errorText ) );
if ( !m_parser->parse( parseOptions ) )
std::map<QString, std::pair<QString, double>> unitMapping = { { "Sm3", { "SM3", 1.0 } },
{ "Sm3/day", { "SM3/DAY", 1.0 } },
{ "Sm3/day/bar", { "SM3/DAY/BAR", 1.0 } },
{ "Sm3/Sm3", { "SM3/SM3", 1.0 } },
{ "rm3", { "RM3", 1.0 } },
{ "rm3/day", { "RM3/DAY", 1.0 } },
{ "rm3/day/bar", { "RM3/DAY/BAR", 1.0 } },
{ "Rm3/day/bar", { "RM3/DAY/BAR", 1.0 } },
{ "BARa", { "BARSA", 1.0 } },
{ "fraction", { "", 1.0 } },
{ "1000Sm3/d", { "SM3/DAY", 1000.0 } },
{ "MSm3", { "SM3", 1000000.0 } } };
if ( !m_parser->parse( parseOptions, unitMapping ) )
{
RiaLogging::error( QString( "Failed to parse file" ) );
return false;