def _preconditions(self, row=dict): try: _row = FactServicesStorefrontSubscription.objects.get(id=row['id']) except FactServicesStorefrontSubscription.DoesNotExist: # this is fine, as there is no previous row, so we dont need to assert anything _row = None if _row: current_state = FactServicesStorefrontSubscription.get_last_event( subscription_id=_row.subscription_id, date=_row.event_utc_datetime) state, err = get_rule(status=_row.subscription_status.id, current_state=current_state, window_ongoing=_row.window.on_going) _state_obj, _ = DimensionSubscriptionState.objects.get_or_create( state=state) _row.subscription_state = _state_obj _row.subscription_state_error = err _row.save() row['subscription_state_id__state'] = state row['subscription_state_error'] = err del row['subscription_id'] return row, True
def _preconditions(self, row=dict): try: _row = FactServicesStorefrontSubscription.objects.get(id=row["id"]) except FactServicesStorefrontSubscription.DoesNotExist: # this is fine, as there is no previous row, so we dont need to assert anything _row = None if _row: current_state = FactServicesStorefrontSubscription.get_last_event( subscription_id=_row.subscription_id, date=_row.event_utc_datetime ) state, err = get_rule( status=_row.subscription_status.id, current_state=current_state, window_ongoing=_row.window.on_going ) _state_obj, _ = DimensionSubscriptionState.objects.get_or_create(state=state) _row.subscription_state = _state_obj _row.subscription_state_error = err _row.save() row["subscription_state_id__state"] = state row["subscription_state_error"] = err del row["subscription_id"] return row, True
def create_fact(cls, logs, **data): # dims platform = save_platform(data, event='Storefront Subscription') territory = DimensionTerritory.insert(code=data['territory']) if exists('territory', data) else None client = DimensionClient.insert(client_id=data['client_id']) if exists('client_id', data) else None du = save_user(data, territory, client, event='Storefront Subscription') dst = DST.insert( period=data['subscription_period'] if exists('subscription_period', data) else None, recurrence=data['subscription_recurrence'] if exists('subscription_recurrence', data) else None ) if any([d in data for d in ['subscription_period', 'subscription_recurrence']]) else None dss_status, _ = DSS.insert(event=int(data['subscription_status'])) if exists('subscription_status', data) else None state, err = get_rule( status=data.get('subscription_status', None), current_state=FactServicesStorefrontSubscription.get_last_event( subscription_id=data.get('subscription_id', None) ), window_ongoing=bool(data.get('window_on_going', False)) ) dsse, _ = DSSe.objects.get_or_create(state=state) item = DimensionItem.insert(item_id=data.get('item_id')) if exists('item_id', data) else None product = DimensionProduct.insert(product_id=data.get('product_id')) if exists('product_id', data) else None usage_right = DimensionRight.insert( right_id=data.get('window_usage_right_id') ) if exists('window_usage_right_id', data) else None window = DimensionWindow.insert( window_id=data.get('window_id', None), item=item, product=product, start_date=data['window_start_date'], end_date=data['window_end_date'], pricing_id=data['window_pricing_id'], usage_right_id=usage_right, tier=data['window_tier'], deleted=data['window_deleted_date'], window_type=data['window_type'], on_going=data['window_on_going'], repeat_count=data['window_repeat_count'], auto_upgrade=data['window_auto_upgrade'], allow_repurchase=data['window_allow_repurchase'], apple_product_id=data['apple_product_id'], )if any([i in data for i in [ 'window_id', 'item_id', 'product_id', 'window_start_date', 'window_end_date', 'window_pricing_id', 'window_usage_right_id', 'window_tier', 'window_deleted_date', 'window_type', 'window_on_going', 'window_repeat_count', 'window_auto_upgrade', 'window_allow_repurchase', 'apple_product_id', ]]) else None # fact create fact = FactServicesStorefrontSubscription.objects.create( user=du, subscription_id=data.get('subscription_id', None), subscription_type=dst, subscription_status=dss_status, subscription_state=dsse, subscription_state_error=err, platform=platform, window=window, transaction_id=data.get('transaction_id', None), event_utc_date=DimensionUTCDate.date_from_datetime(datetime=data['event_time']), event_utc_datetime=data.get('event_time', None) ) try: FactServicesStorefrontSubscription.objects.get(pk=fact.pk) exist = True except FactServicesStorefrontSubscription.DoesNotExist: exist = False logs.completed = exist logs.save()
def create_fact(cls, logs, **data): # dims platform = save_platform(data, event='Storefront Subscription') territory = DimensionTerritory.insert( code=data['territory']) if exists('territory', data) else None client = DimensionClient.insert( client_id=data['client_id']) if exists('client_id', data) else None du = save_user(data, territory, client, event='Storefront Subscription') dst = DST.insert( period=data['subscription_period'] if exists( 'subscription_period', data) else None, recurrence=data['subscription_recurrence'] if exists('subscription_recurrence', data) else None) if any([ d in data for d in ['subscription_period', 'subscription_recurrence'] ]) else None dss_status, _ = DSS.insert( event=int(data['subscription_status'])) if exists( 'subscription_status', data) else None state, err = get_rule( status=data.get('subscription_status', None), current_state=FactServicesStorefrontSubscription.get_last_event( subscription_id=data.get('subscription_id', None)), window_ongoing=bool(data.get('window_on_going', False))) dsse, _ = DSSe.objects.get_or_create(state=state) item = DimensionItem.insert( item_id=data.get('item_id')) if exists('item_id', data) else None product = DimensionProduct.insert( product_id=data.get('product_id')) if exists('product_id', data) else None usage_right = DimensionRight.insert( right_id=data.get('window_usage_right_id')) if exists( 'window_usage_right_id', data) else None window = DimensionWindow.insert( window_id=data.get('window_id', None), item=item, product=product, start_date=data['window_start_date'], end_date=data['window_end_date'], pricing_id=data['window_pricing_id'], usage_right_id=usage_right, tier=data['window_tier'], deleted=data['window_deleted_date'], window_type=data['window_type'], on_going=data['window_on_going'], repeat_count=data['window_repeat_count'], auto_upgrade=data['window_auto_upgrade'], allow_repurchase=data['window_allow_repurchase'], apple_product_id=data['apple_product_id'], ) if any([ i in data for i in [ 'window_id', 'item_id', 'product_id', 'window_start_date', 'window_end_date', 'window_pricing_id', 'window_usage_right_id', 'window_tier', 'window_deleted_date', 'window_type', 'window_on_going', 'window_repeat_count', 'window_auto_upgrade', 'window_allow_repurchase', 'apple_product_id', ] ]) else None # fact create fact = FactServicesStorefrontSubscription.objects.create( user=du, subscription_id=data.get('subscription_id', None), subscription_type=dst, subscription_status=dss_status, subscription_state=dsse, subscription_state_error=err, platform=platform, window=window, transaction_id=data.get('transaction_id', None), event_utc_date=DimensionUTCDate.date_from_datetime( datetime=data['event_time']), event_utc_datetime=data.get('event_time', None)) try: FactServicesStorefrontSubscription.objects.get(pk=fact.pk) exist = True except FactServicesStorefrontSubscription.DoesNotExist: exist = False logs.completed = exist logs.save()