from typing import Tuple from server.constants.dsp import ALL_VENDORS, AMAZON, APPLE, SPOTIFY _STREAMS_INFO_POSTFIX = "_streams_info" _GENDERS_KEY = "genders" _AGE_BANDS_POSTFIX = "_age_bands" def all_extra_streams_fields(dsp: str) -> Tuple[str, str, str]: """Returns tuple of names for all extra (controlled with 'include' parameter) delphi streams fields.""" return _GENDERS_KEY, f"{dsp}{_AGE_BANDS_POSTFIX}", f"{dsp}{_STREAMS_INFO_POSTFIX}" class StreamsInclude: DEMOGRAPHICS = "demographics" SAVES = "saves" SKIPS = "skips" STREAMS_INFO = "dsp_streams_info" ALL = "all" SOURCES = "sources" ENGAGEMENT = "engagement" ALL_FIELDS = (ALL, DEMOGRAPHICS, SAVES, SKIPS, STREAMS_INFO, SOURCES, ENGAGEMENT) INNER_FIELDS = (SOURCES, ENGAGEMENT) # Inner values, Delphi does not provide these types. # Mapping for inner include types to Delphi include types. INNER_FIELDS_MAPPING = { StreamsInclude.SOURCES: (StreamsInclude.STREAMS_INFO,), StreamsInclude.ENGAGEMENT: (StreamsInclude.STREAMS_INFO,), } # Extra (managed by 'include' types) data filters map in format: # {include type: {dsp: {filtered field name: iterable of only nested attributes to save or None to save all}}} STREAMS_EXTRA_FIELDS_FILTERS = { StreamsInclude.SOURCES: { APPLE: {f"{APPLE}{_STREAMS_INFO_POSTFIX}": ("source", "listeners", "container_type")}, SPOTIFY: {f"{SPOTIFY}{_STREAMS_INFO_POSTFIX}": ("source", "shuffle_play")}, AMAZON: {f"{AMAZON}{_STREAMS_INFO_POSTFIX}": ("selection_source_type",)}, }, StreamsInclude.ENGAGEMENT: { APPLE: {f"{APPLE}{_STREAMS_INFO_POSTFIX}": ("listener_engagement",)}, SPOTIFY: {f"{SPOTIFY}{_STREAMS_INFO_POSTFIX}": ("engagement",)}, AMAZON: {f"{AMAZON}{_STREAMS_INFO_POSTFIX}": ("engagement",)}, }, StreamsInclude.DEMOGRAPHICS: {dsp: {_GENDERS_KEY: None, f"{dsp}{_AGE_BANDS_POSTFIX}": None} for dsp in ALL_VENDORS}, StreamsInclude.SAVES: {dsp: {f"{dsp}{_STREAMS_INFO_POSTFIX}": ("saves",)} for dsp in ALL_VENDORS}, StreamsInclude.SKIPS: {dsp: {f"{dsp}{_STREAMS_INFO_POSTFIX}": ("skips",)} for dsp in ALL_VENDORS}, StreamsInclude.ALL: {dsp: {field: None for field in all_extra_streams_fields(dsp)} for dsp in ALL_VENDORS}, } # Extra (managed by 'include' types) data keys by dsp STREAMS_EXTRA_FIELDS_KEYS = { APPLE: all_extra_streams_fields(APPLE), SPOTIFY: all_extra_streams_fields(SPOTIFY), AMAZON: (f"{AMAZON}{_STREAMS_INFO_POSTFIX}",), }