Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::TerminalProgressBarDisplay Class Reference
Inheritance diagram for duckdb::TerminalProgressBarDisplay:
Collaboration diagram for duckdb::TerminalProgressBarDisplay:

Public Member Functions

void Update (double percentage) override
void Finish () override

Static Public Member Functions

static string FormatETA (double seconds, bool elapsed=false)
static string FormatProgressBar (const ProgressBarDisplayInfo &display_info, int32_t percentage)

Public Attributes

ProgressBarDisplayInfo display_info

Protected Member Functions

virtual void PrintProgressInternal (int32_t percentage, double estimated_remaining_seconds, bool is_finished=false)
double GetElapsedDuration ()
void StopPeriodicUpdates ()

Static Protected Member Functions

static int32_t NormalizePercentage (double percentage)

Private Member Functions

void PeriodicUpdate ()

Private Attributes

UnscentedKalmanFilter ukf
std::chrono::steady_clock::time_point start_time
struct TerminalProgressBarDisplayedProgressInfo displayed_progress_info

Constructor & Destructor Documentation

◆ TerminalProgressBarDisplay()

duckdb::TerminalProgressBarDisplay::TerminalProgressBarDisplay ( )
inline
92757 {
92758 start_time = std::chrono::steady_clock::now();
92759 displayed_progress_info = {optional_idx(), optional_idx()};
92760 }

◆ ~TerminalProgressBarDisplay()

duckdb::TerminalProgressBarDisplay::~TerminalProgressBarDisplay ( )
inlineoverride
92762 {
92763 }

Member Function Documentation

◆ Update()

void duckdb::TerminalProgressBarDisplay::Update ( double percentage)
overridevirtual

Implements duckdb::ProgressBarDisplay.

93074 {
93075 const double current_time = GetElapsedDuration();
93076
93077 // Filters go from 0 to 1, percentage is from 0-100
93078 const double filter_percentage = percentage / 100.0;
93079
93080 ukf.Update(filter_percentage, current_time);
93081
93082 double estimated_seconds_remaining;
93083 // If the query is mostly completed, there can be oscillation of estimated
93084 // time to completion since the progress updates seem sparse near the very
93085 // end of the query, so clamp time remaining to not oscillate with estimates
93086 // that are unlikely to be correct.
93087 if (filter_percentage > 0.99) {
93088 estimated_seconds_remaining = 0.5;
93089 } else {
93090 estimated_seconds_remaining = std::min(ukf.GetEstimatedRemainingSeconds(), 2147483647.0);
93091 }
93092 auto percentage_int = NormalizePercentage(percentage);
93093
93094 TerminalProgressBarDisplayedProgressInfo updated_progress_info = {(idx_t)percentage_int,
93095 (idx_t)estimated_seconds_remaining};
93096 if (displayed_progress_info != updated_progress_info) {
93097 PrintProgressInternal(percentage_int, estimated_seconds_remaining);
93098 Printer::Flush(OutputStream::STREAM_STDOUT);
93099 displayed_progress_info = updated_progress_info;
93100 }
93101}
static DUCKDB_API void Flush(OutputStream stream)
Flush an output stream.
Definition duckdb.cpp:92559
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Finish()

void duckdb::TerminalProgressBarDisplay::Finish ( )
overridevirtual

Implements duckdb::ProgressBarDisplay.

93103 {
93104 PrintProgressInternal(100, GetElapsedDuration(), true);
93105 Printer::RawPrint(OutputStream::STREAM_STDOUT, "\n");
93106 Printer::Flush(OutputStream::STREAM_STDOUT);
93107}
static DUCKDB_API void RawPrint(OutputStream stream, const string &str)
Directly prints the string to stdout without a newline.
Definition duckdb.cpp:92535

◆ FormatETA()

string duckdb::TerminalProgressBarDisplay::FormatETA ( double seconds,
bool elapsed = false )
static
92970 {
92971 // for terminal rendering purposes, we need to make sure the length is always the same
92972 // we pad the end with spaces if that is not the case
92973 // the maximum length here is "(~10.35 minutes remaining)" (26 bytes)
92974 // always pad to this amount
92975 static constexpr idx_t RENDER_SIZE = 26;
92976
92977 if (seconds < 0 || seconds == 2147483647) {
92978 // Invalid or unknown ETA, skip rendering estimate
92979 return string(RENDER_SIZE, ' ');
92980 }
92981
92982 if (!elapsed && seconds > 3600 * 99) {
92983 // estimate larger than 99 hours remaining, treat this as invalid/unknown ETA
92984 return string(RENDER_SIZE, ' ');
92985 }
92986
92987 // Round to nearest centisecond as integer
92988 auto total_centiseconds = static_cast<uint64_t>(std::llround(seconds * 100.0));
92989
92990 // Split into seconds and centiseconds
92991 uint64_t total_seconds = total_centiseconds / 100;
92992 uint32_t centiseconds = static_cast<uint32_t>(total_centiseconds % 100);
92993
92994 // Break down total_seconds
92995 uint64_t hours = total_seconds / 3600;
92996 uint32_t minutes = static_cast<uint32_t>((total_seconds % 3600) / 60);
92997 uint32_t secs = static_cast<uint32_t>(total_seconds % 60);
92998 string result;
92999 result = "(";
93000 if (!elapsed) {
93001 if (hours == 0 && minutes == 0 && secs == 0) {
93002 result += StringUtil::Format("<1 second");
93003 } else if (hours == 0 && minutes == 0) {
93004 result += StringUtil::Format("~%u second%s", secs, secs > 1 ? "s" : "");
93005 } else if (hours == 0) {
93006 auto minute_fraction = static_cast<uint32_t>(static_cast<double>(secs) / 60.0 * 10);
93007 result += StringUtil::Format("~%u.%u minutes", minutes, minute_fraction);
93008 } else {
93009 auto hour_fraction = static_cast<uint32_t>(static_cast<double>(minutes) / 60.0 * 10);
93010 result += StringUtil::Format("~%llu.%u hours", hours, hour_fraction);
93011 }
93012 result += " remaining";
93013 } else {
93014 result += StringUtil::Format("%02llu:%02u:%02u.%02llu", hours, minutes, secs, centiseconds);
93015 result += " elapsed";
93016 }
93017 result += ")";
93018 if (result.size() < RENDER_SIZE) {
93019 result += string(RENDER_SIZE - result.size(), ' ');
93020 }
93021 return result;
93022}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
::uint32_t uint32_t
::uint64_t uint64_t

◆ FormatProgressBar()

string duckdb::TerminalProgressBarDisplay::FormatProgressBar ( const ProgressBarDisplayInfo & display_info,
int32_t percentage )
static
93024 {
93025 // we divide the number of blocks by the percentage
93026 // 0% = 0
93027 // 100% = PROGRESS_BAR_WIDTH
93028 // the percentage determines how many blocks we need to draw
93029 double blocks_to_draw = static_cast<double>(display.width) * (percentage / 100.0);
93030 // because of the power of unicode, we can also draw partial blocks
93031 string result;
93032 result += display.progress_start;
93033 idx_t i;
93034 for (i = 0; i < idx_t(blocks_to_draw); i++) {
93035 result += display.progress_block;
93036 }
93037 if (i < display.width) {
93038 // print a partial block based on the percentage of the progress bar remaining
93039 idx_t index = idx_t((blocks_to_draw - static_cast<double>(idx_t(blocks_to_draw))) *
93040 static_cast<double>(display.partial_block_count));
93041 if (index >= display.partial_block_count) {
93042 index = display.partial_block_count - 1;
93043 }
93044 result += display.progress_partial[index];
93045 i++;
93046 }
93047 for (; i < display.width; i++) {
93048 result += display.progress_empty;
93049 }
93050 result += display.progress_end;
93051 return result;
93052}
index

◆ PrintProgressInternal()

void duckdb::TerminalProgressBarDisplay::PrintProgressInternal ( int32_t percentage,
double estimated_remaining_seconds,
bool is_finished = false )
protectedvirtual
93054 {
93055 string result;
93056
93057 // render the percentage with some padding to ensure everything stays nicely aligned
93058 result = "\r";
93059 if (percentage < 100) {
93060 result += " ";
93061 }
93062 if (percentage < 10) {
93063 result += " ";
93064 }
93065 result += to_string(percentage) + "%";
93066 result += " ";
93067 result += FormatProgressBar(display_info, percentage);
93068 result += " ";
93069 result += FormatETA(seconds, finished);
93070
93071 Printer::RawPrint(OutputStream::STREAM_STDOUT, result);
93072}
std::string to_string(const T &value)
Definition duckdb.cpp:19425

◆ NormalizePercentage()

int32_t duckdb::TerminalProgressBarDisplay::NormalizePercentage ( double percentage)
staticprotected
92960 {
92961 if (percentage > 100) {
92962 return 100;
92963 }
92964 if (percentage < 0) {
92965 return 0;
92966 }
92967 return int32_t(percentage);
92968}
::int32_t int32_t

◆ GetElapsedDuration()

double duckdb::TerminalProgressBarDisplay::GetElapsedDuration ( )
inlineprotected
92782 {
92783 auto now = std::chrono::steady_clock::now();
92784 return std::chrono::duration<double>(now - start_time).count();
92785 }

The documentation for this class was generated from the following file: