from functools import reduce


def total_worker_load(worker_id, worker_hours, close_time):
    """
    Calculate load in all time restaurant works.
    :param worker_id: id for current worker
    :param worker_hours: map {id {interval obj: working seconds}}
    :param close_time: model global time to calculate total load correctly
    :return: load value if value < 1 else 1
    """
    period_load = worker_hours[worker_id]

    sum_seconds = reduce(lambda a, b: a + b, period_load.values())
    sum_keys = 0

    for key in period_load:
        sum_keys += (key.toInterval - key.fromInterval) if not key.last \
            else close_time - key.fromInterval

    return round(sum_seconds / sum_keys, 3) if round(sum_seconds / sum_keys, 3) < 1 else 1