Coverage for polar/event/sorting.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 16:17 +0000

1from enum import StrEnum 1a

2from typing import Annotated 1a

3 

4from fastapi import Depends 1a

5 

6from polar.kit.sorting import Sorting, SortingGetter 1a

7 

8 

9class EventSortProperty(StrEnum): 1a

10 timestamp = "timestamp" 1a

11 

12 

13ListSorting = Annotated[ 1a

14 list[Sorting[EventSortProperty]], 

15 Depends(SortingGetter(EventSortProperty, ["-timestamp"])), 

16] 

17 

18 

19class EventNamesSortProperty(StrEnum): 1a

20 event_name = "name" # `name` is a reserved word, so we use `event_name` 1a

21 occurrences = "occurrences" 1a

22 first_seen = "first_seen" 1a

23 last_seen = "last_seen" 1a

24 

25 

26EventNamesSorting = Annotated[ 1a

27 list[Sorting[EventNamesSortProperty]], 

28 Depends( 

29 SortingGetter( 

30 EventNamesSortProperty, 

31 ["-last_seen"], 

32 ) 

33 ), 

34] 

35 

36 

37class EventStatisticsSortProperty(StrEnum): 1a

38 event_name = "name" # `name` is a reserved word, so we use `event_name` 1a

39 occurrences = "occurrences" 1a

40 total = "total" 1a

41 average = "average" 1a

42 p95 = "p95" 1a

43 p99 = "p99" 1a

44 

45 

46EventStatisticsSorting = Annotated[ 1a

47 list[Sorting[EventStatisticsSortProperty]], 

48 Depends( 

49 SortingGetter( 

50 EventStatisticsSortProperty, 

51 ["-total"], 

52 ) 

53 ), 

54]