Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from collections import deque
- class Server:
- def __init__(self, dt):
- self.dt = dt
- self.queue = deque()
- self.last_ids = set()
- self.all_ids = {}
- def register_event(self, id):
- self.queue.append((id, time.time()))
- self.all_ids[id] += 1
- if self.all_ids[id] > 1000:
- self.last_ids.add(id)
- def check(self, ntime):
- while len(self.queue):
- q = self.queue.popleft()
- if ntime - q[1] <= self.dt:
- self.queue.appendleft(q)
- break
- self.all_ids[q[0]] -= 1
- if self.all_ids[id] < 1000 and q[0] in self.last_ids:
- self.last_ids.remove(q[0])
- def get_ids(self):
- self.check(time.time())
- return self.last_ids
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement