Functional Weave
Code in TypeScript

manufacturing.takt-time@1.0.0

impl/python.py

1,161 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .manufacturing_takt_time_types import TaktTime
from .math_rational import rational, rational_to_integer  ← from math.rational ^1.0.0 · built alongside by fune
from .math_round_div import RoundingMode  ← from math.round-div ^1.0.0 · built alongside by fune

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))