mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#8048 Everest Import: Group into separate ensembles
This commit is contained in:
@@ -19,17 +19,52 @@
|
||||
#include "RiaEnsembleNameTools.h"
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
#include "RimCaseDisplayNameTools.h"
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QRegularExpression>
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaEnsembleNameTools::EnsembleGroupingMode>::setUp()
|
||||
{
|
||||
addItem( RiaEnsembleNameTools::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE, "FMU_FOLDER_MODE", "FMU Folder Structure" );
|
||||
addItem( RiaEnsembleNameTools::EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE,
|
||||
"EVEREST_FOLDER_MODE",
|
||||
"Everest Folder Structure" );
|
||||
addItem( RiaEnsembleNameTools::EnsembleGroupingMode::NONE, "None", "None" );
|
||||
setDefault( RiaEnsembleNameTools::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEnsembleNameTools::findSuitableEnsembleName( const QStringList& fileNames )
|
||||
QString RiaEnsembleNameTools::findSuitableEnsembleName( const QStringList& fileNames, EnsembleGroupingMode folderLevel )
|
||||
{
|
||||
QStringList iterations = findUniqueIterations( fileNames );
|
||||
if ( folderLevel == EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE )
|
||||
{
|
||||
QString commonRoot = RiaTextStringTools::commonRoot( fileNames );
|
||||
commonRoot = commonRoot.left( commonRoot.lastIndexOf( '/' ) );
|
||||
QStringList rootComponents = RiaFilePathTools::splitPathIntoComponents( commonRoot );
|
||||
|
||||
if ( !rootComponents.empty() )
|
||||
{
|
||||
return rootComponents.back();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<QStringList> componentsForAllFilePaths;
|
||||
|
||||
for ( const auto& filePath : fileNames )
|
||||
{
|
||||
QStringList components = RiaFilePathTools::splitPathIntoComponents( filePath );
|
||||
componentsForAllFilePaths.push_back( components );
|
||||
}
|
||||
|
||||
QStringList iterations = findUniqueEnsembleNames( fileNames, componentsForAllFilePaths, folderLevel );
|
||||
if ( iterations.size() == 1u )
|
||||
{
|
||||
return iterations.front();
|
||||
@@ -55,9 +90,18 @@ QString RiaEnsembleNameTools::findSuitableEnsembleName( const QStringList& fileN
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QStringList> RiaEnsembleNameTools::groupFilesByEnsemble( const QStringList& fileNames )
|
||||
std::vector<QStringList> RiaEnsembleNameTools::groupFilesByEnsemble( const QStringList& fileNames,
|
||||
EnsembleGroupingMode groupingMode )
|
||||
{
|
||||
QStringList iterations = findUniqueIterations( fileNames );
|
||||
std::vector<QStringList> componentsForAllFilePaths;
|
||||
|
||||
for ( const auto& filePath : fileNames )
|
||||
{
|
||||
QStringList components = RiaFilePathTools::splitPathIntoComponents( filePath );
|
||||
componentsForAllFilePaths.push_back( components );
|
||||
}
|
||||
|
||||
QStringList iterations = findUniqueEnsembleNames( fileNames, componentsForAllFilePaths, groupingMode );
|
||||
if ( iterations.size() <= 1 )
|
||||
{
|
||||
// All the files are in the same ensemble
|
||||
@@ -65,14 +109,22 @@ std::vector<QStringList> RiaEnsembleNameTools::groupFilesByEnsemble( const QStri
|
||||
}
|
||||
|
||||
std::vector<QStringList> groupedByIteration;
|
||||
for ( auto iteration : iterations )
|
||||
for ( const auto& iteration : iterations )
|
||||
{
|
||||
QStringList fileNamesFromIteration;
|
||||
for ( auto filePath : fileNames )
|
||||
|
||||
for ( int i = 0; i < fileNames.size(); i++ )
|
||||
{
|
||||
if ( filePath.contains( iteration ) )
|
||||
auto components = componentsForAllFilePaths[i];
|
||||
bool foundMatch = false;
|
||||
for ( const auto& component : components )
|
||||
{
|
||||
fileNamesFromIteration << filePath;
|
||||
if ( component == iteration ) foundMatch = true;
|
||||
}
|
||||
|
||||
if ( foundMatch )
|
||||
{
|
||||
fileNamesFromIteration << fileNames[i];
|
||||
}
|
||||
}
|
||||
groupedByIteration.push_back( fileNamesFromIteration );
|
||||
@@ -84,30 +136,58 @@ std::vector<QStringList> RiaEnsembleNameTools::groupFilesByEnsemble( const QStri
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RiaEnsembleNameTools::findUniqueIterations( const QStringList& fileNames )
|
||||
QStringList RiaEnsembleNameTools::findUniqueEnsembleNames( const QStringList& fileNames,
|
||||
const std::vector<QStringList>& fileNameComponents,
|
||||
EnsembleGroupingMode groupingMode )
|
||||
{
|
||||
std::vector<QStringList> componentsForAllFilePaths;
|
||||
|
||||
for ( const auto& filePath : fileNames )
|
||||
{
|
||||
QStringList components = RiaFilePathTools::splitPathIntoComponents( filePath );
|
||||
componentsForAllFilePaths.push_back( components );
|
||||
}
|
||||
|
||||
// Find list of all folders inside a folder matching realization-*
|
||||
QRegularExpression realizationRe( "realization\\-\\d+" );
|
||||
|
||||
QStringList iterations;
|
||||
for ( const auto& fileComponents : componentsForAllFilePaths )
|
||||
if ( groupingMode == EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE )
|
||||
{
|
||||
QString lastComponent = "";
|
||||
for ( auto it = fileComponents.rbegin(); it != fileComponents.rend(); ++it )
|
||||
QString commonRoot = RiaTextStringTools::commonRoot( fileNames );
|
||||
QStringList rootComponents = RiaFilePathTools::splitPathIntoComponents( commonRoot );
|
||||
auto commonComponentCount = rootComponents.size();
|
||||
|
||||
// Example:
|
||||
// /myPath/batch_01/realization-1/....
|
||||
// /myPath/batch_01/realization-2/....
|
||||
// /myPath/batch_01/realization-N/....
|
||||
// /myPath/batch_02/realization-1/....
|
||||
// /myPath/batch_02/realization-2/....
|
||||
// /myPath/batch_02/realization-N/....
|
||||
|
||||
// commonRoot will return /myPath/batch_
|
||||
// ensembleNameSet will contain [batch_01, batch_02]
|
||||
|
||||
std::set<QString> ensembleNameSet;
|
||||
for ( const auto& componentsForFile : fileNameComponents )
|
||||
{
|
||||
if ( realizationRe.match( *it ).hasMatch() )
|
||||
if ( commonComponentCount - 1 < componentsForFile.size() )
|
||||
{
|
||||
iterations.push_back( lastComponent );
|
||||
ensembleNameSet.insert( componentsForFile[commonComponentCount - 1] );
|
||||
}
|
||||
}
|
||||
|
||||
for ( const auto& ensembleName : ensembleNameSet )
|
||||
{
|
||||
iterations.push_back( ensembleName );
|
||||
}
|
||||
}
|
||||
else if ( groupingMode == EnsembleGroupingMode::FMU_FOLDER_STRUCTURE )
|
||||
{
|
||||
// Find list of all folders inside a folder matching realization-*
|
||||
QRegularExpression realizationRe( "realization\\-\\d+" );
|
||||
|
||||
for ( const auto& fileComponents : fileNameComponents )
|
||||
{
|
||||
QString lastComponent = "";
|
||||
for ( auto it = fileComponents.rbegin(); it != fileComponents.rend(); ++it )
|
||||
{
|
||||
if ( realizationRe.match( *it ).hasMatch() )
|
||||
{
|
||||
iterations.push_back( lastComponent );
|
||||
}
|
||||
lastComponent = *it;
|
||||
}
|
||||
lastComponent = *it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user