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)
Example #2
0
    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, logs, **data):

        platform = get_platform(local_data=data, model=FactServicesStorefrontRegistration)
        territory = DimensionTerritory.insert(code=data['territory'])
        client = DimensionClient.insert(client_id=data['client_id'])
        try:
            device = DimensionDevice.insert(
                device_id=data.get('device_id', ''),
                make=data.get('make', ''),
                model=data.get('model', ''),
                os=data.get('os', ''),
                os_version=data.get('version', '')
            )
        except:
            device = None

        try:
            user_info = data.get('attributes', None)
            user = DimensionUser.insert(
                internal_user_id=data.get('internal_user_id', data.get('user_id', '')),
                external_user_id=data.get('external_user_id', ''),
                territory=territory,
                client=client,
                email=data.get('email', None),
                first_name=user_info.get('first_name', '') if user_info else '',
                last_name=user_info.get('last_name', '') if user_info else '',
                marketing_preference=user_info.get('marketing_preference', '') if user_info else '',
                country_of_residence=user_info.get('country_of_residence', '') if user_info else None
            )
        except Exception:
            user = None

        try:
            account = DimensionAccount.insert(
                account_id=data.get('external_user_id', data.get('internal_user_id', '')),
                account_created=data.get('account_created', None)
            )
        except:
            account = None

        fact = FactServicesStorefrontRegistration.objects.create(
            account=account,
            user=user,
            client=client,
            platform=platform,
            device=device,
            event_utc_date=DimensionUTCDate.date_from_datetime(datetime=data['event_time']),
            event_utc_datetime=data['event_time'],
            mnc=data.get('MNC', None),
            mcc=data.get('MCC', None)
        )

        try:
            FactServicesStorefrontRegistration.objects.get(pk=fact.pk)
            exist = True
        except FactServicesStorefrontRegistration.DoesNotExist:
            exist = False

        logs.completed = exist
        logs.save()
    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']),
        )
Example #6
0
def save_user(data, territory, client, event='unknown'):
    res = DimensionUser.insert(
        external_user_id=data.get('external_user_id', None),
        internal_user_id=data.get('internal_user_id', None),
        territory=territory,
        client=client
    ) if any([
        data.get('external_user_id', None),
        data.get('internal_user_id', False),
        territory,
        client
    ]) else None

    if not res:
        register_flag(
            type=MISSING_DATA,
            event=event,
            description='No user information provided in event.'
        )
    return res
Example #7
0
    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']),
        )
Example #8
0
    def create_fact(cls, logs, **data):

        platform = get_platform(local_data=data,
                                model=FactServicesStorefrontRegistration)
        territory = DimensionTerritory.insert(code=data['territory'])
        client = DimensionClient.insert(client_id=data['client_id'])
        try:
            device = DimensionDevice.insert(device_id=data.get(
                'device_id', ''),
                                            make=data.get('make', ''),
                                            model=data.get('model', ''),
                                            os=data.get('os', ''),
                                            os_version=data.get('version', ''))
        except:
            device = None

        try:
            user_info = data.get('attributes', None)
            user = DimensionUser.insert(
                internal_user_id=data.get('internal_user_id',
                                          data.get('user_id', '')),
                external_user_id=data.get('external_user_id', ''),
                territory=territory,
                client=client,
                email=data.get('email', None),
                first_name=user_info.get('first_name', '')
                if user_info else '',
                last_name=user_info.get('last_name', '') if user_info else '',
                marketing_preference=user_info.get('marketing_preference', '')
                if user_info else '',
                country_of_residence=user_info.get('country_of_residence', '')
                if user_info else None)
        except Exception:
            user = None

        try:
            account = DimensionAccount.insert(
                account_id=data.get('external_user_id',
                                    data.get('internal_user_id', '')),
                account_created=data.get('account_created', None))
        except:
            account = None

        fact = FactServicesStorefrontRegistration.objects.create(
            account=account,
            user=user,
            client=client,
            platform=platform,
            device=device,
            event_utc_date=DimensionUTCDate.date_from_datetime(
                datetime=data['event_time']),
            event_utc_datetime=data['event_time'],
            mnc=data.get('MNC', None),
            mcc=data.get('MCC', None))

        try:
            FactServicesStorefrontRegistration.objects.get(pk=fact.pk)
            exist = True
        except FactServicesStorefrontRegistration.DoesNotExist:
            exist = False

        logs.completed = exist
        logs.save()