Fix handling of statistics before data is available and fix normalization factor

This commit is contained in:
BlackMark 2020-04-08 13:44:54 +02:00
parent 1694e3bbab
commit ed2fddc427

View File

@ -243,15 +243,35 @@ class Terminal {
static void printStatistics()
{
m_serial << F("Minimum temperature .: ") << Statistics::getMinTemperature() << F(" C") << detail::ENDL;
m_serial << F("Maximum temperature .: ") << Statistics::getMaxTemperature() << F(" C") << detail::ENDL;
const auto minTemp = Statistics::getMinTemperature();
const auto maxTemp = Statistics::getMaxTemperature();
m_serial << F("Minimum temperature .: ");
if (minTemp != Statistics::TEMPERATURE_RANGE) {
m_serial << minTemp << F(" C");
} else {
m_serial << F("Not available");
}
m_serial << detail::ENDL << F("Maximum temperature .: ");
if (maxTemp != Statistics::TEMPERATURE_RANGE) {
m_serial << maxTemp << F(" C");
} else {
m_serial << F("Not available");
}
m_serial << detail::ENDL;
}
static void printHistogram()
{
const auto totalSamples = Statistics::getTotalHistogramSamples();
if (totalSamples > 0) {
const auto maximumSamples = Statistics::getHighestHistogramSamples();
const auto normalizationFactor = (maximumSamples / 100 > 1) ? (maximumSamples / 100) : 1;
auto normalizationFactor = (maximumSamples / 100 > 1) ? (maximumSamples / 100) : 1;
while (maximumSamples / normalizationFactor > 100)
++normalizationFactor;
for (uint8_t t = Statistics::getMinTemperature(); t <= Statistics::getMaxTemperature(); ++t) {
const auto histogramSamples = Statistics::getHistogram(t);
@ -265,6 +285,9 @@ class Terminal {
}
m_serial << detail::ENDL;
}
} else {
m_serial << "There is no data yet!" << detail::ENDL;
}
}
static void printVersion()