Add an event to the window. Event should be of the form (dict, count). This will also pop the oldest events and call onRemoved on them until the window size is less than timeframe.
(self, event)
| 314 | self.running_count = 0 |
| 315 | |
| 316 | def append(self, event): |
| 317 | """ Add an event to the window. Event should be of the form (dict, count). |
| 318 | This will also pop the oldest events and call onRemoved on them until the |
| 319 | window size is less than timeframe. """ |
| 320 | self.data.add(event) |
| 321 | self.running_count += event[1] |
| 322 | |
| 323 | while self.duration() >= self.timeframe: |
| 324 | oldest = self.data[0] |
| 325 | self.data.remove(oldest) |
| 326 | self.running_count -= oldest[1] |
| 327 | self.onRemoved and self.onRemoved(oldest) |
| 328 | |
| 329 | def duration(self): |
| 330 | """ Get the size in timedelta of the window. """ |