Advertisement
Korotkodul

Задача 1. DAU, WAU, MAU

Oct 24th, 2024 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from uuid import UUID
  2. from typing import Sequence
  3.  
  4.  
  5. class PeriodActiveUsers:
  6.     Users = {}
  7.     def __init__(self, accumulation_period: int) -> None:
  8.         try:
  9.             accumulation_period = round(accumulation_period)
  10.         except:
  11.             raise TypeError
  12.         if accumulation_period < 1:
  13.             raise ValueError
  14.         self._accumulation_period = accumulation_period
  15.  
  16.     def add_active_users_for_curr_day(self, users: Sequence[UUID]) -> None:
  17.         need_to_pop = []
  18.         for id in self.Users:
  19.             self.Users[id] += 1
  20.             if self.Users[id] > self._accumulation_period:
  21.                 need_to_pop.append(id)
  22.         for id in need_to_pop:
  23.             self.Users.pop(id)
  24.         for id in users:
  25.             self.Users[id] = 1
  26.  
  27.     @property
  28.     def unique_users_amount(self) -> int:
  29.         return len(self.Users)
  30.  
  31.     @property
  32.     def accumulation_period(self) -> int:
  33.         return self._accumulation_period
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement