Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from uuid import UUID
- from typing import Sequence
- class PeriodActiveUsers:
- Users = {}
- def __init__(self, accumulation_period: int) -> None:
- try:
- accumulation_period = round(accumulation_period)
- except:
- raise TypeError
- if accumulation_period < 1:
- raise ValueError
- self._accumulation_period = accumulation_period
- def add_active_users_for_curr_day(self, users: Sequence[UUID]) -> None:
- need_to_pop = []
- for id in self.Users:
- self.Users[id] += 1
- if self.Users[id] > self._accumulation_period:
- need_to_pop.append(id)
- for id in need_to_pop:
- self.Users.pop(id)
- for id in users:
- self.Users[id] = 1
- @property
- def unique_users_amount(self) -> int:
- return len(self.Users)
- @property
- def accumulation_period(self) -> int:
- return self._accumulation_period
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement