from .manufacturing_takt_time_types import TaktTime from .math_rational import rational, rational_to_integer from .math_round_div import RoundingMode MAX_SAFE = 2**53 - 1 def takt_time(available_seconds: int, demand: int, mode: RoundingMode) -> TaktTime: """Takt time, available time / demand, as an exact fraction and in whole seconds. The whole seconds are rounded once from the exact fraction, so a caller balancing a line on ``exact`` never inherits a rounding step. """ if ( isinstance(available_seconds, bool) or not isinstance(available_seconds, int) or available_seconds < 0 or available_seconds > MAX_SAFE ): raise ValueError( "availableSeconds must be a whole number of seconds, not negative, received %r" % (available_seconds,) ) if isinstance(demand, bool) or not isinstance(demand, int) or demand <= 0 or demand > MAX_SAFE: raise ValueError("demand must be a whole number of units greater than zero, received %r" % (demand,)) exact = rational(available_seconds, demand) return TaktTime(exact=exact, seconds=rational_to_integer(exact, mode))