#14772 Forward computeCaseGroupStatistics to RimcEclipseStatisticsCase_computeStatistics

Add an UpdateViews parameter to the existing object method. The legacy
command calls computeStatisticsAndUpdateViews() (which also creates a
view if none exists) while the object method only computes; the default
(false) keeps the object method behavior and the Ricf forwarder passes
true. RicfComputeCaseGroupStatistics resolves the statistics cases and
loops over them.

GridCaseGroup.compute_statistics(case_ids=...) in Python now loops over
statistics_cases() and emits a DeprecationWarning.
This commit is contained in:
Kristian Bendiksen committed 2026-09-22 14:19:23 +02:00
1 parent 111741b365
commit 1eabb5f5f6
4 files changed
+78 -56

No files matched your search

@@ -18,19 +18,18 @@
#include "RicfComputeCaseGroupStatistics.h"
#include "Rim3dView.h"
#include "RimCaseCollection.h"
#include "RimEclipseCase.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseStatisticsCase.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RiaLogging.h"
#include "RicfCommandForwarding.h"
#include "RimEclipseStatisticsCase.h"
#include "RimProject.h"
#include "RimcEclipseStatisticsCase.h"
#include "cafPdmFieldScriptingCapability.h"
#include <algorithm>
CAF_PDM_SOURCE_INIT( RicfComputeCaseGroupStatistics, "computeCaseGroupStatistics" );
//--------------------------------------------------------------------------------------------------
@@ -47,58 +46,46 @@ RicfComputeCaseGroupStatistics::RicfComputeCaseGroupStatistics()
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicfComputeCaseGroupStatistics::execute()
{
const QString commandName = classKeyword();
caf::PdmScriptResponse response;
std::vector<int> caseIds = m_caseIds.v();
// Collect the statistics cases: explicit case ids, plus all statistics cases when a group id is given.
// Note: legacy behavior is to include statistics cases from all groups when caseGroupId >= 0.
std::vector<RimEclipseStatisticsCase*> statsCases;
for ( int caseId : m_caseIds() )
{
auto statsCase = RicfForwarding::findStatisticsCase( caseId );
if ( !statsCase )
{
QString warning = QString( "%1: %2" ).arg( commandName ).arg( statsCase.error() );
RiaLogging::warning( warning.toStdString() );
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warning );
continue;
}
statsCases.push_back( statsCase.value() );
}
if ( m_groupId() >= 0 )
{
for ( RimIdenticalGridCaseGroup* group : RimProject::current()->activeOilField()->analysisModels()->caseGroups )
for ( RimEclipseStatisticsCase* statsCase : RimProject::current()->descendantsIncludingThisOfType<RimEclipseStatisticsCase>() )
{
for ( RimEclipseCase* c : group->statisticsCaseCollection()->reservoirs )
if ( statsCase && std::find( statsCases.begin(), statsCases.end(), statsCase ) == statsCases.end() )
{
caseIds.push_back( c->caseId() );
statsCases.push_back( statsCase );
}
}
}
for ( int caseId : caseIds )
for ( RimEclipseStatisticsCase* statsCase : statsCases )
{
bool foundCase = false;
for ( RimIdenticalGridCaseGroup* group : RimProject::current()->activeOilField()->analysisModels()->caseGroups )
{
for ( RimEclipseCase* c : group->statisticsCaseCollection()->reservoirs )
{
if ( c->caseId() == caseId )
{
RimEclipseStatisticsCase* statsCase = dynamic_cast<RimEclipseStatisticsCase*>( c );
if ( statsCase )
{
statsCase->computeStatisticsAndUpdateViews();
}
else
{
QString warning = QString( "computeCaseGroupStatistics: Found case with ID %1, but it is not a "
"statistics case, cannot compute statistics." )
.arg( caseId );
RiaLogging::warning( warning.toStdString() );
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warning );
}
foundCase = true;
break;
}
}
RimcEclipseStatisticsCase_computeStatistics method( statsCase );
method.setUpdateViews( true );
if ( foundCase ) break;
}
if ( !foundCase )
{
QString warning = QString( "computeCaseGroupStatistics: Could not find statistics case with ID %1." ).arg( caseId );
RiaLogging::warning( warning.toStdString() );
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warning );
}
auto result = method.execute();
if ( !result ) return RicfForwarding::errorResponse( result.error(), commandName );
}
return response;
}
@@ -70,6 +70,23 @@ CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseStatisticsCase, RimcEclipseStatisti
RimcEclipseStatisticsCase_computeStatistics::RimcEclipseStatisticsCase_computeStatistics( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Compute Statistics", "", "", "Compute statistics for the selected source properties" );
CAF_PDM_InitScriptableField( &m_updateViews,
"UpdateViews",
false,
"Update Views",
"",
"",
"Update the 3D views of the case after computing, and create a view if none exists" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimcEclipseStatisticsCase_computeStatistics::setUpdateViews( bool updateViews )
{
m_updateViews = updateViews;
}
//--------------------------------------------------------------------------------------------------
@@ -78,7 +95,16 @@ RimcEclipseStatisticsCase_computeStatistics::RimcEclipseStatisticsCase_computeSt
std::expected<caf::PdmObjectHandle*, QString> RimcEclipseStatisticsCase_computeStatistics::execute()
{
auto eclipseCase = self<RimEclipseStatisticsCase>();
eclipseCase->computeStatistics();
if ( !eclipseCase ) return std::unexpected( "No statistics case is available." );
if ( m_updateViews() )
{
eclipseCase->computeStatisticsAndUpdateViews();
}
else
{
eclipseCase->computeStatistics();
}
return nullptr;
}
@@ -53,7 +53,12 @@ class RimcEclipseStatisticsCase_computeStatistics : public caf::PdmVoidObjectMet
public:
RimcEclipseStatisticsCase_computeStatistics( caf::PdmObjectHandle* self );
void setUpdateViews( bool updateViews );
std::expected<caf::PdmObjectHandle*, QString> execute() override;
private:
caf::PdmField<bool> m_updateViews;
};
//==================================================================================================
+11 -7
View File
@@ -6,7 +6,7 @@ from .pdmobject import add_method
from .view import View as View
from .case import Case as Case
import Commands_pb2
import warnings
from .resinsight_classes import GridCaseGroup
from .resinsight_classes import EclipseView
from .resinsight_classes import RimStatisticalCalculation
@@ -60,14 +60,18 @@ def view(self, view_id):
def compute_statistics(self, case_ids=None):
"""Compute statistics for the given case ids
Deprecated: use RimStatisticalCalculation.compute_statistics(update_views=True) on each
statistics case (see statistics_cases()) instead.
Arguments:
case_ids(list of integers): List of case ids. If this is None all cases in group are included
"""
if case_ids is None:
case_ids = []
return self._execute_command(
computeCaseGroupStatistics=Commands_pb2.ComputeCaseGroupStatRequest(
caseIds=case_ids, caseGroupId=self.group_id
)
warnings.warn(
"GridCaseGroup.compute_statistics() is deprecated, use compute_statistics() on each statistics case instead",
DeprecationWarning,
stacklevel=3,
)
for statistics_case in self.statistics_cases():
if case_ids is None or statistics_case.id in case_ids:
statistics_case.compute_statistics(update_views=True)