HelperFunctions.kt has some documentation

This commit is contained in:
dtookey 2023-08-06 19:25:19 -04:00
parent 234adbf9b5
commit a8406bbc9a

View File

@ -13,39 +13,24 @@ object HelperFunctions {
0 0
} }
/** /**
* Prints a progress report for the current step. * Prints a progress report to console showing current step, total steps, elapsed time, and estimated remaining time.
* *
* @param step The current step number. * @param step The current step number
* @param of The total number of steps. * @param of The total number of steps
* @param dur The duration in milliseconds so far. * @param dur The elapsed duration so far in milliseconds
*
* This method prints a progress report to the console in the format:
* "Step {step} of {of} ({formattedDuration} complete | ~{remainingTime} remaining)"
*
* It calculates the estimated remaining time based on the current duration and
* number of steps completed vs total steps.
*
* The output is printed on the same line to dynamically update the progress.
*/ */
fun report(step: Int, of: Int, dur: Long) { fun report(step: Int, of: Int, dur: Long) {
val remaining = (dur / step) * (of - step) val remaining = (dur / step) * (of - step)
print("\rStep $step of $of (${prettyTimeString(dur)} complete\t|\t~${prettyTimeString(remaining)} remaining) ") print("\rStep $step of $of (${prettyTimeString(dur)} complete\t|\t~${prettyTimeString(remaining)} remaining) ")
} }
/** /**
* Formats the given duration in milliseconds into a human readable time string. * Converts a duration in milliseconds to a human-readable string.
* *
* @param durationMillis The duration to format in milliseconds. * @param durationMillis The duration to convert, in milliseconds
* * @return A string representation of the duration, in the format XhYmZs
* @return A formatted time string showing the duration broken down into hours, minutes, and seconds.
*
* This converts the duration into hours, minutes, and seconds based on millis per second,
* minute, and hour constants. It returns a string in the format "XhYmZs" where X, Y, and Z are
* the calculated hours, minutes, and seconds.
*
* If durationMillis is 0, it returns "No time data yet" instead.
*/ */
fun prettyTimeString(durationMillis: Long): String { fun prettyTimeString(durationMillis: Long): String {
if (durationMillis == 0L) { if (durationMillis == 0L) {