diff --git a/scripts/app/gen_trans_data.py b/scripts/app/gen_trans_data.py index 8bf89ad..2b7aad9 100644 --- a/scripts/app/gen_trans_data.py +++ b/scripts/app/gen_trans_data.py @@ -57,19 +57,21 @@ def gen_trans_data(user_data, device_obj, card_obj, ip_obj, transaction_obj, app trans_data['ip_country_code'] = trans_data['ip_hash'].replace(ip_obj.ip_hashes_country_code_dict) # add transaction data trans_data['transaction_amount'] = trans_data['application_hash'].replace(application_obj.application_hashes_prices_dict) - trans_data['payment_channel'] = trans_data['transaction_hash'].replace(transaction_obj.transaction_hashes_payment_channel_dict) + trans_data['card_payment_channel'] = trans_data['transaction_hash'].replace(transaction_obj.transaction_hashes_payment_channel_dict) trans_data['transaction_date'] = trans_data['transaction_hash'].replace(transaction_obj.transaction_hashes_dates_dict) # TODO: wrap this logic up into a seperate function # align payment channel with missing card hashes and 0 transaction amounts zero_transaction_amount_filter = (trans_data['transaction_amount'] == 0.0) missing_card_hash_filter = (trans_data['card_hash'].isnull()) - trans_data.loc[zero_transaction_amount_filter | missing_card_hash_filter, ['payment_channel']] = np.nan + trans_data.loc[zero_transaction_amount_filter | missing_card_hash_filter, ['card_payment_channel']] = np.nan trans_data.loc[zero_transaction_amount_filter, ['card_hash', 'card_type', 'card_country_code']] = np.nan - # add app store points indicator for transaction with no payments channel and positive transaction amounts - trans_data['store_points_ind'] = 0 - appstorepoints_filt = (trans_data['card_hash'].isnull()) & (trans_data['payment_channel'].isnull()) & (trans_data['transaction_amount'] > 0.0) - trans_data.loc[appstorepoints_filt, 'store_points_ind'] = appstorepoints_filt.apply(lambda x: np.random.choice(a = list(cons.data_model_app_store_points.keys()), size = 1, p = list(cons.data_model_app_store_points.values()))[0]) + # add payment method as either card, store_wallet or store_points + trans_data['transaction_payment_method'] = 'card' + zero_transaction_amount_filter = (trans_data['transaction_amount'] == 0.0) + missing_card_hash_filter = (trans_data['card_hash'].isnull()) + trans_data.loc[missing_card_hash_filter, 'transaction_payment_method'] = missing_card_hash_filter.apply(lambda x: np.random.choice(a = list(cons.data_model_non_card_trans_methods.keys()), size = 1, p = list(cons.data_model_non_card_trans_methods.values()))[0]) + trans_data.loc[zero_transaction_amount_filter, 'transaction_payment_method'] = np.nan # align country codes for user, ip and card country_code_columns = ['registration_country_code', 'ip_country_code', 'card_country_code'] trans_data[country_code_columns] = trans_data[country_code_columns].apply(lambda series: align_country_codes(series), axis = 1) diff --git a/scripts/cons.py b/scripts/cons.py index 1759997..b6b7d08 100644 --- a/scripts/cons.py +++ b/scripts/cons.py @@ -51,4 +51,4 @@ data_model_transaction_status = {'successful':0.94, 'pending':0.03, 'rejected':0.03} data_model_rejection_codes = {'E900:ConnectionTimeout':0.2, 'E901:SuspectedFraud':0.2, 'E902:AuthenicationFailure':0.2, 'E903:UserCancelled':0.2, 'E904:InsufficientFunds':0.2} data_model_inconsistent_country_codes_rejection_rate = {1:0.001, 2:0.005, 3:0.01} -data_model_app_store_points = {0:0.95, 1:0.05} \ No newline at end of file +data_model_non_card_trans_methods = {'wallet':0.95, 'points':0.05} \ No newline at end of file