示例#1
0
    def maxWait(self, arrival, service):
        q = Queue(data=zip(arrival, service))
        current_time = 0
        max_waiting_time = 0
        while not q.is_empty():

            arrival, service = q.dequeue()
            waiting_time = 0

            if arrival > current_time:
                current_time = arrival

            waiting_time += current_time - arrival

            current_time += service
            max_waiting_time = max(max_waiting_time, waiting_time)

        return max_waiting_time
示例#2
0
    def maxWait(self, arrival, service):
        q = Queue(data=zip(arrival,service))
        current_time = 0
        max_waiting_time = 0
        while not q.is_empty():

            arrival, service = q.dequeue()
            waiting_time = 0

            if arrival > current_time:
                current_time = arrival

            waiting_time += current_time - arrival

            current_time += service
            max_waiting_time = max(max_waiting_time, waiting_time)

        return max_waiting_time
示例#3
0
    def howMuch(self, arrival, departure, wage):

        time_converter = lambda x: datetime.strptime(x, '%H:%M:%S')

        arrival = map(time_converter, arrival)
        departure = map(time_converter, departure)

        q = Queue(zip(arrival, departure))

        evening = datetime.strptime('18:00:00', '%H:%M:%S')
        morning = datetime.strptime('06:00:00', '%H:%M:%S')

        night_shifts = []
        day_shifts = []

        while not q.is_empty():
            arr, dep = q.dequeue()

            if arr < morning and dep < morning:
                night_shifts.append((arr, dep))

            elif arr < morning <= dep:
                night_shifts.append((arr, morning))
                q.enqueue((morning, dep))

            elif morning <= arr < evening and morning <= dep < evening:
                day_shifts.append((arr, dep))

            elif arr < evening <= dep:
                day_shifts.append((arr, evening))
                q.enqueue((evening, dep))

            else:
                night_shifts.append((arr, dep))

        pay = 0
        pay += wage * sum(list(map(self.calculate_time_difference,
                                   day_shifts)))
        pay += wage * sum(
            list(map(self.calculate_time_difference, night_shifts))) * 1.5

        return pay