Measure: Tweaked Max/Min value logging.

This commit is contained in:
spx 2012-10-03 02:36:11 -07:00
parent 93c1cf0411
commit 940b4ff55e
4 changed files with 36 additions and 39 deletions

View File

@ -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<double> 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)

View File

@ -91,8 +91,7 @@ protected:
std::vector<std::wstring> m_Substitute; // Vec of substitute strings
bool m_RegExpSubstitute;
std::vector<double> m_MedianMaxValues; // The values for the median filtering
std::vector<double> m_MedianMinValues; // The values for the median filtering
std::vector<double> m_MedianValues; // The values for the median filtering
UINT m_MedianPos; // Position in the median array, where the new value is placed
std::vector<double> m_AverageValues;

View File

@ -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;
}
}

View File

@ -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;
}
}