Skip to content

Commit

Permalink
#5 replaced store_points_ind with transaction_payment_method with opt…
Browse files Browse the repository at this point in the history
…ional categories card, wallet and points
  • Loading branch information
oislen committed Jun 14, 2023
1 parent 40bd3d1 commit 23b1041
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions scripts/app/gen_trans_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scripts/cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
data_model_non_card_trans_methods = {'wallet':0.95, 'points':0.05}

0 comments on commit 23b1041

Please sign in to comment.