"""Utils and helpers related to store availability.""" from analytics.constants import store from analytics.utils.data_availability import get_feeds_with_outages_v2 def get_store_names(): """Return dict of stores with names and ids. Returns: dict: The dictionary {storeid: store_name}. """ stores = store.ACTIVE_STORE_NAMES stores.update(store.ACTIVE_VIDEO_STORE_NAMES) return stores def get_download_store_names(): """Return dict of download stores with names and ids. Returns: dict: The dictionary {storeid: store_name}. """ return store.ACTIVE_DOWNLOAD_STORE_NAMES def get_video_store_names(): """Return dict of video streaming stores with names and ids. Returns: dict: The dictionary {storeid: store_name}. """ return store.ACTIVE_VIDEO_STORE_NAMES def get_store_ids(): """Return list of storeids. Returns: list: The list with stores ids. """ return list(get_store_names().keys()) def get_video_store_ids(): """Return list of video streaming storeids. Returns: list: The list with stores ids. """ return list(get_video_store_names().keys()) def get_sources(): """Return dict of stores with names and ids. Returns: list: The list with stores ids. """ return store.ALL_SOURCES.copy() def get_video_sources(): """Return dict of stores with names and ids. Returns: list: The list with stores ids. """ return store.ALL_VIDEO_SOURCES def get_demographic_store_ids(): """Return list of demographic ids. Returns: list: Integer the store ids """ return list(store.ACTIVE_DEMOGRAPHIC_STORE_NAMES.keys()) def get_demographic_sources(): """Return dict of stores with names and ids. Returns: list: The list with stores ids. """ return store.ALL_DEMOGRAPHIC_SOURCES def get_query_store_ids(store_ids, store_type=""): """Use query param ids to work out which store ids to use. If there are no param store ids use defaults. Returns: list: The list of useable store ids. """ available_stores = get_store_ids() if store_type == store.VIDEO_STORE: available_stores = get_video_store_ids() if not store_ids: return available_stores return sorted(list(set(store_ids).intersection(available_stores))) def is_apple_spotify_data_in_sync(): feed_statuses = get_feeds_with_outages_v2().get("feed_statuses") # Check store_high_water_mark date for Spotify(1) and APPLE(4) in FEEDS # if DSPs have the same store_high_water_mark then growth_percentage_1_day should be returned store_high_water_mark = { fs.get("store_high_water_mark") for fs in feed_statuses if fs.get("feed_id") in {1, 4} # Spotify(1) and APPLE(4) in FEEDS } return len(store_high_water_mark) == 1