Skip to content

Commit

Permalink
#9773: import StimPlan time series data.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Mar 15, 2023
1 parent 57df7f7 commit eba9368
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 11 deletions.
2 changes: 2 additions & 0 deletions ApplicationLibCode/Commands/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicImportPressureDepthDataFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicReloadPressureDepthDataFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportRevealSummaryCaseFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportStimPlanSummaryCaseFeature.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -177,6 +178,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicImportPressureDepthDataFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicReloadPressureDepthDataFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportRevealSummaryCaseFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportStimPlanSummaryCaseFeature.cpp
)

if(RESINSIGHT_USE_QT_CHARTS)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicImportStimPlanSummaryCaseFeature.h"

#include "RiaApplication.h"

#include "RimCsvSummaryCase.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryCaseMainCollection.h"

#include "RiuFileDialogTools.h"

#include <QAction>

CAF_CMD_SOURCE_INIT( RicImportStimPlanSummaryCaseFeature, "RicImportStimPlanSummaryCaseFeature" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportStimPlanSummaryCaseFeature::isCommandEnabled()
{
return true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportStimPlanSummaryCaseFeature::onActionTriggered( bool isChecked )
{
RiaApplication* app = RiaApplication::instance();
RimProject* project = app->project();

RimSummaryCaseMainCollection* sumCaseColl = project->activeOilField() ? project->activeOilField()->summaryCaseMainCollection() : nullptr;
if ( !sumCaseColl ) return;

QString pattern = "StimPlan Summary Files (*.csv)";
QString defaultDir = app->lastUsedDialogDirectory( "SUMMARY_CASE_DIR" );
QStringList filePaths = RiuFileDialogTools::getOpenFileNames( nullptr, "Import Data File", defaultDir, pattern );
for ( const QString& filePath : filePaths )
{
auto newSumCase = new RimCsvSummaryCase();
newSumCase->setFileType( RimCsvSummaryCase::FileType::STIMPLAN );
newSumCase->setSummaryHeaderFileName( filePath );
newSumCase->updateOptionSensitivity();
project->assignCaseIdToSummaryCase( newSumCase );

sumCaseColl->addCase( newSumCase );
}

sumCaseColl->loadAllSummaryCaseData();
sumCaseColl->updateConnectedEditors();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportStimPlanSummaryCaseFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/SummaryCase.svg" ) );
actionToSetup->setText( "Import StimPlan Summary Case" );
}
34 changes: 34 additions & 0 deletions ApplicationLibCode/Commands/RicImportStimPlanSummaryCaseFeature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafCmdFeature.h"

//==================================================================================================
///
//==================================================================================================
class RicImportStimPlanSummaryCaseFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;

protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class AsciiDataParseOptions
QString cellSeparator;
QString timeSeriesColumnName;

bool assumeNumericDataColumns;
QDateTime startDateTime;
bool assumeNumericDataColumns;

RifEclipseSummaryAddress::SummaryVarCategory defaultCategory;

Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/FileInterface/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RifCsvSummaryReader.h
${CMAKE_CURRENT_LIST_DIR}/RifRevealSummaryCsvReader.h
${CMAKE_CURRENT_LIST_DIR}/RifRevealCsvSectionSummaryReader.h
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanCsvSummaryReader.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -163,6 +164,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RifCsvSummaryReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifRevealCsvSummaryReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifRevealCsvSectionSummaryReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanCsvSummaryReader.cpp
)

list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
Expand Down
17 changes: 15 additions & 2 deletions ApplicationLibCode/FileInterface/RifCsvUserDataParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,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() )
Expand Down Expand Up @@ -539,6 +541,12 @@ bool RifCsvUserDataParser::parseColumnBasedData( const AsciiDataParseOptions& pa
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() )
{
if ( m_errorText ) m_errorText->append( "CSV import: Failed to parse date time value" );
Expand Down Expand Up @@ -571,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;

Expand Down
77 changes: 77 additions & 0 deletions ApplicationLibCode/FileInterface/RifStimPlanCsvSummaryReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RifStimPlanCsvSummaryReader.h"

#include "RiaDateStringParser.h"
#include "RiaLogging.h"
#include "RiaQDateTimeTools.h"

#include "RifCsvUserDataParser.h"
#include "RifEclipseUserDataKeywordTools.h"
#include "RifEclipseUserDataParserTools.h"

#include "SummaryPlotCommands/RicPasteAsciiDataToSummaryPlotFeatureUi.h"

#include "cafUtils.h"

#include <QDateTime>
#include <QFile>
#include <QTextStream>

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifStimPlanCsvSummaryReader::RifStimPlanCsvSummaryReader()
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifStimPlanCsvSummaryReader::~RifStimPlanCsvSummaryReader()
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifStimPlanCsvSummaryReader::parse( const QString& fileName, const QDateTime& startDateTime, QString* errorText )
{
m_allResultAddresses.clear();
m_mapFromAddressToResultIndex.clear();

AsciiDataParseOptions parseOptions;
parseOptions.useCustomDateTimeFormat = true;
parseOptions.dateTimeFormat = "m.zzz";
parseOptions.cellSeparator = ",";
parseOptions.decimalSeparator = ".";
parseOptions.timeSeriesColumnName = "Time";
parseOptions.startDateTime = startDateTime;

m_parser = std::unique_ptr<RifCsvUserDataFileParser>( new RifCsvUserDataFileParser( fileName, errorText ) );
if ( !m_parser->parse( parseOptions ) )
{
RiaLogging::error( QString( "Failed to parse file" ) );
return false;
}

buildTimeStepsAndMappings();

return true;
}
39 changes: 39 additions & 0 deletions ApplicationLibCode/FileInterface/RifStimPlanCsvSummaryReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RifCsvSummaryReader.h"

class QString;

class RifCsvUserDataParser;
class RifEclipseSummaryAddress;

//==================================================================================================
//
//
//==================================================================================================
class RifStimPlanCsvSummaryReader : public RifCsvSummaryReader
{
public:
RifStimPlanCsvSummaryReader();
~RifStimPlanCsvSummaryReader() override;

bool parse( const QString& fileName, const QDateTime& startDateTime, QString* errorText = nullptr );
};
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
{
menuBuilder << "RicImportSummaryCaseFeature";
menuBuilder << "RicImportRevealSummaryCaseFeature";
menuBuilder << "RicImportStimPlanSummaryCaseFeature";
menuBuilder << "RicImportSummaryCasesFeature";
menuBuilder << "RicImportSummaryGroupFeature";
menuBuilder << "RicImportEnsembleFeature";
Expand Down
Loading

0 comments on commit eba9368

Please sign in to comment.