Coverage for kwai/modules/training/trainings/training_query.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

1"""Module that defines an interface for a training query.""" 

2from abc import ABC, abstractmethod 

3from datetime import datetime 

4 

5from kwai.core.domain.repository.query import Query 

6from kwai.modules.training.coaches.coach import CoachEntity 

7from kwai.modules.training.teams.team import TeamEntity 

8from kwai.modules.training.trainings.training import TrainingIdentifier 

9from kwai.modules.training.trainings.training_definition import TrainingDefinitionEntity 

10 

11 

12class TrainingQuery(Query, ABC): 

13 """Interface for a training query.""" 

14 

15 @abstractmethod 

16 def filter_by_id(self, id_: TrainingIdentifier) -> "TrainingQuery": 

17 """Add a filter on a training identifier. 

18 

19 Args: 

20 id_: id of a training. 

21 """ 

22 raise NotImplementedError 

23 

24 @abstractmethod 

25 def filter_by_year_month( 

26 self, year: int, month: int | None = None 

27 ) -> "TrainingQuery": 

28 """Add filter to get only trainings for the given year/month. 

29 

30 Args: 

31 year: The year to use for the filter. 

32 month: The month to use for the filter. 

33 """ 

34 raise NotImplementedError 

35 

36 @abstractmethod 

37 def filter_by_dates(self, start: datetime, end: datetime) -> "TrainingQuery": 

38 """Add filter to get only trainings between two dates. 

39 

40 Args: 

41 start: The start date to use for the filter. 

42 end: The end date to use for the filter. 

43 """ 

44 raise NotImplementedError 

45 

46 @abstractmethod 

47 def filter_by_coach(self, coach: CoachEntity) -> "TrainingQuery": 

48 """Add filter to get only trainings for the given week. 

49 

50 Args: 

51 coach: The coach to use for the filter. 

52 """ 

53 raise NotImplementedError 

54 

55 @abstractmethod 

56 def filter_by_team(self, team: TeamEntity) -> "TrainingQuery": 

57 """Add filter to get only trainings for the given team. 

58 

59 Args: 

60 team: The team to use for the filter. 

61 """ 

62 raise NotImplementedError 

63 

64 @abstractmethod 

65 def filter_by_definition( 

66 self, definition: TrainingDefinitionEntity 

67 ) -> "TrainingQuery": 

68 """Add filter to get only trainings for the given definition. 

69 

70 Args: 

71 definition: The definition to use for the filter. 

72 """ 

73 raise NotImplementedError 

74 

75 @abstractmethod 

76 def filter_active(self) -> "TrainingQuery": 

77 """Add filter to get only the active trainings.""" 

78 raise NotImplementedError 

79 

80 @abstractmethod 

81 def order_by_date(self) -> "TrainingQuery": 

82 """Order the trainings by date.""" 

83 raise NotImplementedError