"""Constants for analytics microservice.""" class EntityTypes: """Entity type enumerator class.""" LABEL = 'L' SUBACCOUNT = 'S' ALBUM = 'A' @classmethod def get_entity_from_name(cls, name): """Get the entity type from name. Args: name (str): the name of the entity (not case sensitive) Returns: str: the entity type. """ for entity in dir(cls): if entity.lower() == name.lower(): value = getattr(cls, entity) if isinstance(value, str): return value class UserFields: """ User fields enumerator class. Whenever we need to verify if a user has access to a specific row or result set - we can just do so by turning the user type into a specific field. """ L = 'label_id' S = 'subaccount_id' SOURCE_DEFAULT = 'store_ids' SOURCE_SOCIAL_MEDIA = 'social_media_ids' class TransactionType: """ Transaction Type. Representation of a transaction type within our different systems (fact analytics and fact social). This new transaction type conserves some values that are part of our legacy such as the source_type, sequence_id and source_id (all the optional values.) This object is used later on in the response to transform the data passed to it. TODO(mortali): we might want to add some tests if this class gets more complex – but for now only one line (testing: self.source_type) would be a valuable test. """ def __init__( self, id, name, abbr, source_type=None, sequence_id=None, source_id=None): """Create a Transaction Type. Args: name (str): name of the transaction type. abbr (str): abbreviation of the transaction type. source_type (str): origin of the data (store or social) sequence_id (str): legacy information used by the frontend. source_id (str): legacy information used by the frontend. """ self.id = id self.name = name self.abbr = abbr # Social has a collision with our other graphs, the source_type # allows to distinguish the two. self.source_type = source_type or SOURCE_DEFAULT # The sequence id is used by the graph to be sorted. self.sequence_id = sequence_id or self.id self.source_id = source_id # TODO(mortali): make this variable more consistant, it should be # TransactionTypes. TRANSACTION_TYPES = { 1: TransactionType(1, name='Subscription Audio Streams', abbr='S'), 2: TransactionType(2, name='Sync Revenue', abbr='SR'), 3: TransactionType(3, name='Royalty Collections', abbr='RC'), 4: TransactionType(4, name='Downloaded Ringtones', abbr='DR'), 5: TransactionType(5, name='Ringbacks', abbr='RB'), 6: TransactionType(6, name='Upgraded Download Albums', abbr='UA'), 7: TransactionType(7, name='Upgraded Download Tracks', abbr='UT'), 8: TransactionType(8, name='Upgraded Download Videos', abbr='UV'), 9: TransactionType(9, name='Ad-Supported Video Streams', abbr='AV'), 10: TransactionType(10, name='Ad-Supported Audio Streams', abbr='AS'), 12: TransactionType(12, name='Video Download Purchases', abbr='DV'), 13: TransactionType(13, name='Download Rentals', abbr='RD'), 14: TransactionType(14, name='Term Licenses', abbr='TL'), 15: TransactionType(15, name='Video Bundles', abbr='VB'), 16: TransactionType(16, name='Video Rentals', abbr='VR'), 17: TransactionType(17, name='Subscription Video Streams', abbr='SV'), 18: TransactionType(18, name='Trailers', abbr='TR'), 19: TransactionType(19, name='Download Tracks', abbr='DT'), 20: TransactionType(20, name='Tethered Downloads', abbr='TD'), 21: TransactionType(21, name='Segments', abbr='SE'), 22: TransactionType(22, name='Mobile Videos', abbr='MV'), 23: TransactionType(23, name='Download Albums', abbr='DA'), 25: TransactionType(25, name='Video Ringtones', abbr='RV'), 26: TransactionType(26, name='Pre Cut Ringtones', abbr='PR'), 27: TransactionType(27, name='Non-Interactive Radio', abbr='NR'), 28: TransactionType(28, name='Cloud Match Units', abbr='CL'), 29: TransactionType(29, name='Tethered Albums', abbr='TA'), 30: TransactionType(30, name='Video Seasons', abbr='VS'), 31: TransactionType(31, name='Ad-Disabled Audio Streams', abbr='US'), 32: TransactionType(32, name='Ad-Disabled Video Streams', abbr='VU'), 33: TransactionType(33, name='Audio UGC Matches', abbr='CA'), 34: TransactionType(34, name='Visual UGC Matches', abbr='CV'), 35: TransactionType(35, name='AudioVisual UGC Matches', abbr='CAV'), 37: TransactionType(37, name='Ad-Enabled Audio Streams', abbr='AEA'), 38: TransactionType(38, name='Ad-Enabled Video Streams', abbr='AEV'), 48: TransactionType(48, name='Mid-Tier Subscription Audio Streams', abbr='MT'), # Social # Notes(mortali): # I've discussed with Rishi. The keys (FFA, FFR, and FEEI) # are now matching more closely what facebok uses (fan unique adds, # fan unique removes, and fan interactions.) 10001: TransactionType( 1, 'Fans Gained', abbr='FFA', source_type=SOURCE_SOCIAL_MEDIA, sequence_id='FansGain-1', source_id='social_1'), 10002: TransactionType( 2, 'Fans Lost', abbr='FFR', source_type=SOURCE_SOCIAL_MEDIA, sequence_id='FansLost-2', source_id='social_2'), # Dislikes 10003: TransactionType( 3, 'Facebook Impressions', abbr='FEI', source_type=SOURCE_SOCIAL_MEDIA, sequence_id='Engagement-3', source_id='social_3') } ARRAY_DEFAULT_KEY = 'items' MAX_DAYS_IN_DATE_RANGE = 375 GENDERS = ('women', 'men', 'unknown') SPOTIFY_ID = '286' APPLE_MUSIC_ID = '1' AVAILABLE_DEMOGRAPHICS_STORE_IDS = [SPOTIFY_ID, APPLE_MUSIC_ID]