retrait TODO.
[minwii.git] / src / logging / EventLog.py
1 '''
2 Created on 21 aout 2009
3
4 @author: Samuel Benveniste
5 '''
6 import time
7
8 class EventLog:
9 '''
10 classdocs
11 '''
12
13 def __init__(self,eventGroups = [], times = []):
14 '''
15 Constructor
16 '''
17 self.eventGroups = eventGroups
18 self.times = times
19 self.rate = 1
20 self.yielder = self.eventGroupYielder()
21 self.yieldPointer = 0
22
23 self._timeCounter = 0
24
25 def __getstate__(self):
26 d = []
27 d.append(self.eventGroups)
28 d.append(self.times)
29 return d
30
31 def __setstate__(self,d):
32 self.eventGroups = d[0]
33 self.times = d[1]
34 self.yielder = self.eventGroupYielder()
35
36 self._timeCounter = 0
37
38 def appendEventGroup(self, eventGroup):
39 t = time.clock()*1000
40 self.times.append(t)
41 self.eventGroups.append(eventGroup)
42
43 def update(self,timePassed):
44 self._timeCounter += timePassed
45
46 def setReplayRate(self,rate):
47 self.rate = rate
48 self.yielder = self.eventGroupYielder()
49
50 def getPickledEvents(self):
51 return(self.yielder.next())
52
53 def getCurrentTime(self):
54 return(self.times[self.yieldPointer])
55
56 def eventGroupYielder(self):
57 '''
58 Will return the next event to post if enough time has passed and [] otherwise
59 '''
60 i = 0
61 while i in range(len(self.eventGroups)):
62 print "rate is " + str(self.rate)
63 if self._timeCounter*self.rate>self.times[i]:
64 print str(self._timeCounter*self.rate)+" > "+ str(self.times[i])
65 self.yieldPointer = i
66 yield self.eventGroups[i]
67 i += 1
68 else:
69 yield []