def create_fact(cls, **data): item = DimensionItem.insert(item_id=data['item_id']) device, _ = DimensionDevice.objects.get_or_create(device_id=data['device_id']) client = DimensionClient.insert(client_id=data['client_id']) external_user_id = get(data, 'external_user_id', default='') internal_user_id = get(data, 'internal_user_id', default='') user = DimensionUser.insert( external_user_id=external_user_id, internal_user_id=internal_user_id, client=client ) # store the fact cls.objects.create( item=item, user=user, device=device, product_id=data['product_id'], asset_id=data['asset_id'], status=data['status'], network=data['network'], expiry_date=data['expiry_date'], event_utc_datetime=data['event_time'], event_utc_date=DimensionUTCDate.date_from_datetime(data['event_time']), )
def create_fact(cls, **data): event_time = data['date'] # using geoip we assert what our country code is based upon the ip address chain country_code = '' for ip_address in data['ip_address_chain']: country_code = GEO_IP_LOOKUP.get_country_code(ip_address) if country_code: break # lets now fill in our dimensions territory = DimensionTerritory.insert(code=country_code) client = DimensionClient.insert(client_id=data['client_id']) item = DimensionItem.insert(item_id=data['item_id']) device = DimensionDevice.insert(item_id=data['device_id']) status = DimensionPlayStatus.insert(status=data['status']) user = DimensionUser.insert(internal_user_id=data['internal_user_id'], external_user_id=data['external_user_id'], client=client) # we create our fact play object fshp = FactServicesHeartbeatPlay.objects.create( item_id=item, user=user, device_id=device, status=status, event_time=event_time, country_code=territory, event_utc_date=DimensionUTCDate.date_from_datetime(event_time), position=get(data, 'position', disallow=['']), # Preserve 0 bit_rate=get(data, 'bitrate', disallow=['']), # Preserve 0 ) # for any occuring buffers we create a play buffer, we can then add this to our many to many relation for buffer_duration in get(data, 'buffer_events', disallow=[None, ''], default=[]): fshpb = FactServicesHeartbeatPlayBuffer.objects.create( duration=buffer_duration, event_utc_date=DimensionUTCDate.date_from_datetime(event_time), event_time=event_time) fshp.play_buffer.add(fshpb) # if we have an init in our event - we can add this and add the foreign key to our play event # this will make for good and easy lookup of full fact play data init_duration = get(data, 'init_length', disallow=['']) if init_duration is not None: init_licensed = get(data, 'init_licensed', disallow=['', None], default=False) FactServicesHeartbeatPlayInit.objects.create( heartbeat=fshp, duration=init_duration, licensed=init_licensed, event_utc_date=DimensionUTCDate.date_from_datetime(event_time), event_time=event_time)
def create_fact(cls, data): # This is a DRM Device Id, not a Device Id. device, _ = DimensionDevice.objects.get_or_create(device_id=data['device_id']) client = DimensionClient.insert(client_id=data['client_id']) external_user_id = get(data, 'external_user_id', default=None) if external_user_id: user = DimensionUser.insert(external_user_id=external_user_id, client=client) else: user = DimensionUser.objects.get(id=-1) cls.objects.create( device=device, drm_type=data['drm_type'], user=user, transaction_id=data.get('transaction_id', None), event_utc_datetime=data['event_time'], event_utc_date=DimensionUTCDate.date_from_datetime(data['event_time']), )
def create_fact(cls, data): # This is a DRM Device Id, not a Device Id. device, _ = DimensionDevice.objects.get_or_create( device_id=data['device_id']) client = DimensionClient.insert(client_id=data['client_id']) external_user_id = get(data, 'external_user_id', default=None) if external_user_id: user = DimensionUser.insert(external_user_id=external_user_id, client=client) else: user = DimensionUser.objects.get(id=-1) cls.objects.create( device=device, drm_type=data['drm_type'], user=user, transaction_id=data.get('transaction_id', None), event_utc_datetime=data['event_time'], event_utc_date=DimensionUTCDate.date_from_datetime( data['event_time']), )