From 1e9f77274a0a079b8c6a1a290ae6fa45ba358185 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 26 Oct 2015 10:17:15 +0100 Subject: [PATCH] Minor refactor --- .../RigStatisticsDataCache.cpp | 38 +++++++++++-------- .../RigStatisticsDataCache.h | 17 +++++---- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp index a4abdfe85d..5b4a7182b4 100644 --- a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp +++ b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp @@ -173,20 +173,7 @@ void RigStatisticsDataCache::posNegClosestToZero(size_t timeStepIndex, double& p //-------------------------------------------------------------------------------------------------- const std::vector& RigStatisticsDataCache::cellScalarValuesHistogram() { - if (m_histogram.size() == 0) - { - double min; - double max; - size_t nBins = 100; - this->minMaxCellScalarValues(min, max); - - RigHistogramCalculator histCalc(min, max, nBins, &m_histogram); - - m_statisticsCalculator->addDataToHistogramCalculator(histCalc); - - m_p10 = histCalc.calculatePercentil(0.1); - m_p90 = histCalc.calculatePercentil(0.9); - } + computeStatisticsIfNeeded(); return m_histogram; } @@ -197,7 +184,7 @@ const std::vector& RigStatisticsDataCache::cellScalarValuesHistogram() void RigStatisticsDataCache::p10p90CellScalarValues(double& p10, double& p90) { // First make sure they are calculated - const std::vector& histogr = this->cellScalarValuesHistogram(); + computeStatisticsIfNeeded(); p10 = m_p10; p90 = m_p90; @@ -217,3 +204,24 @@ void RigStatisticsDataCache::meanCellScalarValues(double& meanValue) meanValue = m_meanValue; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigStatisticsDataCache::computeStatisticsIfNeeded() +{ + if (m_histogram.size() == 0) + { + double min; + double max; + size_t nBins = 100; + this->minMaxCellScalarValues(min, max); + + RigHistogramCalculator histCalc(min, max, nBins, &m_histogram); + + m_statisticsCalculator->addDataToHistogramCalculator(histCalc); + + m_p10 = histCalc.calculatePercentil(0.1); + m_p90 = histCalc.calculatePercentil(0.9); + } +} + diff --git a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h index 7df62c7c56..ae4c262f35 100644 --- a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h +++ b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.h @@ -47,20 +47,23 @@ public: const std::vector& cellScalarValuesHistogram(); private: - double m_minValue; - double m_maxValue; + void computeStatisticsIfNeeded(); + +private: + double m_minValue; + double m_maxValue; bool m_isMaxMinCalculated; - double m_posClosestToZero; - double m_negClosestToZero; + double m_posClosestToZero; + double m_negClosestToZero; bool m_isClosestToZeroCalculated; - double m_p10; - double m_p90; + double m_p10; + double m_p90; double m_meanValue; bool m_isMeanCalculated; - std::vector m_histogram; + std::vector m_histogram; std::vector > m_maxMinValuesPrTs; ///< Max min values for each time step std::vector m_isMaxMinPrTsCalculated;