from performance.repository import BreakdownOptionsRepository from performance.schemas import BreakdownOptionSchema from models import PerformanceBreakdownOption from typing import List from enum import Enum from models.performance_breakdown_option import BreakdownOptions class BreakdownType(Enum): ARTISTS = 1 PROJECTS = 2 CAMPAIGNS = 3 UNASSIGNED_CAMPAIGNS = 4 class BreakdownOptionsService: repository: BreakdownOptionsRepository = BreakdownOptionsRepository() # Details here: DEC-4069 disabled_options = [BreakdownOptions.AGE_AND_GENDERS.value, BreakdownOptions.GOALS.value] excluded_campaigns_options = [ BreakdownOptions.ARTISTS.value, BreakdownOptions.PROJECTS.value, BreakdownOptions.CAMPAIGNS.value, BreakdownOptions.CATEGORIES.value, BreakdownOptions.OBJECTIVES.value, BreakdownOptions.CAMPAIGN_TYPES.value, ] excluded_options = { BreakdownType.ARTISTS: [BreakdownOptions.ARTISTS.value], BreakdownType.PROJECTS: [BreakdownOptions.ARTISTS.value, BreakdownOptions.PROJECTS.value], BreakdownType.CAMPAIGNS: excluded_campaigns_options, BreakdownType.UNASSIGNED_CAMPAIGNS: excluded_campaigns_options, } def get_sorted_options_list(self, breakdown_type: BreakdownType) -> List[BreakdownOptionSchema]: excluded_options = self.excluded_options[breakdown_type] + self.disabled_options sorted_options = self.repository.get_sorted_options_list(excluded_options) return self.__map_options_to_schema(sorted_options) def __map_options_to_schema(self, options: List[PerformanceBreakdownOption]) -> List[BreakdownOptionSchema]: return [self.__map_option_to_schema(option) for option in options] def __map_option_to_schema(self, option: PerformanceBreakdownOption) -> BreakdownOptionSchema: return BreakdownOptionSchema(id=option.id, name=option.name, group=option.group, daysRange=option.days_range)