From a59c8d0a3fe6153749fd9868e8f7f511fb18f39c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 8 Aug 2025 09:57:25 +0200 Subject: [PATCH] #12722 Fix grouping of files and detection of realization number * Detect single ensemble for Everest file grouping * Enhance realization number extraction to support underscore separator --- .../Tools/RiaEnsembleNameTools.cpp | 7 +++++++ .../FileInterface/RifOpmSummaryTools.cpp | 5 +++-- ...ifCaseRealizationParametersReader-Test.cpp | 19 ++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ApplicationLibCode/Application/Tools/RiaEnsembleNameTools.cpp b/ApplicationLibCode/Application/Tools/RiaEnsembleNameTools.cpp index 6262e93eb9..e2084c2dc7 100644 --- a/ApplicationLibCode/Application/Tools/RiaEnsembleNameTools.cpp +++ b/ApplicationLibCode/Application/Tools/RiaEnsembleNameTools.cpp @@ -122,6 +122,13 @@ std::map, std::vector> auto commonFolder = internal::findLastCommonFolder( normalizedPaths ); + if ( RiaStdStringTools::toUpper( commonFolder ).contains( "BATCH" ) ) + { + // If the common folder is "BATCH", we assume all files are in the same ensemble and group them under the common folder name + groupedPaths[{ commonFolder, commonFolder }] = filepaths; + return groupedPaths; + } + for ( const auto& filepath : normalizedPaths ) { auto rest = filepath.substr( commonPrefix.size() ); diff --git a/ApplicationLibCode/FileInterface/RifOpmSummaryTools.cpp b/ApplicationLibCode/FileInterface/RifOpmSummaryTools.cpp index cdf87c5e4b..936cde5c82 100644 --- a/ApplicationLibCode/FileInterface/RifOpmSummaryTools.cpp +++ b/ApplicationLibCode/FileInterface/RifOpmSummaryTools.cpp @@ -221,9 +221,10 @@ bool RifOpmSummaryTools::isEsmryConversionRequired( const QString& fileName ) //-------------------------------------------------------------------------------------------------- std::expected RifOpmSummaryTools::extractRealizationNumber( const QString& path ) { - QRegularExpression pattern( "realization-(\\d+)", QRegularExpression::CaseInsensitiveOption ); - QRegularExpressionMatch match = pattern.match( path ); + // Regular expression to match realization number in the format "realization-" or "realization_" + QRegularExpression pattern( "realization[-_](\\d+)", QRegularExpression::CaseInsensitiveOption ); + QRegularExpressionMatch match = pattern.match( path ); if ( match.hasMatch() ) { bool ok; diff --git a/ApplicationLibCode/UnitTests/RifCaseRealizationParametersReader-Test.cpp b/ApplicationLibCode/UnitTests/RifCaseRealizationParametersReader-Test.cpp index 9eb7dd1fe7..39f92d02dc 100644 --- a/ApplicationLibCode/UnitTests/RifCaseRealizationParametersReader-Test.cpp +++ b/ApplicationLibCode/UnitTests/RifCaseRealizationParametersReader-Test.cpp @@ -100,10 +100,19 @@ TEST( RifCaseRealizationParametersReaderTest, SuccessfulParsing ) //-------------------------------------------------------------------------------------------------- TEST( RifCaseRealizationParametersReaderTest, FindRealizationNumber ) { - QString filePath = "d:/gitroot-ceesol/ResInsight-regression-test/ModelData/ensemble_reek_with_params/realization-" - "7/iter-0/eclipse/model/3_R001_REEK-7.SMSPEC"; + { + QString filePath = "d:/gitroot-ceesol/ResInsight-regression-test/ModelData/ensemble_reek_with_params/realization-" + "7/iter-0/eclipse/model/3_R001_REEK-7.SMSPEC"; - auto realisationNumber = RifOpmSummaryTools::extractRealizationNumber( filePath ); - EXPECT_TRUE( realisationNumber.has_value() ); - EXPECT_EQ( 7, realisationNumber.value() ); + auto realisationNumber = RifOpmSummaryTools::extractRealizationNumber( filePath ); + EXPECT_TRUE( realisationNumber.has_value() ); + EXPECT_EQ( 7, realisationNumber.value() ); + } + { + QString filePath = "f:/Models/scratch/my_case/batch_1/geo_realization_2/simulation_2/eclipse/model/PROJECT-0.SMSPEC"; + + auto realisationNumber = RifOpmSummaryTools::extractRealizationNumber( filePath ); + EXPECT_TRUE( realisationNumber.has_value() ); + EXPECT_EQ( 2, realisationNumber.value() ); + } }