diff --git a/.ipynb_checkpoints/main-checkpoint.ipynb b/.ipynb_checkpoints/main-checkpoint.ipynb index f073ae1..957e4f3 100644 --- a/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/.ipynb_checkpoints/main-checkpoint.ipynb @@ -148,6 +148,7 @@ " cols = [\"Focal_id\", \"Total_Wire_Deposit_Amt\",\n", " \"Segment\", \"Risk\", \"SAR_FLAG\"]\n", " df = pd.DataFrame(row_list, columns = cols)\n", + " df['Segment'] = 'Individual'\n", " return df" ] }, @@ -170,7 +171,9 @@ "id": "157c4e46-2cff-4f6f-acba-faf4d73538cf", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#tst cmt" + ] } ], "metadata": { diff --git a/.ipynb_checkpoints/main-checkpoint.py b/.ipynb_checkpoints/main-checkpoint.py new file mode 100644 index 0000000..e6ec357 --- /dev/null +++ b/.ipynb_checkpoints/main-checkpoint.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[1]: + + +import pandas as pd + + +# In[2]: + + +from tms_data_interface import SQLQueryInterface +seq = SQLQueryInterface(schema="transactionschema") + + +# In[3]: + + +seq.execute_raw("show tables") + + +# In[4]: +#tst + +query = """ + select final.CUSTOMER_NUMBER_main as Focal_id, + final.Credit_transaction_amount, + final.SEGMENT, + final.RISK, + final.SAR_FLAG + from + ( + ( + select subquery.CUSTOMER_NUMBER_1 as CUSTOMER_NUMBER_main, + subquery.Credit_transaction_amount + from + ( + ( + select customer_number as CUSTOMER_NUMBER_1, + sum(transaction_amount) as Credit_transaction_amount + from + ( + select * + from {trans_data} as trans_table + left join {acc_data} as acc_table + on trans_table.benef_account_number = acc_table.account_number + where trans_table.transaction_desc = 'WIRE RELATED TRANSACTION' + ) + where account_number not in ('None') + group by 1 + ) credit + ) subquery + ) main left join + ( + select subquery.CUSTOMER_NUMBER_3 as CUSTOMER_NUMBER_cust, + subquery.SEGMENT, + subquery.RISK, + case + when subquery.SAR_FLAG is NULL then 'N' + else subquery.SAR_FLAG + end as SAR_FLAG + from + ( + ( + select customer_number as CUSTOMER_NUMBER_3, + business_segment as SEGMENT, + case + when RISK_CLASSIFICATION = 1 then 'Low Risk' + when RISK_CLASSIFICATION = 2 then 'Medium Risk' + when RISK_CLASSIFICATION = 3 then 'High Risk' + else 'Unknown Risk' + end AS RISK + from {cust_data} + ) cd left join + ( + select customer_number as CUSTOMER_NUMBER_4, + sar_flag as SAR_FLAG + from {alert_data} + ) ad on cd.CUSTOMER_NUMBER_3 = ad.CUSTOMER_NUMBER_4 + ) subquery + ) cust_alert on cust_alert.CUSTOMER_NUMBER_cust = main.CUSTOMER_NUMBER_main + ) final +""" + + +# In[5]: + + +from tms_data_interface import SQLQueryInterface + +class Scenario: + seq = SQLQueryInterface(schema="transactionschema") + + def logic(self, **kwargs): + row_list = self.seq.execute_raw(query.format(trans_data="transaction10m", + cust_data="customer_data_v1", + acc_data="account_data_v1", + alert_data="alert_data_v1") + ) + cols = ["Focal_id", "Total_Wire_Deposit_Amt", + "Segment", "Risk", "SAR_FLAG"] + df = pd.DataFrame(row_list, columns = cols) + df['Segment'] = 'Individual' + return df + + +# In[7]: + + +# sen = Scenario() +# sen.logic() + + +# In[ ]: + + + + diff --git a/main.ipynb b/main.ipynb index f073ae1..957e4f3 100644 --- a/main.ipynb +++ b/main.ipynb @@ -148,6 +148,7 @@ " cols = [\"Focal_id\", \"Total_Wire_Deposit_Amt\",\n", " \"Segment\", \"Risk\", \"SAR_FLAG\"]\n", " df = pd.DataFrame(row_list, columns = cols)\n", + " df['Segment'] = 'Individual'\n", " return df" ] }, @@ -170,7 +171,9 @@ "id": "157c4e46-2cff-4f6f-acba-faf4d73538cf", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#tst cmt" + ] } ], "metadata": { diff --git a/main.py b/main.py index 8f31a3b..bab5257 100644 --- a/main.py +++ b/main.py @@ -101,6 +101,7 @@ class Scenario: cols = ["Focal_id", "Total_Wire_Deposit_Amt", "Segment", "Risk", "SAR_FLAG"] df = pd.DataFrame(row_list, columns = cols) + df['Segment'] = 'Individual' return df @@ -114,5 +115,5 @@ class Scenario: # In[ ]: - +#tst cmt