mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5470 Add a new median calculator and make rkbdiff default to median well path rkb
This commit is contained in:
@@ -32,6 +32,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaTimeHistoryCurveResampler.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStatisticsTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOffshoreSphericalCoords.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaMedianCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.inl
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.h
|
||||
|
||||
77
ApplicationCode/Application/Tools/RiaMedianCalculator.h
Normal file
77
ApplicationCode/Application/Tools/RiaMedianCalculator.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020- 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 "cafAssert.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
class RiaMedianCalculator
|
||||
{
|
||||
public:
|
||||
RiaMedianCalculator() = default;
|
||||
|
||||
void add( T value );
|
||||
double median() const;
|
||||
bool valid() const;
|
||||
|
||||
private:
|
||||
std::vector<T> m_values;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
void RiaMedianCalculator<T>::add( T value )
|
||||
{
|
||||
m_values.insert( std::lower_bound( m_values.begin(), m_values.end(), value ), value );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
double RiaMedianCalculator<T>::median() const
|
||||
{
|
||||
CAF_ASSERT( valid() && "You must ensure the result is valid before calling this" );
|
||||
|
||||
auto count = m_values.size();
|
||||
if ( count == 1u )
|
||||
return m_values.front();
|
||||
else if ( count % 2 == 0 )
|
||||
{
|
||||
return ( m_values[count / 2 - 1] + m_values[count / 2] ) * 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_values[count / 2];
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
bool RiaMedianCalculator<T>::valid() const
|
||||
{
|
||||
return !m_values.empty();
|
||||
}
|
||||
Reference in New Issue
Block a user