Define long names for summary vectors in JSON files

This commit is contained in:
Magne Sjaastad 2024-10-13 13:28:28 +02:00
parent 0330c3cacd
commit 4719090b5f
11 changed files with 8337 additions and 2129 deletions

View File

@ -19,6 +19,7 @@
#include "RiaArgumentParser.h"
#include "RiaMainTools.h"
#include "RiaPreferences.h"
#include "RiaQuantityInfoTools.h"
#ifdef ENABLE_GRPC
#include "RiaGrpcConsoleApplication.h"
@ -92,6 +93,7 @@ int main( int argc, char* argv[] )
// Create feature manager before the application object is created
RiaMainTools::initializeSingletons();
RiaQuantityInfoTools::initializeSummaryKeywords();
// https://www.w3.org/wiki/CSS/Properties/color/keywords
caf::UiAppearanceSettings::instance()->setAutoValueEditorColor( "moccasin" );

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/keywords">
<file>keyword-description/keywords_eclipse.json</file>
<file>keyword-description/keywords_6x.json</file>
</qresource>
</RCC>

File diff suppressed because it is too large Load Diff

View File

@ -55,6 +55,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTextTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaFileLogger.h
${CMAKE_CURRENT_LIST_DIR}/RiaProjectBackupTools.h
${CMAKE_CURRENT_LIST_DIR}/RiaQuantityInfoTools.h
)
set(SOURCE_GROUP_SOURCE_FILES
@ -107,6 +108,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaRegressionTextTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaFileLogger.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaProjectBackupTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaQuantityInfoTools.cpp
)
list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES})

View File

@ -0,0 +1,131 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RiaQuantityInfoTools.h"
#include "RiaLogging.h"
#include "RiuSummaryQuantityNameInfoProvider.h"
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QString>
#include <unordered_map>
namespace RiaQuantityInfoTools
{
namespace internal
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void writeToFile( const QString& filename, const std::unordered_map<std::string, std::pair<std::string, std::string>>& map )
{
QJsonObject jsonObj;
for ( const auto& item : map )
{
QJsonObject itemObj;
itemObj["category"] = QString::fromStdString( item.second.first );
itemObj["description"] = QString::fromStdString( item.second.second );
jsonObj[QString::fromStdString( item.first )] = itemObj;
}
QJsonDocument jsonDoc( jsonObj );
QFile file( filename );
if ( !file.open( QIODevice::WriteOnly ) )
{
RiaLogging::error( "Couldn't open file : " + filename );
return;
}
file.write( jsonDoc.toJson() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::unordered_map<std::string, std::pair<std::string, std::string>> importFromFile( const QString& filename )
{
QFile file( filename );
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
RiaLogging::error( "Couldn't open file : " + filename );
return {};
}
QByteArray data = file.readAll();
QJsonDocument jsonDoc( QJsonDocument::fromJson( data ) );
if ( !jsonDoc.isObject() )
{
RiaLogging::error( "Invalid JSON format in : " + filename );
return {};
}
std::unordered_map<std::string, std::pair<std::string, std::string>> map;
QJsonObject jsonObj = jsonDoc.object();
for ( auto it = jsonObj.begin(); it != jsonObj.end(); ++it )
{
auto key = it.key().toStdString();
QJsonObject value = it.value().toObject();
auto category = value["category"].toString().toStdString();
auto description = value["description"].toString().toStdString();
map.insert( { key, { category, description } } );
}
return map;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void importKeywords( const QString& keywordEclipseFilePath, const QString& keyword6XFilePath )
{
auto quantityInfos = internal::importFromFile( keywordEclipseFilePath );
auto info6x = internal::importFromFile( keyword6XFilePath );
for ( const auto& other : info6x )
{
if ( !quantityInfos.contains( other.first ) )
{
quantityInfos.insert( other );
}
}
RiuSummaryQuantityNameInfoProvider::instance()->setQuantityInfos( quantityInfos );
}
} // namespace internal
} // namespace RiaQuantityInfoTools
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaQuantityInfoTools::initializeSummaryKeywords()
{
QString keywordEclipseFilePath = ":keywords/keyword-description/keywords_eclipse.json";
QString keyword6XFilePath = ":keywords/keyword-description/keywords_6x.json";
RiaQuantityInfoTools::internal::importKeywords( keywordEclipseFilePath, keyword6XFilePath );
}

View File

@ -0,0 +1,29 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QString>
//==================================================================================================
//
//==================================================================================================
namespace RiaQuantityInfoTools
{
void initializeSummaryKeywords();
} // namespace RiaQuantityInfoTools

View File

@ -220,8 +220,10 @@ endif()
# ##############################################################################
source_group("ModelVisualization" FILES ${MODEL_VISUALIZATION_FILES})
qt_add_resources(QRC_FILES Application/Resources/ApplicationLibCode.qrc)
list(APPEND ALL_SOURCE_FILES ${CPP_SOURCES} ${MOC_SOURCE_FILES}
${FORM_FILES_CPP}
${FORM_FILES_CPP} ${QRC_FILES}
)
add_library(${PROJECT_NAME} OBJECT ${ALL_SOURCE_FILES})
@ -389,6 +391,7 @@ set(UNITY_EXCLUDE_FILES
qrc_cafAnimControl.cpp
qrc_ResInsight.cpp
qrc_cafCommandFeatures.cpp
qrc_ApplicationLibCode.cpp
# Exclude files including opm-common
ProjectDataModel/RimVfpTableExtractor.cpp
ProjectDataModel/RimVfpPlot.cpp

View File

@ -19,6 +19,7 @@
#include "gtest/gtest.h"
#include "RiaConsoleApplication.h"
#include "RiaQuantityInfoTools.h"
#include "RiaRegressionTestRunner.h"
#include <QLocale>
@ -30,6 +31,7 @@ int main( int argc, char** argv )
{
// Create feature manager before the application object is created
RiaRegressionTestRunner::createSingleton();
RiaQuantityInfoTools::initializeSummaryKeywords();
RiaApplication* app = new RiaConsoleApplication( argc, argv );
app->initialize();

View File

@ -35,6 +35,8 @@ public:
std::string longNameFromVectorName( const std::string& vectorName, bool returnVectorNameIfNotFound = false ) const;
void setQuantityInfos( const std::unordered_map<std::string, std::pair<std::string, std::string>>& infos );
private:
class RiuSummaryQuantityInfo
{
@ -59,8 +61,8 @@ private:
RiuSummaryQuantityInfo quantityInfo( const std::string& vectorName, bool exactMatch = false ) const;
RifEclipseSummaryAddressDefines::SummaryCategory categoryFromVectorName( const std::string& vectorName, bool exactMatch = false ) const;
static std::unordered_map<std::string, RiuSummaryQuantityInfo> createInfoForEclipseKeywords();
static std::unordered_map<std::string, RiuSummaryQuantityInfo> createInfoFor6xKeywords();
static std::string stringFromEnum( RifEclipseSummaryAddressDefines::SummaryCategory category );
static RifEclipseSummaryAddressDefines::SummaryCategory enumFromString( const std::string& category );
private:
std::unordered_map<std::string, RiuSummaryQuantityInfo> m_summaryToDescMap;