diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimFractureGroupStatistics.cpp b/ApplicationLibCode/ProjectDataModel/Completions/RimFractureGroupStatistics.cpp index 257f50c56b..f49a3b4d5d 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimFractureGroupStatistics.cpp +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimFractureGroupStatistics.cpp @@ -29,12 +29,30 @@ #include "RifCsvDataTableFormatter.h" #include "RifStimPlanXmlReader.h" +#include "cafAppEnum.h" #include "cafPdmUiTextEditor.h" #include #include +namespace caf +{ +template <> +void caf::AppEnum::setUp() +{ + addItem( RimFractureGroupStatistics::StatisticsType::MEAN, "MEAN", "Mean" ); + addItem( RimFractureGroupStatistics::StatisticsType::MIN, "MIN", "Minimum" ); + addItem( RimFractureGroupStatistics::StatisticsType::MAX, "MAX", "Maximum" ); + addItem( RimFractureGroupStatistics::StatisticsType::P10, "P10", "P10" ); + addItem( RimFractureGroupStatistics::StatisticsType::P50, "P50", "P50" ); + addItem( RimFractureGroupStatistics::StatisticsType::P90, "P90", "P90" ); + addItem( RimFractureGroupStatistics::StatisticsType::OCCURRENCE, "OCCURRENCE", "Occurrence" ); + setDefault( RimFractureGroupStatistics::StatisticsType::MEAN ); +} + +} // namespace caf + CAF_PDM_SOURCE_INIT( RimFractureGroupStatistics, "FractureGroupStatistics" ); //-------------------------------------------------------------------------------------------------- @@ -143,16 +161,16 @@ void RimFractureGroupStatistics::computeStatistics() std::vector> samples( numSamplesX * numSamplesY ); sampleAllGrids( fractureGrids, samples, minX, minY, numSamplesX, numSamplesY, sampleDistanceX, sampleDistanceY ); - std::map> statisticsGrids; + std::map> statisticsGrids; generateStatisticsGrids( samples, numSamplesX, numSamplesY, statisticsGrids ); - writeStatisticsToCsv( "/tmp/mean.csv", *statisticsGrids["mean"] ); - writeStatisticsToCsv( "/tmp/min.csv", *statisticsGrids["min"] ); - writeStatisticsToCsv( "/tmp/max.csv", *statisticsGrids["max"] ); - writeStatisticsToCsv( "/tmp/p10.csv", *statisticsGrids["p10"] ); - writeStatisticsToCsv( "/tmp/p50.csv", *statisticsGrids["p50"] ); - writeStatisticsToCsv( "/tmp/p90.csv", *statisticsGrids["p90"] ); - writeStatisticsToCsv( "/tmp/occurrence.csv", *statisticsGrids["occurrence"] ); + for ( size_t i = 0; i < caf::AppEnum::size(); ++i ) + { + caf::AppEnum t = + caf::AppEnum::fromIndex( i ); + QString text = t.text(); + writeStatisticsToCsv( "/tmp/" + text + ".csv", *statisticsGrids[t.value()] ); + } } //-------------------------------------------------------------------------------------------------- @@ -381,17 +399,19 @@ bool RimFractureGroupStatistics::writeStatisticsToCsv( const QString& filePath, //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimFractureGroupStatistics::generateStatisticsGrids( const std::vector>& samples, - int numSamplesX, - int numSamplesY, - std::map>& statisticsGrids ) +void RimFractureGroupStatistics::generateStatisticsGrids( + const std::vector>& samples, + int numSamplesX, + int numSamplesY, + std::map>& statisticsGrids ) { - std::vector names = { "mean", "max", "min", "p10", "p50", "p90", "occurrence" }; - - for ( auto name : names ) + for ( size_t i = 0; i < caf::AppEnum::size(); ++i ) { std::shared_ptr grid = std::make_shared( numSamplesX, numSamplesY ); - statisticsGrids[name] = grid; + + caf::AppEnum t = + caf::AppEnum::fromIndex( i ); + statisticsGrids[t.value()] = grid; } for ( int y = 0; y < numSamplesY; y++ ) @@ -407,20 +427,20 @@ void RimFractureGroupStatistics::generateStatisticsGrids( const std::vectorsetValue( x, y, mean ); - statisticsGrids["min"]->setValue( x, y, min ); - statisticsGrids["max"]->setValue( x, y, max ); + statisticsGrids[RimFractureGroupStatistics::StatisticsType::MEAN]->setValue( x, y, mean ); + statisticsGrids[RimFractureGroupStatistics::StatisticsType::MIN]->setValue( x, y, min ); + statisticsGrids[RimFractureGroupStatistics::StatisticsType::MAX]->setValue( x, y, max ); double p10; double p50; double p90; RigStatisticsMath::calculateStatisticsCurves( samples[idx], &p10, &p50, &p90, &mean ); - statisticsGrids["p10"]->setValue( x, y, p10 ); - statisticsGrids["p50"]->setValue( x, y, p50 ); - statisticsGrids["p90"]->setValue( x, y, p90 ); + statisticsGrids[RimFractureGroupStatistics::StatisticsType::P10]->setValue( x, y, p10 ); + statisticsGrids[RimFractureGroupStatistics::StatisticsType::P50]->setValue( x, y, p50 ); + statisticsGrids[RimFractureGroupStatistics::StatisticsType::P90]->setValue( x, y, p90 ); - statisticsGrids["occurrence"]->setValue( x, y, samples[idx].size() ); + statisticsGrids[RimFractureGroupStatistics::StatisticsType::OCCURRENCE]->setValue( x, y, samples[idx].size() ); } } } diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimFractureGroupStatistics.h b/ApplicationLibCode/ProjectDataModel/Completions/RimFractureGroupStatistics.h index c61ee94cb3..8ec4f431fd 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimFractureGroupStatistics.h +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimFractureGroupStatistics.h @@ -34,6 +34,17 @@ class RimFractureGroupStatistics : public RimNamedObject CAF_PDM_HEADER_INIT; public: + enum class StatisticsType + { + MEAN, + MIN, + MAX, + P10, + P50, + P90, + OCCURRENCE + }; + RimFractureGroupStatistics(); ~RimFractureGroupStatistics() override; void addFilePath( const QString& filePath ); @@ -72,10 +83,11 @@ protected: double sampleDistanceX, double sampleDistanceY ); - static void generateStatisticsGrids( const std::vector>& samples, - int numSamplesX, - int numSamplesY, - std::map>& statisticsGrids ); + static void generateStatisticsGrids( + const std::vector>& samples, + int numSamplesX, + int numSamplesY, + std::map>& statisticsGrids ); static bool writeStatisticsToCsv( const QString& filePath, const RigSlice2D& samples );