Change histogram to only print from min to max

This commit is contained in:
BlackMark 2020-04-08 12:58:59 +02:00
parent 02565c9396
commit 1694e3bbab
3 changed files with 14 additions and 12 deletions

View File

@ -15,7 +15,7 @@ uint32_t Statistics::m_temperatureHistogram[TEMPERATURE_RANGE];
namespace { namespace {
// Must be in translation unit and cannot be forward declared // Must be in translation unit and cannot be forward declared
EEARRAY(uint32_t, e_temperatureHistogram, 100); EEARRAY(uint32_t, e_temperatureHistogram, Statistics::TEMPERATURE_RANGE);
// Could be declared in every function that uses it, but that would be code duplication // Could be declared in every function that uses it, but that would be code duplication
EepromArray<e_temperatureHistogram, EEARRAY_SIZE(e_temperatureHistogram), true> g_eepTemperatureHistogram; EepromArray<e_temperatureHistogram, EEARRAY_SIZE(e_temperatureHistogram), true> g_eepTemperatureHistogram;
@ -26,8 +26,7 @@ void Statistics::init()
{ {
for (uint8_t i = 0; i < g_eepTemperatureHistogram.size(); ++i) { for (uint8_t i = 0; i < g_eepTemperatureHistogram.size(); ++i) {
m_temperatureHistogram[i] = g_eepTemperatureHistogram[i]; m_temperatureHistogram[i] = g_eepTemperatureHistogram[i];
using temperature_t = type::decay_t<decltype(m_temperatureHistogram[0])>; if (m_temperatureHistogram[i] == type::numeric_limits<uint32_t>::max()) {
if (m_temperatureHistogram[i] == type::numeric_limits<temperature_t>::max()) {
m_temperatureHistogram[i] = 0; m_temperatureHistogram[i] = 0;
} }
} }
@ -49,7 +48,7 @@ void Statistics::callback()
} }
} }
uint8_t Statistics::getMinTemp() uint8_t Statistics::getMinTemperature()
{ {
for (uint8_t i = 0; i < TEMPERATURE_RANGE; ++i) { for (uint8_t i = 0; i < TEMPERATURE_RANGE; ++i) {
if (m_temperatureHistogram[i] > 0) if (m_temperatureHistogram[i] > 0)
@ -59,7 +58,7 @@ uint8_t Statistics::getMinTemp()
return TEMPERATURE_RANGE; return TEMPERATURE_RANGE;
} }
uint8_t Statistics::getMaxTemp() uint8_t Statistics::getMaxTemperature()
{ {
for (int8_t i = TEMPERATURE_RANGE - 1; i >= 0; --i) { for (int8_t i = TEMPERATURE_RANGE - 1; i >= 0; --i) {
if (m_temperatureHistogram[i] > 0) if (m_temperatureHistogram[i] > 0)
@ -82,12 +81,14 @@ uint64_t Statistics::getTotalHistogramSamples()
uint32_t Statistics::getHighestHistogramSamples() uint32_t Statistics::getHighestHistogramSamples()
{ {
uint32_t max = 1; // Avoid division by zero uint32_t max = 0;
for (uint8_t i = 0; i < TEMPERATURE_RANGE; ++i) { for (uint8_t i = 0; i < TEMPERATURE_RANGE; ++i) {
if (m_temperatureHistogram[i] > max) { if (m_temperatureHistogram[i] > max) {
max = m_temperatureHistogram[i]; max = m_temperatureHistogram[i];
} }
} }
return max; return max;
} }

View File

@ -4,11 +4,13 @@
class Statistics { class Statistics {
public: public:
static constexpr auto TEMPERATURE_RANGE = 100;
static void init(); static void init();
static void callback(); static void callback();
static uint8_t getMinTemp(); static uint8_t getMinTemperature();
static uint8_t getMaxTemp(); static uint8_t getMaxTemperature();
static uint64_t getTotalHistogramSamples(); static uint64_t getTotalHistogramSamples();
static uint32_t getHighestHistogramSamples(); static uint32_t getHighestHistogramSamples();
@ -17,7 +19,6 @@ class Statistics {
private: private:
static constexpr auto TEMPERATURE_WRITEBACK_DELAY = 1'800'000; static constexpr auto TEMPERATURE_WRITEBACK_DELAY = 1'800'000;
static constexpr auto TEMPERATURE_SAMPLE_DELAY = 1'000; static constexpr auto TEMPERATURE_SAMPLE_DELAY = 1'000;
static constexpr auto TEMPERATURE_RANGE = 100;
static uint64_t m_lastTemperatureWriteback; static uint64_t m_lastTemperatureWriteback;
static uint64_t m_lastTemperatureSample; static uint64_t m_lastTemperatureSample;

View File

@ -243,8 +243,8 @@ class Terminal {
static void printStatistics() static void printStatistics()
{ {
m_serial << F("Minimum temperature .: ") << Statistics::getMinTemp() << F(" C") << detail::ENDL; m_serial << F("Minimum temperature .: ") << Statistics::getMinTemperature() << F(" C") << detail::ENDL;
m_serial << F("Maximum temperature .: ") << Statistics::getMaxTemp() << F(" C") << detail::ENDL; m_serial << F("Maximum temperature .: ") << Statistics::getMaxTemperature() << F(" C") << detail::ENDL;
} }
static void printHistogram() static void printHistogram()
@ -253,7 +253,7 @@ class Terminal {
const auto maximumSamples = Statistics::getHighestHistogramSamples(); const auto maximumSamples = Statistics::getHighestHistogramSamples();
const auto normalizationFactor = (maximumSamples / 100 > 1) ? (maximumSamples / 100) : 1; const auto normalizationFactor = (maximumSamples / 100 > 1) ? (maximumSamples / 100) : 1;
for (uint8_t t = 10; t <= 60; ++t) { for (uint8_t t = Statistics::getMinTemperature(); t <= Statistics::getMaxTemperature(); ++t) {
const auto histogramSamples = Statistics::getHistogram(t); const auto histogramSamples = Statistics::getHistogram(t);
m_serial.template txNumber<uint8_t, 10, 2>(t); m_serial.template txNumber<uint8_t, 10, 2>(t);
m_serial << F(" C = "); m_serial << F(" C = ");