Statistics
| Branch: | Revision:

mobicen / util / EventScheduler.py @ fa4a0a42

History | View | Annotate | Download (903 Bytes)

1
import heapq
2

    
3
class EventScheduler:
4
        def __init__(self):
5
                self.queue = []
6
                self.time = 0
7
                self.last = 0
8
                self._step = 0
9
                self.counter = 0
10

    
11
        def schedule_event(self, interval, e):
12
                t = self.time + interval
13
                if t > self.last:
14
                    self.last = t
15
                heapq.heappush(self.queue, (t, e))
16

    
17
        def pop_event(self):
18
                e = heapq.heappop(self.queue)
19
                self._step = e[0] - self.time
20
                self.time = e[0]
21
                self.counter += 1
22
                return e[1]
23

    
24
        def elapsed_time(self):
25
                return self.time
26

    
27
        def last_event_time(self):
28
                return self.last
29

    
30
        def step(self):
31
            return self._step
32

    
33
        def processed_events(self):
34
            return self.counter