otx.api.utils.time_utils#

This module implements time related utility functions.

Functions

now()

Return the current UTC creation_date and time up to a millisecond accuracy.

timeit(func)

This function can be used as a decorator as @timeit.

Classes

TimeEstimator([smoothing_factor, ...])

The time estimator.

class otx.api.utils.time_utils.TimeEstimator(smoothing_factor: float = 0.02, inflation_factor: float = 1.1, update_window: float = 1.0, starting_progress: float = 1.0)[source]#

Bases: object

The time estimator.

Estimate the remaining time given the progress, and the progress changes. The estimator starts estimation at a starting progress that is not necessarily 0. This choice is motivated by the fact that the first percent of progress often takes a much longer time than the following percents.

Parameters:
  • smoothing_factor (float) – Smoothing factor for the exponentially weighted moving average. There’s a great explanation at https://www.wallstreetmojo.com/ewma/

  • inflation_factor (float) – The factor by which the initial total time estimation is inflated to ensure decreasing

  • update_window (float) – Last update happened at progress1, next update will happen at (progress1 + update window)

  • starting_progress (float) – The progress at which the time_remaining estimation starts time estimation

get_time_remaining()[source]#

If the new estimation is higher than the previous one by up to 2 seconds, return old estimation.

Returns:

Estimated remaining time in seconds (float)

time_remaining_from_progress(progress: float) float[source]#

Updates the current progress, and returns the estimated remaining time in seconds (float).

Parameters:

progress (float) – The new progress (floating point percentage, 0.0 - 100.0)

Returns:

The expected remaining time in seconds (float)

update(progress: float)[source]#

Update the estimator with a new progress (floating point percentage, between 0.0 - 100.0).

Parameters:

progress (float) – Progress of the process

Returns:

None

otx.api.utils.time_utils.now() datetime[source]#

Return the current UTC creation_date and time up to a millisecond accuracy.

This function is preferable over the Python datetime.datetime.now() function because it uses the same accuracy (milliseconds) as MongoDB rather than microsecond accuracy.

Returns:

Date and time up to a millisecond precision.

otx.api.utils.time_utils.timeit(func)[source]#

This function can be used as a decorator as @timeit.

It will print out how long the function took to execute.

Parameters:

func – The decorated function

Returns:

The wrapped function