///////////////////////////////////////////////////////////////////////////////// // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RiaSumoExplore.h" #include "RiaLogging.h" #include "RiaQStringFormatter.h" #include "RiaSumoConnector.h" #include #include #include #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RiaSumoExplore::RiaSumoExplore( RiaSumoConnector& connector ) : m_connector( connector ) { } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RiaSumoExplore::assets() { return parseAssets( m_connector.getBlocking( "/assets", "Loading assets from Sumo" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RiaSumoExplore::cases( const QString& assetName ) { const QString path = QString( "/cases?asset_name=%1" ).arg( QString( QUrl::toPercentEncoding( assetName ) ) ); return parseCases( m_connector.getBlocking( path, QString( "Loading the cases of %1 from Sumo" ).arg( assetName ) ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RiaSumoExplore::ensembleNames( const SumoCaseId& caseId ) { const QString path = QString( "/cases/%1/ensembles" ).arg( caseId.get() ); return parseEnsembleNames( m_connector.getBlocking( path, "Loading ensembles from Sumo" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RiaSumoExplore::realizationIds( const SumoCaseId& caseId, const QString& ensembleName ) { const QString encodedEnsembleName = QUrl::toPercentEncoding( ensembleName ); const QString path = QString( "/cases/%1/ensembles/%2/realizations" ).arg( caseId.get() ).arg( encodedEnsembleName ); return parseRealizationIds( m_connector.getBlocking( path, "Loading realizations from Sumo" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RiaSumoExplore::parseAssets( const QByteArray& body ) { std::vector 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 RiaSumoExplore::parseCases( const QByteArray& body ) { std::vector 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 RiaSumoExplore::parseEnsembleNames( const QByteArray& body ) { std::vector 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 RiaSumoExplore::parseRealizationIds( const QByteArray& body ) { std::vector realizationIds; QJsonDocument doc = QJsonDocument::fromJson( body ); QJsonArray jsonArray = doc.array(); for ( const QJsonValue& value : jsonArray ) { realizationIds.push_back( QString::number( value.toInt() ) ); } return realizationIds; }