-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9773 Add summary reader for Reveal csv data.
- Loading branch information
Showing
11 changed files
with
1,266 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
ApplicationLibCode/FileInterface/RifRevealCsvSectionSummaryReader.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2023- Equinor 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 "RifRevealCsvSectionSummaryReader.h" | ||
|
||
#include "RiaDateStringParser.h" | ||
#include "RiaLogging.h" | ||
#include "RiaQDateTimeTools.h" | ||
|
||
#include "RifCsvUserDataParser.h" | ||
#include "RifEclipseUserDataKeywordTools.h" | ||
#include "RifEclipseUserDataParserTools.h" | ||
|
||
#include "cafUtils.h" | ||
|
||
#include <QDateTime> | ||
#include <QFile> | ||
#include <QTextStream> | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
RifRevealCsvSectionSummaryReader::RifRevealCsvSectionSummaryReader() | ||
{ | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
RifRevealCsvSectionSummaryReader::~RifRevealCsvSectionSummaryReader() | ||
{ | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RifRevealCsvSectionSummaryReader::parse( const QString& text, QString* errorText ) | ||
{ | ||
m_allResultAddresses.clear(); | ||
m_mapFromAddressToResultIndex.clear(); | ||
|
||
AsciiDataParseOptions parseOptions; | ||
parseOptions.useCustomDateTimeFormat = true; | ||
parseOptions.dateTimeFormat = "dd.MM.yyyy hh:mm:ss"; | ||
parseOptions.fallbackDateTimeFormat = "dd.MM.yyyy"; | ||
parseOptions.cellSeparator = ","; | ||
parseOptions.decimalSeparator = "."; | ||
parseOptions.timeSeriesColumnName = "Date"; | ||
|
||
m_parser = std::unique_ptr<RifCsvUserDataPastedTextParser>( new RifCsvUserDataPastedTextParser( text, errorText ) ); | ||
if ( !m_parser->parse( parseOptions ) ) | ||
{ | ||
RiaLogging::error( QString( "Failed to parse file" ) ); | ||
return false; | ||
} | ||
|
||
buildTimeStepsAndMappings(); | ||
|
||
return true; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RifRevealCsvSectionSummaryReader::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const | ||
{ | ||
auto search = m_mapFromAddressToResultIndex.find( resultAddress ); | ||
if ( search != m_mapFromAddressToResultIndex.end() ) | ||
{ | ||
size_t columnIndex = search->second; | ||
|
||
const Column* ci = m_parser->columnInfo( columnIndex ); | ||
if ( !ci ) return false; | ||
|
||
values->clear(); | ||
values->reserve( ci->values.size() ); | ||
for ( double val : ci->values ) | ||
{ | ||
values->push_back( val ); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
std::vector<time_t> RifRevealCsvSectionSummaryReader::timeSteps( const RifEclipseSummaryAddress& resultAddress ) const | ||
{ | ||
// First, check whether date time values exist for the current address | ||
auto search = m_mapFromAddressToResultIndex.find( resultAddress ); | ||
if ( search != m_mapFromAddressToResultIndex.end() ) | ||
{ | ||
size_t index = m_mapFromAddressToResultIndex.at( resultAddress ); | ||
if ( !m_parser->tableData().columnInfos()[index].dateTimeValues.empty() ) | ||
{ | ||
return m_parser->tableData().columnInfos()[index].dateTimeValues; | ||
} | ||
} | ||
|
||
// Then check for a separate date time column | ||
int index = m_parser->tableData().dateTimeColumnIndex(); | ||
if ( index >= 0 ) | ||
{ | ||
return m_parser->tableData().columnInfos()[index].dateTimeValues; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
std::string RifRevealCsvSectionSummaryReader::unitName( const RifEclipseSummaryAddress& resultAddress ) const | ||
{ | ||
auto search = m_mapFromAddressToResultIndex.find( resultAddress ); | ||
if ( search != m_mapFromAddressToResultIndex.end() ) | ||
{ | ||
size_t columnIndex = search->second; | ||
|
||
const Column* ci = m_parser->columnInfo( columnIndex ); | ||
if ( ci ) | ||
{ | ||
return ci->unitName; | ||
} | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
RiaDefines::EclipseUnitSystem RifRevealCsvSectionSummaryReader::unitSystem() const | ||
{ | ||
return RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
void RifRevealCsvSectionSummaryReader::buildTimeStepsAndMappings() | ||
{ | ||
auto tableData = m_parser->tableData(); | ||
|
||
for ( size_t columnIndex = 0; columnIndex < tableData.columnInfos().size(); columnIndex++ ) | ||
{ | ||
const Column& ci = tableData.columnInfos()[columnIndex]; | ||
if ( ci.dataType == Column::NUMERIC ) | ||
{ | ||
RifEclipseSummaryAddress sumAddress = ci.summaryAddress; | ||
|
||
m_allResultAddresses.insert( sumAddress ); | ||
if ( sumAddress.isErrorResult() ) m_allErrorAddresses.insert( sumAddress ); | ||
|
||
m_mapFromAddressToResultIndex[sumAddress] = columnIndex; | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
ApplicationLibCode/FileInterface/RifRevealCsvSectionSummaryReader.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2023- Equinor 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 "RifSummaryReaderInterface.h" | ||
|
||
#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h" | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <vector> | ||
|
||
class QString; | ||
|
||
class RifCsvUserDataParser; | ||
class RifEclipseSummaryAddress; | ||
|
||
//================================================================================================== | ||
// | ||
// | ||
//================================================================================================== | ||
class RifRevealCsvSectionSummaryReader : public RifSummaryReaderInterface | ||
{ | ||
public: | ||
RifRevealCsvSectionSummaryReader(); | ||
~RifRevealCsvSectionSummaryReader() override; | ||
|
||
bool parse( const QString& fileName, QString* errorText = nullptr ); | ||
|
||
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override; | ||
|
||
bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override; | ||
|
||
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override; | ||
|
||
RiaDefines::EclipseUnitSystem unitSystem() const override; | ||
|
||
private: | ||
void buildTimeStepsAndMappings(); | ||
|
||
private: | ||
std::unique_ptr<RifCsvUserDataParser> m_parser; | ||
|
||
std::map<RifEclipseSummaryAddress, size_t> m_mapFromAddressToResultIndex; | ||
}; |
75 changes: 75 additions & 0 deletions
75
ApplicationLibCode/FileInterface/RifRevealCsvSummaryReader.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2023- Equinor 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 "RifRevealCsvSummaryReader.h" | ||
|
||
#include "RifCsvUserDataParser.h" | ||
#include "RifRevealCsvSectionSummaryReader.h" | ||
|
||
#include <QFile> | ||
#include <QTextStream> | ||
#include <Qt> | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
RifRevealCsvSummaryReader::RifRevealCsvSummaryReader() | ||
{ | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
RifRevealCsvSummaryReader::~RifRevealCsvSummaryReader() | ||
{ | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RifRevealCsvSummaryReader::parse( const QString& fileName, QString* errorText ) | ||
{ | ||
QFile file( fileName ); | ||
|
||
if ( !file.open( QFile::ReadOnly | QFile::Text ) ) return false; | ||
|
||
QTextStream in( &file ); | ||
|
||
// Skip first line | ||
in.readLine(); | ||
|
||
// Split files on strange header line (starts with ",Date"). | ||
QString fileContents = in.readAll(); | ||
QStringList parts = fileContents.split( ",Date", QString::SkipEmptyParts ); | ||
|
||
// Parse each section separately | ||
for ( auto p : parts ) | ||
{ | ||
p.prepend( "Name,Date" ); | ||
cvf::ref<RifRevealCsvSectionSummaryReader> sectionReader = new RifRevealCsvSectionSummaryReader; | ||
|
||
addReader( sectionReader.p() ); | ||
QString errorMessage; | ||
if ( !sectionReader->parse( p, &errorMessage ) ) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
36 changes: 36 additions & 0 deletions
36
ApplicationLibCode/FileInterface/RifRevealCsvSummaryReader.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2023- Equinor 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 "RifMultipleSummaryReaders.h" | ||
|
||
class QString; | ||
|
||
//================================================================================================== | ||
// | ||
// | ||
//================================================================================================== | ||
class RifRevealCsvSummaryReader : public RifMultipleSummaryReaders | ||
{ | ||
public: | ||
RifRevealCsvSummaryReader(); | ||
~RifRevealCsvSummaryReader() override; | ||
|
||
bool parse( const QString& fileName, QString* errorText = nullptr ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.