otx.api.utils.time_utils#
This module implements time related utility functions.
Functions
|
Return the current UTC creation_date and time up to a millisecond accuracy. |
|
This function can be used as a decorator as @timeit. |
Classes
|
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)
- 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.