From 940b4ff55e6f88c416a670e50a56ab14c7295062 Mon Sep 17 00:00:00 2001 From: spx Date: Wed, 3 Oct 2012 02:36:11 -0700 Subject: [PATCH] Measure: Tweaked Max/Min value logging. --- Library/Measure.cpp | 55 ++++++++++++++++++--------------------- Library/Measure.h | 3 +-- Library/MeasureNet.cpp | 11 +++++--- Library/MeasurePlugin.cpp | 6 ++--- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/Library/Measure.cpp b/Library/Measure.cpp index 6319c62e..05fbfffc 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -61,7 +61,7 @@ static const double g_TblScale[2][4] = { } }; -const int MEDIAN_SIZE = 7; +const int MEDIAN_SIZE = 3; extern CRainmeter* Rainmeter; @@ -440,32 +440,6 @@ bool CMeasure::Update() if (m_UpdateCounter < m_UpdateDivider) return false; m_UpdateCounter = 0; - // If we're logging the maximum value of the measure, check if - // the new value is greater than the old one, and update if necessary. - if (m_LogMaxValue) - { - if (m_MedianMaxValues.empty()) - { - m_MedianMaxValues.resize(MEDIAN_SIZE, 0); - m_MedianMinValues.resize(MEDIAN_SIZE, 0); - } - - m_MedianMaxValues[m_MedianPos] = m_Value; - m_MedianMinValues[m_MedianPos] = m_Value; - ++m_MedianPos; - m_MedianPos %= MEDIAN_SIZE; - - std::vector medianArray; - - medianArray = m_MedianMaxValues; - std::sort(medianArray.begin(), medianArray.end()); - m_MaxValue = max(m_MaxValue, medianArray[MEDIAN_SIZE / 2]); - - medianArray = m_MedianMinValues; - std::sort(medianArray.begin(), medianArray.end()); - m_MinValue = min(m_MinValue, medianArray[MEDIAN_SIZE / 2]); - } - // Call derived method to update value UpdateValue(); @@ -485,12 +459,33 @@ bool CMeasure::Update() m_AveragePos %= averageValuesSize; // Calculate the average value - m_Value = 0; + double value = 0; for (size_t i = 0; i < averageValuesSize; ++i) { - m_Value += m_AverageValues[i]; + value += m_AverageValues[i]; } - m_Value /= (double)averageValuesSize; + m_Value = value / (double)averageValuesSize; + } + + // If we're logging the maximum value of the measure, check if + // the new value is greater than the old one, and update if necessary. + if (m_LogMaxValue) + { + if (m_MedianValues.empty()) + { + m_MedianValues.resize(MEDIAN_SIZE, 0); + } + + m_MedianValues[m_MedianPos] = m_Value; + ++m_MedianPos; + m_MedianPos %= MEDIAN_SIZE; + + auto medianArray = m_MedianValues; + std::sort(&medianArray[0], &medianArray[MEDIAN_SIZE]); + + double medianValue = medianArray[MEDIAN_SIZE / 2]; + m_MaxValue = max(m_MaxValue, medianValue); + m_MinValue = min(m_MinValue, medianValue); } if (m_MeterWindow) diff --git a/Library/Measure.h b/Library/Measure.h index c42c4210..db6edc86 100644 --- a/Library/Measure.h +++ b/Library/Measure.h @@ -91,8 +91,7 @@ protected: std::vector m_Substitute; // Vec of substitute strings bool m_RegExpSubstitute; - std::vector m_MedianMaxValues; // The values for the median filtering - std::vector m_MedianMinValues; // The values for the median filtering + std::vector m_MedianValues; // The values for the median filtering UINT m_MedianPos; // Position in the median array, where the new value is placed std::vector m_AverageValues; diff --git a/Library/MeasureNet.cpp b/Library/MeasureNet.cpp index 7c5b7472..eb90a64e 100644 --- a/Library/MeasureNet.cpp +++ b/Library/MeasureNet.cpp @@ -450,14 +450,19 @@ void CMeasureNet::ReadOptions(CConfigParser& parser, const WCHAR* section, NET n Rainmeter->SetNetworkStatisticsTimer(); } - if (maxValue == 0) + if (maxValue == 0.0) { - m_MaxValue = 1; - m_LogMaxValue = true; + if (!m_LogMaxValue) + { + m_MaxValue = 1.0; + m_LogMaxValue = true; + m_MedianValues.clear(); + } } else { m_MaxValue = maxValue / 8; + m_LogMaxValue = false; } } diff --git a/Library/MeasurePlugin.cpp b/Library/MeasurePlugin.cpp index fb3186df..88887f4d 100644 --- a/Library/MeasurePlugin.cpp +++ b/Library/MeasurePlugin.cpp @@ -193,14 +193,12 @@ void CMeasurePlugin::ReadOptions(CConfigParser& parser, const WCHAR* section) { m_MaxValue = 1.0; m_LogMaxValue = true; - - // Plugin options changed, so reset - m_MedianMaxValues.clear(); - m_MedianMinValues.clear(); + m_MedianValues.clear(); } else { m_MaxValue = maxValue; + m_LogMaxValue = false; } }