Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. from enum import Enum
  2. from sortedcontainers import SortedList
  3.  
  4.  
  5. class EventType(Enum):
  6.     ENQUEUE = 0
  7.     DEQUEUE = 1
  8.  
  9.  
  10. class Client(object):
  11.     def __init__(self, id=None, time_in=0, time_out=0, time_queue=None):
  12.         self.id = id
  13.         self.time_in = time_in
  14.         self.time_out = time_out
  15.         self.time_queue = time_queue
  16.  
  17.  
  18. class Event(object):
  19.     def __init__(self, client_id=None, time=0, event_type=None):
  20.         self.client_id = client_id
  21.         self.time = time
  22.         self.type = event_type
  23.  
  24.     def __lt__(self, other):
  25.         return self.time < other.time
  26.  
  27.  
  28. def fill_events():
  29.  
  30.     for client in clients:
  31.         if len(event_calendar) == 0:
  32.             event_calendar.add(Event(client.id, client.time_in, EventType.ENQUEUE))
  33.         else:
  34.             event_calendar.add(Event(client.id, client.time_in + event_calendar[-1].time, EventType.ENQUEUE))
  35.  
  36.  
  37. if __name__ == '__main__':
  38.  
  39.     clients = list()
  40.     clients.append(Client(0, 2.2, 2.7))
  41.     clients.append(Client(1, 1.4, 0.9))
  42.     clients.append(Client(2, 1.6, 1.2))
  43.  
  44.     event_calendar = SortedList()
  45.     fill_events()
  46.  
  47.     for event in event_calendar:
  48.         print(event.time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement