2026-08-20 11:48:25 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2024- 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 "RiaSumoExplore.h"
|
|
|
|
|
|
|
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
#include "RiaQStringFormatter.h"
|
|
|
|
|
#include "RiaSumoConnector.h"
|
|
|
|
|
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RiaSumoExplore::RiaSumoExplore( RiaSumoConnector& connector )
|
|
|
|
|
: m_connector( connector )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<SumoAsset> RiaSumoExplore::assets()
|
|
|
|
|
{
|
2026-09-10 10:33:58 +02:00
|
|
|
return parseAssets( m_connector.getBlocking( "/assets", "Loading assets from Sumo" ) );
|
2026-08-20 11:48:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<SumoCase> RiaSumoExplore::cases( const QString& assetName )
|
|
|
|
|
{
|
2026-09-10 10:33:58 +02:00
|
|
|
const QString path = QString( "/cases?asset_name=%1" ).arg( QString( QUrl::toPercentEncoding( assetName ) ) );
|
2026-08-20 11:48:25 +02:00
|
|
|
|
2026-09-10 10:33:58 +02:00
|
|
|
return parseCases( m_connector.getBlocking( path, QString( "Loading the cases of %1 from Sumo" ).arg( assetName ) ) );
|
2026-08-20 11:48:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<QString> RiaSumoExplore::ensembleNames( const SumoCaseId& caseId )
|
|
|
|
|
{
|
2026-09-10 10:33:58 +02:00
|
|
|
const QString path = QString( "/cases/%1/ensembles" ).arg( caseId.get() );
|
2026-08-20 11:48:25 +02:00
|
|
|
|
2026-09-10 10:33:58 +02:00
|
|
|
return parseEnsembleNames( m_connector.getBlocking( path, "Loading ensembles from Sumo" ) );
|
2026-08-20 11:48:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<QString> RiaSumoExplore::realizationIds( const SumoCaseId& caseId, const QString& ensembleName )
|
|
|
|
|
{
|
|
|
|
|
const QString encodedEnsembleName = QUrl::toPercentEncoding( ensembleName );
|
|
|
|
|
|
2026-09-10 10:33:58 +02:00
|
|
|
const QString path = QString( "/cases/%1/ensembles/%2/realizations" ).arg( caseId.get() ).arg( encodedEnsembleName );
|
2026-08-20 11:48:25 +02:00
|
|
|
|
2026-09-10 10:33:58 +02:00
|
|
|
return parseRealizationIds( m_connector.getBlocking( path, "Loading realizations from Sumo" ) );
|
2026-08-20 11:48:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<SumoAsset> RiaSumoExplore::parseAssets( const QByteArray& body )
|
|
|
|
|
{
|
|
|
|
|
std::vector<SumoAsset> assets;
|
|
|
|
|
|
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson( body );
|
|
|
|
|
QJsonArray jsonArray = doc.array();
|
|
|
|
|
|
|
|
|
|
// This json is an array of AssetInfo
|
|
|
|
|
for ( const QJsonValue& assetInfo : jsonArray )
|
|
|
|
|
{
|
|
|
|
|
QString assetName = assetInfo["name"].toString();
|
|
|
|
|
assets.push_back( SumoAsset{ SumoAssetId( "" ), "", assetName } );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( const auto& asset : assets )
|
|
|
|
|
{
|
|
|
|
|
RiaLogging::debug( std::format( "Asset: {}", asset.name ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return assets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<SumoCase> RiaSumoExplore::parseCases( const QByteArray& body )
|
|
|
|
|
{
|
|
|
|
|
std::vector<SumoCase> cases;
|
|
|
|
|
|
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson( body );
|
|
|
|
|
QJsonArray jsonArray = doc.array();
|
|
|
|
|
|
|
|
|
|
for ( const QJsonValue& value : jsonArray )
|
|
|
|
|
{
|
|
|
|
|
QJsonObject caseObj = value.toObject();
|
|
|
|
|
|
|
|
|
|
QString id = caseObj["id"].toString();
|
|
|
|
|
QString kind = "";
|
|
|
|
|
QString name = caseObj["name"].toString();
|
|
|
|
|
cases.push_back( SumoCase{ SumoCaseId( id ), kind, name } );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RiaLogging::debug( std::format( "Case count : {}", cases.size() ) );
|
|
|
|
|
|
|
|
|
|
return cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<QString> RiaSumoExplore::parseEnsembleNames( const QByteArray& body )
|
|
|
|
|
{
|
|
|
|
|
std::vector<QString> ensembleNames;
|
|
|
|
|
|
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson( body );
|
|
|
|
|
QJsonArray jsonArray = doc.array();
|
|
|
|
|
|
|
|
|
|
for ( const QJsonValue& value : jsonArray )
|
|
|
|
|
{
|
|
|
|
|
QJsonObject ensembleObj = value.toObject();
|
|
|
|
|
ensembleNames.push_back( ensembleObj["name"].toString() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RiaLogging::debug( std::format( "Ensemble count : {}", ensembleNames.size() ) );
|
|
|
|
|
|
|
|
|
|
return ensembleNames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<QString> RiaSumoExplore::parseRealizationIds( const QByteArray& body )
|
|
|
|
|
{
|
|
|
|
|
std::vector<QString> realizationIds;
|
|
|
|
|
|
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson( body );
|
|
|
|
|
QJsonArray jsonArray = doc.array();
|
|
|
|
|
|
|
|
|
|
for ( const QJsonValue& value : jsonArray )
|
|
|
|
|
{
|
|
|
|
|
realizationIds.push_back( QString::number( value.toInt() ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return realizationIds;
|
|
|
|
|
}
|