Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Measure: Tweaked Max/Min value logging.

  • Loading branch information...
commit 940b4ff55e6f88c416a670e50a56ab14c7295062 1 parent 93c1cf0
@spx268 spx268 authored
View
55 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<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]);
@brianferguson Collaborator

In debug mode, I am getting a fatal error on startup that traces back to this line. In release mode, everything works fine.

-Brian

@spx268 Collaborator
spx268 added a note

I think it's std::vector's range checking. It's checked only in debug mode. (medianArray[MEDIAN_SIZE] is indeed out of range.)
If you don't prefer it, I'll revert it.

@brianferguson Collaborator

I would prefer to fix the fatal error part of this bug, I am fine with the rest. (I use debug mode more then I should)

-Brian

@spx268 Collaborator
spx268 added a note

Added workaround in c1bd586. I think it would solve the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ double medianValue = medianArray[MEDIAN_SIZE / 2];
+ m_MaxValue = max(m_MaxValue, medianValue);
+ m_MinValue = min(m_MinValue, medianValue);
}
if (m_MeterWindow)
View
3  Library/Measure.h
@@ -91,8 +91,7 @@ class CMeasure : public CSection
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
11 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;
}
}
View
6 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;
}
}

1 comment on commit 940b4ff

@spx268
Collaborator

In ancient version 0.9, "Implemented a median filter in the automatic max value tracker to strip out the spikes." is listed. However, it doesn't track "correct" max value as a side effect. This commit will reduce it, but I think it should be removed in tue future, if possible.

Please sign in to comment.
Something went wrong with that request. Please try again.