eive-obsw/mission/utility/ProgressPrinter.cpp
Robin Mueller 7d9ef6f887
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
run afmt
2022-05-23 18:37:04 +02:00

26 lines
917 B
C++

#include "ProgressPrinter.h"
#include <cmath>
#include <iomanip>
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
ProgressPrinter::ProgressPrinter(std::string name, uint32_t numSteps, float percentageResolution)
: name(name), numSteps(numSteps), percentageResolution(percentageResolution) {}
ProgressPrinter::~ProgressPrinter() {}
void ProgressPrinter::print(uint32_t currentStep) {
float progressInPercent = static_cast<float>(currentStep) / static_cast<float>(numSteps) * 100;
if (progressInPercent >= nextProgressPrint) {
sif::info << name << " progress: " << std::setprecision(4) << progressInPercent << " %"
<< std::endl;
nextProgressPrint += percentageResolution;
}
if (nextProgressPrint - progressInPercent < 0) {
nextProgressPrint =
(std::floor(progressInPercent / percentageResolution) * percentageResolution) +
percentageResolution;
}
}